Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
夏有凉风,冬有雪
Paddle
提交
57c27b4e
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,发现更多精彩内容 >>
提交
57c27b4e
编写于
7月 19, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make EigenTensor default unaligned and follow comments
上级
cff8762f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
16 addition
and
44 deletion
+16
-44
paddle/framework/eigen.h
paddle/framework/eigen.h
+14
-39
paddle/framework/tensor.h
paddle/framework/tensor.h
+2
-5
未找到文件。
paddle/framework/eigen.h
浏览文件 @
57c27b4e
...
...
@@ -36,14 +36,15 @@ struct EigenDim {
};
// Interpret paddle::platform::Tensor as EigenTensor and EigenConstTensor.
template
<
typename
T
,
size_t
D
,
typename
IndexType
=
Eigen
::
DenseIndex
>
template
<
typename
T
,
size_t
D
,
int
MajorType
=
Eigen
::
RowMajor
,
typename
IndexType
=
Eigen
::
DenseIndex
>
struct
EigenTensor
{
using
Type
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
D
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
;
// TODO(qijun) Now, default type in unaligned, and we will make a benchmark on
// the speed of aligned and unaligned version in future.
using
Type
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
D
,
MajorType
,
IndexType
>>
;
using
ConstType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
D
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
;
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
D
,
MajorType
,
IndexType
>>
;
static
Type
From
(
Tensor
&
tensor
,
DDim
dims
)
{
return
Type
(
tensor
.
data
<
T
>
(),
EigenDim
<
D
>::
From
(
dims
));
...
...
@@ -60,50 +61,24 @@ struct EigenTensor {
}
};
// Interpret paddle::platform::Tensor as EigenVecotr and EigenConstVector.
template
<
typename
T
,
typename
IndexType
=
Eigen
::
DenseIndex
>
struct
EigenVector
{
using
Type
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
1
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
;
using
ConstType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
1
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
;
// From is to transfer a one dimension Tensor into a one dimension EigenVector
static
Type
From
(
Tensor
&
tensor
)
{
return
EigenTensor
<
T
,
1
>::
From
(
tensor
);
}
template
<
typename
T
,
int
MajorType
=
Eigen
::
RowMajor
,
typename
IndexType
=
Eigen
::
DenseIndex
>
struct
EigenVector
:
public
EigenTensor
<
T
,
1
,
MajorType
,
IndexType
>
{
// Flatten is to reshape a Tensor into a one dimension EigenVector
static
Type
Flatten
(
Tensor
&
tensor
)
{
static
typename
EigenTensor
<
T
,
1
>::
Type
Flatten
(
Tensor
&
tensor
)
{
return
EigenTensor
<
T
,
1
>::
From
(
tensor
,
make_ddim
({
static_cast
<
int
>
(
product
(
tensor
.
dims_
))}));
}
static
ConstType
From
(
const
Tensor
&
tensor
)
{
return
EigenTensor
<
T
,
1
>::
From
(
tensor
);
}
static
ConstType
Flatten
(
const
Tensor
&
tensor
)
{
static
typename
EigenTensor
<
T
,
1
>::
ConstType
Flatten
(
const
Tensor
&
tensor
)
{
return
EigenTensor
<
T
,
1
>::
From
(
tensor
,
make_ddim
({
static_cast
<
int
>
(
product
(
tensor
.
dims_
))}));
}
};
// Interpret paddle::platform::Tensor as EigenMatrix and EigenConstMatrix.
template
<
typename
T
,
typename
IndexType
=
Eigen
::
DenseIndex
>
struct
EigenMatrix
{
using
Type
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
2
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
;
using
ConstType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
2
,
Eigen
::
RowMajor
,
IndexType
>
,
Eigen
::
Aligned
>
;
static
Type
From
(
Tensor
&
tensor
)
{
return
EigenTensor
<
T
,
2
>::
From
(
tensor
);
}
static
ConstType
From
(
const
Tensor
&
tensor
)
{
return
EigenTensor
<
T
,
2
>::
From
(
tensor
);
}
};
template
<
typename
T
,
int
MajorType
=
Eigen
::
RowMajor
,
typename
IndexType
=
Eigen
::
DenseIndex
>
using
EigenMatrix
=
EigenTensor
<
T
,
2
,
MajorType
,
IndexType
>
;
}
// namespace framework
}
// namespace paddle
paddle/framework/tensor.h
浏览文件 @
57c27b4e
...
...
@@ -37,15 +37,12 @@ class Tensor {
template
<
bool
less
,
size_t
i
,
typename
...
args
>
friend
struct
paddle
::
pybind
::
details
::
CastToPyBufferImpl
;
template
<
typename
T
,
size_t
D
,
typename
IndexType
>
template
<
typename
T
,
size_t
D
,
int
MajorType
,
typename
IndexType
>
friend
struct
EigenTensor
;
template
<
typename
T
,
typename
IndexType
>
template
<
typename
T
,
int
MajorType
,
typename
IndexType
>
friend
struct
EigenVector
;
template
<
typename
T
,
typename
IndexType
>
friend
struct
EigenMatrix
;
public:
Tensor
()
:
offset_
(
0
)
{}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录