Math.Matrix revisited

View: New views
9 Messages — Rating Filter:   Alert me  

Math.Matrix revisited

by Felip Alàez Nadal :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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


matrix_code.h (37K) Download Attachment

Math.Matrix revisited

by Jonas Walldén @ Pike importmöte för mailinglistan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You create a diff with

  diff -u <old file> <new file>


Math.Matrix revisited

by Jonas Walldén @ Pike importmöte för mailinglistan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 >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?


Parent Message unknown Re: Math.Matrix revisited

by Felip Alàez Nadal :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm sorry. I forgot to send this mail to pike too:

Here you have an usable matrix_code.h file. The lu decomposition is ok there.

I've noticed what seems to be a bug with pike 7.8. It's an issue with math_error (or error_math, I don't remember It well) at the C code. Well, when a math_error is signaled, pike shows what I believe that is a malformed error message. As an example:

Math.Matrix a = Math.Matrix( ({ ({ 1.2 , 3.5 }) , ({ 2.4 , 5.7 }) }) ) ;
> a->norm() ;
Cannot compute norm of non 1xn or nx1 matricesUnknown program: norm()
src/modules/Math/math_module.
c:90:
    Math.Matrix( ({ ({    1.2,    3.5}),                                     
                    ({    2.4,    5.7}) }) )->norm()                         
HilfeInput:1: HilfeInput()->___HilfeWrapper()

It's obvius that norm is a known method for class Math.Matrix, as a->norm() is called and It signals an error correctly. But I believe that the rest of the message It's wrong.



--
Felip Alàez Nadal


matrix_code.h (36K) Download Attachment

Re: Math.Matrix revisited

by Martin Stjernholm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

"Felip Alàez Nadal" <uu.nix.uu@...> wrote:

> Math.Matrix a = Math.Matrix( ({ ({ 1.2 , 3.5 }) , ({ 2.4 , 5.7 }) }) ) ;
>> a->norm() ;
> Cannot compute norm of non 1xn or nx1 matricesUnknown program: norm()
/.../
> It's obvius that norm is a known method for class Math.Matrix, as a->norm()
> is called and It signals an error correctly. But I believe that the rest of
> the message It's wrong.

There's a newline missing at the end of the error message that
apparently makes you misinterpret it (the "Unknown program" bit comes
from that the backtrace formatter couldn't find the name of the
program that contains norm()). I've now fixed newlines for several
error messages in matrix_code.h. Thanks.

As for your math patches, I hope someone else more familiar with that
area will review your contribution so that we get it in. Note however
that 7.8 is in strict feature freeze, so it's unlikely that it'll get
into that version.


Re: Math.Matrix revisited

by Jonas Walldén @ Pike importmöte för mailinglistan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

What is the delay for 7.8 release right now?


Re: Math.Matrix revisited

by Jonas Walldén @ Pike importmöte för mailinglistan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Changelog. Absolutely only the changelog. Has been for weeks.


Re: Math.Matrix revisited

by Jonas Walldén @ Pike importmöte för mailinglistan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Anyone working on that?


Re: Math.Matrix revisited

by Jonas Walldén @ Pike importmöte för mailinglistan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

There hasn't been a lot of man-hours dedicated to it lately. Feel free
to pick a FIXME from CHANGES and fill out the details.

LightInTheBox - Buy quality products at wholesale price!