Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d03dbc0b
提交
d03dbc0b
authored
1月 16, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bla
上级
159a0597
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
45 行增加
和
57 行删除
+45
-57
compile.py
compile.py
+1
-1
core.py
core.py
+23
-35
test.py
test.py
+21
-21
没有找到文件。
compile.py
浏览文件 @
d03dbc0b
...
@@ -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
...
...
core.py
浏览文件 @
d03dbc0b
...
@@ -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
)
test.py
浏览文件 @
d03dbc0b
...
@@ -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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论