I have the following snippet which maps a 2d tensor (num instances, seq 
length) to a 3d tensor (num instances, seq length - window + 1, window). It 
performs a rolling matrix multiplication:
 

*def rolling_window(input_vector, window_size, func=None):*
* """*
* :param input_vector: Ideally a 3dtensor needs testing atm just a matrix*


* :return: Sliding transform  func on input_vecor*
* """*

* t = T.cmatrix("t")*
* segment_size = T.iscalar("segment_size")*

* if func is not None:*
* func = func["func"](window_size, func["mat"])*

* def stride_update(idx, vector, size, func=func):*

* # Extract vector for this particular permutation*
* sub_vector = vector[:,idx:idx + size]*
* print("sub vector shape:" + str(sub_vector.shape))*

* # Carry out func transform*
* if func is None:*
* transformation = sub_vector*
* else:*
* print("ATTEMPT")*
* transformation = func.apply(sub_vector.T)*


* return transformation*

* # Make a seq containing the init idx of every segment*

* segment_init_indices = T.arange(t.shape[-1] - segment_size + 1)*

* result, updates = theano.scan(fn=stride_update,*
*                              sequences=[segment_init_indices],*
*                              non_sequences=[t, segment_size])*

* f_bind = theano.function([t, segment_size], result)*

* return f_bind(input_vector, window_size)*

Now I would like the input to be (num instances, channels,  seq length) and 
map to  (num instances, channels,  seq length - window + 1, window) 
logically it just seems that I need to modify *sub_vector = 
vector[:,idx:idx + size] *to *sub_vector = vector[:,:,idx:idx + size] *How 
ever that fails with a rehsape error in scan that really seems like its 
trying to  downshape the output and failing:


Traceback (most recent call last):
  File "main.py", line 35, in <module>
    main()
  File "main.py", line 28, in main
    
print(short_time_discrete_time_fourier_transform(np.array(range(17)).reshape(1,1,-1).astype(np.complex64),
 
5))
  File "/home/kaggleteviot/TheanoSP/fourier_ops/integral_transforms.py", 
line 64, in short_time_discrete_time_fourier_transform
    return rolling_window(signal_tensor, window, {"func": Func, "mat": dft})
  File "/home/kaggleteviot/TheanoSP/utils/rolling_windows.py", line 85, in 
rolling_window
    return f_bind(input_vector, window_size)
  File 
"/home/kaggleteviot/theano-env/local/lib/python2.7/site-packages/theano/compile/function_module.py",
 
line 871, in __call__
    storage_map=getattr(self.fn, 'storage_map', None))
  File 
"/home/kaggleteviot/theano-env/local/lib/python2.7/site-packages/theano/gof/link.py",
 
line 314, in raise_with_op
    reraise(exc_type, exc_value, exc_trace)
  File 
"/home/kaggleteviot/theano-env/local/lib/python2.7/site-packages/theano/compile/function_module.py",
 
line 859, in __call__
    outputs = self.fn()
  File 
"/home/kaggleteviot/theano-env/local/lib/python2.7/site-packages/theano/scan_module/scan_op.py",
 
line 953, in rval
    r = p(n, [x[0] for x in i], o)
  File 
"/home/kaggleteviot/theano-env/local/lib/python2.7/site-packages/theano/scan_module/scan_op.py",
 
line 940, in <lambda>
    self, node)
  File "theano/scan_module/scan_perform.pyx", line 405, in 
theano.scan_module.scan_perform.perform 
(/home/kaggleteviot/.theano/compiledir_Linux-3.19--generic-x86_64-with-Ubuntu-14.04-trusty-x86_64-2.7.6-64/scan_perform/mod.cpp:4316)
  File 
"/home/kaggleteviot/theano-env/local/lib/python2.7/site-packages/theano/gof/link.py",
 
line 314, in raise_with_op
    reraise(exc_type, exc_value, exc_trace)
  File "theano/scan_module/scan_perform.pyx", line 397, in 
theano.scan_module.scan_perform.perform 
(/home/kaggleteviot/.theano/compiledir_Linux-3.19--generic-x86_64-with-Ubuntu-14.04-trusty-x86_64-2.7.6-64/scan_perform/mod.cpp:4193)
ValueError: total size of new array must be unchanged
Apply node that caused the error: Reshape{2}(InplaceDimShuffle{1,2,0}.0, 
MakeVector{dtype='int64'}.0)
Toposort index: 11
Inputs types: [TensorType(complex64, 3D), TensorType(int64, vector)]
Inputs shapes: [(1, 5, 1), (2,)]
Inputs strides: [(40, 8, 8), (8,)]
Inputs values: [array([[[ 0.+0.j],
        [ 1.+0.j],
        [ 2.+0.j],
        [ 3.+0.j],
        [ 4.+0.j]]], dtype=complex64), array([ 1, 25])]
Outputs clients: [[Elemwise{Identity}(Reshape{2}.0)]]


Is this a bug of mine ? or just scan cannot handle this functionality ?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to