Jeremy Howard wrote:
>
> Karl Glazebrook wrote:
> > you should look at the PDL mv() and xchg() methods
> > and factor this into your thinking!
> >
> Actually, the RFC is based on PDL's xchg()! I forgot to document using
> negative numbers to count from the last dimension--I'll add that into the
> next version. Are there any other differences with xchg() that you think
> would be useful?
>
> I haven't used mv() before, but now I look at it I can see it's pretty
> interesting. Is this used much? If we add it to the RFC, do you think we'd
> want a separate function, or add another arg to transpose:
>
> transpose([$a,$b], 0, @arr); # xchg
> transpose([$a,$b], 1, @arr); # mv
How about (if perl6 allows passing arrays implicitly by reference
without arglist flattening)
transpose @arr, $a, $b; # xchg
transpose @arr, {$a => $b}; # mv
transpose @arr, [0,3,4,1,2]; # PDL reorder
Aliasing for bounded typed arrays is simple:
each array has a block of data (void *) and vectors of shape (int[]),
strides (int[]) and offset (int). To get element arr[i;j;k] Perl
accesses into the typecast block
((type *) data)[offset+i*stride[0]+j*stride[1]+k*stride[2]]
When creating an alias only the shape, strides and offset are
manipulated which tells the new alias how to interpret the same block of
data differently. This kind of implementation is used in PDL, NumPy and
GSL AFAIK.
In PDL we have found it useful to have a method turning the alias into a
being of its own ($pdl->sever, oops undocumented).
Christian