提交 d03dbc0b authored 作者: Olivier Breuleux's avatar Olivier Breuleux

bla

上级 159a0597
...@@ -13,7 +13,7 @@ import core ...@@ -13,7 +13,7 @@ import core
def to_func(inputs, outputs): def to_func(inputs, outputs):
# print gof.Env(inputs, outputs).io_toposort() # print gof.Env(inputs, outputs).io_toposort()
p = prog(inputs, outputs) p = prog(inputs, outputs)
print p.env # print p.env
def f(*args): def f(*args):
for input, value in zip(inputs, args): for input, value in zip(inputs, args):
p[input] = value p[input] = value
......
...@@ -289,9 +289,6 @@ def sub_scalar_l(x, a): ...@@ -289,9 +289,6 @@ def sub_scalar_l(x, a):
def isub_scalar_r(x, a): def isub_scalar_r(x, a):
return iadd_scalar(x, -a) return iadd_scalar(x, -a)
# def isub_scalar_l(x, a):
# return iadd_scalar(ineg(x), a)
## Element-wise multiplication ## ## Element-wise multiplication ##
...@@ -366,9 +363,6 @@ def div_scalar_l(x, a): ...@@ -366,9 +363,6 @@ def div_scalar_l(x, a):
def idiv_scalar_r(x, a): def idiv_scalar_r(x, a):
return iscale(x, inv_elemwise(a)) return iscale(x, inv_elemwise(a))
# def idiv_scalar_l(x, a):
# return iscale(inv_elemwise(x), a)
## Scaling ## ## Scaling ##
...@@ -426,40 +420,30 @@ class array_copy(omega_op): ...@@ -426,40 +420,30 @@ class array_copy(omega_op):
## Power ## ## Power ##
class proto_pow(omega_op): class proto_pow(omega_op):
pass def grad(x, s, gz):
return gz * s * (pow_elemwise(x, s-1.0))
class pow_elemwise(proto_pow): class pow_elemwise(proto_pow):
impl = assert_same_shapes(numpy.ndarray.__pow__) impl = assert_same_shapes(numpy.ndarray.__pow__)
def grad(x, s, gz):
return gz * s * (pow_elemwise(x, s-1.0))
class pow_scalar_l(proto_pow): class ipow_elemwise(proto_pow, inplace):
impl = assert_same_shapes(numpy.ndarray.__ipow__)
class pow_scalar_l(omega_op):
impl = tensor_scalar_op(numpy.ndarray.__pow__) impl = tensor_scalar_op(numpy.ndarray.__pow__)
def grad(x, s, gz): def grad(x, s, gz):
return gz * x * (pow_scalar_l(s,x-1.0)) return gz * x * (pow_scalar_l(s,x-1.0))
class pow_scalar_r(proto_pow): class pow_scalar_r(omega_op):
impl = tensor_scalar_op(numpy.ndarray.__pow__) impl = tensor_scalar_op(numpy.ndarray.__pow__)
def grad(x, s, gz): def grad(x, s, gz):
return gz * s * (pow_scalar_r(x,s-1.0)) return gz * s * (pow_scalar_r(x,s-1.0))
class proto_ipow(omega_op): class ipow_scalar_r(omega_op, inplace):
pass impl = tensor_scalar_op(numpy.ndarray.__ipow__)
def grad(x, s, gz):
class ipow_elemwise(proto_ipow): return gz * s * (pow_scalar_r(x,s-1.0))
def __init__(self, *args, **kwargs):
omega_op.__init__(self, *args, **kwargs)
raise NotImplementedError()
class ipow_scalar_l(proto_ipow):
def __init__(self, *args, **kwargs):
omega_op.__init__(self, *args, **kwargs)
raise NotImplementedError()
class ipow_scalar_r(proto_ipow):
def __init__(self, *args, **kwargs):
omega_op.__init__(self, *args, **kwargs)
raise NotImplementedError()
## Others ## ## Others ##
...@@ -477,14 +461,18 @@ class sum(omega_op): ...@@ -477,14 +461,18 @@ class sum(omega_op):
return fill(x, gz) return fill(x, gz)
# array_copy = wrapper("copy", ## Array slicing ##
# numpy.array,
# lambda x, gz: gz)
# array slicing
class get_slice(omega_op, view):
def grad(x, gz):
raise NotImplementedError()
def impl(x, dims):
return x.__getitem__(*dims)
# class set_slice(omega_op, inplace):
# def impl(x, dims):
# x.__setitem__(*dims)
# return x
add = scalar_switch(add_elemwise, add_scalar, add_scalar) add = scalar_switch(add_elemwise, add_scalar, add_scalar)
...@@ -500,7 +488,7 @@ div = scalar_switch(div_elemwise, div_scalar_r, div_scalar_l) ...@@ -500,7 +488,7 @@ div = scalar_switch(div_elemwise, div_scalar_r, div_scalar_l)
idiv = scalar_switch(idiv_elemwise, idiv_scalar_r) idiv = scalar_switch(idiv_elemwise, idiv_scalar_r)
pow = scalar_switch(pow_elemwise, pow_scalar_r, pow_scalar_l) pow = scalar_switch(pow_elemwise, pow_scalar_r, pow_scalar_l)
ipow = scalar_switch(ipow_elemwise, ipow_scalar_r, ipow_scalar_l) ipow = scalar_switch(ipow_elemwise, ipow_scalar_r)
...@@ -230,27 +230,27 @@ print w.data ...@@ -230,27 +230,27 @@ print w.data
############################ ############################
x = core.ones((2, 2)) # x = core.ones((2, 2))
y = core.zeros((1, 1)) # y = core.zeros((1, 1))
#print "?", gof.graph.ops([], [x + y]) # #print "?", gof.graph.ops([], [x + y])
# x + x # # x + x
# print "1", gof.eval_env#.ops() # # print "1", gof.eval_env#.ops()
# y + y # # y + y
# print "2", gof.eval_env#.ops() # # print "2", gof.eval_env#.ops()
# x + x # # x + x
# print "3", gof.eval_env#.ops() # # print "3", gof.eval_env#.ops()
core.build_eval_mode() # core.build_eval_mode()
x = core.ones((2, 2)) # x = core.ones((2, 2))
y = core.ones((2, 2)) * 2 # y = core.ones((2, 2)) * 2
x += y.T # x += y.T
# z = core.iadd(x, y) # # z = core.iadd(x, y)
# core.iadd(x, y) # # core.iadd(x, y)
print x # print x
core.pop_mode() # core.pop_mode()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论