Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
e01e77d7
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e01e77d7
编写于
5月 13, 2020
作者:
M
mapingshuo
提交者:
GitHub
5月 13, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix error log, test=develop (#24419) (#24462)
* fix error log: resahpe, range, reverse.
上级
e3c6812b
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
120 addition
and
38 deletion
+120
-38
paddle/fluid/operators/range_op.cc
paddle/fluid/operators/range_op.cc
+32
-6
paddle/fluid/operators/range_op.h
paddle/fluid/operators/range_op.h
+15
-5
paddle/fluid/operators/reshape_op.cc
paddle/fluid/operators/reshape_op.cc
+18
-10
paddle/fluid/operators/reverse_op.cc
paddle/fluid/operators/reverse_op.cc
+13
-5
paddle/fluid/operators/reverse_op.h
paddle/fluid/operators/reverse_op.h
+3
-3
paddle/fluid/operators/shape_op.cc
paddle/fluid/operators/shape_op.cc
+6
-4
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+2
-1
python/paddle/fluid/layers/tensor.py
python/paddle/fluid/layers/tensor.py
+6
-0
python/paddle/fluid/tests/unittests/test_reverse_op.py
python/paddle/fluid/tests/unittests/test_reverse_op.py
+25
-4
未找到文件。
paddle/fluid/operators/range_op.cc
浏览文件 @
e01e77d7
...
@@ -24,18 +24,44 @@ class RangeOp : public framework::OperatorWithKernel {
...
@@ -24,18 +24,44 @@ class RangeOp : public framework::OperatorWithKernel {
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
if
(
ctx
->
HasInput
(
"Start"
))
{
if
(
ctx
->
HasInput
(
"Start"
))
{
auto
s_dims
=
ctx
->
GetInputDim
(
"Start"
);
auto
s_dims
=
ctx
->
GetInputDim
(
"Start"
);
PADDLE_ENFORCE
((
s_dims
.
size
()
==
1
)
&&
(
s_dims
[
0
]
==
1
),
PADDLE_ENFORCE_EQ
(
"The shape of Input(Start) should be [1]."
);
s_dims
.
size
(),
1
,
platform
::
errors
::
InvalidArgument
(
"The dim of the shape of Input(Start) should be 1, but got %d"
,
s_dims
.
size
()));
PADDLE_ENFORCE_EQ
(
s_dims
[
0
],
1
,
platform
::
errors
::
InvalidArgument
(
"The first dim of the shape of Input(Start) should "
"be 1, but got %d"
,
s_dims
[
0
]));
}
}
if
(
ctx
->
HasInput
(
"End"
))
{
if
(
ctx
->
HasInput
(
"End"
))
{
auto
e_dims
=
ctx
->
GetInputDim
(
"End"
);
auto
e_dims
=
ctx
->
GetInputDim
(
"End"
);
PADDLE_ENFORCE
((
e_dims
.
size
()
==
1
)
&&
(
e_dims
[
0
]
==
1
),
PADDLE_ENFORCE_EQ
(
"The shape of Input(End) should be [1]."
);
e_dims
.
size
(),
1
,
platform
::
errors
::
InvalidArgument
(
"The dim of the shape of Input(End) should be 1, but got %d"
,
e_dims
.
size
()));
PADDLE_ENFORCE_EQ
(
e_dims
[
0
],
1
,
platform
::
errors
::
InvalidArgument
(
"The first dim of the shape of "
"Input(End) should be 1, but got %d"
,
e_dims
[
0
]));
}
}
if
(
ctx
->
HasInput
(
"Step"
))
{
if
(
ctx
->
HasInput
(
"Step"
))
{
auto
step_dims
=
ctx
->
GetInputDim
(
"Step"
);
auto
step_dims
=
ctx
->
GetInputDim
(
"Step"
);
PADDLE_ENFORCE
((
step_dims
.
size
()
==
1
)
&&
(
step_dims
[
0
]
==
1
),
PADDLE_ENFORCE_EQ
(
"The shape of Input(Step) should be [1]."
);
step_dims
.
size
(),
1
,
platform
::
errors
::
InvalidArgument
(
"The dim of the shape of Input(Step) should be 1, but got %d"
,
step_dims
.
size
()));
PADDLE_ENFORCE_EQ
(
step_dims
[
0
],
1
,
platform
::
errors
::
InvalidArgument
(
"The first dim of the shape of Input(Step) should "
"be 1, but got %d"
,
step_dims
[
0
]));
}
}
ctx
->
SetOutputDim
(
"Out"
,
{
-
1
});
ctx
->
SetOutputDim
(
"Out"
,
{
-
1
});
}
}
...
...
paddle/fluid/operators/range_op.h
浏览文件 @
e01e77d7
...
@@ -22,11 +22,21 @@ namespace operators {
...
@@ -22,11 +22,21 @@ namespace operators {
template
<
typename
T
>
template
<
typename
T
>
void
GetSize
(
T
start
,
T
end
,
T
step
,
int64_t
*
size
)
{
void
GetSize
(
T
start
,
T
end
,
T
step
,
int64_t
*
size
)
{
PADDLE_ENFORCE
(
!
std
::
equal_to
<
T
>
()(
step
,
0
),
PADDLE_ENFORCE_NE
(
step
,
0
,
platform
::
errors
::
InvalidArgument
(
"The step of range op should not be 0."
);
"The step of range op should not be 0."
));
PADDLE_ENFORCE
(((
start
<
end
)
&&
(
step
>
0
))
||
((
start
>
end
)
&&
(
step
<
0
)),
"The step should be greater than 0 while start < end. And the "
if
(
start
<
end
)
{
"step should be less than 0 while start > end."
);
PADDLE_ENFORCE_GT
(
step
,
0
,
platform
::
errors
::
InvalidArgument
(
"The step should be greater than 0 while start < end."
));
}
if
(
start
>
end
)
{
PADDLE_ENFORCE_LT
(
step
,
0
,
platform
::
errors
::
InvalidArgument
(
"step should be less than 0 while start > end."
));
}
*
size
=
std
::
is_integral
<
T
>::
value
*
size
=
std
::
is_integral
<
T
>::
value
?
((
std
::
abs
(
end
-
start
)
+
std
::
abs
(
step
)
-
1
)
/
std
::
abs
(
step
))
?
((
std
::
abs
(
end
-
start
)
+
std
::
abs
(
step
)
-
1
)
/
std
::
abs
(
step
))
:
std
::
ceil
(
std
::
abs
((
end
-
start
)
/
step
));
:
std
::
ceil
(
std
::
abs
((
end
-
start
)
/
step
));
...
...
paddle/fluid/operators/reshape_op.cc
浏览文件 @
e01e77d7
...
@@ -56,9 +56,11 @@ class ReshapeOp : public framework::OperatorWithKernel {
...
@@ -56,9 +56,11 @@ class ReshapeOp : public framework::OperatorWithKernel {
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"X"
),
true
,
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"X"
),
true
,
"Input(X) of ReshapeOp should not be null."
);
platform
::
errors
::
InvalidArgument
(
"Input(X) of ReshapeOp should not be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"Out"
),
true
,
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"Out"
),
true
,
"Output(Out) of ReshapeOp should not be null."
);
platform
::
errors
::
InvalidArgument
(
"Output(Out) of ReshapeOp should not be null."
));
if
(
ctx
->
HasInputs
(
"ShapeTensor"
))
{
if
(
ctx
->
HasInputs
(
"ShapeTensor"
))
{
// top prority shape
// top prority shape
...
@@ -304,9 +306,12 @@ class ReshapeGradOp : public framework::OperatorWithKernel {
...
@@ -304,9 +306,12 @@ class ReshapeGradOp : public framework::OperatorWithKernel {
:
OperatorWithKernel
(
type
,
inputs
,
outputs
,
attrs
)
{}
:
OperatorWithKernel
(
type
,
inputs
,
outputs
,
attrs
)
{}
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"X"
),
true
,
"Input(X) shouldn't be null."
);
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"X"
),
true
,
platform
::
errors
::
InvalidArgument
(
"Input(X) shouldn't be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
true
,
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
true
,
"Input(Out@GRAD) shouldn't be null."
);
platform
::
errors
::
InvalidArgument
(
"Input(Out@GRAD) shouldn't be null."
));
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X"
),
ctx
->
GetInputDim
(
"X"
));
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X"
),
ctx
->
GetInputDim
(
"X"
));
}
}
...
@@ -403,7 +408,8 @@ class Reshape2Op : public ReshapeOp {
...
@@ -403,7 +408,8 @@ class Reshape2Op : public ReshapeOp {
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"XShape"
),
true
,
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"XShape"
),
true
,
"Output(XShape) of ReshapeOp should not be null."
);
platform
::
errors
::
InvalidArgument
(
"Output(XShape) of ReshapeOp should not be null."
));
const
auto
&
x_dims
=
ctx
->
GetInputDim
(
"X"
);
const
auto
&
x_dims
=
ctx
->
GetInputDim
(
"X"
);
std
::
vector
<
int64_t
>
xshape_dims
(
x_dims
.
size
()
+
1
);
std
::
vector
<
int64_t
>
xshape_dims
(
x_dims
.
size
()
+
1
);
xshape_dims
[
0
]
=
0
;
xshape_dims
[
0
]
=
0
;
...
@@ -472,10 +478,12 @@ class Reshape2GradOp : public framework::OperatorWithKernel {
...
@@ -472,10 +478,12 @@ class Reshape2GradOp : public framework::OperatorWithKernel {
:
OperatorWithKernel
(
type
,
inputs
,
outputs
,
attrs
)
{}
:
OperatorWithKernel
(
type
,
inputs
,
outputs
,
attrs
)
{}
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"XShape"
),
true
,
PADDLE_ENFORCE_EQ
(
"Input(XShape) shouldn't be null."
);
ctx
->
HasInput
(
"XShape"
),
true
,
platform
::
errors
::
InvalidArgument
(
"Input(XShape) shouldn't be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
true
,
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
true
,
"Input(Out@GRAD) shouldn't be null."
);
platform
::
errors
::
InvalidArgument
(
"Input(Out@GRAD) shouldn't be null."
));
auto
xshape_dims
=
ctx
->
GetInputDim
(
"XShape"
);
auto
xshape_dims
=
ctx
->
GetInputDim
(
"XShape"
);
auto
x_dims
=
framework
::
slice_ddim
(
xshape_dims
,
1
,
xshape_dims
.
size
());
auto
x_dims
=
framework
::
slice_ddim
(
xshape_dims
,
1
,
xshape_dims
.
size
());
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X"
),
x_dims
);
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X"
),
x_dims
);
...
@@ -511,8 +519,8 @@ class Reshape2DoubleGradOp : public framework::OperatorWithKernel {
...
@@ -511,8 +519,8 @@ class Reshape2DoubleGradOp : public framework::OperatorWithKernel {
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"DDX"
),
true
,
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"DDX"
),
true
,
"Input(X@GRAD_GRAD) shouldn't be null."
);
platform
::
errors
::
InvalidArgument
(
"Input(X@GRAD_GRAD) shouldn't be null."
));
if
(
ctx
->
HasOutput
(
"DDOut"
)
&&
ctx
->
HasInput
(
"DDX"
))
{
if
(
ctx
->
HasOutput
(
"DDOut"
)
&&
ctx
->
HasInput
(
"DDX"
))
{
ctx
->
ShareDim
(
"DOut"
,
"DDOut"
);
ctx
->
ShareDim
(
"DOut"
,
"DDOut"
);
}
}
...
...
paddle/fluid/operators/reverse_op.cc
浏览文件 @
e01e77d7
...
@@ -24,20 +24,28 @@ class ReverseOp : public framework::OperatorWithKernel {
...
@@ -24,20 +24,28 @@ class ReverseOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"Input(X) should not be null"
);
PADDLE_ENFORCE_EQ
(
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
"Output(Out) should not be null"
);
ctx
->
HasInput
(
"X"
),
true
,
platform
::
errors
::
InvalidArgument
(
"Input(X) should not be null"
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"Out"
),
true
,
platform
::
errors
::
InvalidArgument
(
"Output(Out) should not be null"
));
const
auto
&
x_dims
=
ctx
->
GetInputDim
(
"X"
);
const
auto
&
x_dims
=
ctx
->
GetInputDim
(
"X"
);
const
auto
&
axis
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"axis"
);
const
auto
&
axis
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"axis"
);
PADDLE_ENFORCE
(
!
axis
.
empty
(),
"'axis' can not be empty."
);
PADDLE_ENFORCE_NE
(
axis
.
empty
(),
true
,
platform
::
errors
::
InvalidArgument
(
"'axis' can not be empty."
));
for
(
int
a
:
axis
)
{
for
(
int
a
:
axis
)
{
PADDLE_ENFORCE_LT
(
a
,
x_dims
.
size
(),
PADDLE_ENFORCE_LT
(
a
,
x_dims
.
size
(),
paddle
::
platform
::
errors
::
OutOfRange
(
paddle
::
platform
::
errors
::
OutOfRange
(
"The axis must be less than input tensor's rank."
));
"The axis must be less than input tensor's rank. "
"but got %d >= %d"
,
a
,
x_dims
.
size
()));
PADDLE_ENFORCE_GE
(
PADDLE_ENFORCE_GE
(
a
,
-
x_dims
.
size
(),
a
,
-
x_dims
.
size
(),
paddle
::
platform
::
errors
::
OutOfRange
(
paddle
::
platform
::
errors
::
OutOfRange
(
"The axis must be greater than the negative number of "
"The axis must be greater than the negative number of "
"input tensor's rank."
));
"input tensor's rank, but got %d < %d"
,
a
,
-
x_dims
.
size
()));
}
}
ctx
->
SetOutputDim
(
"Out"
,
x_dims
);
ctx
->
SetOutputDim
(
"Out"
,
x_dims
);
}
}
...
...
paddle/fluid/operators/reverse_op.h
浏览文件 @
e01e77d7
...
@@ -80,9 +80,9 @@ class ReverseKernel : public framework::OpKernel<T> {
...
@@ -80,9 +80,9 @@ class ReverseKernel : public framework::OpKernel<T> {
functor6
(
dev_ctx
,
*
x
,
out
,
axis
);
functor6
(
dev_ctx
,
*
x
,
out
,
axis
);
break
;
break
;
default:
default:
PADDLE_THROW
(
PADDLE_THROW
(
paddle
::
platform
::
errors
::
OutOfRange
(
"
Reserve operator doesn't supports tensors whose ranks are greater
"
"
The reserve operator does not support input tensors
"
"
than 6."
);
"
whose ranks are greater than 6."
)
);
}
}
}
}
};
};
...
...
paddle/fluid/operators/shape_op.cc
浏览文件 @
e01e77d7
...
@@ -24,10 +24,12 @@ class ShapeOp : public framework::OperatorWithKernel {
...
@@ -24,10 +24,12 @@ class ShapeOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Input"
),
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"Input"
),
true
,
"Input (Input) of get_shape op should not be null."
);
platform
::
errors
::
InvalidArgument
(
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
"Input (Input) of get_shape op should not be null."
));
"Output (Out) of get_shape op should not be null."
);
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"Out"
),
true
,
platform
::
errors
::
InvalidArgument
(
"Output (Out) of get_shape op should not be null."
));
auto
in_dim
=
ctx
->
GetInputDim
(
"Input"
);
auto
in_dim
=
ctx
->
GetInputDim
(
"Input"
);
ctx
->
SetOutputDim
(
"Out"
,
{
in_dim
.
size
()});
ctx
->
SetOutputDim
(
"Out"
,
{
in_dim
.
size
()});
}
}
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
e01e77d7
...
@@ -12056,7 +12056,8 @@ def shape(input):
...
@@ -12056,7 +12056,8 @@ def shape(input):
res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output])
res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output])
print(res) # [array([ 3, 100, 100], dtype=int32)]
print(res) # [array([ 3, 100, 100], dtype=int32)]
"""
"""
check_variable_and_dtype(input, 'input',
['float32', 'float64', 'int32', 'int64'], 'shape')
helper = LayerHelper('shape', **locals())
helper = LayerHelper('shape', **locals())
out = helper.create_variable_for_type_inference(dtype='int32')
out = helper.create_variable_for_type_inference(dtype='int32')
helper.append_op(
helper.append_op(
...
...
python/paddle/fluid/layers/tensor.py
浏览文件 @
e01e77d7
...
@@ -1108,6 +1108,9 @@ def reverse(x, axis):
...
@@ -1108,6 +1108,9 @@ def reverse(x, axis):
result1 = fluid.layers.reverse(data, 0) # [[6., 7., 8.], [3., 4., 5.], [0., 1., 2.]]
result1 = fluid.layers.reverse(data, 0) # [[6., 7., 8.], [3., 4., 5.], [0., 1., 2.]]
result2 = fluid.layers.reverse(data, [0, 1]) # [[8., 7., 6.], [5., 4., 3.], [2., 1., 0.]]
result2 = fluid.layers.reverse(data, [0, 1]) # [[8., 7., 6.], [5., 4., 3.], [2., 1., 0.]]
"""
"""
check_variable_and_dtype
(
x
,
'x'
,
(
'float32'
,
'float64'
,
'int32'
,
'int64'
,
'uint8'
),
'reverse'
)
check_type
(
axis
,
'axis'
,
(
int
,
tuple
,
list
),
'reverse'
)
if
isinstance
(
axis
,
int
):
if
isinstance
(
axis
,
int
):
axis
=
[
axis
]
axis
=
[
axis
]
helper
=
LayerHelper
(
"reverse"
,
**
locals
())
helper
=
LayerHelper
(
"reverse"
,
**
locals
())
...
@@ -1303,6 +1306,9 @@ def range(start, end, step, dtype):
...
@@ -1303,6 +1306,9 @@ def range(start, end, step, dtype):
data = fluid.layers.range(0, 10, 2, 'int32')
data = fluid.layers.range(0, 10, 2, 'int32')
"""
"""
check_type
(
start
,
'start'
,
(
float
,
int
,
Variable
),
'range'
)
check_type
(
end
,
'end'
,
(
float
,
int
,
Variable
),
'range'
)
check_type
(
step
,
'step'
,
(
float
,
int
,
Variable
),
'range'
)
helper
=
LayerHelper
(
"range"
,
**
locals
())
helper
=
LayerHelper
(
"range"
,
**
locals
())
check_dtype
(
dtype
,
'create data type'
,
check_dtype
(
dtype
,
'create data type'
,
...
...
python/paddle/fluid/tests/unittests/test_reverse_op.py
浏览文件 @
e01e77d7
...
@@ -17,6 +17,8 @@ from __future__ import print_function
...
@@ -17,6 +17,8 @@ from __future__ import print_function
import
unittest
import
unittest
import
numpy
as
np
import
numpy
as
np
from
op_test
import
OpTest
from
op_test
import
OpTest
import
paddle.fluid
as
fluid
from
paddle.fluid
import
core
class
TestReverseOp
(
OpTest
):
class
TestReverseOp
(
OpTest
):
...
@@ -47,7 +49,7 @@ class TestCase0(TestReverseOp):
...
@@ -47,7 +49,7 @@ class TestCase0(TestReverseOp):
self
.
axis
=
[
1
]
self
.
axis
=
[
1
]
class
TestCase0
(
TestReverseOp
):
class
TestCase0
_neg
(
TestReverseOp
):
def
initTestCase
(
self
):
def
initTestCase
(
self
):
self
.
x
=
np
.
random
.
random
((
3
,
40
)).
astype
(
'float64'
)
self
.
x
=
np
.
random
.
random
((
3
,
40
)).
astype
(
'float64'
)
self
.
axis
=
[
-
1
]
self
.
axis
=
[
-
1
]
...
@@ -59,7 +61,7 @@ class TestCase1(TestReverseOp):
...
@@ -59,7 +61,7 @@ class TestCase1(TestReverseOp):
self
.
axis
=
[
0
,
1
]
self
.
axis
=
[
0
,
1
]
class
TestCase
0
(
TestReverseOp
):
class
TestCase
1_neg
(
TestReverseOp
):
def
initTestCase
(
self
):
def
initTestCase
(
self
):
self
.
x
=
np
.
random
.
random
((
3
,
40
)).
astype
(
'float64'
)
self
.
x
=
np
.
random
.
random
((
3
,
40
)).
astype
(
'float64'
)
self
.
axis
=
[
0
,
-
1
]
self
.
axis
=
[
0
,
-
1
]
...
@@ -71,7 +73,7 @@ class TestCase2(TestReverseOp):
...
@@ -71,7 +73,7 @@ class TestCase2(TestReverseOp):
self
.
axis
=
[
0
,
2
]
self
.
axis
=
[
0
,
2
]
class
TestCase2
(
TestReverseOp
):
class
TestCase2
_neg
(
TestReverseOp
):
def
initTestCase
(
self
):
def
initTestCase
(
self
):
self
.
x
=
np
.
random
.
random
((
3
,
4
,
10
)).
astype
(
'float64'
)
self
.
x
=
np
.
random
.
random
((
3
,
4
,
10
)).
astype
(
'float64'
)
self
.
axis
=
[
0
,
-
2
]
self
.
axis
=
[
0
,
-
2
]
...
@@ -83,11 +85,30 @@ class TestCase3(TestReverseOp):
...
@@ -83,11 +85,30 @@ class TestCase3(TestReverseOp):
self
.
axis
=
[
1
,
2
]
self
.
axis
=
[
1
,
2
]
class
TestCase3
(
TestReverseOp
):
class
TestCase3
_neg
(
TestReverseOp
):
def
initTestCase
(
self
):
def
initTestCase
(
self
):
self
.
x
=
np
.
random
.
random
((
3
,
4
,
10
)).
astype
(
'float64'
)
self
.
x
=
np
.
random
.
random
((
3
,
4
,
10
)).
astype
(
'float64'
)
self
.
axis
=
[
-
1
,
-
2
]
self
.
axis
=
[
-
1
,
-
2
]
class
TestCase4
(
unittest
.
TestCase
):
def
test_error
(
self
):
place
=
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
train_program
=
fluid
.
Program
()
startup_program
=
fluid
.
Program
()
with
fluid
.
program_guard
(
train_program
,
startup_program
):
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
],
dtype
=
"int64"
)
rev
=
fluid
.
layers
.
reverse
(
label
,
axis
=
[
-
1
,
-
2
])
def
_run_program
():
x
=
np
.
random
.
random
(
size
=
(
10
,
1
,
1
,
1
,
1
,
1
,
1
)).
astype
(
'int64'
)
exe
.
run
(
train_program
,
feed
=
{
"label"
:
x
})
self
.
assertRaises
(
core
.
EnforceNotMet
,
_run_program
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录