Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
4b13c80e
P
Paddle
项目概览
机器未来
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4b13c80e
编写于
10月 12, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add selected rows
上级
4838ea25
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
118 addition
and
0 deletion
+118
-0
paddle/framework/CMakeLists.txt
paddle/framework/CMakeLists.txt
+3
-0
paddle/framework/selected_rows.cc
paddle/framework/selected_rows.cc
+16
-0
paddle/framework/selected_rows.h
paddle/framework/selected_rows.h
+52
-0
paddle/framework/selected_rows_test.cc
paddle/framework/selected_rows_test.cc
+47
-0
未找到文件。
paddle/framework/CMakeLists.txt
浏览文件 @
4b13c80e
...
@@ -53,3 +53,6 @@ endif()
...
@@ -53,3 +53,6 @@ endif()
cc_library
(
tensor_array SRCS tensor_array.cc DEPS lod_tensor
)
cc_library
(
tensor_array SRCS tensor_array.cc DEPS lod_tensor
)
cc_test
(
tensor_array_test SRCS tensor_array_test.cc DEPS tensor_array place
)
cc_test
(
tensor_array_test SRCS tensor_array_test.cc DEPS tensor_array place
)
cc_library
(
selected_rows SRCS selected_rows.cc DEPS tensor
)
cc_test
(
selected_rows_test SRCS selected_rows_test.cc DEPS selected_rows
)
paddle/framework/selected_rows.cc
0 → 100644
浏览文件 @
4b13c80e
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/framework/selected_rows.h"
namespace
paddle
{
namespace
framework
{}
// namespace framework
}
// namespace paddle
paddle/framework/selected_rows.h
0 → 100644
浏览文件 @
4b13c80e
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include "paddle/framework/tensor.h"
namespace
paddle
{
namespace
framework
{
class
SelectedRows
{
public:
SelectedRows
(
const
std
::
vector
<
int64_t
>&
rows
,
const
int64_t
&
height
)
:
rows_
(
rows
),
height_
(
height
)
{
value_
.
reset
(
new
Tensor
());
}
SelectedRows
()
{}
platform
::
Place
place
()
const
{
return
value_
->
place
();
}
Tensor
&
value
()
const
{
return
*
value_
;
}
int64_t
height
()
const
{
return
height_
;
}
void
set_height
(
int64_t
height
)
{
height_
=
height
;
}
const
std
::
vector
<
int64_t
>&
rows
()
const
{
return
rows_
;
}
void
set_rows
(
const
std
::
vector
<
int64_t
>&
rows
)
{
rows_
=
rows
;
}
DDim
GetCompleteDims
()
const
{
std
::
vector
<
int64_t
>
dims
=
vectorize
(
value_
->
dims
());
dims
[
0
]
=
height_
;
return
make_ddim
(
dims
);
}
private:
std
::
vector
<
int64_t
>
rows_
;
std
::
unique_ptr
<
Tensor
>
value_
{
nullptr
};
int64_t
height_
;
};
}
// namespace framework
}
// namespace paddle
paddle/framework/selected_rows_test.cc
0 → 100644
浏览文件 @
4b13c80e
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/framework/selected_rows.h"
#include "gtest/gtest.h"
namespace
paddle
{
namespace
framework
{
class
SelectedRowsTester
:
public
::
testing
::
Test
{
public:
virtual
void
SetUp
()
override
{
std
::
vector
<
int64_t
>
rows
{
0
,
4
,
7
};
int64_t
height
=
10
;
int64_t
row_numel
=
100
;
selected_rows_
.
reset
(
new
SelectedRows
(
rows
,
height
));
Tensor
&
value
=
selected_rows_
->
value
();
value
.
mutable_data
<
float
>
(
make_ddim
({
static_cast
<
int64_t
>
(
rows
.
size
()),
row_numel
}),
place_
);
}
protected:
platform
::
CPUPlace
place_
;
std
::
unique_ptr
<
SelectedRows
>
selected_rows_
{
nullptr
};
};
TEST_F
(
SelectedRowsTester
,
height
)
{
ASSERT_EQ
(
selected_rows_
->
height
(),
10
);
}
TEST_F
(
SelectedRowsTester
,
dims
)
{
ASSERT_EQ
(
selected_rows_
->
value
().
dims
(),
make_ddim
({
3
,
100
}));
}
TEST_F
(
SelectedRowsTester
,
complete_dims
)
{
ASSERT_EQ
(
selected_rows_
->
GetCompleteDims
(),
make_ddim
({
10
,
100
}));
}
}
// namespace framework
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录