Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4765f30e
提交
4765f30e
authored
6月 12, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Additional correctins on class Unique
上级
83570378
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
12 行增加
和
25 行删除
+12
-25
extra_ops.py
theano/tensor/extra_ops.py
+8
-14
test_extra_ops.py
theano/tensor/tests/test_extra_ops.py
+4
-11
没有找到文件。
theano/tensor/extra_ops.py
浏览文件 @
4765f30e
import
numpy
as
np
import
numpy
as
np
import
numpy
import
numpy
import
warnings
import
warnings
import
theano
import
theano
from
theano.tensor
import
basic
from
theano.tensor
import
basic
from
theano.tensor
import
nlinalg
from
theano.tensor
import
nlinalg
from
theano
import
gof
,
scalar
from
theano
import
gof
,
scalar
from
theano.gradient
import
DisconnectedType
from
theano.gradient
import
DisconnectedType
tensor
=
basic
tensor
=
basic
...
@@ -1014,29 +1013,24 @@ class Unique(theano.Op):
...
@@ -1014,29 +1013,24 @@ class Unique(theano.Op):
return_counts
=
False
):
return_counts
=
False
):
self
.
return_index
=
return_index
self
.
return_index
=
return_index
self
.
return_inverse
=
return_inverse
self
.
return_inverse
=
return_inverse
self
.
return_counts
=
return_counts
self
.
return_counts
=
return_counts
if
self
.
return_counts
==
True
and
np
.
__version__
<
"1.9.0"
:
numpy_ver
=
[
int
(
n
)
for
n
in
numpy
.
__version__
.
split
(
'.'
)[:
2
]]
if
self
.
return_counts
==
True
and
bool
(
numpy_ver
<
[
1
,
9
])
:
raise
RuntimeError
(
raise
RuntimeError
(
"Numpy version = "
+
np
.
__version__
+
"Numpy version = "
+
np
.
__version__
+
". Option 'return_counts=True' works starting"
". Option 'return_counts=True' works starting"
" from version 1.9.0."
)
" from version 1.9.0."
)
def
make_node
(
self
,
x
):
def
make_node
(
self
,
x
):
x
=
basic
.
as_tensor_variable
(
x
)
x
=
basic
.
as_tensor_variable
(
x
)
#x = x.flatten()
outputs
=
[
basic
.
TensorType
(
broadcastable
=
[
False
],
dtype
=
x
.
dtype
)()]
outputs
=
[]
# output0 = basic.TensorType(broadcastable=[False], dtype=x.dtype)()
output0
=
x
.
flatten
()
.
type
()
outputs
.
append
(
output0
)
typ
=
basic
.
TensorType
(
broadcastable
=
[
False
],
dtype
=
'int64'
)
typ
=
basic
.
TensorType
(
broadcastable
=
[
False
],
dtype
=
'int64'
)
if
self
.
return_index
:
if
self
.
return_index
:
outputs
.
append
(
typ
())
outputs
.
append
(
typ
())
if
self
.
return_inverse
:
if
self
.
return_inverse
:
outputs
.
append
(
typ
())
outputs
.
append
(
typ
())
if
self
.
return_counts
:
if
self
.
return_counts
:
outputs
.
append
(
typ
())
outputs
.
append
(
typ
())
return
theano
.
Apply
(
self
,
[
x
],
outputs
)
return
theano
.
Apply
(
self
,
[
x
],
outputs
)
def
perform
(
self
,
node
,
inputs
,
output_storage
):
def
perform
(
self
,
node
,
inputs
,
output_storage
):
...
@@ -1061,7 +1055,7 @@ class Unique(theano.Op):
...
@@ -1061,7 +1055,7 @@ class Unique(theano.Op):
def
infer_shape
(
self
,
node
,
i0_shapes
):
def
infer_shape
(
self
,
node
,
i0_shapes
):
ret
=
node
.
fgraph
.
shape_feature
.
default_infer_shape
(
node
,
i0_shapes
)
ret
=
node
.
fgraph
.
shape_feature
.
default_infer_shape
(
node
,
i0_shapes
)
if
self
.
return_inverse
:
if
self
.
return_inverse
:
shape
=
(
np
.
prod
(
i0_shapes
[
0
]),
)
shape
=
(
basic
.
prod
(
i0_shapes
[
0
]),
)
if
self
.
return_index
:
if
self
.
return_index
:
ret
[
2
]
=
shape
ret
[
2
]
=
shape
return
ret
return
ret
...
...
theano/tensor/tests/test_extra_ops.py
浏览文件 @
4765f30e
...
@@ -2,10 +2,9 @@ from nose.plugins.attrib import attr
...
@@ -2,10 +2,9 @@ from nose.plugins.attrib import attr
import
numpy
as
np
import
numpy
as
np
import
numpy
import
numpy
import
unittest
import
unittest
import
theano
import
theano
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
from
theano.tensor.extra_ops
import
(
CumsumOp
,
cumsum
,
CumprodOp
,
cumprod
,
from
theano.tensor.extra_ops
import
(
CumsumOp
,
cumsum
,
CumprodOp
,
cumprod
,
BinCountOp
,
bincount
,
DiffOp
,
diff
,
BinCountOp
,
bincount
,
DiffOp
,
diff
,
squeeze
,
compress
,
RepeatOp
,
repeat
,
squeeze
,
compress
,
RepeatOp
,
repeat
,
...
@@ -671,7 +670,7 @@ class test_Unique(utt.InferShapeTester):
...
@@ -671,7 +670,7 @@ class test_Unique(utt.InferShapeTester):
Unique
(
True
),
Unique
(
True
),
Unique
(
False
,
True
),
Unique
(
False
,
True
),
Unique
(
True
,
True
)]
Unique
(
True
,
True
)]
if
np
.
__version__
>=
"1.9.0"
:
if
bool
(
numpy_ver
>=
[
1
,
9
])
:
self
.
ops
.
extend
([
self
.
ops
.
extend
([
Unique
(
False
,
False
,
True
),
Unique
(
False
,
False
,
True
),
Unique
(
True
,
False
,
True
),
Unique
(
True
,
False
,
True
),
...
@@ -689,7 +688,7 @@ class test_Unique(utt.InferShapeTester):
...
@@ -689,7 +688,7 @@ class test_Unique(utt.InferShapeTester):
np
.
unique
(
inp
,
True
),
np
.
unique
(
inp
,
True
),
np
.
unique
(
inp
,
False
,
True
),
np
.
unique
(
inp
,
False
,
True
),
np
.
unique
(
inp
,
True
,
True
)]
np
.
unique
(
inp
,
True
,
True
)]
if
np
.
__version__
>=
"1.9.0"
:
if
bool
(
numpy_ver
>=
[
1
,
9
])
:
list_outs_expected
.
extend
([
list_outs_expected
.
extend
([
np
.
unique
(
inp
,
False
,
False
,
True
),
np
.
unique
(
inp
,
False
,
False
,
True
),
np
.
unique
(
inp
,
True
,
False
,
True
),
np
.
unique
(
inp
,
True
,
False
,
True
),
...
@@ -698,11 +697,8 @@ class test_Unique(utt.InferShapeTester):
...
@@ -698,11 +697,8 @@ class test_Unique(utt.InferShapeTester):
for
op
,
outs_expected
in
zip
(
self
.
ops
,
list_outs_expected
)
:
for
op
,
outs_expected
in
zip
(
self
.
ops
,
list_outs_expected
)
:
f
=
theano
.
function
(
inputs
=
[
x
],
outputs
=
op
(
x
,
return_list
=
True
))
f
=
theano
.
function
(
inputs
=
[
x
],
outputs
=
op
(
x
,
return_list
=
True
))
outs
=
f
(
inp
)
outs
=
f
(
inp
)
print
outs
# Compare the result computed to the expected value.
# Compare the result computed to the expected value.
for
out
,
out_exp
in
zip
(
outs
,
outs_expected
):
for
out
,
out_exp
in
zip
(
outs
,
outs_expected
):
print
out
print
out_exp
utt
.
assert_allclose
(
out
,
out_exp
)
utt
.
assert_allclose
(
out
,
out_exp
)
def
test_basic_matrix
(
self
):
def
test_basic_matrix
(
self
):
...
@@ -715,7 +711,7 @@ class test_Unique(utt.InferShapeTester):
...
@@ -715,7 +711,7 @@ class test_Unique(utt.InferShapeTester):
np
.
unique
(
inp
,
True
),
np
.
unique
(
inp
,
True
),
np
.
unique
(
inp
,
False
,
True
),
np
.
unique
(
inp
,
False
,
True
),
np
.
unique
(
inp
,
True
,
True
)]
np
.
unique
(
inp
,
True
,
True
)]
if
np
.
__version__
>=
"1.9.0"
:
if
bool
(
numpy_ver
>=
[
1
,
9
])
:
list_outs_expected
.
extend
([
list_outs_expected
.
extend
([
np
.
unique
(
inp
,
False
,
False
,
True
),
np
.
unique
(
inp
,
False
,
False
,
True
),
np
.
unique
(
inp
,
True
,
False
,
True
),
np
.
unique
(
inp
,
True
,
False
,
True
),
...
@@ -724,11 +720,8 @@ class test_Unique(utt.InferShapeTester):
...
@@ -724,11 +720,8 @@ class test_Unique(utt.InferShapeTester):
for
op
,
outs_expected
in
zip
(
self
.
ops
,
list_outs_expected
):
for
op
,
outs_expected
in
zip
(
self
.
ops
,
list_outs_expected
):
f
=
theano
.
function
(
inputs
=
[
x
],
outputs
=
op
(
x
,
return_list
=
True
))
f
=
theano
.
function
(
inputs
=
[
x
],
outputs
=
op
(
x
,
return_list
=
True
))
outs
=
f
(
inp
)
outs
=
f
(
inp
)
print
outs
# Compare the result computed to the expected value.
# Compare the result computed to the expected value.
for
out
,
out_exp
in
zip
(
outs
,
outs_expected
):
for
out
,
out_exp
in
zip
(
outs
,
outs_expected
):
print
out
print
out_exp
utt
.
assert_allclose
(
out
,
out_exp
)
utt
.
assert_allclose
(
out
,
out_exp
)
def
test_infer_shape_vector
(
self
):
def
test_infer_shape_vector
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论