Hi Peleg,
It would be better if matrix would do a type check for partial function.
Currently it does not, the relevant line is
{{{
if isinstance(arg, (types.FunctionType, types.LambdaType,
types.MethodType)):
}}}
in sage/matrix/constructor.pyx the function MatrixFactory.
Concerning a direct solution, you can cheat with
sage: matrix(QQ, 3, 3, lambda i,j: g(i,j))
Or even more directly with
sage: matrix(QQ, 3, 3, lambda i,j: f(i,j,7))
Vincent
Le 21/12/2016 à 13:29, Peleg Michaeli a écrit :
> The matrix (or Matrix) documentation reads:
>
> INPUT:
>
> * "ring" -- the base ring for the entries of the matrix.
>
> * "nrows" -- the number of rows in the matrix.
>
> * "ncols" -- the number of columns in the matrix.
>
> * "sparse" -- create a sparse matrix. This defaults to "True"
> when the entries are given as a dictionary, otherwise defaults to
> "False".
>
> * "entries" -- see examples below.
>
>
> However, the examples below do not give any example of using "entries" as a *keyword
> argument*. And, indeed, passing `entries=...` in the call of Matrix raises
> TypeError.
>
> I can overcome this using positional arguments only. Here is a working
> example:
>
> sage: def f(i, j):
> ....: return i+j
> ....:
> sage: matrix(QQ, 3, 3, f)
>
> [0 1 2]
> [1 2 3]
> [2 3 4]
>
> But if I am passing a *partial function*, this does not work any more: