Dav1dde / gl3n

OpenGL Maths for D (not glm for D).
http://dav1dde.github.com/gl3n/
Other
103 stars 49 forks source link

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

Closed mbj2011 closed 10 years ago

mbj2011 commented 10 years ago

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;
Dav1dde commented 10 years ago

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 commented 10 years ago

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!