ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 16 Jun 2015 10:29:24 +0200Why can 'matrix' not use cached functions?https://ask.sagemath.org/question/27111/why-can-matrix-not-use-cached-functions/Consider
def L(n,k):
if n==k: return 1
if k<0 or k>n: return 0
return L(n-1,k-1)+(n+k-1)*L(n-1,k)
print parent(L)
matrix(ZZ, 8, L)
This works. However, as soon as I decorate the above function L with the very reasonable "@CachedFunction" I receive an ValueError: "Invalid matrix constructor".
Mon, 15 Jun 2015 22:09:01 +0200https://ask.sagemath.org/question/27111/why-can-matrix-not-use-cached-functions/Answer by rws for <p>Consider </p>
<pre><code>def L(n,k):
if n==k: return 1
if k<0 or k>n: return 0
return L(n-1,k-1)+(n+k-1)*L(n-1,k)
print parent(L)
matrix(ZZ, 8, L)
</code></pre>
<p>This works. However, as soon as I decorate the above function L with the very reasonable "@CachedFunction" I receive an ValueError: "Invalid matrix constructor".</p>
https://ask.sagemath.org/question/27111/why-can-matrix-not-use-cached-functions/?answer=27115#post-id-27115(after change of `CachedFunction` to `cached_function` there is a `ValueError`)
It's a bug. When I add `sage.misc.cachefunc.CachedFunction` to this line in `matrix/constructor.py` it works fine:
if isinstance(args[0], (types.FunctionType, types.LambdaType, types.MethodType)):
I have submitted the fix for review: http://trac.sagemath.org/ticket/18713Tue, 16 Jun 2015 09:38:51 +0200https://ask.sagemath.org/question/27111/why-can-matrix-not-use-cached-functions/?answer=27115#post-id-27115Comment by Peter Luschny for <p>(after change of <code>CachedFunction</code> to <code>cached_function</code> there is a <code>ValueError</code>)</p>
<p>It's a bug. When I add <code>sage.misc.cachefunc.CachedFunction</code> to this line in <code>matrix/constructor.py</code> it works fine:</p>
<pre><code>if isinstance(args[0], (types.FunctionType, types.LambdaType, types.MethodType)):
</code></pre>
<p>I have submitted the fix for review: <a href="http://trac.sagemath.org/ticket/18713">http://trac.sagemath.org/ticket/18713</a></p>
https://ask.sagemath.org/question/27111/why-can-matrix-not-use-cached-functions/?comment=27117#post-id-27117Of course it's a bug. It does not make any sense. Thanks!Tue, 16 Jun 2015 10:29:24 +0200https://ask.sagemath.org/question/27111/why-can-matrix-not-use-cached-functions/?comment=27117#post-id-27117