提交 bc96ed14 authored 作者: A. Flaxman's avatar A. Flaxman

ENH: allow numpy.*(theano_var) to build a graph

上级 f4edcc59
...@@ -9,7 +9,13 @@ def test_numpy_method(): ...@@ -9,7 +9,13 @@ def test_numpy_method():
# This type of code is used frequently by PyMC3 users # This type of code is used frequently by PyMC3 users
x = tt.dmatrix('x') x = tt.dmatrix('x')
data = np.random.rand(5, 5) data = np.random.rand(5, 5)
for fct in [np.exp]: x.tag.test_value = data
for fct in [np.arccos, np.arccosh, np.arcsin, np.arcsinh,
np.arctan, np.arctanh, np.ceil, np.cos, np.cosh, np.deg2rad,
np.exp, np.exp2, np.expm1, np.floor, np.log,
np.log10, np.log1p, np.log2, np.rad2deg,
np.sin, np.sinh, np.sqrt, np.tan, np.tanh, np.trunc]:
y = fct(x) y = fct(x)
f = theano.function([x], y) f = theano.function([x], y)
utt.assert_allclose(f(data), fct(data)) utt.assert_allclose(np.nan_to_num(f(data)),
np.nan_to_num(fct(data)))
...@@ -355,9 +355,81 @@ class _tensor_py_operators: ...@@ -355,9 +355,81 @@ class _tensor_py_operators:
return theano.tensor.basic.diagonal(self, offset, axis1, axis2) return theano.tensor.basic.diagonal(self, offset, axis1, axis2)
# Elemwise # Elemwise
def arccos(self):
return theano.tensor.arccos(self)
def arccosh(self):
return theano.tensor.arccosh(self)
def arcsin(self):
return theano.tensor.arcsin(self)
def arcsinh(self):
return theano.tensor.arcsinh(self)
def arctan(self):
return theano.tensor.arctan(self)
def arctanh(self):
return theano.tensor.arctanh(self)
def ceil(self):
return theano.tensor.ceil(self)
def cos(self):
return theano.tensor.cos(self)
def cosh(self):
return theano.tensor.cosh(self)
def deg2rad(self):
return theano.tensor.deg2rad(self)
def exp(self): def exp(self):
return theano.tensor.exp(self) return theano.tensor.exp(self)
def exp2(self):
return theano.tensor.exp2(self)
def expm1(self):
return theano.tensor.expm1(self)
def floor(self):
return theano.tensor.floor(self)
def log(self):
return theano.tensor.log(self)
def log10(self):
return theano.tensor.log10(self)
def log1p(self):
return theano.tensor.log1p(self)
def log2(self):
return theano.tensor.log2(self)
def rad2deg(self):
return theano.tensor.rad2deg(self)
def sin(self):
return theano.tensor.sin(self)
def sinh(self):
return theano.tensor.sinh(self)
def sqrt(self):
return theano.tensor.sqrt(self)
def tan(self):
return theano.tensor.tan(self)
def tanh(self):
return theano.tensor.tanh(self)
def trunc(self):
return theano.tensor.trunc(self)
# CASTING # CASTING
def astype(self, dtype): def astype(self, dtype):
return theano.tensor.cast(self, dtype) return theano.tensor.cast(self, dtype)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论