Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
simple-array vs displaced-to
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Martin Raspaud  
View profile  
 More options Jan 17 2004, 9:44 am
Newsgroups: comp.lang.lisp
From: Martin Raspaud <martin.rasp...@wanadoo.fr>
Date: Sat, 17 Jan 2004 15:48:16 +0100
Local: Sat, Jan 17 2004 9:48 am
Subject: simple-array vs displaced-to
Hi all

Imagine you have a big array and that you want to process it by little
pieces.
One solution would be to make a new array which is displaced to another,
and that would be great because you don't use up memory space for
nothing, since you donc copy the elements.
However imagine, that your process can only handle simple-arrays. Then,
using cmucl as I do, this small array can't be displaced-to anymore
since it would transform it to a vector. Using subseq is then what I do,
but it takes a lot of space.

One would say "why not give as parameter to the processing funtion the
big array and an offset ?"
Well, I don't really like this, it doesn't feel the write way to do it
to me.

So am I wrong with this or is there another solution, ie having a kind
of displaced-to array that would be a simple-array ?

Thanx for any answer...

Martin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Cliff Crawford  
View profile  
 More options Jan 17 2004, 10:28 am
Newsgroups: comp.lang.lisp
From: Cliff Crawford <cj...@cornell.edu>
Date: Sat, 17 Jan 2004 15:28:29 GMT
Local: Sat, Jan 17 2004 10:28 am
Subject: Re: simple-array vs displaced-to
On 2004-01-17, Martin Raspaud <martin.rasp...@wanadoo.fr> wrote:
|
|  One would say "why not give as parameter to the processing funtion the
|  big array and an offset ?"
|  Well, I don't really like this, it doesn't feel the write way to do it
|  to me.

Why not?  This is how sequence functions like find, replace, remove,
etc. handle this situation, by using optional :start and :end
arguments.

--
 Cliff Crawford             ***             cj...@cornell.edu

"In theory there is no difference between theory and practice.
 In practice there is."                         -- Yogi Berra


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas F. Burdick  
View profile  
 More options Jan 17 2004, 3:50 pm
Newsgroups: comp.lang.lisp
From: t...@famine.OCF.Berkeley.EDU (Thomas F. Burdick)
Date: 17 Jan 2004 12:50:18 -0800
Local: Sat, Jan 17 2004 3:50 pm
Subject: Re: simple-array vs displaced-to

Martin Raspaud <martin.rasp...@wanadoo.fr> writes:
> So am I wrong with this or is there another solution

I'd say you have unreasonable restrictions here.  If you want to be
able to efficiently process portions of large arrays, use start/end
args.  Otherwise, you can use displaced arrays, but then you have to
remove the simple-array restriction on your utility functions.  If you
write them so they expect a simple array, *and* they don't take bounds
arguments, they're badly written for your purpose.

> , ie having a kind
> of displaced-to array that would be a simple-array ?

No, that's exactly the distinction between the types ARRAY and
SIMPLE-ARRAY: a SIMPLE-ARRAY has no fill-pointer, and is not
displaced.  This lets the implementation do more efficient access.

--
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                              
   |     ) |                              
  (`-.  '--.)                              
   `. )----'                              


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas F. Burdick  
View profile  
 More options Jan 17 2004, 3:54 pm
Newsgroups: comp.lang.lisp
From: t...@famine.OCF.Berkeley.EDU (Thomas F. Burdick)
Date: 17 Jan 2004 12:54:54 -0800
Local: Sat, Jan 17 2004 3:54 pm
Subject: Re: simple-array vs displaced-to

Martin Raspaud <martin.rasp...@wanadoo.fr> writes:
> One would say "why not give as parameter to the processing funtion the
> big array and an offset ?"
> Well, I don't really like this, it doesn't feel the write way to do it
> to me.

Incidentally, if you just don't like having to pass three args to your
processing functions, you could wrap it all up in a class:

  (defclass darray ()
    ((array :initarg displaced-to)
     (start :initarg start)
     (end :initarg end)))

  (defun consumer (darray)
    (with-slots (array start end) darray
      (declare (type <x> array))
      (loop for i from start below end
            ...)))

--
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                              
   |     ) |                              
  (`-.  '--.)                              
   `. )----'                              


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Naggum  
View profile  
 More options Jan 17 2004, 4:38 pm
Newsgroups: comp.lang.lisp
From: Erik Naggum <e...@naggum.no>
Date: 17 Jan 2004 21:38:04 +0000
Local: Sat, Jan 17 2004 4:38 pm
Subject: Re: simple-array vs displaced-to
* Martin Raspaud
| One would say "why not give as parameter to the processing funtion
| the big array and an offset ?"  Well, I don't really like this, it
| doesn't feel the right way to do it to me.
|
| So am I wrong with this or is there another solution, ie having a kind
| of displaced-to array that would be a simple-array ?

  One common optimization when working with non-simple arrays is to
  dig out the underlying simple-array and the start and end positions
  that a displaced array makes into one convenient object.

  The function ARRAY-DISPLACEMENT returns the values of the arguments
  :DISPLACED-TO and and :DISPLACED-INDEX-OFFSETgiven to MAKE-ARRAY or
  ADJUST-ARRAY, or NIL and 0 if it was not displaced.

(defun undisplace-array (array)
  "Return the fundamental array and the start and end positions into
it of a displaced array."
  (let ((length (length array))
        (start 0))
    (loop
      (multiple-value-bind (to offset) (array-displacement array)
        (if to
            (setq array to
                  start (+ start offset))
          (return (values array start (+ start length))))))))

--
Erik Naggum | Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Raymond Toy  
View profile  
 More options Jan 17 2004, 9:44 pm
Newsgroups: comp.lang.lisp
From: Raymond Toy <r...@earthlink.net>
Date: Sun, 18 Jan 2004 02:44:04 GMT
Local: Sat, Jan 17 2004 9:44 pm
Subject: Re: simple-array vs displaced-to

[snip]

This is, incidentally, how f2cl (Fortran-to-Lisp converter) handles
Fortran arrays.  For speed, you want specialized arrays.  However, in
Fortran, when you call a routine with a slice of an array, f2cl uses a
displaced array.  The called routine then uses array-displacement as
many times as needed to find the original array, which is a specialized
array.

This isn't as good a Fortran, but it does get as close as possible.

Ray


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »