[Csnd] Reverse array?

Hi,
Does anyone know of an efficient way of reversing the order of items in an array? Potentially hundreds of items, so it would be best not to iterate and copy them one by one to a new array…
all best
Øyvind

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Mar 13 2022, Oeyvind Brandtsegg has written:

Hi,
Does anyone know of an efficient way of reversing the order of items in an
array?

...
Possibly a very stupid question: is it unfeasible of reverting the
indexing with the help of lenarray? An efficient way of doing that might
be with linlin remapping indices running from 0.

Best wishes,

Jeanette

If you want to reverse an array in place then you loop on half the length and swap a[i] with a[n-1]. Of course fiddling the index as Jeanette suggested is more efficient but not always possible.

Of course fiddling the index as Jeanette suggested is more efficient but not always possible.

May i ask why this?

Just curious.

Thanks,

ciao,

francesco.

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here

I wonder if an opcode to reverse 1-D arrays would be the fastest thing?

Prof. Victor Lazzarini
Maynooth University
Ireland

An optional argument of an existing opcode ?

Dr. Richard Boulanger
Professor
Electronic Production and Design
Berklee College of Music

A reversearray opcode would be nice, and also nice if it could be done as an extension of an existing opcode. Maybe slicearray could do it? (if istart is larger than iend, the output slice would be reversed)
iarr[] fillarray 1,2,3,4
ireverse slicearray iarr,3,0
(this does not work now btw, but could be practical)
Øyvind

I think reversearray would make it easier to find in the docs.

Btw, has there been any work done on this issue, is this something that is already in Csound 7?
https://github.com/csound/csound/issues/781

And thanks for the linlin suggestion, Jeanette. It looks like a good way to get around it with existing opcodes.

Or allow a negative ‘istride’ argument (e.g. -1) for slicearray.