Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d7f7854a
提交
d7f7854a
authored
7月 06, 2017
作者:
Frédéric Bastien
提交者:
GitHub
7月 06, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6108 from abergeron/careduce_compile
Make the CAReduce tests faster
上级
9069b555
bef2354d
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
65 行增加
和
56 行删除
+65
-56
params_type.py
theano/gof/params_type.py
+3
-1
test_elemwise.py
theano/gpuarray/tests/test_elemwise.py
+16
-5
elemwise.py
theano/tensor/elemwise.py
+2
-2
elemwise_cgen.py
theano/tensor/elemwise_cgen.py
+2
-4
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+42
-44
没有找到文件。
theano/gof/params_type.py
浏览文件 @
d7f7854a
...
@@ -655,7 +655,7 @@ class ParamsType(Type):
...
@@ -655,7 +655,7 @@ class ParamsType(Type):
return
list
(
sorted
(
list
(
c_support_code_set
)))
+
[
final_struct_code
]
return
list
(
sorted
(
list
(
c_support_code_set
)))
+
[
final_struct_code
]
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
((
2
,),
tuple
(
t
.
c_code_cache_version
()
for
t
in
self
.
types
))
return
((
3
,),
tuple
(
t
.
c_code_cache_version
()
for
t
in
self
.
types
))
# As this struct has constructor and destructor, it could be instanciated on stack,
# As this struct has constructor and destructor, it could be instanciated on stack,
# but current implementations of C ops will then pass the instance by value at functions,
# but current implementations of C ops will then pass the instance by value at functions,
...
@@ -684,6 +684,7 @@ class ParamsType(Type):
...
@@ -684,6 +684,7 @@ class ParamsType(Type):
/* Seems c_init() is not called for a op param. So I call `new` here. */
/* Seems c_init() is not called for a op param. So I call `new` here. */
%(name)
s = new
%(struct_name)
s;
%(name)
s = new
%(struct_name)
s;
{ // This need a separate namespace for Clinker
const char* fields[] = {
%(fields_list)
s};
const char* fields[] = {
%(fields_list)
s};
if (py_
%(name)
s == Py_None) {
if (py_
%(name)
s == Py_None) {
PyErr_SetString(PyExc_ValueError, "ParamsType: expected an object, not None.");
PyErr_SetString(PyExc_ValueError, "ParamsType: expected an object, not None.");
...
@@ -703,5 +704,6 @@ class ParamsType(Type):
...
@@ -703,5 +704,6 @@ class ParamsType(Type):
%(fail)
s
%(fail)
s
}
}
}
}
}
"""
%
dict
(
name
=
name
,
struct_name
=
self
.
name
,
length
=
self
.
length
,
fail
=
sub
[
'fail'
],
"""
%
dict
(
name
=
name
,
struct_name
=
self
.
name
,
length
=
self
.
length
,
fail
=
sub
[
'fail'
],
fields_list
=
'"
%
s"'
%
'", "'
.
join
(
self
.
fields
))
fields_list
=
'"
%
s"'
%
'", "'
.
join
(
self
.
fields
))
theano/gpuarray/tests/test_elemwise.py
浏览文件 @
d7f7854a
...
@@ -7,7 +7,7 @@ import scipy.special
...
@@ -7,7 +7,7 @@ import scipy.special
import
theano
import
theano
from
theano
import
scalar
,
gof
,
tensor
from
theano
import
scalar
,
gof
,
tensor
from
theano.compile
import
DebugMode
from
theano.compile
import
DebugMode
,
Mode
from
theano.tests.unittest_tools
import
SkipTest
,
assert_allclose
from
theano.tests.unittest_tools
import
SkipTest
,
assert_allclose
from
theano.tensor.tests
import
test_elemwise
from
theano.tensor.tests
import
test_elemwise
...
@@ -212,7 +212,9 @@ class test_GpuCAReduceCPY(test_elemwise.test_CAReduce):
...
@@ -212,7 +212,9 @@ class test_GpuCAReduceCPY(test_elemwise.test_CAReduce):
def
test_perform
(
self
):
def
test_perform
(
self
):
for
dtype
in
self
.
dtypes
+
self
.
bin_dtypes
:
for
dtype
in
self
.
dtypes
+
self
.
bin_dtypes
:
for
op
in
self
.
reds
:
for
op
in
self
.
reds
:
self
.
with_linker
(
gof
.
PerformLinker
(),
op
,
dtype
=
dtype
,
self
.
with_mode
(
Mode
(
linker
=
'py'
,
optimizer
=
mode_with_gpu
.
optimizer
),
op
,
dtype
=
dtype
,
pre_scalar_op
=
self
.
pre_scalar_op
)
pre_scalar_op
=
self
.
pre_scalar_op
)
def
test_perform_nan
(
self
):
def
test_perform_nan
(
self
):
...
@@ -220,14 +222,18 @@ class test_GpuCAReduceCPY(test_elemwise.test_CAReduce):
...
@@ -220,14 +222,18 @@ class test_GpuCAReduceCPY(test_elemwise.test_CAReduce):
if
not
dtype
.
startswith
(
'float'
):
if
not
dtype
.
startswith
(
'float'
):
continue
continue
for
op
in
self
.
reds
:
for
op
in
self
.
reds
:
self
.
with_linker
(
gof
.
PerformLinker
(),
op
,
dtype
=
dtype
,
self
.
with_mode
(
Mode
(
linker
=
'py'
,
optimizer
=
mode_with_gpu
.
optimizer
),
op
,
dtype
=
dtype
,
test_nan
=
True
,
test_nan
=
True
,
pre_scalar_op
=
self
.
pre_scalar_op
)
pre_scalar_op
=
self
.
pre_scalar_op
)
def
test_c
(
self
):
def
test_c
(
self
):
for
dtype
in
self
.
dtypes
+
self
.
bin_dtypes
:
for
dtype
in
self
.
dtypes
+
self
.
bin_dtypes
:
for
op
in
self
.
reds
:
for
op
in
self
.
reds
:
self
.
with_linker
(
gof
.
CLinker
(),
op
,
dtype
=
dtype
,
self
.
with_mode
(
Mode
(
linker
=
'c'
,
optimizer
=
mode_with_gpu
.
optimizer
),
op
,
dtype
=
dtype
,
pre_scalar_op
=
self
.
pre_scalar_op
)
pre_scalar_op
=
self
.
pre_scalar_op
)
def
test_c_nan
(
self
):
def
test_c_nan
(
self
):
...
@@ -235,7 +241,9 @@ class test_GpuCAReduceCPY(test_elemwise.test_CAReduce):
...
@@ -235,7 +241,9 @@ class test_GpuCAReduceCPY(test_elemwise.test_CAReduce):
if
not
dtype
.
startswith
(
'float'
):
if
not
dtype
.
startswith
(
'float'
):
continue
continue
for
op
in
self
.
reds
:
for
op
in
self
.
reds
:
self
.
with_linker
(
gof
.
CLinker
(),
op
,
dtype
=
dtype
,
self
.
with_mode
(
Mode
(
linker
=
'c'
,
optimizer
=
mode_with_gpu
.
optimizer
),
op
,
dtype
=
dtype
,
test_nan
=
True
,
test_nan
=
True
,
pre_scalar_op
=
self
.
pre_scalar_op
)
pre_scalar_op
=
self
.
pre_scalar_op
)
...
@@ -334,6 +342,9 @@ class test_GpuCAReduceCuda(test_GpuCAReduceCPY):
...
@@ -334,6 +342,9 @@ class test_GpuCAReduceCuda(test_GpuCAReduceCPY):
scalar
.
maximum
,
scalar
.
minimum
]
scalar
.
maximum
,
scalar
.
minimum
]
pre_scalar_op
=
None
pre_scalar_op
=
None
def
test_perform_noopt
(
self
):
return
def
test_perform
(
self
):
def
test_perform
(
self
):
return
return
...
...
theano/tensor/elemwise.py
浏览文件 @
d7f7854a
...
@@ -1202,7 +1202,7 @@ second dimension
...
@@ -1202,7 +1202,7 @@ second dimension
return
support_code
return
support_code
def
c_code_cache_version_apply
(
self
,
node
):
def
c_code_cache_version_apply
(
self
,
node
):
version
=
[
1
2
]
# the version corresponding to the c code in this Op
version
=
[
1
3
]
# the version corresponding to the c code in this Op
# now we insert versions for the ops on which we depend...
# now we insert versions for the ops on which we depend...
scalar_node
=
Apply
(
scalar_node
=
Apply
(
...
@@ -1622,7 +1622,7 @@ class CAReduce(Op):
...
@@ -1622,7 +1622,7 @@ class CAReduce(Op):
def
c_code_cache_version_apply
(
self
,
node
):
def
c_code_cache_version_apply
(
self
,
node
):
# the version corresponding to the c code in this Op
# the version corresponding to the c code in this Op
version
=
[
7
]
version
=
[
8
]
# now we insert versions for the ops on which we depend...
# now we insert versions for the ops on which we depend...
scalar_node
=
Apply
(
scalar_node
=
Apply
(
...
...
theano/tensor/elemwise_cgen.py
浏览文件 @
d7f7854a
...
@@ -72,16 +72,12 @@ def make_checks(loop_orders, dtypes, sub):
...
@@ -72,16 +72,12 @@ def make_checks(loop_orders, dtypes, sub):
%(var)
s_n
%(index)
s = PyArray_DIMS(
%(var)
s)[
%(index)
s];
%(var)
s_n
%(index)
s = PyArray_DIMS(
%(var)
s)[
%(index)
s];
%(var)
s_stride
%(index)
s = PyArray_STRIDES(
%(var)
s)[
%(index)
s] / sizeof(
%(dtype)
s);
%(var)
s_stride
%(index)
s = PyArray_STRIDES(
%(var)
s)[
%(index)
s] / sizeof(
%(dtype)
s);
%(var)
s_jump
%(index)
s_
%(j)
s =
%(jump)
s;
%(var)
s_jump
%(index)
s_
%(j)
s =
%(jump)
s;
//printf("
%(var)
s_jump
%(index)
s_
%(j)
s is:");
//std::cout <<
%(var)
s_jump
%(index)
s_
%(j)
s << std::endl;
"""
%
locals
()
"""
%
locals
()
adjust
=
"
%(var)
s_n
%(index)
s*
%(var)
s_stride
%(index)
s"
%
locals
()
adjust
=
"
%(var)
s_n
%(index)
s*
%(var)
s_stride
%(index)
s"
%
locals
()
else
:
else
:
jump
=
"-(
%
s)"
%
adjust
jump
=
"-(
%
s)"
%
adjust
init
+=
"""
init
+=
"""
%(var)
s_jump
%(index)
s_
%(j)
s =
%(jump)
s;
%(var)
s_jump
%(index)
s_
%(j)
s =
%(jump)
s;
//printf("
%(var)
s_jump
%(index)
s_
%(j)
s is:");
//std::cout <<
%(var)
s_jump
%(index)
s_
%(j)
s << std::endl;
"""
%
locals
()
"""
%
locals
()
adjust
=
"0"
adjust
=
"0"
check
=
""
check
=
""
...
@@ -169,6 +165,8 @@ def make_alloc(loop_orders, dtype, sub, fortran='0'):
...
@@ -169,6 +165,8 @@ def make_alloc(loop_orders, dtype, sub, fortran='0'):
PyErr_Clear();
PyErr_Clear();
Py_XDECREF(
%(olv)
s);
Py_XDECREF(
%(olv)
s);
%(olv)
s = (PyArrayObject*)PyArray_EMPTY(
%(nd)
s, dims,
%(type)
s, 0);
%(olv)
s = (PyArrayObject*)PyArray_EMPTY(
%(nd)
s, dims,
%(type)
s, 0);
} else {
Py_DECREF(success);
}
}
}
}
if (!
%(olv)
s) {
if (!
%(olv)
s) {
...
...
theano/tensor/tests/test_elemwise.py
浏览文件 @
d7f7854a
...
@@ -15,7 +15,7 @@ from theano import gof, scalar, config
...
@@ -15,7 +15,7 @@ from theano import gof, scalar, config
from
theano
import
tensor
from
theano
import
tensor
from
theano.tensor
import
TensorType
,
as_tensor_variable
from
theano.tensor
import
TensorType
,
as_tensor_variable
from
theano.compile.mode
import
get_default_mode
from
theano.compile.mode
import
get_default_mode
,
Mode
from
theano.tensor.elemwise
import
(
CAReduce
,
Elemwise
,
DimShuffle
,
from
theano.tensor.elemwise
import
(
CAReduce
,
Elemwise
,
DimShuffle
,
Prod
,
ProdWithoutZeros
)
Prod
,
ProdWithoutZeros
)
from
theano.tests
import
unittest_tools
from
theano.tests
import
unittest_tools
...
@@ -365,7 +365,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
...
@@ -365,7 +365,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
((),
())]
((),
())]
type
=
TensorType
type
=
TensorType
def
with_
linker
(
self
,
linker
,
scalar_op
=
scalar
.
add
,
dtype
=
"floatX"
,
def
with_
mode
(
self
,
mode
,
scalar_op
=
scalar
.
add
,
dtype
=
"floatX"
,
pre_scalar_op
=
None
,
pre_scalar_op
=
None
,
test_nan
=
False
,
tensor_op
=
None
):
test_nan
=
False
,
tensor_op
=
None
):
for
xsh
,
tosum
in
self
.
cases
:
for
xsh
,
tosum
in
self
.
cases
:
...
@@ -383,7 +383,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
...
@@ -383,7 +383,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
if
tosum
is
None
:
if
tosum
is
None
:
tosum
=
list
(
range
(
len
(
xsh
)))
tosum
=
list
(
range
(
len
(
xsh
)))
f
=
copy
(
linker
)
.
accept
(
FunctionGraph
([
x
],
[
e
]))
.
make_function
(
)
f
=
theano
.
function
([
x
],
e
,
mode
=
mode
)
xv
=
np
.
asarray
(
np
.
random
.
rand
(
*
xsh
))
xv
=
np
.
asarray
(
np
.
random
.
rand
(
*
xsh
))
if
dtype
not
in
tensor
.
discrete_dtypes
:
if
dtype
not
in
tensor
.
discrete_dtypes
:
...
@@ -495,8 +495,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
...
@@ -495,8 +495,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
e
=
tensor_op
(
x
,
axis
=
tosum
)
e
=
tensor_op
(
x
,
axis
=
tosum
)
if
tosum
is
None
:
if
tosum
is
None
:
tosum
=
list
(
range
(
len
(
xsh
)))
tosum
=
list
(
range
(
len
(
xsh
)))
f
=
copy
(
linker
)
.
accept
(
FunctionGraph
([
x
],
f
=
theano
.
function
([
x
],
e
.
shape
,
mode
=
mode
)
[
e
.
shape
]))
.
make_function
()
if
not
(
scalar_op
in
[
scalar
.
maximum
,
scalar
.
minimum
]
and
if
not
(
scalar_op
in
[
scalar
.
maximum
,
scalar
.
minimum
]
and
((
xsh
==
()
or
np
.
prod
(
xsh
)
==
0
))):
((
xsh
==
()
or
np
.
prod
(
xsh
)
==
0
))):
try
:
try
:
...
@@ -505,69 +504,78 @@ class test_CAReduce(unittest_tools.InferShapeTester):
...
@@ -505,69 +504,78 @@ class test_CAReduce(unittest_tools.InferShapeTester):
# GpuCAReduce don't implement all cases when size is 0
# GpuCAReduce don't implement all cases when size is 0
assert
xv
.
size
==
0
assert
xv
.
size
==
0
def
test_perform_noopt
(
self
):
self
.
with_mode
(
Mode
(
linker
=
'py'
,
optimizer
=
None
),
scalar
.
add
,
dtype
=
'floatX'
)
def
test_perform
(
self
):
def
test_perform
(
self
):
for
dtype
in
[
"bool"
,
"floatX"
,
"complex64"
,
"complex128"
,
"int8"
,
"uint8"
]:
for
dtype
in
[
"bool"
,
"floatX"
,
"complex64"
,
"complex128"
,
"int8"
,
"uint8"
]:
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
add
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
add
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
mul
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
mul
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
maximum
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
maximum
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
minimum
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
minimum
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
and_
,
dtype
=
dtype
,
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
and_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
all
)
tensor_op
=
tensor
.
all
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
or_
,
dtype
=
dtype
,
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
or_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
any
)
tensor_op
=
tensor
.
any
)
for
dtype
in
[
"int8"
,
"uint8"
]:
for
dtype
in
[
"int8"
,
"uint8"
]:
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
or_
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
or_
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
and_
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
and_
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
xor
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
xor
,
dtype
=
dtype
)
def
test_perform_nan
(
self
):
def
test_perform_nan
(
self
):
for
dtype
in
[
"floatX"
,
"complex64"
,
"complex128"
]:
for
dtype
in
[
"floatX"
,
"complex64"
,
"complex128"
]:
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
add
,
dtype
=
dtype
,
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
add
,
dtype
=
dtype
,
test_nan
=
True
)
test_nan
=
True
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
mul
,
dtype
=
dtype
,
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
mul
,
dtype
=
dtype
,
test_nan
=
True
)
test_nan
=
True
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
maximum
,
dtype
=
dtype
,
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
maximum
,
dtype
=
dtype
,
test_nan
=
True
)
test_nan
=
True
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
minimum
,
dtype
=
dtype
,
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
minimum
,
dtype
=
dtype
,
test_nan
=
True
)
test_nan
=
True
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
or_
,
dtype
=
dtype
,
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
or_
,
dtype
=
dtype
,
test_nan
=
True
,
tensor_op
=
tensor
.
any
)
test_nan
=
True
,
tensor_op
=
tensor
.
any
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
and_
,
dtype
=
dtype
,
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
and_
,
dtype
=
dtype
,
test_nan
=
True
,
tensor_op
=
tensor
.
all
)
test_nan
=
True
,
tensor_op
=
tensor
.
all
)
def
test_c_noopt
(
self
):
# We need to make sure that we cover the corner cases that
# optimizations normally cover
if
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
self
.
with_mode
(
Mode
(
linker
=
'c'
,
optimizer
=
None
),
scalar
.
add
,
dtype
=
'floatX'
)
@attr
(
'slow'
)
@attr
(
'slow'
)
def
test_c
(
self
):
def
test_c
(
self
):
if
not
theano
.
config
.
cxx
:
if
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
for
dtype
in
[
"bool"
,
"floatX"
,
"complex64"
,
"complex128"
,
"int8"
,
"uint8"
]:
for
dtype
in
[
"bool"
,
"floatX"
,
"complex64"
,
"complex128"
,
"int8"
,
"uint8"
]:
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
add
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
add
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
mul
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
mul
,
dtype
=
dtype
)
for
dtype
in
[
"bool"
,
"floatX"
,
"int8"
,
"uint8"
]:
for
dtype
in
[
"bool"
,
"floatX"
,
"int8"
,
"uint8"
]:
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
minimum
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
minimum
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
maximum
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
maximum
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
and_
,
dtype
=
dtype
,
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
and_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
all
)
tensor_op
=
tensor
.
all
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
or_
,
dtype
=
dtype
,
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
or_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
any
)
tensor_op
=
tensor
.
any
)
for
dtype
in
[
"bool"
,
"int8"
,
"uint8"
]:
for
dtype
in
[
"bool"
,
"int8"
,
"uint8"
]:
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
or_
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
or_
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
and_
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
and_
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
xor
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
xor
,
dtype
=
dtype
)
@attr
(
'slow'
)
@attr
(
'slow'
)
def
test_c_nan
(
self
):
def
test_c_nan
(
self
):
if
not
theano
.
config
.
cxx
:
if
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
for
dtype
in
[
"floatX"
,
"complex64"
,
"complex128"
]:
for
dtype
in
[
"floatX"
,
"complex64"
,
"complex128"
]:
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
add
,
dtype
=
dtype
,
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
add
,
dtype
=
dtype
,
test_nan
=
True
)
test_nan
=
True
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
mul
,
dtype
=
dtype
,
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
mul
,
dtype
=
dtype
,
test_nan
=
True
)
test_nan
=
True
)
for
dtype
in
[
"floatX"
]:
for
dtype
in
[
"floatX"
]:
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
minimum
,
dtype
=
dtype
,
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
minimum
,
dtype
=
dtype
,
test_nan
=
True
)
test_nan
=
True
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
maximum
,
dtype
=
dtype
,
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
maximum
,
dtype
=
dtype
,
test_nan
=
True
)
test_nan
=
True
)
def
test_infer_shape
(
self
,
dtype
=
None
,
pre_scalar_op
=
None
):
def
test_infer_shape
(
self
,
dtype
=
None
,
pre_scalar_op
=
None
):
...
@@ -1241,16 +1249,6 @@ def test_gt_grad():
...
@@ -1241,16 +1249,6 @@ def test_gt_grad():
cost
=
(
scores
*
(
scores
>
0
))
.
sum
()
cost
=
(
scores
*
(
scores
>
0
))
.
sum
()
T
.
grad
(
cost
,
input_
)
T
.
grad
(
cost
,
input_
)
"""
if __name__ == '__main__':
#unittest.main()
suite = unittest.TestSuite([test_Prod('test_mul_without_zeros_zeros')])
#suite.addTest(test_Prod('test_verify_grad_with_zeros'))
#suite.addTest(test_Prod('test_prod_without_zeros'))
#suite.addTest(test_Prod('test_other_grad_tests'))
unittest.TextTestRunner().run(suite)
"""
def
test_clip_grad
():
def
test_clip_grad
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论