Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
500dc182
提交
500dc182
authored
1月 15, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added a correct build_eval mode
上级
6888f0f3
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
24 行增加
和
15 行删除
+24
-15
core.py
core.py
+4
-3
test.py
test.py
+20
-12
没有找到文件。
core.py
浏览文件 @
500dc182
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
)
...
@@ -215,7 +216,7 @@ def assert_same_shapes(impl):
...
@@ -215,7 +216,7 @@ def assert_same_shapes(impl):
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 +224,7 @@ def assert_same_shapes(impl):
...
@@ -223,7 +224,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
...
...
test.py
浏览文件 @
500dc182
...
@@ -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
...
@@ -224,23 +228,27 @@ print w.data
...
@@ -224,23 +228,27 @@ print w.data
############################
############################
x
=
core
.
ones
((
2
,
2
))
y
=
core
.
zeros
((
1
,
1
))
#print "?", gof.graph.ops([], [x + y])
#print "?", gof.graph.ops([], [x + y])
print
x
#
print x
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()
x
+=
(
x
+
x
)
#x += (x + x)
print
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论