Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8cb589f1
提交
8cb589f1
authored
3月 24, 2015
作者:
Amjad Almahairi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
checked if all elements are nonnegative, added an argument to enable the check, added a test
上级
f9d4ec48
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
13 行增加
和
2 行删除
+13
-2
extra_ops.py
theano/tensor/extra_ops.py
+9
-2
test_extra_ops.py
theano/tensor/tests/test_extra_ops.py
+4
-0
没有找到文件。
theano/tensor/extra_ops.py
浏览文件 @
8cb589f1
...
@@ -436,7 +436,7 @@ class BinCountOp(theano.Op):
...
@@ -436,7 +436,7 @@ class BinCountOp(theano.Op):
return
self
.
__class__
.
__name__
return
self
.
__class__
.
__name__
def
bincount
(
x
,
weights
=
None
,
minlength
=
None
):
def
bincount
(
x
,
weights
=
None
,
minlength
=
None
,
assert_nonneg
=
False
):
"""Count number of occurrences of each value in array of ints.
"""Count number of occurrences of each value in array of ints.
The number of bins (of size 1) is one larger than the largest
The number of bins (of size 1) is one larger than the largest
...
@@ -453,7 +453,9 @@ def bincount(x, weights=None, minlength=None):
...
@@ -453,7 +453,9 @@ def bincount(x, weights=None, minlength=None):
Optional.
Optional.
:param minlength: A minimum number of bins for the output array.
:param minlength: A minimum number of bins for the output array.
Optional.
Optional.
:param assert_nonneg: A flag that inserts an assert_op to check if
every input x is nonnegative.
Optional.
.. versionadded:: 0.6
.. versionadded:: 0.6
"""
"""
compatible_type
=
(
'int8'
,
'int16'
,
'int32'
,
'int64'
,
compatible_type
=
(
'int8'
,
'int16'
,
'int32'
,
'int64'
,
...
@@ -471,6 +473,11 @@ def bincount(x, weights=None, minlength=None):
...
@@ -471,6 +473,11 @@ def bincount(x, weights=None, minlength=None):
if
x
.
ndim
!=
1
:
if
x
.
ndim
!=
1
:
raise
TypeError
(
"Inputs must be of dimension 1."
)
raise
TypeError
(
"Inputs must be of dimension 1."
)
if
assert_nonneg
:
from
theano.tensor.opt
import
Assert
assert_op
=
Assert
(
'Input to bincount has negative values!'
)
x
=
assert_op
(
x
,
theano
.
tensor
.
all
(
x
>=
0
))
max_value
=
theano
.
tensor
.
cast
(
x
.
max
()
+
1
,
'int64'
)
max_value
=
theano
.
tensor
.
cast
(
x
.
max
()
+
1
,
'int64'
)
if
minlength
is
not
None
:
if
minlength
is
not
None
:
...
...
theano/tensor/tests/test_extra_ops.py
浏览文件 @
8cb589f1
...
@@ -14,6 +14,7 @@ from theano.tensor.extra_ops import (CumsumOp, cumsum, CumprodOp, cumprod,
...
@@ -14,6 +14,7 @@ from theano.tensor.extra_ops import (CumsumOp, cumsum, CumprodOp, cumprod,
to_one_hot
)
to_one_hot
)
from
theano
import
tensor
as
T
from
theano
import
tensor
as
T
from
theano
import
config
,
tensor
,
function
from
theano
import
config
,
tensor
,
function
from
nose.tools
import
assert_raises
numpy_ver
=
[
int
(
n
)
for
n
in
numpy
.
__version__
.
split
(
'.'
)[:
2
]]
numpy_ver
=
[
int
(
n
)
for
n
in
numpy
.
__version__
.
split
(
'.'
)[:
2
]]
...
@@ -138,6 +139,9 @@ class TestBinCountOp(utt.InferShapeTester):
...
@@ -138,6 +139,9 @@ class TestBinCountOp(utt.InferShapeTester):
f4
=
theano
.
function
([
x
],
bincount
(
x
,
minlength
=
5
))
f4
=
theano
.
function
([
x
],
bincount
(
x
,
minlength
=
5
))
assert
(
np
.
bincount
(
a
,
minlength
=
23
)
==
f3
(
a
))
.
all
()
assert
(
np
.
bincount
(
a
,
minlength
=
23
)
==
f3
(
a
))
.
all
()
assert
(
np
.
bincount
(
a
,
minlength
=
5
)
==
f4
(
a
))
.
all
()
assert
(
np
.
bincount
(
a
,
minlength
=
5
)
==
f4
(
a
))
.
all
()
a
[
0
]
=
-
1
f5
=
theano
.
function
([
x
],
bincount
(
x
,
assert_nonneg
=
True
))
self
.
assertRaises
(
AssertionError
,
f5
,
a
)
def
test_bincountOp
(
self
):
def
test_bincountOp
(
self
):
w
=
T
.
vector
(
'w'
)
w
=
T
.
vector
(
'w'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论