cmatrix.Matrix.strassen

Matrix.strassen()

Compute the multiply using the Strassen algorithm to get faster multiplication(not necessary on small matrix).

Strassen algorithm is evaluate in 6 steps :
  • Split the self matrix into 4 equal-length submatrix

  • Split the second term matrix into 4 equal-length submatrix

  • Allocating memory for temporary computing

  • Apply the Strassen multiplication rules (M matrix)

  • Compute the C matrix from M Matrix

  • Rebuild the final matrix with temporary matrix

Parameters

type

Description

m2

Matrix

The second member of the multiplication

Returns
Matrix

The computed multiplication.

Examples

>>> m=rand(4)
>>> u=unit(4)
>>> print(m)
| +14.000 | +12.000 | +12.000 | +1.000 |
| +7.000 | +16.000 | +8.000 | +8.000 |
| +9.000 | +6.000 | +8.000 | +2.000 |
| +11.000 | +1.000 | +8.000 | +7.000 |
printed
>>> print(u)
| +1.000 | +0.000 | +0.000 | +0.000 |
| +0.000 | +1.000 | +0.000 | +0.000 |
| +0.000 | +0.000 | +1.000 | +0.000 |
| +0.000 | +0.000 | +0.000 | +1.000 |
printed
>>> print(m.strassen(u))
| +14.000 | +12.000 | +12.000 | +1.000 |
| +7.000 | +16.000 | +8.000 | +8.000 |
| +9.000 | +6.000 | +8.000 | +2.000 |
| +11.000 | +1.000 | +8.000 | +7.000 |
printed