Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b1b835dd
提交
b1b835dd
authored
10月 17, 2016
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove BinCountOp since it's deprecated and the test breaks with bool.
上级
dd288e88
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
2 行增加
和
173 行删除
+2
-173
extra_ops.py
theano/tensor/extra_ops.py
+0
-92
test_extra_ops.py
theano/tensor/tests/test_extra_ops.py
+2
-81
没有找到文件。
theano/tensor/extra_ops.py
浏览文件 @
b1b835dd
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
as
np
import
numpy
as
np
import
numpy
import
numpy
import
warnings
from
six.moves
import
xrange
from
six.moves
import
xrange
import
theano
import
theano
...
@@ -561,97 +560,6 @@ def diff(x, n=1, axis=-1):
...
@@ -561,97 +560,6 @@ def diff(x, n=1, axis=-1):
return
DiffOp
(
n
=
n
,
axis
=
axis
)(
x
)
return
DiffOp
(
n
=
n
,
axis
=
axis
)(
x
)
class
BinCountOp
(
theano
.
Op
):
"""
.. note:: Deprecated
Use bincount() instead.
See function bincount for docstring.
"""
compatible_type
=
(
'int8'
,
'int16'
,
'int32'
,
'int64'
,
'uint8'
,
'uint16'
,
'uint32'
,
'uint64'
)
"""Tuple of all compatible dtype for the parameter of this op."""
__props__
=
(
"minlength"
,)
def
__init__
(
self
,
minlength
=
None
):
self
.
minlength
=
minlength
def
make_node
(
self
,
x
,
weights
):
warnings
.
warn
((
"Tile op is deprecated, use tile function instead."
),
stacklevel
=
3
)
x
=
basic
.
as_tensor_variable
(
x
)
if
x
.
dtype
not
in
BinCountOp
.
compatible_type
:
raise
TypeError
(
"Inputs dtype must be an integer."
)
# Some dtypes are not supported by numpy's implementation of bincount.
# Until another one is available, we should fail at graph construction
# time, not wait for execution.
int_bitwidth
=
theano
.
configdefaults
.
python_int_bitwidth
()
if
int_bitwidth
==
64
:
numpy_unsupported_dtypes
=
(
'uint64'
,)
if
int_bitwidth
==
32
:
numpy_unsupported_dtypes
=
(
'uint32'
,
'int64'
,
'uint64'
)
intp_bitwidth
=
theano
.
configdefaults
.
local_bitwidth
()
if
intp_bitwidth
==
32
:
out_type
=
basic
.
ivector
()
elif
intp_bitwidth
==
64
:
out_type
=
basic
.
lvector
()
if
x
.
dtype
in
numpy_unsupported_dtypes
:
raise
TypeError
(
(
"Input dtypes
%
s are not supported by numpy.bincount, "
%
numpy_unsupported_dtypes
),
x
.
dtype
)
if
x
.
ndim
!=
1
:
raise
TypeError
(
"Inputs must be of dimension 1."
)
if
weights
is
None
:
weights
=
theano
.
gof
.
Constant
(
theano
.
gof
.
Generic
(),
None
)
else
:
weights
=
basic
.
as_tensor_variable
(
weights
)
out_type
=
basic
.
dvector
()
if
weights
.
ndim
!=
1
:
raise
TypeError
(
"Weights cannot have a number of"
"dimension different of 1."
)
return
theano
.
Apply
(
self
,
[
x
,
weights
],
[
out_type
])
def
perform
(
self
,
node
,
inputs
,
output_storage
):
x
=
inputs
[
0
]
weights
=
inputs
[
1
]
z
=
output_storage
[
0
]
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
:
out
=
np
.
bincount
(
x
,
weights
=
weights
,
minlength
=
self
.
minlength
)
else
:
out
=
np
.
bincount
(
x
,
weights
=
weights
)
z
[
0
]
=
theano
.
_asarray
(
out
,
dtype
=
node
.
outputs
[
0
]
.
dtype
)
def
grad
(
self
,
inputs
,
outputs_gradients
):
output
=
self
(
*
inputs
)
if
output
.
dtype
.
find
(
'int'
)
!=
-
1
:
return
[
inp
.
zeros_like
()
.
astype
(
theano
.
config
.
floatX
)
for
inp
in
inputs
]
raise
NotImplementedError
()
def
infer_shape
(
self
,
node
,
ins_shapes
):
x
=
node
.
inputs
[
0
]
m
=
basic
.
max
(
x
)
+
1
if
self
.
minlength
is
not
None
:
m
=
basic
.
maximum
(
m
,
self
.
minlength
)
return
[[
m
]]
def
bincount
(
x
,
weights
=
None
,
minlength
=
None
,
assert_nonneg
=
False
):
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.
...
...
theano/tensor/tests/test_extra_ops.py
浏览文件 @
b1b835dd
...
@@ -8,7 +8,7 @@ from theano.tests import unittest_tools as utt
...
@@ -8,7 +8,7 @@ from theano.tests import unittest_tools as utt
from
theano.tensor.extra_ops
import
(
SearchsortedOp
,
searchsorted
,
from
theano.tensor.extra_ops
import
(
SearchsortedOp
,
searchsorted
,
CumsumOp
,
cumsum
,
CumprodOp
,
cumprod
,
CumsumOp
,
cumsum
,
CumprodOp
,
cumprod
,
CpuContiguous
,
cpu_contiguous
,
BinCountOp
,
CpuContiguous
,
cpu_contiguous
,
bincount
,
DiffOp
,
diff
,
squeeze
,
compress
,
bincount
,
DiffOp
,
diff
,
squeeze
,
compress
,
RepeatOp
,
repeat
,
Bartlett
,
bartlett
,
RepeatOp
,
repeat
,
Bartlett
,
bartlett
,
FillDiagonal
,
fill_diagonal
,
FillDiagonal
,
fill_diagonal
,
...
@@ -215,12 +215,7 @@ class TestCumprodOp(utt.InferShapeTester):
...
@@ -215,12 +215,7 @@ class TestCumprodOp(utt.InferShapeTester):
utt
.
verify_grad
(
self
.
op_class
(
axis
=
axis
),
[
a
])
utt
.
verify_grad
(
self
.
op_class
(
axis
=
axis
),
[
a
])
class
TestBinCountOp
(
utt
.
InferShapeTester
):
class
TestBinCount
(
utt
.
InferShapeTester
):
def
setUp
(
self
):
super
(
TestBinCountOp
,
self
)
.
setUp
()
self
.
op_class
=
BinCountOp
self
.
op
=
BinCountOp
()
def
test_bincountFn
(
self
):
def
test_bincountFn
(
self
):
w
=
T
.
vector
(
'w'
)
w
=
T
.
vector
(
'w'
)
...
@@ -260,80 +255,6 @@ class TestBinCountOp(utt.InferShapeTester):
...
@@ -260,80 +255,6 @@ class TestBinCountOp(utt.InferShapeTester):
f5
=
theano
.
function
([
x
],
bincount
(
x
,
assert_nonneg
=
True
))
f5
=
theano
.
function
([
x
],
bincount
(
x
,
assert_nonneg
=
True
))
self
.
assertRaises
(
AssertionError
,
f5
,
a
)
self
.
assertRaises
(
AssertionError
,
f5
,
a
)
def
test_bincountOp
(
self
):
w
=
T
.
vector
(
'w'
)
for
dtype
in
(
'int8'
,
'int16'
,
'int32'
,
'int64'
,
'uint8'
,
'uint16'
,
'uint32'
,
'uint64'
):
# uint64 always fails
# int64 and uint32 also fail if python int are 32-bit
int_bitwidth
=
theano
.
configdefaults
.
python_int_bitwidth
()
if
int_bitwidth
==
64
:
numpy_unsupported_dtypes
=
(
'uint64'
,)
if
int_bitwidth
==
32
:
numpy_unsupported_dtypes
=
(
'uint32'
,
'int64'
,
'uint64'
)
x
=
T
.
vector
(
'x'
,
dtype
=
dtype
)
if
dtype
in
numpy_unsupported_dtypes
:
self
.
assertRaises
(
TypeError
,
BinCountOp
(),
x
)
else
:
a
=
np
.
random
.
randint
(
1
,
51
,
size
=
(
25
))
.
astype
(
dtype
)
weights
=
np
.
random
.
random
((
25
,))
.
astype
(
config
.
floatX
)
f1
=
theano
.
function
([
x
],
BinCountOp
()(
x
,
weights
=
None
))
f2
=
theano
.
function
([
x
,
w
],
BinCountOp
()(
x
,
weights
=
w
))
assert
(
np
.
bincount
(
a
)
==
f1
(
a
))
.
all
()
assert
np
.
allclose
(
np
.
bincount
(
a
,
weights
=
weights
),
f2
(
a
,
weights
))
f3
=
theano
.
function
([
x
],
BinCountOp
(
minlength
=
23
)(
x
,
weights
=
None
))
f4
=
theano
.
function
([
x
],
BinCountOp
(
minlength
=
5
)(
x
,
weights
=
None
))
assert
(
np
.
bincount
(
a
,
minlength
=
23
)
==
f3
(
a
))
.
all
()
assert
(
np
.
bincount
(
a
,
minlength
=
5
)
==
f4
(
a
))
.
all
()
@attr
(
'slow'
)
def
test_infer_shape
(
self
):
for
dtype
in
tensor
.
discrete_dtypes
:
# uint64 always fails
# int64 and uint32 also fail if python int are 32-bit
int_bitwidth
=
theano
.
configdefaults
.
python_int_bitwidth
()
if
int_bitwidth
==
64
:
numpy_unsupported_dtypes
=
(
'uint64'
,)
if
int_bitwidth
==
32
:
numpy_unsupported_dtypes
=
(
'uint32'
,
'int64'
,
'uint64'
)
x
=
T
.
vector
(
'x'
,
dtype
=
dtype
)
if
dtype
in
numpy_unsupported_dtypes
:
self
.
assertRaises
(
TypeError
,
BinCountOp
(),
x
)
else
:
self
.
_compile_and_check
([
x
],
[
BinCountOp
()(
x
,
None
)],
[
np
.
random
.
randint
(
1
,
51
,
size
=
(
25
,))
.
astype
(
dtype
)],
self
.
op_class
)
weights
=
np
.
random
.
random
((
25
,))
.
astype
(
config
.
floatX
)
self
.
_compile_and_check
([
x
],
[
BinCountOp
()(
x
,
weights
=
weights
)],
[
np
.
random
.
randint
(
1
,
51
,
size
=
(
25
,))
.
astype
(
dtype
)],
self
.
op_class
)
self
.
_compile_and_check
([
x
],
[
BinCountOp
(
minlength
=
60
)(
x
,
weights
=
weights
)],
[
np
.
random
.
randint
(
1
,
51
,
size
=
(
25
,))
.
astype
(
dtype
)],
self
.
op_class
)
self
.
_compile_and_check
([
x
],
[
BinCountOp
(
minlength
=
5
)(
x
,
weights
=
weights
)],
[
np
.
random
.
randint
(
1
,
51
,
size
=
(
25
,))
.
astype
(
dtype
)],
self
.
op_class
)
class
TestDiffOp
(
utt
.
InferShapeTester
):
class
TestDiffOp
(
utt
.
InferShapeTester
):
nb
=
10
# Number of time iterating for n
nb
=
10
# Number of time iterating for n
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论