Skip to content

Conversation

@WhiteBlackGoose
Copy link
Contributor

A^13 = A^6 * A^6 * A...


private class SquareMatrixFactory
{
private List<Matrix<T>> cache = new List<Matrix<T>>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is probably better to replace List with your type to keep the "ecosystem"

Multiply(mp2, dest, ref tmp);
mp2 = tmp;
}
destination = mp2;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof that was supposed to be .Clone I guess

if (power == 0)
{
if (!(c is null) && c._matrix.Length == a._matrix.Length)
if (!(destination is null) && destination.IsSquare)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use IsSquare to keep the code readable, the power operation is extremely pricy, 1-2 ns isn't worth saving

if (power == 1)
return;
if (squareMatrixFactory is null || squareMatrixFactory.DiagonalLength != a._rows)
squareMatrixFactory = new SquareMatrixFactory(a._rows);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you already have a square matrix factory, this should be replaced with your type. Also my factory won't work if we change matrix' size after each operation, e. g.

Power(A, 3);
Power(A, 4);
Power(A, -13);

Is fast because we pull square matrices from the factory, while

Power(A, 3);
Power(B, 4);
Power(A, -13);

Because we re-create the factory in the second and third lines

@WhiteBlackGoose
Copy link
Contributor Author

oof not to merge now, I discovered a few bugs

@WhiteBlackGoose
Copy link
Contributor Author

Now it's ready

@ZacharyPatten ZacharyPatten added the On Hold issues that are on hold for any reason label Jul 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

On Hold issues that are on hold for any reason

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants