Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
ad64ca5d
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ad64ca5d
编写于
9月 12, 2017
作者:
Q
qingqing01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Call Tensor::numel() everywhere.
上级
a2a69f2a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
8 addition
and
5 deletion
+8
-5
paddle/framework/tensor.h
paddle/framework/tensor.h
+4
-1
paddle/framework/tensor_impl.h
paddle/framework/tensor_impl.h
+4
-4
未找到文件。
paddle/framework/tensor.h
浏览文件 @
ad64ca5d
...
@@ -162,7 +162,10 @@ class Tensor {
...
@@ -162,7 +162,10 @@ class Tensor {
/*! points to dimensions of memory block. */
/*! points to dimensions of memory block. */
DDim
dims_
;
DDim
dims_
;
/*! the element count of tensor. */
/**
* A cache of the number of elements in a tensor.
* Would be 0 for an uninitialized tensor.
*/
int64_t
numel_
;
int64_t
numel_
;
/**
/**
...
...
paddle/framework/tensor_impl.h
浏览文件 @
ad64ca5d
...
@@ -24,7 +24,7 @@ inline void Tensor::check_memory_size() const {
...
@@ -24,7 +24,7 @@ inline void Tensor::check_memory_size() const {
PADDLE_ENFORCE_NOT_NULL
(
PADDLE_ENFORCE_NOT_NULL
(
holder_
,
"Tenosr holds no memory. Call Tensor::mutable_data first."
);
holder_
,
"Tenosr holds no memory. Call Tensor::mutable_data first."
);
PADDLE_ENFORCE_GE
(
PADDLE_ENFORCE_GE
(
holder_
->
size
(),
numel
_
*
sizeof
(
T
)
+
offset_
,
holder_
->
size
(),
numel
()
*
sizeof
(
T
)
+
offset_
,
"Tensor's dims_ is out of bound. Call Tensor::mutable_data "
"Tensor's dims_ is out of bound. Call Tensor::mutable_data "
"first to re-allocate memory.
\n
"
"first to re-allocate memory.
\n
"
"or maybe the required data-type mismatches the data already stored."
);
"or maybe the required data-type mismatches the data already stored."
);
...
@@ -54,11 +54,11 @@ inline T* Tensor::mutable_data(DDim dims, platform::Place place) {
...
@@ -54,11 +54,11 @@ inline T* Tensor::mutable_data(DDim dims, platform::Place place) {
template
<
typename
T
>
template
<
typename
T
>
inline
T
*
Tensor
::
mutable_data
(
platform
::
Place
place
)
{
inline
T
*
Tensor
::
mutable_data
(
platform
::
Place
place
)
{
static_assert
(
std
::
is_pod
<
T
>::
value
,
"T must be POD"
);
static_assert
(
std
::
is_pod
<
T
>::
value
,
"T must be POD"
);
PADDLE_ENFORCE_GT
(
numel
_
,
0
,
PADDLE_ENFORCE_GT
(
numel
()
,
0
,
"Tensor's numel must be larger than zero to call "
"Tensor's numel must be larger than zero to call "
"Tensor::mutable_data. Call Tensor::set_dim first."
);
"Tensor::mutable_data. Call Tensor::set_dim first."
);
/* some versions of boost::variant don't have operator!= */
/* some versions of boost::variant don't have operator!= */
int64_t
size
=
numel
_
*
sizeof
(
T
);
int64_t
size
=
numel
()
*
sizeof
(
T
);
if
(
holder_
==
nullptr
||
!
(
holder_
->
place
()
==
place
)
||
if
(
holder_
==
nullptr
||
!
(
holder_
->
place
()
==
place
)
||
holder_
->
size
()
<
size
+
offset_
)
{
holder_
->
size
()
<
size
+
offset_
)
{
if
(
platform
::
is_cpu_place
(
place
))
{
if
(
platform
::
is_cpu_place
(
place
))
{
...
@@ -131,7 +131,7 @@ inline Tensor Tensor::Slice(const int& begin_idx, const int& end_idx) const {
...
@@ -131,7 +131,7 @@ inline Tensor Tensor::Slice(const int& begin_idx, const int& end_idx) const {
PADDLE_ENFORCE_LT
(
begin_idx
,
end_idx
,
PADDLE_ENFORCE_LT
(
begin_idx
,
end_idx
,
"Begin index must be less than end index."
);
"Begin index must be less than end index."
);
PADDLE_ENFORCE_NE
(
dims_
[
0
],
1
,
"Can not slice a tensor with dims_[0] = 1."
);
PADDLE_ENFORCE_NE
(
dims_
[
0
],
1
,
"Can not slice a tensor with dims_[0] = 1."
);
size_t
base
=
numel
_
/
dims_
[
0
];
size_t
base
=
numel
()
/
dims_
[
0
];
Tensor
dst
;
Tensor
dst
;
dst
.
holder_
=
holder_
;
dst
.
holder_
=
holder_
;
DDim
dst_dims
=
dims_
;
DDim
dst_dims
=
dims_
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录