Re: reshare array

Madhu <[email protected]>
Newsgroups gmane.lisp.cmucl.general
Message-ID <[email protected]>
* Tamas K Papp <[email protected]> :
|
| 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.