From: allchemist on
The 'elements' accessor gives a native array-storage-vector for an lla-
matrix.
Is there any facility for getting a native 2d-array avoiding copying?
The same does GSLL's accessor 'cl-array'
From: Thomas M. Hermann on
On Apr 14, 11:29 am, allchemist <hohlovi...(a)gmail.com> wrote:
> The 'elements' accessor gives a native array-storage-vector for an lla-
> matrix.
> Is there any facility for getting a native 2d-array avoiding copying?
> The same does GSLL's accessor 'cl-array'

I'm not familiar with lla-matrix, but you could use the :DISPLACED-TO
keyword argument to MAKE-ARRAY if the array-storage-vector is in row-
major order.

SCRATCH> (defvar *flat-array* (make-array 9 :initial-contents '(1 2 3
4 5 6 7 8 9)))
*FLAT-ARRAY*

SCRATCH> (defvar *array* (make-array '(3 3) :displaced-to *flat-
array*))
*ARRAY*

SCRATCH> *array*
#2A((1 2 3) (4 5 6) (7 8 9))

SCRATCH> (setf (aref *flat-array* 3) 0)
0

SCRATCH> *array*
#2A((1 2 3) (0 5 6) (7 8 9))

This avoids copying in SBCL, CCL, and LispWorks. I think it should in
general, but that may be implementation dependent. If the data is in
column-major order, it will still work, but you'll have to take that
into account when specifying indices.

SCRATCH> (setf *flat-array* (make-array 9 :initial-contents '(1 4 7 2
5 8 3 6 9)))
#(1 4 7 2 5 8 3 6 9)

SCRATCH> (setf *array* (make-array '(3 3) :displaced-to *flat-array*))
#2A((1 4 7) (2 5 8) (3 6 9))

Hope that helps.

~ Tom
From: allchemist on
there are two problems:
1. displaces-arrays are not simple-arrays. so the following usage of
such array is very narrow.
2. in lla data in matrix is stored in column-major order, so the
displacement returnes a transposed matrix. if is is'n square,
transposition will need copying.
From: Tamas K Papp on
On Wed, 14 Apr 2010 09:29:09 -0700, allchemist wrote:

> The 'elements' accessor gives a native array-storage-vector for an lla-
> matrix.
> Is there any facility for getting a native 2d-array avoiding copying?
> The same does GSLL's accessor 'cl-array'

Given that LLA's arrays are column major and CL's are row major, what
you are asking is impossible.

That said, you can displace the 1d simple-array to a 2d array and
access elements with the indexes exchanged - eg

(aref displaced-array col row)

But see the :lla-vector and :lla-matrix extensions to bind, you will
find examples in the unit tests.

Also, I don't really see why you need cheap copying to row-major.
Doing all operations in LLA will be consistent, you will be dealing
with column-major arrays. You can transpose when you use the results
in Lisp, transposing is a very cheap operation.

Judging from your posts on c.l.l., you are either working on an
application where squeezing out the last 10% of performance is
important (in which case you should be using blocks of Fortran,
perhaps controlled by CL at the highest level), or you are getting
distracted by "optimizing" operations which are very cheap in practice
and hardly worth bothering about.

Best,

Tamas
From: Tamas K Papp on
On Wed, 14 Apr 2010 11:10:46 -0700, allchemist wrote:

> there are two problems:
> 1. displaces-arrays are not simple-arrays. so the following usage of
> such array is very narrow.

Again, I don't understand. If you need CL arrays, presumably you are
operating on them using CL functions, which are perfectly fine with
whatever kind of array you throw at them. Or if not, you copy to a
simple-array.

> 2. in lla data in matrix is stored in column-major order, so the
> displacement returnes a transposed matrix. if is is'n square,
> transposition will need copying.

How large are your matrices? What fraction of CPU time does copying
currently take up?

Tamas
 |  Next  |  Last
Pages: 1 2
Prev: Statistics in lisp
Next: Great mysteries of our time