On Thu, 08 Oct 2015 14:48:50 -0400, Bruce Johnson wrote:
On Oct 8, 2015, at 12:45 PM, Eric Barnhill <[email protected]>
wrote:
Dear commons-math.complex maintainers,
I would like to add a static method to the Complex class that would
work as
follows:
double[] d = Complex.getInterleaved(Complex[] c);
It would export the data from a Complex[] as a double[] twice the
size of
the Complex[] array with real and imaginary components alternating.
Historically, methods sometimes have used interleaved data because
it can
be returned from methods in a single 1D primitive array which can be
computationally advantageous. The JTransforms library is an example.
However, interleaved is still a popular format for data especially
with the
advent of CUDA and OpenCL.
OpenCL in particular makes use of a float2() class to handle complex
numbers, and when Complex[] data is exported into an interleaved
float[]
array it can be passed directly to an OpenCL buffer without further
manipulation.
A related static method, say Complex[] c =
Complex.interleavedToComplex(double[] d) would make a good
complement to
the above method and remove some extraneous boilerplate for people
converting between these two (like me).
There may be a better class for these static methods than the
Complex class
itself. Here I am thinking of methods like Integer.toString() .
Would those involved with commons-math be happy if I checked out the
code
and submitted a pull request with this changes?
Thanks,
Eric
I’d use this. Perhaps they should be in ComplexUtil,
"ComplexUtils" was also my first thought.
I think that we could find a better name; in any case, I wouldn't
use "get..." as this is not an accessor.
Also, the reverse method could perhaps use additional parameters in
order to try and signal wrong usage or to extract only some part of
the input array data.
Maybe something along the lines:
Complex[] convertInterleavedToComplex(double[] interleaved, int from,
int to)
where "from" and "to" would be the range of complex elements to
create. Thus, to convert the whole of "interleaved":
from = 1,
to = interleaved.length / 2
We could also make it more general and use the new "range" method
defined in "o.a.c.m.util.IntegerSequence".
Perhaps the basic building block should be a method:
Complex extractInterleavedAtIndex(double[] interleaved, int index)
where the real and imaginary parts to be extracted are the array
elements located at "index" and "index + 1", respectively.
What do you think?
Gilles
where there already is:
Complex[] convertToComplex(double[] real)
Bruce
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]