List Info

Thread: Re: reshare array




Re: reshare array
country flaguser name
United States
2007-04-05 06:15:54
* Tamas K Papp <20070405021710.GA26710pu100877.student.princeton.edu> :
|
| I am a Lisp newbie, sorry if this question has a simple
answer, I
| tried googling and found nothing.
|
| Consider an n-dimensional simple array, eg
|
| (setf a (make-array '(2 3 4) :element-type
'double-float))
|
| If I understand correctly, a simple boxed array is just a
vector of
| numbers (in this case, 12 zeros), and information on the
dimension (2
| 3 4).  Is it possible to "reshape" the array by
changing only the
| latter?  Eg 

There are 24 elements in the array. Perhaps you can use a
displaced-array for your purpose

Try
(defparameter $b
  (make-array '(6 4) :displaced-to a :element-type
'double-float))


And read the common lisp hyperspec entry for MAKE-ARRAY
which talks
about :dipsplaced-to and :displaced-index-offset for
displaced arrays
and also 15.1.1.3.2.1


| (reshape a '(4 3))
|
| would give a 4x3 array with the same elements, etc.  A
special case
| would be reshaping to a simple vector, or reshaping a
simple vector to
| an array.
|
| Is there such a function already in CMUCL, or is it
possible to write
| one without too much hassle?  Even a desctructive reshape!
would be
| enough for my purposes.

--
Madhu



[1]

about | contact  Other archives ( Real Estate discussion Medical topics )