Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleRec
提交
2f60e4a7
P
PaddleRec
项目概览
PaddlePaddle
/
PaddleRec
通知
68
Star
12
Fork
5
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
27
列表
看板
标记
里程碑
合并请求
10
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleRec
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
27
Issue
27
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2f60e4a7
编写于
8月 01, 2019
作者:
R
rensilin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix
Change-Id: I7f5b40e412b045082b7dad1cbc1e346a9e0ca14d
上级
4fc0ae30
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
13 addition
and
47 deletion
+13
-47
paddle/fluid/train/custom_trainer/feed/unit_test/test_executor.cc
...luid/train/custom_trainer/feed/unit_test/test_executor.cc
+13
-47
未找到文件。
paddle/fluid/train/custom_trainer/feed/unit_test/test_executor.cc
浏览文件 @
2f60e4a7
...
@@ -25,16 +25,11 @@ namespace paddle {
...
@@ -25,16 +25,11 @@ namespace paddle {
namespace
custom_trainer
{
namespace
custom_trainer
{
namespace
feed
{
namespace
feed
{
<<<<<<<
HEAD
TEST
(
testSimpleExecutor
,
initialize
)
{
SimpleExecutor
execute
;
auto
context_ptr
=
std
::
make_shared
<
TrainerContext
>
();
=======
const
char
test_data_dir
[]
=
"test_data"
;
const
char
test_data_dir
[]
=
"test_data"
;
const
char
main_program_path
[]
=
"test_data/main_program"
;
const
char
main_program_path
[]
=
"test_data/main_program"
;
const
char
startup_program_path
[]
=
"test_data/startup_program"
;
const
char
startup_program_path
[]
=
"test_data/startup_program"
;
class
SimpleExecut
e
Test
:
public
testing
::
Test
class
SimpleExecut
or
Test
:
public
testing
::
Test
{
{
public:
public:
static
void
SetUpTestCase
()
static
void
SetUpTestCase
()
...
@@ -85,52 +80,23 @@ public:
...
@@ -85,52 +80,23 @@ public:
std
::
shared_ptr
<
TrainerContext
>
context_ptr
;
std
::
shared_ptr
<
TrainerContext
>
context_ptr
;
};
};
TEST_F
(
SimpleExecuteTest
,
initialize
)
{
TEST_F
(
SimpleExecutorTest
,
initialize
)
{
SimpleExecute
execute
;
SimpleExecutor
executor
;
>>>>>>>
add_executor_ut
YAML
::
Node
config
=
YAML
::
Load
(
"[1, 2, 3]"
);
YAML
::
Node
config
=
YAML
::
Load
(
"[1, 2, 3]"
);
ASSERT_NE
(
0
,
execut
e
.
initialize
(
config
,
context_ptr
));
ASSERT_NE
(
0
,
execut
or
.
initialize
(
config
,
context_ptr
));
config
=
YAML
::
Load
(
std
::
string
()
+
"{startup_program: "
+
startup_program_path
+
", main_program: "
+
main_program_path
+
"}"
);
config
=
YAML
::
Load
(
std
::
string
()
+
"{startup_program: "
+
startup_program_path
+
", main_program: "
+
main_program_path
+
"}"
);
ASSERT_EQ
(
0
,
execut
e
.
initialize
(
config
,
context_ptr
));
ASSERT_EQ
(
0
,
execut
or
.
initialize
(
config
,
context_ptr
));
config
=
YAML
::
Load
(
std
::
string
()
+
"{thread_num: 2, startup_program: "
+
startup_program_path
+
", main_program: "
+
main_program_path
+
"}"
);
config
=
YAML
::
Load
(
std
::
string
()
+
"{thread_num: 2, startup_program: "
+
startup_program_path
+
", main_program: "
+
main_program_path
+
"}"
);
ASSERT_EQ
(
0
,
execut
e
.
initialize
(
config
,
context_ptr
));
ASSERT_EQ
(
0
,
execut
or
.
initialize
(
config
,
context_ptr
));
}
}
<<<<<<<
HEAD
TEST_F
(
SimpleExecutorTest
,
run
)
{
float
uniform
(
float
min
,
float
max
)
{
SimpleExecutor
executor
;
float
result
=
(
float
)
rand
()
/
RAND_MAX
;
return
min
+
result
*
(
max
-
min
);
}
void
next_batch
(
int
batch_size
,
const
paddle
::
platform
::
Place
&
place
,
paddle
::
framework
::
LoDTensor
*
x_tensor
,
paddle
::
framework
::
LoDTensor
*
y_tensor
)
{
x_tensor
->
Resize
({
batch_size
,
2
});
auto
x_data
=
x_tensor
->
mutable_data
<
float
>
(
place
);
y_tensor
->
Resize
({
batch_size
,
1
});
auto
y_data
=
y_tensor
->
mutable_data
<
float
>
(
place
);
for
(
int
i
=
0
;
i
<
batch_size
;
++
i
)
{
x_data
[
i
*
2
]
=
uniform
(
-
2
,
2
);
x_data
[
i
*
2
+
1
]
=
uniform
(
-
2
,
2
);
float
dis
=
x_data
[
i
*
2
]
*
x_data
[
i
*
2
]
+
x_data
[
i
*
2
+
1
]
*
x_data
[
i
*
2
+
1
];
y_data
[
i
]
=
dis
<
1.0
?
1.0
:
0.0
;
}
}
TEST
(
testSimpleExecutor
,
run
)
{
SimpleExecutor
execute
;
auto
context_ptr
=
std
::
make_shared
<
TrainerContext
>
();
auto
config
=
YAML
::
Load
(
"{thread_num: 2, startup_program: ./data/startup_program, main_program: ./data/main_program}"
);
=======
TEST_F
(
SimpleExecuteTest
,
run
)
{
SimpleExecute
execute
;
auto
config
=
YAML
::
Load
(
std
::
string
()
+
"{thread_num: 2, startup_program: "
+
startup_program_path
+
", main_program: "
+
main_program_path
+
"}"
);
auto
config
=
YAML
::
Load
(
std
::
string
()
+
"{thread_num: 2, startup_program: "
+
startup_program_path
+
", main_program: "
+
main_program_path
+
"}"
);
>>>>>>>
add_executor_ut
ASSERT_EQ
(
0
,
executor
.
initialize
(
config
,
context_ptr
));
ASSERT_EQ
(
0
,
execute
.
initialize
(
config
,
context_ptr
));
auto
x_var
=
execut
e
.
mutable_var
<::
paddle
::
framework
::
LoDTensor
>
(
"x"
);
auto
x_var
=
execut
or
.
mutable_var
<::
paddle
::
framework
::
LoDTensor
>
(
"x"
);
execut
e
.
mutable_var
<::
paddle
::
framework
::
LoDTensor
>
(
"mean"
);
execut
or
.
mutable_var
<::
paddle
::
framework
::
LoDTensor
>
(
"mean"
);
ASSERT_NE
(
nullptr
,
x_var
);
ASSERT_NE
(
nullptr
,
x_var
);
int
x_len
=
10
;
int
x_len
=
10
;
...
@@ -143,9 +109,9 @@ TEST_F(SimpleExecuteTest, run) {
...
@@ -143,9 +109,9 @@ TEST_F(SimpleExecuteTest, run) {
}
}
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
ASSERT_EQ
(
0
,
execut
e
.
run
());
ASSERT_EQ
(
0
,
execut
or
.
run
());
auto
mean_var
=
execut
e
.
var
<::
paddle
::
framework
::
LoDTensor
>
(
"mean"
);
auto
mean_var
=
execut
or
.
var
<::
paddle
::
framework
::
LoDTensor
>
(
"mean"
);
auto
mean
=
mean_var
.
data
<
float
>
()[
0
];
auto
mean
=
mean_var
.
data
<
float
>
()[
0
];
std
::
cout
<<
"mean: "
<<
mean
<<
std
::
endl
;
std
::
cout
<<
"mean: "
<<
mean
<<
std
::
endl
;
ASSERT_NEAR
(
4.5
,
mean
,
1e-9
);
ASSERT_NEAR
(
4.5
,
mean
,
1e-9
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录