【发布时间】:2016-01-26 13:42:08
【问题描述】:
我运行了以下代码来计算矩阵的伪逆,但似乎我是否打开 GPU 没有任何区别。
mat = theano.shared(numpy.eye(300, dtype="float32")+1)
fn = theano.function([], theano.tensor.nlinalg.pinv(mat))
fn()
然后我查看了Theano的theano.tensor.nlinalg.MatrixPinv的源代码,发现它只是在下面的代码中调用了Numpy的numpy.linalg.pinv(我将省略cmets)。
class MatrixPinv(Op):
__props__ = ()
def __init__(self):
pass
def make_node(self, x):
x = as_tensor_variable(x)
assert x.ndim == 2
return Apply(self, [x], [x.type()])
def perform(self, node, inputs, outputs):
(x,) = inputs
(z,) = outputs
z[0] = numpy.linalg.pinv(x).astype(x.dtype)
pinv = MatrixPinv()
我对 Numpy 的实现方式不是很熟悉,它可以在 GPU 上运行吗?
如果不是,那是否意味着每次我想在 Theano 中计算矩阵求逆时,我都必须从 GPU 回到 CPU?
【问题讨论】:
标签: python numpy matrix linear-algebra theano