This project has moved. For the latest updates, please go here.

Kronecker Product optimization

May 4, 2012 at 5:07 AM

I just lost what I had written... sigh. Short version:

I have been using the kronecker product for some large matrices and noticed your code allocates a lot of temporaries.

for (var j = 0; j < ColumnCount; j++)
{
for (var i = 0; i < RowCount; i++)
{
result.SetSubMatrix(i * other.RowCount, other.RowCount, j * other.ColumnCount, other.ColumnCount, At(i, j) * other);
}
}

The problem is in At(i, j) * other. Every time that happens, a copy is made. I added 2 additional nested for loops to complete the computation manually and saw tremendous benefit. You should consider doing the same.