Tuesday, July 29, 2008

FFA split into two packages

Besides providing `foreign friendly' arrays, my FFA package contained a lot of functions that implement commonly used array operations, including elementwise algebra operations, array minima and maxima, etc. Because these do not depend on CFFI, I decided I would put them into a separate package, named ARRAY-OPERATIONS, which is also installable with ASDF-Install. It contains a reimplementation of array-range, and also a macro for vectorizing operations, called vectorize:
 (let ((a #(1d0 2d0 3d0))
       (b #(4d0 5d0 6d0))
       (c 0.25d0))
   (vectorize (a b)
              (+ a b c 0.25)))  ; => #(5.5d0 7.5d0 9.5d0)
(vectorize (&rest vectors) expression) sets up symbol macros so that vector names in vectors refer to the appropriate element, then evaluates expression repeatedly and returns the results as a vector. It also has two keyword arguments: result-element-type (which default to 'double-float) determines the element type of this vector, while into places the results in one of the vectors instead (of course the two arguments are mutually exclusive).
 (let ((a (vector 1 2 3)))
   (vectorize (a) (+ 1 (* a 2)) :into a)
   a)  ; => #(3 5 7)
Functions in the new package still strive to create arrays that are foreign-friendly.

No comments:

Post a Comment