So, I am trying to figure out strassen's method for matrix multiplication, I am using C++, but it could be any language. Right now, it is looking like:
typedef vector<long int> ROW;
typedef vector<ROW> MATRIX;
void getQuad(const MATRIX& IN, MATRIX& OUT0, MATRIX& OUT1
MATRIX& OUT2, MATRIX& OUT3)
{ /*determine quadrants*/ }
void strassen(const MATRIX& A, const MATRIX& B, MATRIX& C
{
if (A.size() == 2 && A[0] == 2) //know that its 2x2, stop
{
// Get M1-M7 vars and set MATRIX C with them
}
else
{
/*
getQuad(...) returns the quadrants
___________
| X0 | X1 |
-----------
| X2 | X3 |
-----------
*/
MATRIX A0,A1,A2,A3;
getQuad(A,A0,A1,A2,A3);
MATRIX B0,B1,B2,B3;
getQuad(B,B0,B1,B2,B3);
}
}
I am not sure where to go next with the individual quadrants i.e. how to derive M1-M7 matrices at this point. I would imagine that the M1-M7 matrices (as opposed to primitive data types in base case) would be used in the same manner as the base case. I am just not certain how the unraveling would look like here.
I know its a bit difficult to read someone else's code, but hopefully it has been made clear.
I am certain that my base case is correct, and I am certain that I am splitting the matrix correctly, I just am unclear of where to go next. Perhaps I have written my algorithm wrong.