提交 41b7bcc9 authored 作者: James Bergstra's avatar James Bergstra

merge

......@@ -87,7 +87,6 @@ class ProfileMode(Mode):
flops_msg=''
for a,t in op_time.items():
if hasattr(a,'flops'):
print "if true!"
flops=True
flops_msg=' <MFlops/s>'
print '\nHACK WARNING: we print the flops for some OP, but the logic don\' always work. You need to know the internal of Theano to make it work correctly. Otherwise don\'t use!'
......
......@@ -870,7 +870,7 @@ class TensorFromScalar(Op):
def perform(self, node, (s, ), (out, )):
out[0] = numpy.asarray(s)
def grad(self, (s,), (dt,)):
return [ScalarFromTensor(dt)]
return [scalar_from_tensor(dt)]
tensor_from_scalar = TensorFromScalar()
class ScalarFromTensor(Op):
......
import sys
import copy, sys
import numpy, theano
from theano import tensor
from theano.tensor.nnet import crossentropy_softmax_argmax_1hot_with_bias
def test_bug_2009_06_02_trac_387():
......@@ -31,3 +32,40 @@ def test_bug_2009_07_17_borrowed_output():
print z # Should still be zero.
assert numpy.linalg.norm(z) == 0
# The code above was supposed to fail when it was written (or, more
# accurately, on the next revision, i.e. when it was merged with the
# rest of the code, i.e. on revision cac9c9e9f08e).
# However, for some reason, it does not fail anymore when at this revision.
# Thus, a new test (below) was added that exhibits the same issue. Note
# that it may better be moved into the test_nnet.py test file if it turns
# out the bug was caused by 'crossentropy_softmax_argmax_1hot_with_bias',
# and was not a more general issue.
test_output_activation_no_bias = theano.tensor.dmatrix()
test_b2 = theano.tensor.dvector()
test_target = theano.tensor.ivector()
nll_softmax_argmax = (
crossentropy_softmax_argmax_1hot_with_bias(
test_output_activation_no_bias,
test_b2,
test_target))
output = nll_softmax_argmax[1]
g = theano.function([test_output_activation_no_bias, test_b2, test_target],
theano.Out(output, borrow=False))
a = numpy.zeros((1, 5))
b = numpy.ones(5)
c = numpy.zeros(1, dtype=numpy.int32)
z = g(a, b, c)
z_backup = copy.copy(z)
id_z = id(z)
print('Output z after first call: %s' % (z, ))
a[0, 0] = 1
id_other = id(g(a, b, c))
print ('Output z after second call: %s' % (z, ))
# Ensure that calling the function again returns a pointer towards a new
# array.
assert id_z != id_other
# Just to be 100% sure, ensure that z was not altered.
assert (z == z_backup).all()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论