Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c4fbfa30
提交
c4fbfa30
authored
2月 23, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adding a minimal Op that is useful for debugging
上级
04603e7a
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
66 行增加
和
0 行删除
+66
-0
minimal.py
theano/sandbox/minimal.py
+66
-0
没有找到文件。
theano/sandbox/minimal.py
0 → 100644
浏览文件 @
c4fbfa30
import
numpy
,
scipy
.
linalg
from
theano
import
gof
,
tensor
,
scalar
,
function
import
unittest
class
Minimal
(
gof
.
Op
):
# if the Op has any attributes,
# consider using them in the eq function. If two Apply nodes have the same inputs and the
# ops compare equal... then they will be MERGED so they had better have computed the same
# thing!
def
__init__
(
self
):
# If you put things here, think about whether they change the outputs computed by
# self.perform()
# - If they do, then you should take them into consideration in __eq__ and __hash__
# - If they do not, then you should not use them in __eq__ and __hash__
super
(
Minimal
,
self
)
.
__init__
()
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
make_node
(
self
,
*
args
):
# HERE `args` must be THEANO VARIABLES
return
gof
.
Apply
(
op
=
self
,
inputs
=
args
,
outputs
=
[
tensor
.
lscalar
()])
def
perform
(
self
,
node
,
inputs
,
(
output
,
)):
# HERE `inputs` are PYTHON OBJECTS
# do what you want here,
# but do not modify any of the arguments [inplace].
print
"perform got
%
i arguments"
%
len
(
inputs
)
print
"Max of input[0] is "
,
numpy
.
max
(
inputs
[
0
])
# return some computed value.
# do not return something that is aliased to one of the inputs.
output
[
0
]
=
numpy
.
asarray
(
0
,
dtype
=
'int64'
)
minimal
=
Minimal
()
## TODO: test dtype conversion
## TODO: test that invalid types are rejected by make_node
## TODO: test that each valid type for A and b works correctly
from
theano.tests
import
unittest_tools
as
utt
class
T_minimal
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
(
666
))
def
test0
(
self
):
A
=
tensor
.
matrix
()
b
=
tensor
.
vector
()
print
'building function'
f
=
function
([
A
,
b
],
minimal
(
A
,
A
,
b
,
b
,
A
))
print
'built'
Aval
=
self
.
rng
.
randn
(
5
,
5
)
bval
=
numpy
.
array
(
range
(
5
),
dtype
=
float
)
f
(
Aval
,
bval
)
print
'done'
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论