Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex Tensor Implementation Missing? #494

Open
josefwilfinger opened this issue Jun 2, 2023 · 5 comments
Open

Complex Tensor Implementation Missing? #494

josefwilfinger opened this issue Jun 2, 2023 · 5 comments

Comments

@josefwilfinger
Copy link

Hi everybody,

i am just simply trying to create a Complex object, and asking myself it is simply not implemented, because i do not find the Class-Type for complex64 or complex128for the Tout parameter for the "df.dtypes.complex" function. In line 5 i just used TFloat32 to get it compiled.

1 Graph g = new Graph();
2 Ops tf = Ops.create(g);
3 Constant r = tf.constant(Float.valueOf((float)5.0));
4 Constant i = tf.constant(Float.valueOf((float)3.0));
5 Complex c = tf.dtypes.complex(r,i, TFloat32.class);

I understand the problem, in line 5:

Exception in thread "main" org.tensorflow.exceptions.TFInvalidArgumentException: Value for attr 'Tout' of double is not in the list of allowed values: complex64, complex128
; NodeDef: {{node Complex}}; Op<name=Complex; signature=real:T, imag:T -> out:Tout; attr=T:type,default=DT_FLOAT,allowed=[DT_FLOAT, DT_DOUBLE]; attr=Tout:type,default=DT_COMPLEX64,allowed=[DT_COMPLEX64, DT_COMPLEX128]>
at org.tensorflow.internal.c_api.AbstractTF_Status.throwExceptionIfNotOK(AbstractTF_Status.java:87)
at org.tensorflow.GraphOperationBuilder.finish(GraphOperationBuilder.java:461)
at org.tensorflow.GraphOperationBuilder.build(GraphOperationBuilder.java:100)
at org.tensorflow.GraphOperationBuilder.build(GraphOperationBuilder.java:71)
at org.tensorflow.op.dtypes.Complex.create(Complex.java:95)
at org.tensorflow.op.DtypesOps.complex(DtypesOps.java:107)
at TensorflowTest.main(TensorflowTest.java:74)

But i do not find a ComplexDataType like TFLoat32

Can anyone bring light into my deepest darkness? I do not find a documentation or an example how it shall be done in java.

Best Regards

@Craigacp
Copy link
Collaborator

Craigacp commented Jun 2, 2023

At the moment we don't support it, but we'd welcome contributions to add that support. It would need to build the ndarray support and add the types to this package. Complex64 is ok as that can use long as the carrier type and unpack it into two floats for computation, but Java doesn't have a 128-bit primitive type so things have to be boxed and that will cause a lot of problems.

@josefwilfinger
Copy link
Author

So in this case the FFT calculation is also not possible. Are the calculation functions in the native code available for the fft calculations?

Best Regards

@saudet
Copy link
Contributor

saudet commented Jun 11, 2023

We can still do FFTs and what not, and access the raw buffers, that works fine. It's just the high-level API support that isn't there.

@karllessard
Copy link
Collaborator

karllessard commented Jun 13, 2023

But in @josefwilfinger case, the only thing that matters is to map a class extending TType to one of the complex TF datatypes. We don't need to write the whole tensor memory mapping, as long as we don't try to access eagerly the output of Complex or return it as a graph output.

I think that could be done easily by registering a new class in the TensorTypeRegistry and simply throw an exception when trying to map its memory.

@rajatmohan22
Copy link

The error message you are getting is because the Tout parameter of the tf.dtypes.complex function expects a ComplexDataType. However, there is no such thing as a ComplexDataType in TensorFlow Java. The closest thing is the DataType enum, which has two values for complex numbers: DT_COMPLEX64 and DT_COMPLEX128.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants