提交 530453b1 authored 作者: abalkin's avatar abalkin

- exposed eig in linalg

- implemented Eig.infer_shape() and fixed make_node - added test
上级 0d805855
from ops import (cholesky, matrix_inverse, solve,
diag, extract_diag, alloc_diag,
det, psd,
det, psd, eig,
trace, spectral_radius_bound)
......@@ -900,7 +900,9 @@ class Eig(Op):
def make_node(self, x):
x = as_tensor_variable(x)
return Apply(self, [x], [x.type(), x.type()])
w = theano.tensor.vector(x.dtype)
v = theano.tensor.matrix(x.dtype)
return Apply(self, [x], [w, v])
def perform(self, node, (x,), (w, v)):
try:
......@@ -909,6 +911,10 @@ class Eig(Op):
logger.debug('Failed to find eig of %s' % str(node.inputs[0]))
raise
def infer_shape(self, node, shapes):
n = shapes[0][0]
return [(n,), (n,n)]
def __str__(self):
return "Eig"
......
......@@ -26,6 +26,7 @@ from theano.sandbox.linalg.ops import (cholesky,
matrix_dot,
spectral_radius_bound,
imported_scipy,
Eig,
)
from nose.plugins.skip import SkipTest
......@@ -467,3 +468,20 @@ class test_Solve(utt.InferShapeTester):
numpy.asarray(rng.rand(5),
dtype=config.floatX)],
self.op_class)
class test_Eig(utt.InferShapeTester):
def setUp(self):
super(test_Eig, self).setUp()
self.op_class = Eig
self.op = Eig()
def test_infer_shape(self):
rng = numpy.random.RandomState(utt.fetch_seed())
A = theano.tensor.matrix()
X = numpy.asarray(rng.rand(5, 5),
dtype=config.floatX)
self._compile_and_check([A], # theano.function inputs
self.op(A), # theano.function outputs
# A must be square
[X.dot(X.T)],
self.op_class)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论