0

I want to create a complex matrix in nd4j with the method `Nd4j.complexOnes(new int[]{1});`.
Sadly I get the following error:
Exception in thread "main" java.lang.UnsupportedOperationException
    at org.nd4j.linalg.api.complex.BaseComplexNDArray.<init>(BaseComplexNDArray.java:244)
    at org.nd4j.linalg.api.complex.BaseComplexNDArray.<init>(BaseComplexNDArray.java:532)
    at org.nd4j.linalg.cpu.nativecpu.complex.ComplexNDArray.<init>(ComplexNDArray.java:227)
    at org.nd4j.linalg.cpu.nativecpu.CpuNDArrayFactory.createComplex(CpuNDArrayFactory.java:257)
    at org.nd4j.linalg.factory.BaseNDArrayFactory.createComplex(BaseNDArrayFactory.java:1558)
    at org.nd4j.linalg.factory.BaseNDArrayFactory.createComplex(BaseNDArrayFactory.java:1672)
    at org.nd4j.linalg.factory.BaseNDArrayFactory.complexOnes(BaseNDArrayFactory.java:1281)
    at org.nd4j.linalg.factory.Nd4j.complexOnes(Nd4j.java:5809)
    at de.GameOfReal.Multipliers.<init>(Multipliers.java:34)
    at de.GameOfReal.Multipliers.<init>(Multipliers.java:20)
    at de.GameOfReal.GameOfReal.<init>(GameOfReal.java:33)
    at de.GameOfReal.Main.<init>(Main.java:12)
    at de.GameOfReal.Main.main(Main.java:26)

I am using the following versions:

implementation 'org.nd4j:nd4j-api:0.9.1'
implementation 'org.nd4j:nd4j-native:0.9.1'
implementation 'org.nd4j:nd4j-native-platform:0.9.1'

To give more context, I wanted to use Fourier Transformation on a normal NDArray, but any FFT function did not work and I found out that it was caused by not being able to create complex matrices.

I hope that I could give enough details, if you have questions, I'll answer right away.

with kind regards,
Felix

Felix
  • 21
  • 2
  • A complex number is an object type in Java. Unless the nd4j folks created a version that accepts a complex number object you're out of luck. You'll have to do the work to create the real and complex matricies with double entries and do the math yourself for complex FFT. – duffymo Jan 14 '22 at 14:43
  • Thank you very much, this explains a lot haha. – Felix Jan 14 '22 at 22:04
  • 1
    Please provide enough code so others can better understand or reproduce the problem. – Community Jan 23 '22 at 22:36

1 Answers1

0

Nd4j does not support complex ndarrays anymore. We did at one point but a lot of our ops did not directly support it. If you want to use FFTs with nd4j you'll have to do some sort of an approxmation or use a different library and convert you nd4j array to a toDoubleMatrix()/toDoubleVector() and back.

Note that this will of course cause some performance penalties including copying data and a bit of memory overhead if you choose to go the copy route.

Apologies for the confusion there but hopefully that clears up why you don't see as many docs on it.

For the in memory representation a complex ndarray is usually just the components laid out as: real, imaginary, real, imaginary

in the in memory buffer. Nothing would stop you from creating that as well.

Adam Gibson
  • 3,055
  • 1
  • 10
  • 12
  • thank you very much, this explains a lot haha. I saw many methods that had commented out the code and raised an exception and I was confused why. – Felix Jan 14 '22 at 22:03