Ask Your Question
0

Matrix Multiplication

asked 2012-10-24 16:05:58 +0200

SLOtoSF gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-10-24 17:42:34 +0200

kcrisman gravatar image
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):
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-10-24 16:05:58 +0200

Seen: 653 times

Last updated: Oct 24 '12