Matrix Multiplication

Where would I look in the source code (the specific file) to see where matrix multiplication is defined? I want to create my own matrix class so that I can override this definition with something of my own.

edit retag close merge delete

Sort by ยป oldest newest most voted
sage: M = matrix()
sage: M.__mul__??
Definition:     M.__mul__(left, right)
Source:
def __mul__(left, right):
"""
Multiplication of matrix by matrix, vector, or scalar
<snip>
"""
if have_same_parent(left, right):
return (<Matrix>left)._matrix_times_matrix_(<Matrix>right)
else:
global coercion_model
return coercion_model.bin_op(left, right, mul)


Also found at

sage: sage.structure.element.Matrix.__mul__??


So that is the file it lives in. I imagine it is overridden in at least some classes below that, such as these.

sage: search_def('matrix_times_matrix')
matrix/matrix0.pyx:4403:    cdef sage.structure.element.Matrix _matrix_times_matrix_(self, sage.structure.element.Matrix right):
matrix/matrix_cyclo_dense.pyx:567:    cdef baseMatrix _matrix_times_matrix_(self, baseMatrix right):
matrix/matrix_double_dense.pyx:398:    cdef sage.structure.element.Matrix _matrix_times_matrix_(self, sage.structure.element.Matrix right):
matrix/matrix_integer_dense.pyx:781:    cdef sage.structure.element.Matrix _matrix_times_matrix_(self, sage.structure.element.Matrix right):
matrix/matrix_mod2_dense.pyx:675:    cdef Matrix _matrix_times_matrix_(self, Matrix right):
matrix/matrix_mod2e_dense.pyx:418:    cdef Matrix _matrix_times_matrix_(self, Matrix right):
matrix/matrix_modn_dense.pyx:858:    cdef Matrix _matrix_times_matrix_(self, Matrix right):
matrix/matrix_modn_sparse.pyx:320:    cdef sage.structure.element.Matrix _matrix_times_matrix_(self, sage.structure.element.Matrix _right):
matrix/matrix_modn_sparse.pyx:383:    def _matrix_times_matrix_dense(self, sage.structure.element.Matrix _right):
matrix/matrix_rational_dense.pyx:1025:    cdef sage.structure.element.Matrix _matrix_times_matrix_(self, sage.structure.element.Matrix right):
matrix/matrix_rational_sparse.pyx:172:    cdef sage.structure.element.Matrix _matrix_times_matrix_(self, sage.structure.element.Matrix _right):
matrix/matrix_rational_sparse.pyx:210:    def _matrix_times_matrix_dense(self, sage.structure.element.Matrix _right):
structure/element.pxd:123:    cdef Matrix _matrix_times_matrix_(left, Matrix right)                  # OK to override, AND call directly
structure/element.pyx:2745:    cdef Matrix _matrix_times_matrix_(left, Matrix right):

more