Arc Forumnew | comments | leaders | submitlogin
Number crunching in Arc
6 points by sacado 5885 days ago | 2 comments
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.



4 points by almkglor 5884 days ago | link

Seems interesting. Hope pg notices this.

Hmm. How big is the change to ac.scm? We've already made at least one rather serious change to ac.scm on the arc-wiki.git (the define-your-own-object-in-functional-position thing), I wonder how much ac.scm will eventually change.

-----

3 points by sacado 5884 days ago | link

One of the changes is that mzscheme's FFI import a few names starting with an underscore, thus clashing with Arc's namespace. I modified ac.scm so that Arc's names start with a double underscore.

The other problem is that the mzscheme type #<cpointer> is not recognized by Arc : I had to change ac-type so as to add it.

-----