提交 ceb78893 authored 作者: David Warde-Farley's avatar David Warde-Farley

Merge pull request #3369 from yingzha/ccw

Add a 'name' argument to '.copy' method of Theano variables
import numpy as np
from numpy.testing import assert_equal, assert_string_equal
import theano
import theano.tensor as tt
......@@ -19,3 +20,12 @@ def test_numpy_method():
f = theano.function([x], y)
utt.assert_allclose(np.nan_to_num(f(data)),
np.nan_to_num(fct(data)))
def test_copy():
x = tt.dmatrix('x')
data = np.random.rand(5, 5)
y = x.copy(name='y')
f = theano.function([x], y)
assert_equal(f(data), data)
assert_string_equal(y.name, 'y')
......@@ -520,8 +520,11 @@ class _tensor_py_operators:
return theano.tensor.subtensor.take(self, indices, axis, mode)
# COPYING
def copy(self):
return theano.tensor.basic.tensor_copy(self)
def copy(self, name=None):
"""Copy a variable and optionally assign a name."""
copied_variable = theano.tensor.basic.tensor_copy(self)
copied_variable.name = name
return copied_variable
def __iter__(self):
try:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论