Say the matrices are of degree n
. A simple thing you can do if you want to multiply A
and B
is to pad out A
and B
with zeros (say A_pad
, B_pad
so that they are of dim (k,k)
where k
is smallest power of two that upper bounds n
. Since k
is at most twice the original dimensions,
k^log_2(7)<=3 * N^log_2(7)
So the algorithm is still O(N^log_2(7))
.
This approach doesn't quite work with matrices of different dimensions in a situation where one of the matrices is "thin" (say the length of A dominates the height of A). In this case you would need to slice the matrices to get matrices that are more square-like, as mentioned the comment by @neil-edelman. The way you would determine thinness could be to see if BND>dim(A)[1]/dim(A)[0]>bnd
where bnd
and BND
are some constant parameters chosen before-hand, close to 1.