Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ee78a021
提交
ee78a021
authored
7月 04, 2017
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make optimizations run in tests.
上级
3465a406
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
58 行增加
和
65 行删除
+58
-65
elemwise_cgen.py
theano/tensor/elemwise_cgen.py
+0
-4
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+58
-61
没有找到文件。
theano/tensor/elemwise_cgen.py
浏览文件 @
ee78a021
...
...
@@ -72,16 +72,12 @@ def make_checks(loop_orders, dtypes, sub):
%(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_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
()
adjust
=
"
%(var)
s_n
%(index)
s*
%(var)
s_stride
%(index)
s"
%
locals
()
else
:
jump
=
"-(
%
s)"
%
adjust
init
+=
"""
%(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
()
adjust
=
"0"
check
=
""
...
...
theano/tensor/tests/test_elemwise.py
浏览文件 @
ee78a021
...
...
@@ -15,7 +15,7 @@ from theano import gof, scalar, config
from
theano
import
tensor
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
,
Prod
,
ProdWithoutZeros
)
from
theano.tests
import
unittest_tools
...
...
@@ -365,9 +365,9 @@ class test_CAReduce(unittest_tools.InferShapeTester):
((),
())]
type
=
TensorType
def
with_
linker
(
self
,
linker
,
scalar_op
=
scalar
.
add
,
dtype
=
"floatX"
,
pre_scalar_op
=
None
,
test_nan
=
False
,
tensor_op
=
None
):
def
with_
mode
(
self
,
mode
,
scalar_op
=
scalar
.
add
,
dtype
=
"floatX"
,
pre_scalar_op
=
None
,
test_nan
=
False
,
tensor_op
=
None
):
for
xsh
,
tosum
in
self
.
cases
:
if
dtype
==
"floatX"
:
dtype
=
theano
.
config
.
floatX
...
...
@@ -383,7 +383,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
if
tosum
is
None
:
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
))
if
dtype
not
in
tensor
.
discrete_dtypes
:
...
...
@@ -495,8 +495,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
e
=
tensor_op
(
x
,
axis
=
tosum
)
if
tosum
is
None
:
tosum
=
list
(
range
(
len
(
xsh
)))
f
=
copy
(
linker
)
.
accept
(
FunctionGraph
([
x
],
[
e
.
shape
]))
.
make_function
()
f
=
theano
.
function
([
x
],
e
.
shape
,
mode
=
mode
)
if
not
(
scalar_op
in
[
scalar
.
maximum
,
scalar
.
minimum
]
and
((
xsh
==
()
or
np
.
prod
(
xsh
)
==
0
))):
try
:
...
...
@@ -505,70 +504,78 @@ class test_CAReduce(unittest_tools.InferShapeTester):
# GpuCAReduce don't implement all cases when size is 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
):
for
dtype
in
[
"bool"
,
"floatX"
,
"complex64"
,
"complex128"
,
"int8"
,
"uint8"
]:
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
add
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
mul
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
maximum
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
minimum
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
and_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
all
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
or_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
any
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
add
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
mul
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
maximum
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
minimum
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
and_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
all
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
or_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
any
)
for
dtype
in
[
"int8"
,
"uint8"
]:
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
or_
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
and_
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
PerformLinker
(
),
scalar
.
xor
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
or_
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
and_
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'py'
),
scalar
.
xor
,
dtype
=
dtype
)
def
test_perform_nan
(
self
):
for
dtype
in
[
"floatX"
,
"complex64"
,
"complex128"
]:
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
add
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
mul
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
maximum
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
minimum
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
or_
,
dtype
=
dtype
,
test_nan
=
True
,
tensor_op
=
tensor
.
any
)
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
and_
,
dtype
=
dtype
,
test_nan
=
True
,
tensor_op
=
tensor
.
all
)
self
.
with_mode
(
Mode
(
linker
=
'py'
),
scalar
.
add
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_mode
(
Mode
(
linker
=
'py'
),
scalar
.
mul
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_mode
(
Mode
(
linker
=
'py'
),
scalar
.
maximum
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_mode
(
Mode
(
linker
=
'py'
),
scalar
.
minimum
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_mode
(
Mode
(
linker
=
'py'
),
scalar
.
or_
,
dtype
=
dtype
,
test_nan
=
True
,
tensor_op
=
tensor
.
any
)
self
.
with_mode
(
Mode
(
linker
=
'py'
),
scalar
.
and_
,
dtype
=
dtype
,
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'
)
def
test_c
(
self
):
if
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
for
dtype
in
[
"bool"
,
"floatX"
,
"complex64"
,
"complex128"
,
"int8"
,
"uint8"
]:
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
add
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
mul
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
add
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
mul
,
dtype
=
dtype
)
for
dtype
in
[
"bool"
,
"floatX"
,
"int8"
,
"uint8"
]:
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
minimum
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
maximum
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
and_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
all
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
or_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
any
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
minimum
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
maximum
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
and_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
all
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
or_
,
dtype
=
dtype
,
tensor_op
=
tensor
.
any
)
for
dtype
in
[
"bool"
,
"int8"
,
"uint8"
]:
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
or_
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
and_
,
dtype
=
dtype
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
xor
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
or_
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
and_
,
dtype
=
dtype
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
xor
,
dtype
=
dtype
)
@attr
(
'slow'
)
def
test_c_nan
(
self
):
if
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
for
dtype
in
[
"floatX"
,
"complex64"
,
"complex128"
]:
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
add
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
mul
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
add
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
mul
,
dtype
=
dtype
,
test_nan
=
True
)
for
dtype
in
[
"floatX"
]:
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
minimum
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_
linker
(
gof
.
CLinker
(
),
scalar
.
maximum
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
minimum
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_
mode
(
Mode
(
linker
=
'c'
),
scalar
.
maximum
,
dtype
=
dtype
,
test_nan
=
True
)
def
test_infer_shape
(
self
,
dtype
=
None
,
pre_scalar_op
=
None
):
if
dtype
is
None
:
...
...
@@ -1241,16 +1248,6 @@ def test_gt_grad():
cost
=
(
scores
*
(
scores
>
0
))
.
sum
()
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
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论