提交 02cafd6b authored 作者: Tanjay94's avatar Tanjay94

Added Power function and tests.

上级 f14933a5
...@@ -1202,3 +1202,7 @@ class EigvalshGrad(Op): ...@@ -1202,3 +1202,7 @@ class EigvalshGrad(Op):
def eigvalsh(a, b, lower=True): def eigvalsh(a, b, lower=True):
return Eigvalsh(lower)(a, b) return Eigvalsh(lower)(a, b)
def power(x,y):
return x**y
...@@ -31,6 +31,7 @@ from theano.sandbox.linalg.ops import (cholesky, ...@@ -31,6 +31,7 @@ from theano.sandbox.linalg.ops import (cholesky,
imported_scipy, imported_scipy,
Eig, Eig,
inv_as_solve, inv_as_solve,
power
) )
from theano.sandbox.linalg import eig, eigh, eigvalsh from theano.sandbox.linalg import eig, eigh, eigvalsh
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
...@@ -600,3 +601,23 @@ def test_eigvalsh_grad(): ...@@ -600,3 +601,23 @@ def test_eigvalsh_grad():
b = 10 * numpy.eye(5, 5) + rng.randn(5, 5) b = 10 * numpy.eye(5, 5) + rng.randn(5, 5)
tensor.verify_grad(lambda a, b: eigvalsh(a, b).dot([1, 2, 3, 4, 5]), tensor.verify_grad(lambda a, b: eigvalsh(a, b).dot([1, 2, 3, 4, 5]),
[a, b], rng=numpy.random) [a, b], rng=numpy.random)
class T_Power():
def test_numpy_compare(self):
rng = numpy.random.RandomState(utt.fetch_seed())
A = tensor.matrix("A", dtype=theano.config.floatX)
Q = power(A, 3)
fn = function([A], [Q])
a = rng.rand(4, 4).astype(theano.config.floatX)
n_p = numpy.power(a, 3)
t_p = fn(a)
assert numpy.allclose(n_p, t_p)
def test_multiple_power(self):
x = tensor.matrix()
y = [1, 2, 3]
z = power(x,y)
f = function([x], z)
assert allclose(f([1, 2, 3]), [1, 4, 27])
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论