Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7bb6fbee
提交
7bb6fbee
authored
1月 16, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
差异文件
boing
上级
6ea51f27
d03dbc0b
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
57 行增加
和
60 行删除
+57
-60
compile.py
compile.py
+1
-1
core.py
core.py
+33
-42
test.py
test.py
+23
-17
没有找到文件。
compile.py
浏览文件 @
7bb6fbee
...
...
@@ -13,7 +13,7 @@ import core
def
to_func
(
inputs
,
outputs
):
# print gof.Env(inputs, outputs).io_toposort()
p
=
prog
(
inputs
,
outputs
)
print
p
.
env
#
print p.env
def
f
(
*
args
):
for
input
,
value
in
zip
(
inputs
,
args
):
p
[
input
]
=
value
...
...
core.py
浏览文件 @
7bb6fbee
...
...
@@ -145,13 +145,16 @@ class omega_op(gof.PythonOp):
return
UNDEFINED
def
scalar_switch
(
normal_f
,
scalar_f
,
scalar_f_reverse
):
def
scalar_switch
(
normal_f
,
scalar_f
,
scalar_f_reverse
=
None
):
def
f
(
x
,
y
):
x
,
y
=
wrap
(
x
),
wrap
(
y
)
if
x
.
constant
and
not
x
.
data
.
shape
:
return
scalar_f_reverse
(
y
,
x
)
if
y
.
constant
and
not
y
.
data
.
shape
:
return
scalar_f
(
x
,
y
)
if
x
.
constant
and
not
x
.
data
.
shape
:
if
scalar_f_reverse
:
return
scalar_f_reverse
(
y
,
x
)
else
:
raise
TypeError
(
"You cannot do this operation on a scalar."
)
return
normal_f
(
x
,
y
)
return
f
...
...
@@ -286,9 +289,6 @@ def sub_scalar_l(x, a):
def
isub_scalar_r
(
x
,
a
):
return
iadd_scalar
(
x
,
-
a
)
def
isub_scalar_l
(
x
,
a
):
return
iadd_scalar
(
-
x
,
a
)
## Element-wise multiplication ##
...
...
@@ -363,9 +363,6 @@ def div_scalar_l(x, a):
def
idiv_scalar_r
(
x
,
a
):
return
iscale
(
x
,
inv_elemwise
(
a
))
def
idiv_scalar_l
(
x
,
a
):
return
iscale
(
inv_elemwise
(
x
),
a
)
## Scaling ##
...
...
@@ -423,40 +420,30 @@ class array_copy(omega_op):
## Power ##
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
):
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__
)
def
grad
(
x
,
s
,
gz
):
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__
)
def
grad
(
x
,
s
,
gz
):
return
gz
*
s
*
(
pow_scalar_r
(
x
,
s
-
1.0
))
class
proto_ipow
(
omega_op
):
pass
class
ipow_elemwise
(
proto_ipow
):
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
()
class
ipow_scalar_r
(
omega_op
,
inplace
):
impl
=
tensor_scalar_op
(
numpy
.
ndarray
.
__ipow__
)
def
grad
(
x
,
s
,
gz
):
return
gz
*
s
*
(
pow_scalar_r
(
x
,
s
-
1.0
))
## Others ##
...
...
@@ -474,30 +461,34 @@ class sum(omega_op):
return
fill
(
x
,
gz
)
# array_copy = wrapper("copy",
# numpy.array,
# lambda x, gz: gz)
# array slicing
## 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
)
iadd
=
scalar_switch
(
iadd_elemwise
,
iadd_scalar
,
iadd_scalar
)
iadd
=
scalar_switch
(
iadd_elemwise
,
iadd_scalar
)
sub
=
scalar_switch
(
sub_elemwise
,
sub_scalar_r
,
sub_scalar_l
)
isub
=
scalar_switch
(
isub_elemwise
,
isub_scalar_r
,
isub_scalar_l
)
isub
=
scalar_switch
(
isub_elemwise
,
isub_scalar_r
)
mul
=
scalar_switch
(
mul_elemwise
,
scale
,
scale
)
imul
=
scalar_switch
(
imul_elemwise
,
iscale
,
iscale
)
imul
=
scalar_switch
(
imul_elemwise
,
iscale
)
div
=
scalar_switch
(
div_elemwise
,
div_scalar_r
,
div_scalar_l
)
idiv
=
scalar_switch
(
idiv_elemwise
,
idiv_scalar_r
,
idiv_scalar_l
)
idiv
=
scalar_switch
(
idiv_elemwise
,
idiv_scalar_r
)
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
浏览文件 @
7bb6fbee
...
...
@@ -179,6 +179,9 @@ core.pop_mode()
# @omega_compile
def
autoassociator
(
w
,
x
):
forward
=
sigmoid
(
core
.
dot
(
sigmoid
(
core
.
dot
(
x
,
w
)),
w
.
T
))
rec_error
=
core
.
sum
(
core
.
sqr
(
x
-
forward
))
...
...
@@ -227,25 +230,28 @@ print w.data
############################
x
=
core
.
ones
((
2
,
2
))
y
=
core
.
zeros
((
1
,
1
))
#
x = core.ones((2, 2))
#
y = core.zeros((1, 1))
#print "?", gof.graph.ops([], [x + y])
# #print "?", gof.graph.ops([], [x + y])
# # x + x
# # print "1", gof.eval_env#.ops()
# # y + y
# # print "2", gof.eval_env#.ops()
# # x + x
# # print "3", gof.eval_env#.ops()
# 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()
# x + x
# print "1", gof.eval_env#.ops()
# y + y
# print "2", gof.eval_env#.ops()
# x + x
# print "3", gof.eval_env#.ops()
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论