Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
4a8b97ee
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
未验证
提交
4a8b97ee
编写于
3月 14, 2023
作者:
zhouweiwei2014
提交者:
GitHub
3月 14, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Zero Dim] hack process Tensor.numpy() from 0D to 1D to avoid much incompatible (#51586)
上级
145a6cbb
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
4 deletion
+17
-4
paddle/fluid/pybind/eager_method.cc
paddle/fluid/pybind/eager_method.cc
+17
-4
未找到文件。
paddle/fluid/pybind/eager_method.cc
浏览文件 @
4a8b97ee
...
@@ -120,11 +120,24 @@ static PyObject* tensor_method_numpy(TensorObject* self,
...
@@ -120,11 +120,24 @@ static PyObject* tensor_method_numpy(TensorObject* self,
auto
sizeof_dtype
=
phi
::
SizeOf
(
self
->
tensor
.
type
());
auto
sizeof_dtype
=
phi
::
SizeOf
(
self
->
tensor
.
type
());
Py_intptr_t
py_dims
[
paddle
::
framework
::
DDim
::
kMaxRank
];
Py_intptr_t
py_dims
[
paddle
::
framework
::
DDim
::
kMaxRank
];
Py_intptr_t
py_strides
[
paddle
::
framework
::
DDim
::
kMaxRank
];
Py_intptr_t
py_strides
[
paddle
::
framework
::
DDim
::
kMaxRank
];
size_t
py_rank
=
tensor_dims
.
size
();
size_t
numel
=
1
;
size_t
numel
=
1
;
for
(
int
i
=
tensor_dims
.
size
()
-
1
;
i
>=
0
;
--
i
)
{
if
(
py_rank
==
0
)
{
py_dims
[
i
]
=
static_cast
<
size_t
>
(
tensor_dims
[
i
]);
// 0D Tensor hack process to 1D numpy, will remove in future
py_strides
[
i
]
=
sizeof_dtype
*
numel
;
VLOG
(
0
)
<<
"Warning:: 0D Tensor cannot be used as Tensor.numpy()[0], Now "
numel
*=
py_dims
[
i
];
"0D will be changed to 1D numpy to avoid this problem, but it's "
"not correct and will be removed in future. Please change "
"'Tensor.numpy()[0]' to 'float(Tensor)' or "
"'Tensor.numpy().item()' as soon as possible."
;
py_rank
=
1
;
py_dims
[
0
]
=
1
;
py_strides
[
0
]
=
sizeof_dtype
*
numel
;
}
else
{
for
(
int
i
=
tensor_dims
.
size
()
-
1
;
i
>=
0
;
--
i
)
{
py_dims
[
i
]
=
static_cast
<
size_t
>
(
tensor_dims
[
i
]);
py_strides
[
i
]
=
sizeof_dtype
*
numel
;
numel
*=
py_dims
[
i
];
}
}
}
PyObject
*
array
=
api
.
PyArray_NewFromDescr_
(
PyObject
*
array
=
api
.
PyArray_NewFromDescr_
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录