Skip to content

Commit 1f1bab1

Browse files
committed
Fixed constant matrix derivative in matrix_sparse.pyx
1 parent 478bc87 commit 1f1bab1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/sage/matrix/matrix_sparse.pyx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ from cpython cimport *
2323
from cpython.object cimport Py_EQ, Py_NE
2424

2525
import sage.matrix.matrix_space
26+
import sage.calculus.functional
2627

2728

2829
cdef class Matrix_sparse(matrix.Matrix):
@@ -810,13 +811,21 @@ cdef class Matrix_sparse(matrix.Matrix):
810811
sage: m._derivative(x) # needs sage.symbolic
811812
[ 0 1]
812813
[ 2*x 3*x^2]
814+
815+
TESTS:
816+
817+
sage: m = matrix(3, 3, {(1, 1): 2, (0,2): 5})
818+
sage: derivative(m, x)
819+
[0 0 0]
820+
[0 0 0]
821+
[0 0 0]
813822
"""
814823
# We would just use apply_map, except that Cython does not
815824
# allow lambda functions
816825

817826
if self._nrows==0 or self._ncols==0:
818827
return self.__copy__()
819-
v = [(ij, z.derivative(var)) for ij, z in self.dict().iteritems()]
828+
v = [(ij, sage.calculus.functional.derivative(z, var)) for ij, z in self.dict().iteritems()]
820829
if R is None:
821830
w = [x for _, x in v]
822831
w = sage.structure.sequence.Sequence(w)

0 commit comments

Comments
 (0)