Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8ca1bf09
提交
8ca1bf09
authored
3月 16, 2011
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
generic fix to #649: made as_tensor_variable(boolean) raise a TypeError and made…
generic fix to #649: made as_tensor_variable(boolean) raise a TypeError and made some needed changes for tests to pass
上级
8a40497a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
16 行增加
和
4 行删除
+16
-4
basic.py
theano/tensor/basic.py
+9
-1
opt.py
theano/tensor/opt.py
+7
-3
没有找到文件。
theano/tensor/basic.py
浏览文件 @
8ca1bf09
...
@@ -138,6 +138,11 @@ def as_tensor_variable(x, name = None, ndim=None):
...
@@ -138,6 +138,11 @@ def as_tensor_variable(x, name = None, ndim=None):
except
(
TypeError
,
ValueError
):
except
(
TypeError
,
ValueError
):
pass
pass
if
isinstance
(
x
,
bool
):
raise
TypeError
(
"Cannot cast True or False as a tensor variable. Please use 1 or 0. "
"This error might be caused by using the == operator on Variables. "
"v == w does not do what you think it does, use theano.tensor.eq(v, w) instead."
)
try
:
try
:
return
constant
(
x
,
name
=
name
,
ndim
=
ndim
)
return
constant
(
x
,
name
=
name
,
ndim
=
ndim
)
except
TypeError
:
except
TypeError
:
...
@@ -3850,7 +3855,10 @@ class PermuteRowElements(Op):
...
@@ -3850,7 +3855,10 @@ class PermuteRowElements(Op):
def
make_node
(
self
,
x
,
y
,
inverse
):
def
make_node
(
self
,
x
,
y
,
inverse
):
x
=
as_tensor_variable
(
x
)
x
=
as_tensor_variable
(
x
)
y
=
as_tensor_variable
(
y
)
y
=
as_tensor_variable
(
y
)
inverse
=
as_tensor_variable
(
inverse
)
if
inverse
:
# as_tensor_variable does not accept booleans
inverse
=
as_tensor_variable
(
1
)
else
:
inverse
=
as_tensor_variable
(
0
)
# y should contain integers
# y should contain integers
assert
y
.
type
.
dtype
.
startswith
(
'int'
)
or
y
.
type
.
dtype
.
startswith
(
'uint'
)
assert
y
.
type
.
dtype
.
startswith
(
'int'
)
or
y
.
type
.
dtype
.
startswith
(
'uint'
)
...
...
theano/tensor/opt.py
浏览文件 @
8ca1bf09
...
@@ -1141,7 +1141,7 @@ def local_subtensor_merge(node):
...
@@ -1141,7 +1141,7 @@ def local_subtensor_merge(node):
u_start
=
u
.
owner
.
op
.
idx_list
[
0
]
.
start
u_start
=
u
.
owner
.
op
.
idx_list
[
0
]
.
start
if
len
(
u
.
owner
.
inputs
)
==
1
and
isinstance
(
u_start
,
int
):
if
len
(
u
.
owner
.
inputs
)
==
1
and
isinstance
(
u_start
,
int
):
start0
=
u_start
start0
=
T
.
as_tensor_variable
(
u_start
)
elif
(
len
(
u
.
owner
.
inputs
)
==
2
and
elif
(
len
(
u
.
owner
.
inputs
)
==
2
and
isinstance
(
u_start
,
scalar
.
basic
.
Scalar
)):
isinstance
(
u_start
,
scalar
.
basic
.
Scalar
)):
start0
=
T
.
tensor_from_scalar
(
u
.
owner
.
inputs
[
1
])
start0
=
T
.
tensor_from_scalar
(
u
.
owner
.
inputs
[
1
])
...
@@ -1178,7 +1178,7 @@ def local_subtensor_merge(node):
...
@@ -1178,7 +1178,7 @@ def local_subtensor_merge(node):
):
):
idx
=
node
.
op
.
idx_list
[
0
]
idx
=
node
.
op
.
idx_list
[
0
]
if
len
(
node
.
inputs
)
==
1
and
isinstance
(
idx
,
int
):
if
len
(
node
.
inputs
)
==
1
and
isinstance
(
idx
,
int
):
pass
idx
=
T
.
as_tensor_variable
(
idx
)
elif
(
len
(
node
.
inputs
)
==
2
and
elif
(
len
(
node
.
inputs
)
==
2
and
isinstance
(
idx
,
scalar
.
basic
.
Scalar
)):
isinstance
(
idx
,
scalar
.
basic
.
Scalar
)):
idx
=
T
.
tensor_from_scalar
(
node
.
inputs
[
1
])
idx
=
T
.
tensor_from_scalar
(
node
.
inputs
[
1
])
...
@@ -1202,7 +1202,7 @@ def local_subtensor_merge(node):
...
@@ -1202,7 +1202,7 @@ def local_subtensor_merge(node):
slice_idx
=
node
.
op
.
idx_list
[
0
]
slice_idx
=
node
.
op
.
idx_list
[
0
]
idx
=
slice_idx
.
stop
idx
=
slice_idx
.
stop
if
len
(
node
.
inputs
)
==
1
and
isinstance
(
idx
,
int
):
if
len
(
node
.
inputs
)
==
1
and
isinstance
(
idx
,
int
):
pass
idx
=
T
.
as_tensor_variable
(
idx
)
elif
(
len
(
node
.
inputs
)
==
2
and
elif
(
len
(
node
.
inputs
)
==
2
and
isinstance
(
idx
,
scalar
.
basic
.
Scalar
)):
isinstance
(
idx
,
scalar
.
basic
.
Scalar
)):
idx
=
T
.
tensor_from_scalar
(
node
.
inputs
[
1
])
idx
=
T
.
tensor_from_scalar
(
node
.
inputs
[
1
])
...
@@ -1227,8 +1227,12 @@ def local_subtensor_merge(node):
...
@@ -1227,8 +1227,12 @@ def local_subtensor_merge(node):
idx2
=
node
.
op
.
idx_list
[
0
]
.
stop
idx2
=
node
.
op
.
idx_list
[
0
]
.
stop
if
isinstance
(
idx1
,
scalar
.
basic
.
Scalar
):
if
isinstance
(
idx1
,
scalar
.
basic
.
Scalar
):
idx1
=
T
.
tensor_from_scalar
(
u
.
owner
.
inputs
[
1
])
idx1
=
T
.
tensor_from_scalar
(
u
.
owner
.
inputs
[
1
])
elif
isinstance
(
idx1
,
int
):
idx1
=
T
.
as_tensor_variable
(
idx1
)
if
isinstance
(
idx2
,
scalar
.
basic
.
Scalar
):
if
isinstance
(
idx2
,
scalar
.
basic
.
Scalar
):
idx2
=
T
.
tensor_from_scalar
(
node
.
inputs
[
1
])
idx2
=
T
.
tensor_from_scalar
(
node
.
inputs
[
1
])
elif
isinstance
(
idx2
,
int
):
idx2
=
T
.
as_tensor_variable
(
idx1
)
# The maximum is needed to don't have shape[0] - idx1 < 0
# The maximum is needed to don't have shape[0] - idx1 < 0
idx2_neg
=
T
.
maximum
(
u
.
owner
.
inputs
[
0
]
.
shape
[
0
]
+
idx1
,
0
)
idx2_neg
=
T
.
maximum
(
u
.
owner
.
inputs
[
0
]
.
shape
[
0
]
+
idx1
,
0
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论