I want to calculate the total product by the size of one of two multidimensional arrays using Theano.
First I will describe what I want to do using numpy. numpy.tensordotand numpy.dotalways seem like a matrix product, while I'm basically looking for an equivalent vector product. Given xand y, I want to calculate zas follows:
x = np.random.normal(size=(200, 2, 2, 1000))
y = np.random.normal(size=(200, 2, 2))
z = np.sum(y[:,:,:,np.newaxis] * x, axis=1)
Now I know that numpy.einsumI can probably help me here, but again, I want to do this specific calculation in Theano , which has no equivalent einsum. I will need to use dot, tensordotor a specialized subset of entropy function Anano batched_dotor batched_tensordot.
The reason I want to change my approach to this is performance; I suspect that using embedded (CUDA) point products will be faster than relying on broadcasting, the element product, and the amount.
source
share