Re: [racket] math/matrix

2014-05-14 Thread Konrad Hinsen
Jens Axel Søgaard writes: > See my post in this thread 3 days ago. It is attached. It isn't, but I found it in the thread, thanks! I am mostly interested in using it as an example for the Racket FFI, given that I know LAPACK rather well. > > Transposition can be avoided in many practically rel

Re: [racket] math/matrix

2014-05-14 Thread Matthias Felleisen
On May 14, 2014, at 10:40 AM, Jens Axel Søgaard wrote: > 2014-05-13 23:24 GMT+02:00 Matthias Felleisen : >> On May 13, 2014, at 4:19 PM, Neil Toronto wrote: >>> We need a predicate like >>> >>> (: flonum-matrix? (All (A) (-> (Matrix A) Boolean : (Matrix Flonum >> >> >> I think in our wor

Re: [racket] math/matrix

2014-05-14 Thread Jens Axel Søgaard
2014-05-13 23:24 GMT+02:00 Matthias Felleisen : > On May 13, 2014, at 4:19 PM, Neil Toronto wrote: >> We need a predicate like >> >> (: flonum-matrix? (All (A) (-> (Matrix A) Boolean : (Matrix Flonum > > > I think in our world of types we could even have > > (: flonum-matrix? (All (A) (-> (M

Re: [racket] math/matrix

2014-05-14 Thread Jens Axel Søgaard
2014-05-14 15:31 GMT+02:00 Konrad Hinsen : > Neil Toronto writes: > > > One thing we should really do is get your LAPACK FFI into the math > > library and have `flmatrix-solve` use that, but fail over to Racket code > > systems that don't have LAPACK. If I remember right, it would have to > > t

Re: [racket] math/matrix

2014-05-14 Thread Konrad Hinsen
Neil Toronto writes: > One thing we should really do is get your LAPACK FFI into the math > library and have `flmatrix-solve` use that, but fail over to Racket code > systems that don't have LAPACK. If I remember right, it would have to > transpose the data because LAPACK is column-major.

Re: [racket] math/matrix

2014-05-13 Thread Matthias Felleisen
On May 13, 2014, at 4:19 PM, Neil Toronto wrote: > We need a predicate like > > (: flonum-matrix? (All (A) (-> (Matrix A) Boolean : (Matrix Flonum I think in our world of types we could even have (: flonum-matrix? (All (A) (-> (Matrix A) Boolean : (TriangularMatrix A and such and

Re: [racket] math/matrix

2014-05-13 Thread Neil Toronto
We need a predicate like (: flonum-matrix? (All (A) (-> (Matrix A) Boolean : (Matrix Flonum Then `matrix-solve` could dispatch to `flmatrix-solve` and still be well-typed. We could/should do something similar for every operation for which checking flonum-ness is cheap compared to computi

Re: [racket] math/matrix

2014-05-13 Thread Jens Axel Søgaard
That's great! The question is now how to automate this sort of thing. /Jens Axel 2014-05-13 1:39 GMT+02:00 Neil Toronto : > When I change it to operate on (Vectorof FlVector) instead of (Vectorof > (Vectorof Flonum)), I get this: > > cpu time: 996 real time: 995 gc time: 22 > 1.9

Re: [racket] math/matrix

2014-05-12 Thread Neil Toronto
When I change it to operate on (Vectorof FlVector) instead of (Vectorof (Vectorof Flonum)), I get this: cpu time: 996 real time: 995 gc time: 22 1.9335 cpu time: 15387 real time: 15384 gc time: 13006 1.9335 cpu time: 1057 real time: 1056 gc time: 85 1.9335 cpu

Re: [racket] math/matrix

2014-05-12 Thread Jens Axel Søgaard
Hi Eric, You were absolute right. The version below cuts the time in half. It is mostly cut and paste from existing functions and removing non-Flonum cases. /Jens Axel #lang typed/racket (require math/matrix math/array math/private/matrix/utils math/private/vector/vect

Re: [racket] math/matrix

2014-05-11 Thread Eric Dobson
Where is the time spent in the algorithm? I assume that most of it is in the matrix manipulation work not the orchestration of finding a pivot and reducing based on that. I.e. `elim-rows!` is the expensive part. Given that you only specialized the outer part of the loop, I wouldn't expect huge perf

Re: [racket] math/matrix

2014-05-11 Thread Jens Axel Søgaard
I tried restricting the matrix-solve and matrix-gauss-elim to (Matrix Flonum). I can't observe a change in the timings. #lang typed/racket (require math/matrix math/array math/private/matrix/utils math/private/vector/vector-mutate math/private/unsafe (o

Re: [racket] math/matrix

2014-05-11 Thread Neil Toronto
The garbage collection time is probably from cleaning up boxed flonums, and possibly intermediate vectors. If so, a separate implementation of Gaussian elimination for the FlArray type would cut the GC time to nearly zero. Neil ⊥ On 05/11/2014 01:36 PM, Jens Axel Søgaard wrote: Or ... you co

Re: [racket] math/matrix

2014-05-11 Thread Jens Axel Søgaard
Or ... you could take a look at https://github.com/plt/racket/blob/master/pkgs/math-pkgs/math-lib/math/private/matrix/matrix-gauss-elim.rkt at see if something can be improved. /Jens Axel 2014-05-11 21:30 GMT+02:00 Jens Axel Søgaard : > Hi Eduardo, > > The math/matrix library uses the arrays f

Re: [racket] math/matrix

2014-05-11 Thread Jens Axel Søgaard
Hi Eduardo, The math/matrix library uses the arrays from math/array to represent matrices. If you want to try the same representation as Bigloo, you could try Will Farr's matrix library: http://planet.racket-lang.org/package-source/wmfarr/simple-matrix.plt/1/1/planet-docs/simple-matrix/index.htm

Re: [racket] math/matrix

2014-05-11 Thread Eduardo Costa
What is bothering me is the time Racket is spending in garbage collection. ~/wrk/scm/rkt/matrix$ racket matrix.rkt 0.99967226 cpu time: 61416 real time: 61214 gc time: 32164 If I am reading the output correctly, Racket is spending 32 seconds out of 61 seconds in garbage collection. I am

Re: [racket] math/matrix

2014-05-11 Thread Jens Axel Søgaard
2014-05-11 6:09 GMT+02:00 Eduardo Costa : > The documentation says that one should expect typed/racket to be faster than > racket. I tested the math/matrix library and it seems to be almost as slow > in typed/racket as in racket. What was (is?) slow was a call in an untyped module A to a function

Re: [racket] math/matrix

2014-05-11 Thread Eric Dobson
Where are you seeing the slowness in that code? For me the majority of the time is spent in matrix-solve, and since that is another module it doesn't matter what you write your module in. In untyped racket, (set the first line to #lang typed/racket/no-check), it is much slower. 36 seconds to creat

[racket] math/matrix

2014-05-10 Thread Eduardo Costa
The documentation says that one should expect typed/racket to be faster than racket. I tested the math/matrix library and it seems to be almost as slow in typed/racket as in racket. Here is the program in typed racket: #lang typed/racket ; file: matrix.rkt (require math/matrix) (: mx Index) (defi

Re: [racket] math/matrix <--> FFI/array

2013-02-13 Thread Pierpaolo Bernardi
On Wed, Feb 13, 2013 at 6:51 PM, Danny Yoo wrote: > On Wed, Feb 13, 2013 at 10:49 AM, Pierpaolo Bernardi > wrote: >> On Wed, Feb 13, 2013 at 6:14 PM, Danny Yoo wrote: >> >>> Other than that, this should work ok. Can you confirm? >> >> Yes, it works. Thanks! >> >> What's the difference between _

Re: [racket] math/matrix <--> FFI/array

2013-02-13 Thread Danny Yoo
On Wed, Feb 13, 2013 at 10:49 AM, Pierpaolo Bernardi wrote: > On Wed, Feb 13, 2013 at 6:14 PM, Danny Yoo wrote: > >> Other than that, this should work ok. Can you confirm? > > Yes, it works. Thanks! > > What's the difference between _byte and _int8 ? Wow. There should have not been any differ

Re: [racket] math/matrix <--> FFI/array

2013-02-13 Thread Pierpaolo Bernardi
On Wed, Feb 13, 2013 at 6:14 PM, Danny Yoo wrote: > Other than that, this should work ok. Can you confirm? Yes, it works. Thanks! What's the difference between _byte and _int8 ? Racket Users list: http://lists.racket-lang.org/users

Re: [racket] math/matrix <--> FFI/array

2013-02-13 Thread Danny Yoo
On Wed, Feb 13, 2013 at 9:41 AM, Pierpaolo Bernardi wrote: > Another FFI question: > > I want to interface a C function which has the following signature: > > void iauA2tf(int ndp, double angle, char *sign, int ihmsf[4]) Example written: https://github.com/dyoo/ffi-tutorial/tree/master/ffi/

Re: [racket] math/matrix <--> FFI/array

2013-02-13 Thread Pierpaolo Bernardi
Another FFI question: I want to interface a C function which has the following signature: void iauA2tf(int ndp, double angle, char *sign, int ihmsf[4]) The "char *sign" parameter is a single char, not a string, output only, and is giving me problems. The C code uses this parameter simply: *

Re: [racket] math/matrix <--> FFI/array

2013-01-22 Thread Neil Toronto
On 01/22/2013 12:33 PM, Tobias Hammer wrote: When you pass it directly to c-code, maybe you can completely bypass the array and convert matrix -> flarray -> flvector -> cpointer the last 3 conversions should be blazing fast but i guess that won't matter much for 16 elements. Neil, can you neverth

Re: [racket] math/matrix <--> FFI/array

2013-01-22 Thread Tobias Hammer
When you pass it directly to c-code, maybe you can completely bypass the array and convert matrix -> flarray -> flvector -> cpointer the last 3 conversions should be blazing fast but i guess that won't matter much for 16 elements. Neil, can you nevertheless tell me more about the expected perf

Re: [racket] math/matrix <--> FFI/array

2013-01-21 Thread Neil Toronto
On 01/21/2013 02:48 AM, Pierpaolo Bernardi wrote: Hello, what's the most convenient way to convert between math/matrices and FFI/arrays? To reduce the scope of the question, at the moment I'm only interested in conversions from and to the following FFI types: (_array _double 3 3) (_array _

[racket] math/matrix <--> FFI/array

2013-01-21 Thread Pierpaolo Bernardi
Hello, what's the most convenient way to convert between math/matrices and FFI/arrays? To reduce the scope of the question, at the moment I'm only interested in conversions from and to the following FFI types: (_array _double 3 3) (_array _double 3) (_array _double 2 3) Thanks! P. __