提交 9a1acfc6 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #1892 from Tanjay94/Power

Power
......@@ -30,7 +30,7 @@ from theano.sandbox.linalg.ops import (cholesky,
spectral_radius_bound,
imported_scipy,
Eig,
inv_as_solve,
inv_as_solve
)
from theano.sandbox.linalg import eig, eigh, eigvalsh
from nose.plugins.skip import SkipTest
......
......@@ -5022,3 +5022,7 @@ def ptp(a, axis=None):
out = max(a, axis) - min(a, axis)
return out
def power(x, y):
return x**y
......@@ -45,7 +45,7 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
dtensor3, SpecifyShape, Mean,
itensor3, Tile, switch, Diagonal, Diag,
nonzero, flatnonzero, nonzero_values,
stacklists, DimShuffle, hessian, ptp)
stacklists, DimShuffle, hessian, ptp, power)
from theano.tests import unittest_tools as utt
......@@ -6899,6 +6899,32 @@ if __name__ == '__main__':
t.test_infer_shape()
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])
def test_wrong_shape(self):
x = tensor.matrix()
y = [1, 2, 3]
z = power(x, y)
f = function([x], z)
self.assertRaise(ValueError, f, [1, 2, 3, 4])
"""
if __name__ == '__main__':
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论