commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Barnhill <ericbarnh...@gmail.com>
Subject [MATH] Complex.getInterleaved()
Date Thu, 08 Oct 2015 16:45:13 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message