Ticket #7723: trac_7723-generic_multiply.patch
File trac_7723-generic_multiply.patch, 4.7 KB (added by , 11 years ago) |
---|
-
sage/matrix/action.pyx
# HG changeset patch # User Dag Sverre Seljebotn <dagss@student.matnat.uio.no> # Date 1261045212 -3600 # Node ID 977f52f47b09cdf5cfbca81ff74d5fd9f5c257fe # Parent 964c2f4ce74db0417a771de0b0cfc951b1fab73c imported patch structure diff -r 964c2f4ce74d -r 977f52f47b09 sage/matrix/action.pyx
a b 135 135 """ 136 136 cdef Matrix A = g #<Matrix>g 137 137 cdef Matrix B = s #<Matrix>s 138 if A._parent._base is not self._codomain._base: 139 A = A.change_ring(self._codomain._base) 140 if B._parent._base is not self._codomain._base: 141 B = B.change_ring(self._codomain._base) 142 if self.fix_sparseness: 143 if B.is_sparse_c(): 144 B = B.dense_matrix() 145 else: 146 A = A.dense_matrix() 147 prod = A._matrix_times_matrix_(B) 138 prod = A._generic_matrix_times_matrix_(B, self._codomain) 148 139 if A.subdivisions is not None or B.subdivisions is not None: 149 140 Asubs = A.get_subdivisions() 150 141 Bsubs = B.get_subdivisions() -
sage/matrix/matrix0.pyx
diff -r 964c2f4ce74d -r 977f52f47b09 sage/matrix/matrix0.pyx
a b 40 40 from sage.structure.element cimport ModuleElement, Element, RingElement, Vector 41 41 from sage.structure.mutability cimport Mutability 42 42 from sage.misc.misc_c cimport normalize_index 43 from sage.structure.parent cimport Parent 43 44 44 45 from sage.rings.ring cimport CommutativeRing 45 46 from sage.rings.ring import is_Ring … … 3442 3443 ans.set_unsafe(r, c, (<RingElement>self.get_unsafe(r, c))._mul_(x)) 3443 3444 return ans 3444 3445 3446 cdef sage.structure.element.Matrix _generic_matrix_times_matrix_(self, 3447 sage.structure.element.Matrix right, 3448 Parent codomain): 3449 r""" 3450 Return the product of two matrices. 3451 3452 The matrices may have different parents, but are guaranteed to 3453 have a multiplication codomain (e.g. they have conforming 3454 shape). The output should be the product of the matrices in 3455 the ``codomain`` given. 3456 3457 By default: 3458 - Change base ring to that of codomain 3459 - If sparsity differs, make the sparse matrix dense 3460 - Call ``_matrix_times_matrix`` 3461 3462 Specific matrix implementations might override this to provide faster 3463 operations (in particular, perform sparse-dense multiplication). 3464 """ 3465 cdef sage.structure.element.Matrix A = self, B = right 3466 cdef bint left_sparse = self.is_sparse_c() 3467 cdef bint right_sparse = right.is_sparse_c() 3468 base = codomain._base 3469 3470 if A._parent._base is not base: 3471 A = A.change_ring(codomain._base) 3472 if B._parent._base is not base: 3473 B = B.change_ring(codomain._base) 3474 if (left_sparse == 0) != (right_sparse == 0): 3475 if left_sparse: 3476 A = A.dense_matrix() 3477 else: 3478 B = B.dense_matrix() 3479 return A._matrix_times_matrix_(B) 3480 3445 3481 cdef sage.structure.element.Matrix _matrix_times_matrix_(self, sage.structure.element.Matrix right): 3446 3482 r""" 3447 3483 Return the product of two matrices. 3484 3485 The matrices should both the same base ring and either both 3486 should be dense or both sparse. 3448 3487 3449 3488 EXAMPLE of matrix times matrix over same base ring: We multiply 3450 3489 matrices over `\QQ[x,y]`. -
sage/structure/element.pxd
diff -r 964c2f4ce74d -r 977f52f47b09 sage/structure/element.pxd
a b 119 119 cdef Vector _matrix_times_vector_(matrix_left, Vector vector_right) # OK to override, AND call directly 120 120 cdef Matrix _matrix_times_matrix_(left, Matrix right) # OK to override, AND call directly 121 121 122 cdef Matrix _generic_matrix_times_matrix_(left, Matrix right, Parent codomain) # OK to override, AND call directly 123 122 124 cdef bint is_sparse_c(self) 123 125 cdef bint is_dense_c(self) 124 126 -
sage/structure/element.pyx
diff -r 964c2f4ce74d -r 977f52f47b09 sage/structure/element.pyx
a b 2001 2001 cdef Matrix _matrix_times_matrix_(left, Matrix right): 2002 2002 raise TypeError 2003 2003 2004 2004 cdef Matrix _generic_matrix_times_matrix_(left, Matrix right, Parent codomain): 2005 raise TypeError 2005 2006 2006 2007 def is_Matrix(x): 2007 2008 return IS_INSTANCE(x, Matrix)