Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e6bbc361
提交
e6bbc361
authored
6月 15, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make tensor.{all,any} don't crash with other dtype then uint8 and int8.
上级
1bf87a89
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
51 行增加
和
7 行删除
+51
-7
elemwise.py
theano/tensor/elemwise.py
+16
-1
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+34
-5
test_keepdims.py
theano/tensor/tests/test_keepdims.py
+1
-1
没有找到文件。
theano/tensor/elemwise.py
浏览文件 @
e6bbc361
...
...
@@ -1154,7 +1154,10 @@ class CAReduce(Op):
axis2
.
append
(
a
)
assert
len
(
axis
)
==
len
(
axis2
)
axis
=
tuple
(
axis2
)
op
=
self
.
__class__
(
self
.
scalar_op
,
axis
)
# We can't call self.__class__() as there is class that
# inherit from CAReduce that don't have the same signature
op
=
copy
(
self
)
op
.
axis
=
axis
else
:
op
=
self
broadcastable
=
[
x
for
i
,
x
in
enumerate
(
input
.
type
.
broadcastable
)
...
...
@@ -1409,6 +1412,12 @@ class All(CAReduce):
else
:
return
"All{
%
s}"
%
", "
.
join
(
map
(
str
,
self
.
axis
))
def
make_node
(
self
,
input
):
if
input
.
dtype
not
in
[
"int8"
,
"uint8"
]:
input
=
theano
.
tensor
.
neq
(
input
,
0
)
ret
=
super
(
All
,
self
)
.
make_node
(
input
)
return
ret
class
Any
(
CAReduce
):
""" Applies `bitwise or` to all the values of a tensor along the
...
...
@@ -1428,6 +1437,12 @@ class Any(CAReduce):
else
:
return
"Any{
%
s}"
%
", "
.
join
(
map
(
str
,
self
.
axis
))
def
make_node
(
self
,
input
):
if
input
.
dtype
not
in
[
"int8"
,
"uint8"
]:
input
=
theano
.
tensor
.
neq
(
input
,
0
)
ret
=
super
(
Any
,
self
)
.
make_node
(
input
)
return
ret
class
CAReduceDtype
(
CAReduce
):
"""
...
...
theano/tensor/tests/test_elemwise.py
浏览文件 @
e6bbc361
...
...
@@ -181,7 +181,7 @@ class test_CAReduce(unittest.TestCase):
unittest_tools
.
seed_rng
()
def
with_linker
(
self
,
linker
,
scalar_op
=
add
,
dtype
=
"floatX"
,
test_nan
=
False
):
test_nan
=
False
,
tensor_op
=
None
):
for
xsh
,
tosum
in
[((
5
,
6
),
None
),
((
5
,
6
),
(
0
,
1
)),
((
5
,
6
),
(
0
,
)),
...
...
@@ -200,7 +200,11 @@ class test_CAReduce(unittest.TestCase):
if
dtype
==
"floatX"
:
dtype
=
theano
.
config
.
floatX
x
=
TensorType
(
dtype
,
[(
entry
==
1
)
for
entry
in
xsh
])(
'x'
)
e
=
CAReduce
(
scalar_op
,
axis
=
tosum
)(
x
)
if
tensor_op
is
None
:
e
=
CAReduce
(
scalar_op
,
axis
=
tosum
)(
x
)
else
:
e
=
tensor_op
(
x
,
axis
=
tosum
)
if
tosum
is
None
:
tosum
=
range
(
len
(
xsh
))
f
=
copy
(
linker
)
.
accept
(
Env
([
x
],
[
e
]))
.
make_function
()
xv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
xsh
))
...
...
@@ -227,8 +231,17 @@ class test_CAReduce(unittest.TestCase):
else
:
axis2
.
append
(
a
)
assert
len
(
axis2
)
==
len
(
tosum
)
tosum
=
tuple
(
axis2
)
if
scalar_op
==
add
:
if
tensor_op
==
tensor
.
all
:
for
axis
in
reversed
(
sorted
(
tosum
)):
zv
=
numpy
.
all
(
zv
,
axis
)
if
len
(
tosum
)
==
0
:
zv
=
zv
!=
0
elif
tensor_op
==
tensor
.
any
:
for
axis
in
reversed
(
sorted
(
tosum
)):
zv
=
numpy
.
any
(
zv
,
axis
)
if
len
(
tosum
)
==
0
:
zv
=
zv
!=
0
elif
scalar_op
==
add
:
for
axis
in
reversed
(
sorted
(
tosum
)):
zv
=
numpy
.
add
.
reduce
(
zv
,
axis
)
elif
scalar_op
==
mul
:
...
...
@@ -283,7 +296,10 @@ class test_CAReduce(unittest.TestCase):
#the Shape op don't implement c_code!
if
isinstance
(
linker
,
gof
.
PerformLinker
):
x
=
TensorType
(
dtype
,
[(
entry
==
1
)
for
entry
in
xsh
])(
'x'
)
e
=
CAReduce
(
scalar_op
,
axis
=
tosum
)(
x
)
if
tensor_op
is
None
:
e
=
CAReduce
(
scalar_op
,
axis
=
tosum
)(
x
)
else
:
e
=
tensor_op
(
x
,
axis
=
tosum
)
if
tosum
is
None
:
tosum
=
range
(
len
(
xsh
))
f
=
copy
(
linker
)
.
accept
(
Env
([
x
],
[
e
.
shape
]))
.
make_function
()
if
not
(
scalar_op
in
[
maximum
,
minimum
]
and
((
xsh
==
()
or
numpy
.
prod
(
xsh
)
==
0
))):
...
...
@@ -295,6 +311,10 @@ class test_CAReduce(unittest.TestCase):
self
.
with_linker
(
gof
.
PerformLinker
(),
mul
,
dtype
=
dtype
)
self
.
with_linker
(
gof
.
PerformLinker
(),
maximum
,
dtype
=
dtype
)
self
.
with_linker
(
gof
.
PerformLinker
(),
minimum
,
dtype
=
dtype
)
self
.
with_linker
(
gof
.
PerformLinker
(),
and_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
all
)
self
.
with_linker
(
gof
.
PerformLinker
(),
or_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
any
)
for
dtype
in
[
"int8"
,
"uint8"
]:
self
.
with_linker
(
gof
.
PerformLinker
(),
or_
,
dtype
=
dtype
)
self
.
with_linker
(
gof
.
PerformLinker
(),
and_
,
dtype
=
dtype
)
...
...
@@ -317,6 +337,10 @@ class test_CAReduce(unittest.TestCase):
test_nan
=
True
)
self
.
with_linker
(
gof
.
PerformLinker
(),
and_
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_linker
(
gof
.
PerformLinker
(),
or_
,
dtype
=
dtype
,
test_nan
=
True
,
tensor_op
=
tensor
.
any
)
self
.
with_linker
(
gof
.
PerformLinker
(),
and_
,
dtype
=
dtype
,
test_nan
=
True
,
tensor_op
=
tensor
.
all
)
def
test_c
(
self
):
for
dtype
in
[
"floatX"
,
"complex64"
,
"complex128"
,
"int8"
,
"uint8"
]:
...
...
@@ -325,6 +349,11 @@ class test_CAReduce(unittest.TestCase):
for
dtype
in
[
"floatX"
,
"int8"
,
"uint8"
]:
self
.
with_linker
(
gof
.
CLinker
(),
minimum
,
dtype
=
dtype
)
self
.
with_linker
(
gof
.
CLinker
(),
maximum
,
dtype
=
dtype
)
# all and any use neq that don't have c code for complex
self
.
with_linker
(
gof
.
CLinker
(),
and_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
all
)
self
.
with_linker
(
gof
.
CLinker
(),
or_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
any
)
for
dtype
in
[
"int8"
,
"uint8"
]:
self
.
with_linker
(
gof
.
CLinker
(),
or_
,
dtype
=
dtype
)
self
.
with_linker
(
gof
.
CLinker
(),
and_
,
dtype
=
dtype
)
...
...
theano/tensor/tests/test_keepdims.py
浏览文件 @
e6bbc361
...
...
@@ -72,7 +72,7 @@ class TestKeepDims:
# the following ops can be specified with a freely specified axis
# parameter
for
op
in
([
tensor
.
sum
,
tensor
.
prod
,
tensor
.
mean
,
tensor
.
var
,
tensor
.
std
]):
tensor
.
std
,
tensor
.
all
,
tensor
.
any
]):
# FRED: il faudra ajouter les ops suivantes a la boucle ci-dessus:
# tensor.all, tensor.any
# Celles-ci semblent presentement defectueuses puisqu'elles plantent
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论