Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
973fce3e
提交
973fce3e
authored
9月 25, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix test and raise a good error if we have an older numpy version.
上级
4c0c2258
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
19 行增加
和
3 行删除
+19
-3
extra_ops.py
theano/tensor/extra_ops.py
+10
-1
test_extra_ops.py
theano/tensor/tests/test_extra_ops.py
+9
-2
没有找到文件。
theano/tensor/extra_ops.py
浏览文件 @
973fce3e
...
...
@@ -91,6 +91,12 @@ class BinCountOp(theano.Op):
def
__init__
(
self
,
minlength
=
None
):
self
.
minlength
=
minlength
if
minlength
is
not
None
:
numpy_ver
=
[
int
(
n
)
for
n
in
numpy
.
__version__
.
split
(
'.'
)[:
2
]]
if
not
bool
(
numpy_ver
>=
[
1
,
6
]):
raise
NotImplementedError
(
"BinCountOp with minlength attribute"
" need NumPy 1.6 or higher."
)
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
)
and
...
...
@@ -145,8 +151,11 @@ class BinCountOp(theano.Op):
if
weights
is
not
None
and
weights
.
shape
!=
x
.
shape
:
raise
TypeError
(
"All inputs must have the same shape."
)
#Needed for numpy 1.4.1 compatibility
if
self
.
minlength
:
z
[
0
]
=
np
.
bincount
(
x
,
weights
=
weights
,
minlength
=
self
.
minlength
)
else
:
z
[
0
]
=
np
.
bincount
(
x
,
weights
=
weights
)
def
grad
(
self
,
inputs
,
outputs_gradients
):
output
=
self
(
*
inputs
)
...
...
theano/tensor/tests/test_extra_ops.py
浏览文件 @
973fce3e
...
...
@@ -10,6 +10,9 @@ from theano import tensor as T
from
theano
import
config
,
tensor
,
function
numpy_ver
=
[
int
(
n
)
for
n
in
numpy
.
__version__
.
split
(
'.'
)[:
2
]]
numpy_16
=
bool
(
numpy_ver
>=
[
1
,
6
])
class
TestBinCountOp
(
utt
.
InferShapeTester
):
def
setUp
(
self
):
super
(
TestBinCountOp
,
self
)
.
setUp
()
...
...
@@ -39,12 +42,14 @@ class TestBinCountOp(utt.InferShapeTester):
f1
=
theano
.
function
([
x
],
bincount
(
x
))
f2
=
theano
.
function
([
x
,
w
],
bincount
(
x
,
weights
=
w
))
f3
=
theano
.
function
([
x
],
bincount
(
x
,
minlength
=
23
))
f4
=
theano
.
function
([
x
],
bincount
(
x
,
minlength
=
5
))
assert
(
np
.
bincount
(
a
)
==
f1
(
a
))
.
all
()
assert
np
.
allclose
(
np
.
bincount
(
a
,
weights
=
weights
),
f2
(
a
,
weights
))
if
not
numpy_16
:
continue
f3
=
theano
.
function
([
x
],
bincount
(
x
,
minlength
=
23
))
f4
=
theano
.
function
([
x
],
bincount
(
x
,
minlength
=
5
))
assert
(
np
.
bincount
(
a
,
minlength
=
23
)
==
f3
(
a
))
.
all
()
assert
(
np
.
bincount
(
a
,
minlength
=
5
)
==
f4
(
a
))
.
all
()
...
...
@@ -79,6 +84,8 @@ class TestBinCountOp(utt.InferShapeTester):
50
,
size
=
(
25
,))
.
astype
(
dtype
)],
self
.
op_class
)
if
not
numpy_16
:
continue
self
.
_compile_and_check
(
[
x
],
[
bincount
(
x
,
minlength
=
60
)],
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论