Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7f593947
提交
7f593947
authored
9月 30, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make SliceConstant to have its signature hashable.
上级
0e9fe3a9
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
37 行增加
和
2 行删除
+37
-2
test_opt.py
theano/gof/tests/test_opt.py
+5
-2
type_other.py
theano/tensor/type_other.py
+32
-0
没有找到文件。
theano/gof/tests/test_opt.py
浏览文件 @
7f593947
...
...
@@ -414,12 +414,15 @@ class TestEquilibrium(object):
def
test_pre_constant_merge_slice
():
ms
=
theano
.
tensor
.
type_other
.
MakeSlice
()(
1
)
pre_constant_merge
([
ms
])
const_slice
=
theano
.
gof
.
graph
.
Constant
(
const_slice
=
theano
.
tensor
.
type_other
.
Slice
Constant
(
type
=
theano
.
tensor
.
type_other
.
slicetype
,
data
=
slice
(
1
,
None
,
2
))
adv
=
theano
.
tensor
.
subtensor
.
AdvancedSubtensor
()(
theano
.
tensor
.
matrix
(),
[
2
,
3
],
const_slice
)
pre_constant_merge
(
adv
)
cst
=
pre_greedy_local_optimizer
([
theano
.
tensor
.
opt
.
constant_folding
],
ms
)
assert
isinstance
(
cst
,
theano
.
tensor
.
type_other
.
SliceConstant
)
# Make sure constant of slice signature is hashable.
hash
(
c
onst_slice
.
signature
())
hash
(
c
st
.
signature
())
theano/tensor/type_other.py
浏览文件 @
7f593947
#
# Slice type and Op. None Type and NoneConst.
#
import
numpy
import
theano
from
theano.gof
import
Apply
,
Constant
,
Generic
,
Op
,
Type
,
hashtype
from
theano.gradient
import
DisconnectedType
...
...
@@ -76,6 +79,35 @@ class SliceType(Type):
slicetype
=
SliceType
()
class
SliceConstant
(
Constant
):
def
__init__
(
self
,
type
,
data
,
name
=
None
):
assert
isinstance
(
data
,
slice
)
# Numpy ndarray aren't hashable, so get rid of them.
if
isinstance
(
data
.
start
,
numpy
.
ndarray
):
assert
data
.
start
.
ndim
==
0
assert
"int"
in
str
(
data
.
start
.
dtype
)
data
=
slice
(
int
(
data
.
start
),
data
.
stop
,
data
.
step
)
elif
isinstance
(
data
.
stop
,
numpy
.
ndarray
):
assert
data
.
stop
.
ndim
==
0
assert
"int"
in
str
(
data
.
stop
.
dtype
)
data
=
slice
(
data
.
start
,
int
(
data
.
stop
),
data
.
step
)
elif
isinstance
(
data
.
step
,
numpy
.
ndarray
):
assert
data
.
step
.
ndim
==
0
assert
"int"
in
str
(
data
.
step
.
dtype
)
data
=
slice
(
data
.
start
,
int
(
data
.
stop
),
data
.
step
)
Constant
.
__init__
(
self
,
type
,
data
,
name
)
def
signature
(
self
):
return
(
SliceConstant
,
self
.
data
.
start
,
self
.
data
.
stop
,
self
.
data
.
step
)
def
__str__
(
self
):
return
"
%
s{
%
s,
%
s,
%
s}"
%
(
self
.
__class__
.
__name__
,
self
.
data
.
start
,
self
.
data
.
stop
,
self
.
data
.
step
)
SliceType
.
Constant
=
SliceConstant
class
NoneTypeT
(
Generic
):
"""
Inherit from Generic to have c code working.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论