[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Matrix or array operations library
From: |
Daniel Llorens |
Subject: |
Re: Matrix or array operations library |
Date: |
Thu, 27 Dec 2018 19:43:18 +0100 |
>> With regard to NumPy, especially the stuff about the "strides" (whatever
>> that is) in the data buffer of a NumPy array and how what changes when
>> creating a view and changing indices (For example I cannot imagine a
>> single reason, why the ordering of how one writes the indices would
>> matter, except for human readability?) … If I need to keep track of that
>> … Let's just say I dislike working on a low level with a lot of
>> pointers, addresses and segfaults ; )
So I think there are three sides to this. 1) the array type, 2) using the array
type in Scheme, 3) interfacing with C or Fortran (or whavever).
1) Guile already has a multidimensional array type with strides and all that.
Has had it forever. The base library (array-map! etc) is low level and doesn't
do much, and the implementation has some cruft, but the type is there, it's
fairly simple stuff and and there's nothing fundamentally wrong with it. Should
be safe too.
People love to write their own matrix type on top of vectors or bytevectors or
even lists. Sometimes there's a good reason for that but often there isn't.
2) IMO the only real flaw with the current Guile array type is that it's all in
C so the array descriptors are opaque to Scheme, and the compiler isn't smart
enough yet to remove the type dispatches that result from the base library
being type generic [*]. This is an actual problem when you do everything in
Scheme, but it's just the difference between things being slow or very slow.
AFAIK this isn't any worse than what you get in Numpy. If you operate with
arrays ‘in the large’ (manipulating strides, etc.) then everything is fast. Of
course Numpy gives you a ton of ready made functions that would be nice to have
in Guile as well [**].
3) If you're using Guile arrays as an interface to C or Fortran, the above
doesn't matter. Neither C nor Fortran (<90) have a standard way of passing
multidimensional arrays to a function, so you are using pointers whether you
like it or not. Every library has its own particular way of passing strides and
its own quirks about what strides they accept, etc. You have to deal with that
one way or another. Might as well have a nice, already available array type on
the Scheme side!
[*] [**] I have started efforts to fix these two problems (both fizzled due to
lack of time, although I think they contain some valid stuff — e.g. if you need
to slice arrays, I prefer from and amend! in guile-ploy to the Numpy mess). I'd
be happy to contribute to a common effort if anyone else is interested.
PS. Does anyone want to collaborate in wrapping HDF5? I've looked into mwette's
FFI helper for like two seconds but I couldn't get it to work.