| I'm still working on the FFI I was talking about in http://arclanguage.org/item?id=4532 . Well, it is quite working now. I had to hack ac.scm to do so, and to add 2 files : ffi.scm, importing FFI functions from Scheme, and ffi.arc, defining a few macros to make it more Arc-ish. To try this, I made a numarc.arc library, à la Numeric ( the Python library for matrix manipulation). Here is the test code : (loadffi "numarc"
(= mat cptr)
(cdef minit-zeros "init_zeros" mat (mat))
(cdef mget "get" cdouble (mat cint cint))
(cdef mset "set" cvoid (mat cint cint cdouble))
(cdef m-sum "sum" mat (mat mat mat))
(cdef m-add "add" mat (mat cdouble mat)))
Here, I import functions defined in numarc.so, so that they are available to us Arcers without getting down to the bare metal. Then I redefine the + operation so that it is able to add two matrices or a matrix and a double (then all values in the matrix are added that value).Finally, I test it this way : (time:do
(= m1 (mzeros 5000 5000))
(++ m1 3.0)
(= m2 (mzeros 5000 5000))
(mset m2 0 0 1.0)
(mset m2 1 1 2.0)
(= m3 (+ m1 m2)))
Building then adding two 5000 x 5000 matrices takes less than a second. This is quite encouraging as it is the time Numeric takes to do the same operation. I have to clean my code now.I don't know if this is valuable to many others than me, but if it is, I'll push on the git. |