提交 24690dec authored 作者: Frederic Bastien's avatar Frederic Bastien

Example for gh-3040. Allow numpy.exp(theano_var) to build a graph.

上级 3e84371d
import numpy as np
import theano
import theano.tensor as tt
import theano.tests.unittest_tools as utt
def test_numpy_method():
# This type of code is used frequently by PyMC3 users
x = tt.dmatrix('x')
data = np.random.rand(5, 5)
for fct in [np.exp]:
print fct
y = fct(x)
f = theano.function([x], y)
utt.assert_allclose(f(data), fct(data))
...@@ -354,6 +354,10 @@ class _tensor_py_operators: ...@@ -354,6 +354,10 @@ class _tensor_py_operators:
def diagonal(self, offset=0, axis1=0, axis2=1): def diagonal(self, offset=0, axis1=0, axis2=1):
return theano.tensor.basic.diagonal(self, offset, axis1, axis2) return theano.tensor.basic.diagonal(self, offset, axis1, axis2)
# Elemwise
def exp(self):
return theano.tensor.exp(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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论