I had a look at implementing a CPU fft for tensorflow using the eigen tensor fft module. Benoit Steiner offered some advice on how to use it here.
The eigen fft uses the templated type of the corresponding tensor to perform its computation. Unfortunately, the inputs extracted from the OpKernelContext are declared const because inputs are immutable. I thus end up with a bunch of compiler errors that const variables cannot be assigned to (because the TensorFFTOp reuses the templated typename internally).
What's the best way to get around this problem? Some thoughts:
mutable_input but that seems like bending the API just to get around a problemTensorFFTOp with std::remove_const such that non-const variables are used internallyTensorFFTOp rather than using the template member functions defined in TensorBase.hThe last option seems to be the most straightforward but I am struggling with getting all the template arguments right. Any suggestions?
With the help of a co worker, we managed to get the desired behaviour by simply casting the const input array to a non-const one.
typename TTypes<T, 2>::Tensor& casted_input = *reinterpret_cast<typename TTypes<T, 2>::Tensor*>(&input);
auto result = casted_input.template fft<Eigen::BothParts, Eigen::FFT_FORWARD>(dims);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With