def _L(x):
# initialize with zeros
batch_size = x.shape[0]
a = T.zeros((batch_size, num_actuators, num_actuators))
# set diagonal elements
batch_idx = T.extra_ops.repeat(T.arange(batch_size), num_actuators)
diag_idx = T.tile(T.arange(num_actuators), batch_size)
b = T.set_subtensor(a[batch_idx, diag_idx, diag_idx], T.flatten(T.exp(x[:, :num_actuators])))
# set lower triangle
cols = np.concatenate([np.array(range(i), dtype=np.uint) for i in xrange(num_actuators)])
rows = np.concatenate([np.array([i]*i, dtype=np.uint) for i in xrange(num_actuators)])
cols_idx = T.tile(T.as_tensor_variable(cols), batch_size)
rows_idx = T.tile(T.as_tensor_variable(rows), batch_size)
batch_idx = T.extra_ops.repeat(T.arange(batch_size), len(cols))
c = T.set_subtensor(b[batch_idx, rows_idx, cols_idx], T.flatten(x[:, num_actuators:]))
return c
评论列表
文章目录