ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 17 May 2022 23:09:35 +0200What algorithm does Sage use for the product of two matrices?https://ask.sagemath.org/question/62477/what-algorithm-does-sage-use-for-the-product-of-two-matrices/(am new to Sage and programming in general as you can see. Feel free to expand your answer)
I want to find out how a matrix product is calculated.
M = random_matrix(ZZ, 10, density=1)
N = random_matrix(ZZ, 10, density=1)
M*N
Is it simply identical to `M.__mul__(N)` in each case? Or does Sage switch to another algorithm if useful - `M._multiply_strassen(N)` for example?
Tue, 17 May 2022 20:14:12 +0200https://ask.sagemath.org/question/62477/what-algorithm-does-sage-use-for-the-product-of-two-matrices/Comment by dan_fulea for <p>(am new to Sage and programming in general as you can see. Feel free to expand your answer)</p>
<p>I want to find out how a matrix product is calculated.</p>
<pre><code>M = random_matrix(ZZ, 10, density=1)
N = random_matrix(ZZ, 10, density=1)
M*N
</code></pre>
<p>Is it simply identical to <code>M.__mul__(N)</code> in each case? Or does Sage switch to another algorithm if useful - <code>M._multiply_strassen(N)</code> for example?</p>
https://ask.sagemath.org/question/62477/what-algorithm-does-sage-use-for-the-product-of-two-matrices/?comment=62483#post-id-62483The star operation in `M*M` points to `M.__mul__` - this is the called method, the algorithm which is finally taken depends on the class of `M` and the specific implementation. A closer look at `M.__mul__??` shows which logic, and following the logic and the further calls which algorithms are implemented. Possibly `M.__rmul__` is also of interest in similar classes.Tue, 17 May 2022 23:09:35 +0200https://ask.sagemath.org/question/62477/what-algorithm-does-sage-use-for-the-product-of-two-matrices/?comment=62483#post-id-62483