filling and assigning Alex Shinn (06 May 2021 14:32 UTC)
Re: filling and assigning Bradley Lucier (06 May 2021 16:35 UTC)
Re: filling and assigning Alex Shinn (07 May 2021 02:29 UTC)
Re: filling and assigning Bradley Lucier (07 May 2021 11:18 UTC)
Re: filling and assigning Marc Nieper-Wißkirchen (07 May 2021 11:53 UTC)
Re: filling and assigning Alex Shinn (07 May 2021 13:38 UTC)

Re: filling and assigning Bradley Lucier 06 May 2021 16:35 UTC

On 5/6/21 10:32 AM, Alex Shinn wrote:
> Storage classes require a constructor which can take any
> initial value, but there is no way to override the default from
> the storage class.  It would be nice to have a way to do this.
> Otherwise an array-fill! would help, though be less efficient.

Yes, I see that an initial-value argument to make-specialized-array
would be helpful.  Or perhaps a more low-level constructor for
specialized arrays.

array-copy can be helpful here:

(array-copy
   (make-array interval
               (lambda (i) initial-value))
   result-storage-class)

will give a new array with a specified initial value.

> What is the rationale for having array-assign! require the
> destination elements to be stored adjacently in order?  This
> case is easier to optimize for, but it can be useful to assign
> in non-adjacent cases.  In fact, it can be unpredictable when,
> through some series of transformations, an array which use
> to be adjacent no longer is, breaking the assignment.

The documentation says

The array destination must be compatible with source, in the sense that
either destination and source have the same domain, or ...

So there's no requirement of adjacency when the domains are the same.

> I was caught by this implementing a new utility,
> array-concatenate.  Trying to rely on high-level operations,
> a clean way to implement this is to construct the destination
> which is the sum of the two input domains along a dimension,
> then array-assign! each input to its array-extracted offset
> within the destination.  But these elements will not be
> adjacent.
>
> Without being able to use array-assign! and without interval
> cursors, the implementation of concatenate is quite difficult.

You see how to do it, you just have to translate each argument array to
match the domain of the array-extract'ed subarray of the result.

Brad