Felip Alàez Nadal | 16 Sep 22:45
Picon

Math.Matrix revisited

Hello:
I send a "patch" which adds the lu decomposition method to the Math.Matrix object. I don't know how to send patches, then I send the entire matrix_code.h file from src/modules/Math/matrix_code.h. I've verified that compiles with Pike 7.8 from the repository. At the moment, It's not usable because It shows lots of debug information, but maybe It would be good to have It at the repository. Maybe tomorrow If I've time I'll send another patch without debug information.

The lu decomposition is used to solve linear equations systems. It decomposes a matrix , named A, like P x L x U = A , where P is a permutation matrix, L is a lower-diagonal matrix and U is an upper-diagonal matrix. The method doesn't needs any argument and It returns an array with 4 elements : ({ L , U , P , signum }) , where signum is an integer which contains the sign of the permutation. Now I want to implement solving linear equations systems into the Math.Matrix object.

I've noticed something strange within the Math.Matrix object. Instead of using a 2D array, you use a vector (1D array) and then, to acces the (i,j) element you compute it as i * size_of_a_rows + j. This maybe saves some memory , but It's slower accessing the array elements. Maybe I can reimplement the class using 2D arrays if you want.

Well, I'll send any improvement that I do. Bye!

--
Felip Alàez Nadal
Attachment (matrix_code.h): application/octet-stream, 27 KiB
Picon
Picon
Picon

Math.Matrix revisited

 >I've noticed something strange within the Math.Matrix object. Instead of
 >using a 2D array, you use a vector (1D array) and then, to acces the (i,j)
 >element you compute it as i * size_of_a_rows + j. This maybe saves some
 >memory , but It's slower accessing the array elements. 

Exactly how is it slower? Memory is, afaik, a 1d array...

It should preferably be accessed as a pointer deference when speed is
of matter, anyway, but in the case of random access, you need to
create the pointer from base + y * size_of_a_row + x.

It might go faster if you have only size_of_a_row at even base 2, and
use shift instead of multiplication. Is that what you thought of?

Picon
Picon
Picon

Math.Matrix revisited

You create a diff with

  diff -u <old file> <new file>


Gmane