提交 500dc182 authored 作者: Olivier Breuleux's avatar Olivier Breuleux

added a correct build_eval mode

上级 6888f0f3
import gof
from gof import current_mode, set_mode, build_mode, eval_mode, pop_mode, UNCOMPUTED, UNDEFINED, PythonR
from gof import current_mode, set_mode, build_mode, eval_mode, build_eval_mode, pop_mode, UNCOMPUTED, UNDEFINED, PythonR
import numpy
......@@ -165,6 +165,7 @@ class NumpyR(gof.PythonR):
self.data = value
else:
self.data = numpy.array(value)
self.up_to_date = True
def __add__(self, y): return add(self, y)
def __radd__(self, x): return add(x, self)
......@@ -215,7 +216,7 @@ def assert_same_shapes(impl):
shape = x.shape
for other in rest:
if other.shape != shape:
raise TypeError("The dimensions of the inputs do not match.")
raise ValueError("The dimensions of the inputs do not match.")
return impl(x, *rest)
return ret
......@@ -223,7 +224,7 @@ def assert_same_shapes(impl):
def tensor_scalar_op(impl):
def ret(x, a):
if a.shape:
raise TypeError("The second argument to %s must be a scalar." % impl)
raise ValueError("The second argument to %s must be a scalar." % impl)
return impl(x, a)
return ret
......
......@@ -156,8 +156,10 @@ class sigmoid(core.omega_op):
numpy.random.seed(1)
core.build_eval_mode()
x = core.zeros((1, 10))
w = core.input(numpy.random.rand(10, 15))
core.pop_mode()
# x = numpy.zeros((1, 10))
# w = numpy.random.rand(10, 15)
......@@ -188,6 +190,8 @@ f = compile.to_func([w, x], [w2, rec_error])
#f = compile.single(w2, rec_error)
for i in dataset_1hot(x.data, numpy.ndarray((1, )), 10000):
# w.up_to_date = True
# x.up_to_date = True
w2, rec_error = f(w.data, x.data)
if not(i % 1000):
print rec_error
......@@ -224,23 +228,27 @@ print w.data
############################
x = core.ones((2, 2))
y = core.zeros((1, 1))
#print "?", gof.graph.ops([], [x + y])
print x
# print x
x + x
print "1", gof.eval_env#.ops()
y + y
print "2", gof.eval_env#.ops()
x + x
print "3", gof.eval_env#.ops()
# x + x
# print "1", gof.eval_env#.ops()
# y + y
# print "2", gof.eval_env#.ops()
# x + x
# print "3", gof.eval_env#.ops()
x += (x + x)
print x
#x += (x + x)
core.build_eval_mode()
x = core.ones((2, 2))
y = core.ones((2, 2)) * 2
x += y.T
# z = core.iadd(x, y)
# core.iadd(x, y)
print x
core.pop_mode()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论