0

I have a matrix and 3D tensor defined as below :

import numpy as np
import theano
import theano.tensor as T

a = T.matrix('a', dtype='float32')
c = T.tensor3('c',dtype='float32')
d = T.batched_dot(c, a)
g = theano.function([a,c],d)
Y = [[[1, 0, 0, 0],  [0, 1, 0, 0],  [0, 0, 1, 0], [0, 0, 0, 0]], [[0, 0 ,0, 0], [0, 1, 0, 0],[0, 0, 1, 0],[0, 0, 0, 1]]]
X = [[ 0.5052417 ,  0.22012063,  0.21787818,  0.41821062, 1, 1, 1, 0], [ 0.48668074,  0.26137591,  0.240702  ,  0.41308364, 0, 1, 1, 1]]
x = np.array(X, dtype='float32')
y = np.array(Y, dtype='float32')
print g(x[:,0:4], y)

Although it gives correct answer in the end, but in the middle it shows many error as

ValueError: get_scalar_constant_value detected deterministic IndexError: x.shape[2] when x.ndim=2. x=Subtensor{int64}.0
ERROR (theano.gof.opt): Optimization failure due to: local_gpua_gemmbatch
ERROR (theano.gof.opt): node: BatchedDot(c, a)
ERROR (theano.gof.opt): TRACEBACK:
ValueError: get_scalar_constant_value detected deterministic IndexError: x.shape[2] when x.ndim=2. x=Subtensor{int64}.0

My expected output is

[[ 0.50524169  0.22012062  0.21787818  0.        ]
[ 0.          0.2613759   0.240702    0.41308364]]

How can I correctly multiply those two ?

Shyamkkhadka
  • 1,438
  • 4
  • 19
  • 29
  • have you solved this? I have the exact same problem... – Mohamad Ghafourian Jul 10 '17 at 07:45
  • 1
    Hi @MohamadGhafourian, I changed the structure of Y. Instead of 3D tensor, I changed it into a simple matrix and performed elementwise matrix multiplication. Previously `Y` was matrix of diagonal matrices. Now it is simple matrix. New `Y` is [[ 1, 1, 1, 1, 1, 1, 1, 0], [ 1, 1, 1 , 1, 0, 1, 1, 1]]. – Shyamkkhadka Jul 10 '17 at 11:06

0 Answers0