Non-square matrix multiplication and 1xM and Nx1 matrices #30

Closed
mbj2011 opened this Issue Mar 11, 2014 · 2 comments

Comments

Projects
None yet
2 participants

mbj2011 commented Mar 11, 2014

Hi

I would like to do some general linear algebra using the Matrix type but I ran into a couple of issues.

Matrix!(float, 2, 5) A;
A[0][0] = 0;    A[0][1] = 1;    A[0][2] = 2;    A[0][3] = 3;    A[0][4] = 4;
A[1][0] = 5;    A[1][1] = 6;    A[1][2] = 7;    A[1][3] = 8;    A[1][4] = 9;
writeln(A.as_pretty_string);        
Matrix!(float, 5, 2) B;
B[0][0] = 0;    B[0][1] = 1;
B[1][0] = 2;    B[1][1] = 3;
B[2][0] = 4;    B[2][1] = 5;
B[3][0] = 6;    B[3][1] = 7;
B[4][0] = 8;    B[4][1] = 9;
writeln(B.as_pretty_string);
// Compiles but produces the wrong result (half of the matrix is filled with nan's)
auto res1 = B * A;      
writeln(res1.as_pretty_string);
// Gives loads of out of bounds errors on compile time.
auto res2 = A * B;
// Gives a couple of out of bounds errors on compile time.
Matrix!(float, 1, 5) C;
// Ditto
Matrix!(float, 5, 1) D;
Owner

Dav1dde commented Mar 11, 2014

Let me look into this, I always had a more scientific use in mind, but I never really tested it. I think making it useable with arbitrary types shouldnt be too much of an effort.

Dav1dde added the bug label Mar 19, 2014

Dav1dde self-assigned this Mar 19, 2014

@Dav1dde Dav1dde added a commit that referenced this issue Mar 20, 2014

@Dav1dde Dav1dde allow Nx1 and 1xN matrices #30 718f264
Owner

Dav1dde commented Mar 20, 2014

Thank you very much for the report, this revealed a major bug in the matrix multiplication code (even though it was only two characters!). Please reopen the issue if I missed something, if there are more problems, open another issue.

Sorry that fixing these took so long!

Dav1dde closed this Mar 20, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment