Theano 函数使用单个输入元素

Theano function using individual elements of input

我正在尝试构建一个 Theano 函数,它将 T.vector 个欧拉角作为输入,returns 个对应于这些欧拉角的方向向量。首先,我获取向量每个元素的正弦和余弦,然后将它们排列成一个旋转矩阵。最后,我将方向向量 [1, 0, 0] 乘以这个旋转矩阵。我遇到的问题 运行 是我无法将这个 NumPy 数组乘以旋转矩阵。

这是我的代码:

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

euler_angles = T.vector('euler_angles', dtype=theano.config.floatX)
origin_vec = theano.shared(np.asarray([1, 0, 0],
                                      dtype=theano.config.floatX))
sinx = T.sin(euler_angles[0])
siny = T.sin(euler_angles[1])
sinz = T.sin(euler_angles[2])
cosx = T.cos(euler_angles[0])
cosy = T.cos(euler_angles[1])
cosz = T.cos(euler_angles[2])

# Create the rotation matrix
rot_matrix = np.asarray([
        [cosy*cosz, -1*sinz, cosz * siny],
        [(sinx*siny)+(cosx*cosy*sinz), cosx*cosz, (-1*cosy*sinx)+(cosx*siny*sinz)],
        [(-1*cosx*siny)+(cosy*sinx*sinz), cosz*sinx, (cosx*cosy)+(sinx*siny*sinz)]
    ])
vector = T.dot(origin_vec, rot_matrix)
get_vector = theano.function([euler_angles], vector)

倒数第二行抛出此错误:

AsTensorError: ('Cannot convert [[Elemwise{mul,no_inplace}.0 Elemwise{mul,no_inplace}.0\n  Elemwise{mul,no_inplace}.0]\n [Elemwise{add,no_inplace}.0 Elemwise{mul,no_inplace}.0\n  Elemwise{add,no_inplace}.0]\n [Elemwise{add,no_inplace}.0 Elemwise{mul,no_inplace}.0\n  Elemwise{add,no_inplace}.0]] to TensorType', <type 'numpy.ndarray'>)

我想不出有什么方法可以通过欧拉角的矩阵运算来创建这个旋转矩阵。如何以 Theano 可以编译的格式创建此函数?

使用theano.tensor.stacklists().

rot_matrix = T.stacklists([[...], ...])