Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
1981eaf9
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1981eaf9
编写于
7月 18, 2017
作者:
Y
Yi Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix Tensor::data interface
上级
2538e207
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
26 addition
and
25 deletion
+26
-25
paddle/framework/eigen.h
paddle/framework/eigen.h
+8
-13
paddle/framework/eigen_test.cc
paddle/framework/eigen_test.cc
+14
-8
paddle/framework/tensor.h
paddle/framework/tensor.h
+4
-4
未找到文件。
paddle/framework/eigen.h
浏览文件 @
1981eaf9
...
...
@@ -28,7 +28,7 @@ struct EigenDim {
static
Type
From
(
const
DDim
&
dims
)
{
PADDLE_ENFORCE
(
arity
(
dims
)
==
D
,
"D must match arity(DDim)"
);
Type
ret
;
for
(
int
d
=
0
;
d
<
rank
;
d
++
)
{
for
(
int
d
=
0
;
d
<
arity
(
dims
)
;
d
++
)
{
ret
[
d
]
=
dims
[
d
];
}
return
ret
;
...
...
@@ -43,8 +43,7 @@ struct EigenTensor {
using
ConstType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
D
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
ConstTensor
;
Eigen
::
Aligned
>
;
static
Type
From
(
Tensor
&
tensor
,
DDim
dims
)
{
return
Type
(
tensor
.
data
<
T
>
(),
EigenDim
<
D
>::
From
(
dims
));
...
...
@@ -64,11 +63,10 @@ struct EigenTensor {
// Interpret paddle::platform::Tensor as EigenVecotr and EigenConstVector.
template
<
typename
T
,
typename
IndexType
=
Eigen
::
DenseIndex
>
struct
EigenVector
{
using
EigenVector
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
1
,
Eigen
::
RowMajor
,
IndexType
>
,
using
Type
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
1
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
;
using
EigenConstVector
=
using
ConstType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
1
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
;
...
...
@@ -82,13 +80,10 @@ struct EigenVector {
// Interpret paddle::platform::Tensor as EigenMatrix and EigenConstMatrix.
template
<
typename
T
,
typename
IndexType
=
Eigen
::
DenseIndex
>
struct
EigenMatrix
{
template
<
typename
T
,
typename
IndexType
=
Eigen
::
DenseIndex
>
using
EigenMatrix
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
2
,
Eigen
::
RowMajor
,
IndexType
>
,
using
Type
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
2
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
;
template
<
typename
T
,
typename
IndexType
=
Eigen
::
DenseIndex
>
using
EigenConstMatrix
=
using
ConstType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
2
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
;
...
...
paddle/framework/eigen_test.cc
浏览文件 @
1981eaf9
...
...
@@ -12,26 +12,32 @@
*/
#include "paddle/framework/eigen.h"
#include <gtest/gtest.h>
#include "paddle/framework/tensor.h"
namespace
paddle
{
namespace
framework
{
TEST
(
Eigen
,
Tensor
)
{
using
paddle
::
platform
::
Tensor
;
using
paddle
::
platform
::
EigenTensor
;
using
paddle
::
platform
::
make_ddim
;
TEST
(
EigenDim
,
From
)
{
EigenDim
<
3
>::
Type
ed
=
EigenDim
<
3
>::
From
(
make_ddim
({
1
,
2
,
3
}));
EXPECT_EQ
(
1
,
ed
[
0
]);
EXPECT_EQ
(
2
,
ed
[
1
]);
EXPECT_EQ
(
3
,
ed
[
2
]);
}
TEST
(
Eigen
,
Tensor
)
{
Tensor
t
;
float
*
p
=
t
.
mutable_data
<
float
>
(
make_ddim
({
1
,
2
,
3
}),
CPUPlace
());
float
*
p
=
t
.
mutable_data
<
float
>
(
make_ddim
({
1
,
2
,
3
}),
platform
::
CPUPlace
());
for
(
int
i
=
0
;
i
<
1
*
2
*
3
;
i
++
)
{
p
[
i
]
=
static_cast
<
float
>
(
i
);
}
EigenTensor
::
Type
et
=
EigenTensor
::
From
(
t
);
EigenTensor
<
float
,
3
>::
Type
et
=
EigenTensor
<
float
,
3
>
::
From
(
t
);
// TODO: check the content of et.
}
TEST
(
Eigen
,
Vector
)
{}
TEST
(
Eigen
,
Matrix
)
{}
}
// namespace platform
}
// namespace paddle
paddle/framework/tensor.h
浏览文件 @
1981eaf9
...
...
@@ -37,13 +37,13 @@ class Tensor {
template
<
bool
less
,
size_t
i
,
typename
...
args
>
friend
struct
paddle
::
pybind
::
details
::
CastToPyBufferImpl
;
template
<
typename
T
,
size_t
D
,
typename
IndexType
=
Eigen
::
DenseIndex
>
template
<
typename
T
,
size_t
D
,
typename
IndexType
>
friend
struct
EigenTensor
;
template
<
typename
T
,
typename
IndexType
=
Eigen
::
DenseIndex
>
template
<
typename
T
,
typename
IndexType
>
friend
struct
EigenVector
;
template
<
typename
T
,
typename
IndexType
=
Eigen
::
DenseIndex
>
template
<
typename
T
,
typename
IndexType
>
friend
struct
EigenMatrix
;
public:
...
...
@@ -57,7 +57,7 @@ class Tensor {
}
template
<
typename
T
>
T
*
raw_data
()
const
{
T
*
data
()
{
CheckDims
<
T
>
();
return
reinterpret_cast
<
T
*>
(
reinterpret_cast
<
uintptr_t
>
(
holder_
->
ptr
())
+
offset_
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录