Reputation: 111
I have compared tensorflow.spectral.dct with scipy.fftpack.dct using the following example:
in scipy:
from scipy.fftpack import dct
import tensorflow as tf
xx=np.linspace(0,3,3)
x_dct=dct(xx,2,norm='ortho')
print(x_dct)
array([ 2.59807621e+00, -2.12132034e+00, -1.81298661e-16])
in tensorflow:
x= tf.placeholder(tf.float32, shape=(1,3))
x_dct=tf.spectral.dct(x,2, norm='ortho')
x_dct=tf.squeeze(x_dct)
sess=tf.Session()
sess.run(x_dct,{x:xx})
array([ 2.59807611e+00, -2.12132001e+00, 2.92001914e-07], dtype=float32)
The low energy coefficients are not equal. It seems having different low energy coefficinets does not matter so much.
Upvotes: 1
Views: 302
Reputation: 807
I'm the author of tf.signal.dct
. It is designed to be equivalent to scipy.fftpack.dct
, but there are minor numerical differences between them at the moment. I believe your example is computing the fftpack DCT in float64
, while tf.signal.dct
only supports tf.float32
at the moment (I plan to fix that). There is also a minor issue with tf.signal.rfft
(which tf.signal.dct
is implemented in terms of) where its 0th coefficient is not zero. I believe that when both of these issues are fixed the difference you're seeing in the low energy coefficients will get much smaller.
Sorry for not responding to this post sooner!
Upvotes: 1