Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
40f0270a
提交
40f0270a
authored
1月 15, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
差异文件
merged
上级
0c92bd68
500dc182
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
21 行增加
和
18 行删除
+21
-18
core.py
core.py
+4
-6
test.py
test.py
+17
-12
没有找到文件。
core.py
浏览文件 @
40f0270a
import
gof
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
import
numpy
...
@@ -165,6 +165,7 @@ class NumpyR(gof.PythonR):
...
@@ -165,6 +165,7 @@ class NumpyR(gof.PythonR):
self
.
data
=
value
self
.
data
=
value
else
:
else
:
self
.
data
=
numpy
.
array
(
value
)
self
.
data
=
numpy
.
array
(
value
)
self
.
up_to_date
=
True
def
__add__
(
self
,
y
):
return
add
(
self
,
y
)
def
__add__
(
self
,
y
):
return
add
(
self
,
y
)
def
__radd__
(
self
,
x
):
return
add
(
x
,
self
)
def
__radd__
(
self
,
x
):
return
add
(
x
,
self
)
...
@@ -208,14 +209,13 @@ zeros = wrap_producer(numpy.zeros)
...
@@ -208,14 +209,13 @@ zeros = wrap_producer(numpy.zeros)
ones
=
wrap_producer
(
numpy
.
ones
)
ones
=
wrap_producer
(
numpy
.
ones
)
# Wrapper to ensure that all inputs to the function impl have the same size (foils numpy's broadcasting)
# Wrapper to ensure that all inputs to the function impl have the same size (foils numpy's broadcasting)
def
assert_same_shapes
(
impl
):
def
assert_same_shapes
(
impl
):
def
ret
(
x
,
*
rest
):
def
ret
(
x
,
*
rest
):
shape
=
x
.
shape
shape
=
x
.
shape
for
other
in
rest
:
for
other
in
rest
:
if
other
.
shape
!=
shape
:
if
other
.
shape
!=
shape
:
raise
Typ
eError
(
"The dimensions of the inputs do not match."
)
raise
Valu
eError
(
"The dimensions of the inputs do not match."
)
return
impl
(
x
,
*
rest
)
return
impl
(
x
,
*
rest
)
return
ret
return
ret
...
@@ -223,7 +223,7 @@ def assert_same_shapes(impl):
...
@@ -223,7 +223,7 @@ def assert_same_shapes(impl):
def
tensor_scalar_op
(
impl
):
def
tensor_scalar_op
(
impl
):
def
ret
(
x
,
a
):
def
ret
(
x
,
a
):
if
a
.
shape
:
if
a
.
shape
:
raise
Typ
eError
(
"The second argument to
%
s must be a scalar."
%
impl
)
raise
Valu
eError
(
"The second argument to
%
s must be a scalar."
%
impl
)
return
impl
(
x
,
a
)
return
impl
(
x
,
a
)
return
ret
return
ret
...
@@ -240,7 +240,6 @@ class add_elemwise(proto_add_elemwise):
...
@@ -240,7 +240,6 @@ class add_elemwise(proto_add_elemwise):
class
iadd_elemwise
(
proto_add_elemwise
,
inplace
):
class
iadd_elemwise
(
proto_add_elemwise
,
inplace
):
impl
=
assert_same_shapes
(
numpy
.
ndarray
.
__iadd__
)
impl
=
assert_same_shapes
(
numpy
.
ndarray
.
__iadd__
)
class
proto_add_scalar
(
omega_op
):
class
proto_add_scalar
(
omega_op
):
def
grad
(
x
,
a
,
gz
):
def
grad
(
x
,
a
,
gz
):
return
gz
,
sum
(
gz
)
return
gz
,
sum
(
gz
)
...
@@ -355,7 +354,6 @@ class div_elemwise(proto_div_elemwise):
...
@@ -355,7 +354,6 @@ class div_elemwise(proto_div_elemwise):
class
idiv_elemwise
(
proto_div_elemwise
,
inplace
):
class
idiv_elemwise
(
proto_div_elemwise
,
inplace
):
impl
=
assert_same_shapes
(
numpy
.
ndarray
.
__idiv__
)
impl
=
assert_same_shapes
(
numpy
.
ndarray
.
__idiv__
)
def
div_scalar_r
(
x
,
a
):
def
div_scalar_r
(
x
,
a
):
return
scale
(
x
,
inv_elemwise
(
a
))
return
scale
(
x
,
inv_elemwise
(
a
))
...
...
test.py
浏览文件 @
40f0270a
...
@@ -156,8 +156,10 @@ class sigmoid(core.omega_op):
...
@@ -156,8 +156,10 @@ class sigmoid(core.omega_op):
numpy
.
random
.
seed
(
1
)
numpy
.
random
.
seed
(
1
)
core
.
build_eval_mode
()
x
=
core
.
zeros
((
1
,
10
))
x
=
core
.
zeros
((
1
,
10
))
w
=
core
.
input
(
numpy
.
random
.
rand
(
10
,
15
))
w
=
core
.
input
(
numpy
.
random
.
rand
(
10
,
15
))
core
.
pop_mode
()
# x = numpy.zeros((1, 10))
# x = numpy.zeros((1, 10))
# w = numpy.random.rand(10, 15)
# w = numpy.random.rand(10, 15)
...
@@ -188,6 +190,8 @@ f = compile.to_func([w, x], [w2, rec_error])
...
@@ -188,6 +190,8 @@ f = compile.to_func([w, x], [w2, rec_error])
#f = compile.single(w2, rec_error)
#f = compile.single(w2, rec_error)
for
i
in
dataset_1hot
(
x
.
data
,
numpy
.
ndarray
((
1
,
)),
10000
):
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
)
w2
,
rec_error
=
f
(
w
.
data
,
x
.
data
)
if
not
(
i
%
1000
):
if
not
(
i
%
1000
):
print
rec_error
print
rec_error
...
@@ -223,24 +227,25 @@ print w.data
...
@@ -223,24 +227,25 @@ 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])
print
x
# x + x
# print "1", gof.eval_env#.ops()
x
+
x
# y + y
print
"1"
,
gof
.
eval_env
#.ops()
# print "2", gof.eval_env#.ops()
y
+
y
# x + x
print
"2"
,
gof
.
eval_env
#.ops()
# print "3", gof.eval_env#.ops()
x
+
x
print
"3"
,
gof
.
eval_env
#.ops()
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
print
x
core
.
pop_mode
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论