Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ac8ce341
提交
ac8ce341
authored
10月 13, 2016
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make Any and All return bools.
上级
7563a320
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
7 行增加
和
15 行删除
+7
-15
elemwise.py
theano/tensor/elemwise.py
+6
-10
test_basic.py
theano/tensor/tests/test_basic.py
+1
-1
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+0
-4
没有找到文件。
theano/tensor/elemwise.py
浏览文件 @
ac8ce341
...
@@ -1703,18 +1703,16 @@ for(int i=0;i<PyArray_NDIM(%(iname)s);i++){
...
@@ -1703,18 +1703,16 @@ for(int i=0;i<PyArray_NDIM(%(iname)s);i++){
class
All
(
CAReduce
):
class
All
(
CAReduce
):
""" Applies `
bitwise
and` to all the values of a tensor along the
""" Applies `
logical
and` to all the values of a tensor along the
specified axis(es).
specified axis(es).
Equivalent to `CAReduce(scalar.and
\
_, axis=axis)`.
"""
"""
def
__init__
(
self
,
axis
=
None
):
def
__init__
(
self
,
axis
=
None
):
CAReduce
.
__init__
(
self
,
scalar
.
and_
,
axis
)
CAReduce
.
__init__
(
self
,
scalar
.
and_
,
axis
)
def
_output_dtype
(
self
,
idtype
):
def
_output_dtype
(
self
,
idtype
):
return
"
int8
"
return
"
bool
"
def
__str__
(
self
):
def
__str__
(
self
):
if
self
.
axis
is
None
:
if
self
.
axis
is
None
:
...
@@ -1724,7 +1722,7 @@ class All(CAReduce):
...
@@ -1724,7 +1722,7 @@ class All(CAReduce):
def
make_node
(
self
,
input
):
def
make_node
(
self
,
input
):
input
=
as_tensor_variable
(
input
)
input
=
as_tensor_variable
(
input
)
if
input
.
dtype
not
in
[
"int8"
,
"uint8"
]
:
if
input
.
dtype
is
not
"bool"
:
input
=
theano
.
tensor
.
neq
(
input
,
0
)
input
=
theano
.
tensor
.
neq
(
input
,
0
)
ret
=
super
(
All
,
self
)
.
make_node
(
input
)
ret
=
super
(
All
,
self
)
.
make_node
(
input
)
return
ret
return
ret
...
@@ -1738,15 +1736,13 @@ class Any(CAReduce):
...
@@ -1738,15 +1736,13 @@ class Any(CAReduce):
""" Applies `bitwise or` to all the values of a tensor along the
""" Applies `bitwise or` to all the values of a tensor along the
specified axis(es).
specified axis(es).
Equivalent to `CAReduce(scalar.or
\
_, axis=axis)`.
"""
"""
def
__init__
(
self
,
axis
=
None
):
def
__init__
(
self
,
axis
=
None
):
CAReduce
.
__init__
(
self
,
scalar
.
or_
,
axis
)
CAReduce
.
__init__
(
self
,
scalar
.
or_
,
axis
)
def
_output_dtype
(
self
,
idtype
):
def
_output_dtype
(
self
,
idtype
):
return
"
int8
"
return
"
bool
"
def
__str__
(
self
):
def
__str__
(
self
):
if
self
.
axis
is
None
:
if
self
.
axis
is
None
:
...
@@ -1756,7 +1752,7 @@ class Any(CAReduce):
...
@@ -1756,7 +1752,7 @@ class Any(CAReduce):
def
make_node
(
self
,
input
):
def
make_node
(
self
,
input
):
input
=
as_tensor_variable
(
input
)
input
=
as_tensor_variable
(
input
)
if
input
.
dtype
not
in
[
"int8"
,
"uint8"
]
:
if
input
.
dtype
is
not
"bool"
:
input
=
theano
.
tensor
.
neq
(
input
,
0
)
input
=
theano
.
tensor
.
neq
(
input
,
0
)
ret
=
super
(
Any
,
self
)
.
make_node
(
input
)
ret
=
super
(
Any
,
self
)
.
make_node
(
input
)
return
ret
return
ret
...
@@ -1985,7 +1981,7 @@ class Sum(CAReduceDtype):
...
@@ -1985,7 +1981,7 @@ class Sum(CAReduceDtype):
out
=
self
(
*
inp
)
out
=
self
(
*
inp
)
if
out
.
dtype
.
find
(
'int'
)
!=
-
1
:
if
out
.
dtype
not
in
theano
.
tensor
.
continuous_dtypes
:
return
[
x
.
zeros_like
(
dtype
=
theano
.
config
.
floatX
)]
return
[
x
.
zeros_like
(
dtype
=
theano
.
config
.
floatX
)]
gz
,
=
grads
gz
,
=
grads
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
ac8ce341
...
@@ -8178,7 +8178,7 @@ def test_composite_neg_bool():
...
@@ -8178,7 +8178,7 @@ def test_composite_neg_bool():
# `-numpy.bool_(True)` is False and `-numpy.bool_(False)` is True.
# `-numpy.bool_(True)` is False and `-numpy.bool_(False)` is True.
x
=
theano
.
tensor
.
vector
()
x
=
theano
.
tensor
.
vector
()
f
=
theano
.
function
([
x
],
-
(
x
>
0
),
mode
=
theano
.
Mode
(
linker
=
'py'
))
f
=
theano
.
function
([
x
],
-
(
x
>
0
),
mode
=
theano
.
Mode
(
linker
=
'py'
))
utt
.
assert_allclose
(
f
([
-
1
,
0
,
1
]),
[
0
,
0
,
-
1
])
utt
.
assert_allclose
(
f
([
-
1
,
0
,
1
]),
[
False
,
False
,
True
])
"""
"""
...
...
theano/tensor/tests/test_elemwise.py
浏览文件 @
ac8ce341
...
@@ -452,10 +452,6 @@ class test_CAReduce(unittest_tools.InferShapeTester):
...
@@ -452,10 +452,6 @@ class test_CAReduce(unittest_tools.InferShapeTester):
else
:
else
:
self
.
fail
()
self
.
fail
()
else
:
else
:
# numpy.{all,any} return bool type,
# but theano ops return an int8 array instead
if
scalar_op
in
[
scalar
.
and_
,
scalar
.
or_
]:
zv
=
numpy
.
asarray
(
zv
,
dtype
=
'int8'
)
if
test_nan
:
if
test_nan
:
try
:
try
:
self
.
assertTrue
(
self
.
assertTrue
(
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论