def test_basic(self): x = zvector() rng = np.random.RandomState(23) xval = np.asarray( list(np.complex(rng.randn(), rng.randn()) for i in range(10))) assert np.all(xval.real == theano.function([x], real(x))(xval)) assert np.all(xval.imag == theano.function([x], imag(x))(xval))
import numpy as np import scipy.signal as ss import argparse import theano import theano.tensor as T # Theano functions # QEA function x0, x1, x2 = (T.zvector('x0'),T.zvector('x1'), T.zvector('x2')) IF_FUN = T.arccos((x2 + x0) / (2 * x1 + 1e-16)) / np.pi / 2 QEA_FUN = theano.function([x0, x1, x2], IF_FUN) def floatx(np_data): return np.asarray(np_data, dtype=theano.config.floatX) def qea(im): """ Quasi-eigen approximation function Input - im : 1d vector that contains a time series Ouput - ia : instantaneous amplitude - ip : instantaneous phase - ifeq: instantaneous frequency """ im = floatx(im.ravel()) # computes analytic signal H = ss.hilbert(im) H = im+1j*H
def test_cast(self): x = zvector() with pytest.raises(TypeError): cast(x, "int32")
import numpy as np import theano as th import theano.tensor as tt # th.config.device='gpu' # X = tt.dscalar('X') # y = tt.dscalar('y') # z = X + y # f = th.function([X, y], z) # f(2,3) # np.allclose(f(16.3, 12.1), 28.4) X = tt.zvector('X') y = tt.zvector('y') m = tt.dmatrix('m') n = tt.dmatrix('n') zout = tt.dot(m, n) P = th.function([m, n], zout) s_outputs, s_updates = th.scan(fn=lambda i, j: tt.dot(i, j)) P = th.function(inputs=[m, n], outputs=s_outputs, updates=s_updates) M = np.array(3, dtype=th.config.floatX) N = np.array(4, dtype=th.config.floatX) P(M, N)