Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e554dd5a
提交
e554dd5a
authored
5月 19, 2016
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4540 from nouiz/fix_test
Finish the regression fix in gh-4533
上级
5c02b98e
a84654ad
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
21 行增加
和
7 行删除
+21
-7
opt.py
theano/gpuarray/opt.py
+2
-1
extra_ops.py
theano/tensor/extra_ops.py
+13
-2
test_extra_ops.py
theano/tensor/tests/test_extra_ops.py
+6
-4
没有找到文件。
theano/gpuarray/opt.py
浏览文件 @
e554dd5a
...
@@ -975,7 +975,8 @@ def local_assert_no_cpu_op(node):
...
@@ -975,7 +975,8 @@ def local_assert_no_cpu_op(node):
assert_no_cpu_op
=
theano
.
tensor
.
opt
.
in2out
(
local_assert_no_cpu_op
,
assert_no_cpu_op
=
theano
.
tensor
.
opt
.
in2out
(
local_assert_no_cpu_op
,
name
=
'assert_no_cpu_op'
)
name
=
'assert_no_cpu_op'
)
# 49.2 is after device specialization & fusion optimizations for last transfers
# 49.2 is after device specialization & fusion optimizations for last transfers
optdb
.
register
(
'gpua_assert_no_cpu_op'
,
assert_no_cpu_op
,
49.2
)
optdb
.
register
(
'gpua_assert_no_cpu_op'
,
assert_no_cpu_op
,
49.2
,
'assert_no_cpu_op'
)
def
tensor_to_gpu
(
x
,
context_name
):
def
tensor_to_gpu
(
x
,
context_name
):
...
...
theano/tensor/extra_ops.py
浏览文件 @
e554dd5a
...
@@ -102,6 +102,11 @@ class SearchsortedOp(theano.Op):
...
@@ -102,6 +102,11 @@ class SearchsortedOp(theano.Op):
return
theano
.
Apply
(
self
,
[
x
,
v
],
[
out_type
()])
return
theano
.
Apply
(
self
,
[
x
,
v
],
[
out_type
()])
else
:
else
:
sorter
=
basic
.
as_tensor
(
sorter
,
ndim
=
1
)
sorter
=
basic
.
as_tensor
(
sorter
,
ndim
=
1
)
if
(
theano
.
configdefaults
.
python_int_bitwidth
()
==
32
and
sorter
.
dtype
==
'int64'
):
raise
TypeError
(
"numpy.searchsorted with Python 32bit do not support a"
" sorter of int64."
)
if
sorter
.
type
not
in
basic
.
int_vector_types
:
if
sorter
.
type
not
in
basic
.
int_vector_types
:
raise
TypeError
(
'sorter must be an integer vector'
,
raise
TypeError
(
'sorter must be an integer vector'
,
sorter
.
type
)
sorter
.
type
)
...
@@ -119,7 +124,8 @@ class SearchsortedOp(theano.Op):
...
@@ -119,7 +124,8 @@ class SearchsortedOp(theano.Op):
sorter
=
None
sorter
=
None
z
=
output_storage
[
0
]
z
=
output_storage
[
0
]
z
[
0
]
=
np
.
searchsorted
(
x
,
v
,
side
=
params
,
sorter
=
sorter
)
z
[
0
]
=
np
.
searchsorted
(
x
,
v
,
side
=
params
,
sorter
=
sorter
)
.
astype
(
node
.
outputs
[
0
]
.
dtype
)
def
c_support_code_struct
(
self
,
node
,
name
):
def
c_support_code_struct
(
self
,
node
,
name
):
return
"""
return
"""
...
@@ -154,10 +160,15 @@ class SearchsortedOp(theano.Op):
...
@@ -154,10 +160,15 @@ class SearchsortedOp(theano.Op):
right_
%(name)
s ? NPY_SEARCHLEFT : NPY_SEARCHRIGHT, (PyObject*)
%(sorter)
s);
right_
%(name)
s ? NPY_SEARCHLEFT : NPY_SEARCHRIGHT, (PyObject*)
%(sorter)
s);
if (!
%(z)
s)
if (!
%(z)
s)
%(fail)
s;
%(fail)
s;
if (PyArray_TYPE(
%(z)
s) != NPY_INT64){
PyObject * tmp = PyArray_Cast(
%(z)
s, NPY_INT64);
Py_XDECREF(
%(z)
s);
%(z)
s = (PyArrayObject*) tmp;
}
"""
%
locals
()
"""
%
locals
()
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
1
,)
return
(
2
,)
def
grad
(
self
,
inputs
,
output_gradients
):
def
grad
(
self
,
inputs
,
output_gradients
):
num_ins
=
len
(
inputs
)
num_ins
=
len
(
inputs
)
...
...
theano/tensor/tests/test_extra_ops.py
浏览文件 @
e554dd5a
...
@@ -50,14 +50,14 @@ class TestSearchsortedOp(utt.InferShapeTester):
...
@@ -50,14 +50,14 @@ class TestSearchsortedOp(utt.InferShapeTester):
self
.
a
=
30
*
np
.
random
.
random
(
50
)
.
astype
(
config
.
floatX
)
self
.
a
=
30
*
np
.
random
.
random
(
50
)
.
astype
(
config
.
floatX
)
self
.
b
=
30
*
np
.
random
.
random
((
8
,
10
,
5
))
.
astype
(
config
.
floatX
)
self
.
b
=
30
*
np
.
random
.
random
((
8
,
10
,
5
))
.
astype
(
config
.
floatX
)
self
.
idx_sorted
=
np
.
argsort
(
self
.
a
)
self
.
idx_sorted
=
np
.
argsort
(
self
.
a
)
.
astype
(
'int32'
)
def
test_searchsortedOp_on_sorted_input
(
self
):
def
test_searchsortedOp_on_sorted_input
(
self
):
f
=
theano
.
function
([
self
.
x
,
self
.
v
],
searchsorted
(
self
.
x
,
self
.
v
))
f
=
theano
.
function
([
self
.
x
,
self
.
v
],
searchsorted
(
self
.
x
,
self
.
v
))
assert
np
.
allclose
(
np
.
searchsorted
(
self
.
a
[
self
.
idx_sorted
],
self
.
b
),
assert
np
.
allclose
(
np
.
searchsorted
(
self
.
a
[
self
.
idx_sorted
],
self
.
b
),
f
(
self
.
a
[
self
.
idx_sorted
],
self
.
b
))
f
(
self
.
a
[
self
.
idx_sorted
],
self
.
b
))
sorter
=
T
.
vector
(
'sorter'
,
dtype
=
'int
64
'
)
sorter
=
T
.
vector
(
'sorter'
,
dtype
=
'int
32
'
)
f
=
theano
.
function
([
self
.
x
,
self
.
v
,
sorter
],
self
.
x
.
searchsorted
(
self
.
v
,
sorter
=
sorter
,
side
=
'right'
))
f
=
theano
.
function
([
self
.
x
,
self
.
v
,
sorter
],
self
.
x
.
searchsorted
(
self
.
v
,
sorter
=
sorter
,
side
=
'right'
))
assert
np
.
allclose
(
self
.
a
.
searchsorted
(
self
.
b
,
sorter
=
self
.
idx_sorted
,
side
=
'right'
),
assert
np
.
allclose
(
self
.
a
.
searchsorted
(
self
.
b
,
sorter
=
self
.
idx_sorted
,
side
=
'right'
),
f
(
self
.
a
,
self
.
b
,
self
.
idx_sorted
))
f
(
self
.
a
,
self
.
b
,
self
.
idx_sorted
))
...
@@ -80,7 +80,9 @@ class TestSearchsortedOp(utt.InferShapeTester):
...
@@ -80,7 +80,9 @@ class TestSearchsortedOp(utt.InferShapeTester):
self
.
x
,
self
.
v
,
sorter
=
sorter
)
self
.
x
,
self
.
v
,
sorter
=
sorter
)
def
test_searchsortedOp_on_int_sorter
(
self
):
def
test_searchsortedOp_on_int_sorter
(
self
):
compatible_types
=
(
'int8'
,
'int16'
,
'int32'
,
'int64'
,)
compatible_types
=
(
'int8'
,
'int16'
,
'int32'
)
if
theano
.
configdefaults
.
python_int_bitwidth
()
==
64
:
compatible_types
+=
(
'int64'
,)
# 'uint8', 'uint16', 'uint32', 'uint64')
# 'uint8', 'uint16', 'uint32', 'uint64')
for
dtype
in
compatible_types
:
for
dtype
in
compatible_types
:
sorter
=
T
.
vector
(
'sorter'
,
dtype
=
dtype
)
sorter
=
T
.
vector
(
'sorter'
,
dtype
=
dtype
)
...
@@ -104,7 +106,7 @@ class TestSearchsortedOp(utt.InferShapeTester):
...
@@ -104,7 +106,7 @@ class TestSearchsortedOp(utt.InferShapeTester):
self
.
op_class
)
self
.
op_class
)
# Test parameter ``sorter``
# Test parameter ``sorter``
sorter
=
T
.
vector
(
'sorter'
,
dtype
=
"int
64
"
)
sorter
=
T
.
vector
(
'sorter'
,
dtype
=
"int
32
"
)
self
.
_compile_and_check
([
self
.
x
,
self
.
v
,
sorter
],
self
.
_compile_and_check
([
self
.
x
,
self
.
v
,
sorter
],
[
searchsorted
(
self
.
x
,
self
.
v
,
sorter
=
sorter
)],
[
searchsorted
(
self
.
x
,
self
.
v
,
sorter
=
sorter
)],
[
self
.
a
,
self
.
b
,
self
.
idx_sorted
],
[
self
.
a
,
self
.
b
,
self
.
idx_sorted
],
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论