Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
d7fc3781
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
未验证
提交
d7fc3781
编写于
9月 04, 2023
作者:
W
wanghuancoder
提交者:
GitHub
9月 04, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix contiguous (#56863)
* fix contiguous
上级
83b942f3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
4 addition
and
32 deletion
+4
-32
paddle/fluid/pybind/eager_method.cc
paddle/fluid/pybind/eager_method.cc
+4
-3
test/legacy_test/test_stride.py
test/legacy_test/test_stride.py
+0
-29
未找到文件。
paddle/fluid/pybind/eager_method.cc
浏览文件 @
d7fc3781
...
@@ -2819,9 +2819,10 @@ static PyObject* tensor_contiguous(TensorObject* self,
...
@@ -2819,9 +2819,10 @@ static PyObject* tensor_contiguous(TensorObject* self,
return
reinterpret_cast
<
PyObject
*>
(
self
);
return
reinterpret_cast
<
PyObject
*>
(
self
);
}
else
{
}
else
{
eager_gil_scoped_release
guard
;
eager_gil_scoped_release
guard
;
return
ToPyObject
(
self
->
tensor
.
set_impl
(
std
::
make_shared
<
phi
::
DenseTensor
>
(
std
::
move
(
paddle
::
Tensor
(
std
::
make_shared
<
phi
::
DenseTensor
>
(
std
::
move
(
paddle
::
experimental
::
Trans2Contiguous
(
*
(
dense_tensor
.
get
())))));
paddle
::
experimental
::
Trans2Contiguous
(
*
(
dense_tensor
.
get
()))))));
Py_INCREF
(
self
);
return
reinterpret_cast
<
PyObject
*>
(
self
);
}
}
}
else
{
}
else
{
...
...
test/legacy_test/test_stride.py
浏览文件 @
d7fc3781
...
@@ -42,13 +42,11 @@ class TestStride(unittest.TestCase):
...
@@ -42,13 +42,11 @@ class TestStride(unittest.TestCase):
x_c
=
x_transposed1
.
contiguous
()
x_c
=
x_transposed1
.
contiguous
()
self
.
assertTrue
(
np
.
allclose
(
x_c
.
numpy
(),
x_np_transposed1
))
self
.
assertTrue
(
np
.
allclose
(
x_c
.
numpy
(),
x_np_transposed1
))
self
.
assertFalse
(
x_c
.
_is_shared_buffer_with
(
x_transposed1
))
x_transposed2
=
paddle
.
transpose
(
x_transposed1
,
perm
=
[
2
,
0
,
1
])
x_transposed2
=
paddle
.
transpose
(
x_transposed1
,
perm
=
[
2
,
0
,
1
])
x_np_transposed2
=
x_np_transposed1
.
transpose
(
2
,
0
,
1
)
x_np_transposed2
=
x_np_transposed1
.
transpose
(
2
,
0
,
1
)
self
.
assertTrue
(
np
.
allclose
(
x_transposed2
.
numpy
(),
x_np_transposed2
))
self
.
assertTrue
(
np
.
allclose
(
x_transposed2
.
numpy
(),
x_np_transposed2
))
self
.
assertFalse
(
x_transposed2
.
is_contiguous
())
self
.
assertFalse
(
x_transposed2
.
is_contiguous
())
self
.
assertTrue
(
x
.
_is_shared_buffer_with
(
x_transposed2
))
y
=
x_transposed2
+
2
y
=
x_transposed2
+
2
y_np
=
x_np_transposed2
+
2
y_np
=
x_np_transposed2
+
2
...
@@ -96,11 +94,6 @@ class TestStride(unittest.TestCase):
...
@@ -96,11 +94,6 @@ class TestStride(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
out3_c
.
numpy
(),
np_out3
))
self
.
assertTrue
(
np
.
allclose
(
out3_c
.
numpy
(),
np_out3
))
self
.
assertTrue
(
np
.
allclose
(
out4_c
.
numpy
(),
np_out4
))
self
.
assertTrue
(
np
.
allclose
(
out4_c
.
numpy
(),
np_out4
))
self
.
assertFalse
(
out_c
.
_is_shared_buffer_with
(
out
))
self
.
assertFalse
(
out2_c
.
_is_shared_buffer_with
(
out2
))
self
.
assertFalse
(
out3_c
.
_is_shared_buffer_with
(
out3
))
self
.
assertFalse
(
out4_c
.
_is_shared_buffer_with
(
out4
))
def
call_slice
(
self
):
def
call_slice
(
self
):
x_np
=
np
.
random
.
random
(
size
=
[
10
,
10
,
10
,
20
]).
astype
(
'float32'
)
x_np
=
np
.
random
.
random
(
size
=
[
10
,
10
,
10
,
20
]).
astype
(
'float32'
)
x
=
paddle
.
to_tensor
(
x_np
)
x
=
paddle
.
to_tensor
(
x_np
)
...
@@ -141,8 +134,6 @@ class TestStride(unittest.TestCase):
...
@@ -141,8 +134,6 @@ class TestStride(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
out_c
.
numpy
(),
np_out
))
self
.
assertTrue
(
np
.
allclose
(
out_c
.
numpy
(),
np_out
))
self
.
assertFalse
(
out_c
.
_is_shared_buffer_with
(
out
))
def
call_index_select
(
self
):
def
call_index_select
(
self
):
x_np
=
np
.
random
.
random
(
size
=
[
10
,
10
,
10
,
20
]).
astype
(
'float32'
)
x_np
=
np
.
random
.
random
(
size
=
[
10
,
10
,
10
,
20
]).
astype
(
'float32'
)
x
=
paddle
.
to_tensor
(
x_np
)
x
=
paddle
.
to_tensor
(
x_np
)
...
@@ -161,8 +152,6 @@ class TestStride(unittest.TestCase):
...
@@ -161,8 +152,6 @@ class TestStride(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
out_c
.
numpy
(),
np_out
))
self
.
assertTrue
(
np
.
allclose
(
out_c
.
numpy
(),
np_out
))
self
.
assertFalse
(
out_c
.
_is_shared_buffer_with
(
out
))
def
call_reshape
(
self
):
def
call_reshape
(
self
):
x_np
=
np
.
random
.
random
(
size
=
[
10
,
10
,
10
,
20
]).
astype
(
'float32'
)
x_np
=
np
.
random
.
random
(
size
=
[
10
,
10
,
10
,
20
]).
astype
(
'float32'
)
x
=
paddle
.
to_tensor
(
x_np
)
x
=
paddle
.
to_tensor
(
x_np
)
...
@@ -201,8 +190,6 @@ class TestStride(unittest.TestCase):
...
@@ -201,8 +190,6 @@ class TestStride(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
out_c
.
numpy
(),
np_out
))
self
.
assertTrue
(
np
.
allclose
(
out_c
.
numpy
(),
np_out
))
self
.
assertFalse
(
out_c
.
_is_shared_buffer_with
(
out
))
def
call_imag
(
self
):
def
call_imag
(
self
):
x_np
=
np
.
random
.
random
(
size
=
[
10
,
10
,
10
,
20
]).
astype
(
'complex128'
)
x_np
=
np
.
random
.
random
(
size
=
[
10
,
10
,
10
,
20
]).
astype
(
'complex128'
)
x
=
paddle
.
to_tensor
(
x_np
)
x
=
paddle
.
to_tensor
(
x_np
)
...
@@ -221,8 +208,6 @@ class TestStride(unittest.TestCase):
...
@@ -221,8 +208,6 @@ class TestStride(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
out_c
.
numpy
(),
np_out
))
self
.
assertTrue
(
np
.
allclose
(
out_c
.
numpy
(),
np_out
))
self
.
assertFalse
(
out_c
.
_is_shared_buffer_with
(
out
))
def
call_as_real
(
self
):
def
call_as_real
(
self
):
x_np
=
np
.
random
.
random
(
size
=
[
10
,
10
,
10
,
20
]).
astype
(
'complex128'
)
x_np
=
np
.
random
.
random
(
size
=
[
10
,
10
,
10
,
20
]).
astype
(
'complex128'
)
x
=
paddle
.
to_tensor
(
x_np
)
x
=
paddle
.
to_tensor
(
x_np
)
...
@@ -351,10 +336,6 @@ class TestStride(unittest.TestCase):
...
@@ -351,10 +336,6 @@ class TestStride(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
out1_c
.
numpy
(),
np_out1
))
self
.
assertTrue
(
np
.
allclose
(
out1_c
.
numpy
(),
np_out1
))
self
.
assertTrue
(
np
.
allclose
(
out2_c
.
numpy
(),
np_out2
))
self
.
assertTrue
(
np
.
allclose
(
out2_c
.
numpy
(),
np_out2
))
self
.
assertFalse
(
out0_c
.
_is_shared_buffer_with
(
out0
))
self
.
assertFalse
(
out1_c
.
_is_shared_buffer_with
(
out1
))
self
.
assertFalse
(
out2_c
.
_is_shared_buffer_with
(
out2
))
def
call_split2
(
self
):
def
call_split2
(
self
):
x_np
=
np
.
random
.
random
(
size
=
[
3
,
9
,
5
]).
astype
(
'float32'
)
x_np
=
np
.
random
.
random
(
size
=
[
3
,
9
,
5
]).
astype
(
'float32'
)
x
=
paddle
.
to_tensor
(
x_np
)
x
=
paddle
.
to_tensor
(
x_np
)
...
@@ -386,10 +367,6 @@ class TestStride(unittest.TestCase):
...
@@ -386,10 +367,6 @@ class TestStride(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
out1_c
.
numpy
(),
np_out1
))
self
.
assertTrue
(
np
.
allclose
(
out1_c
.
numpy
(),
np_out1
))
self
.
assertTrue
(
np
.
allclose
(
out2_c
.
numpy
(),
np_out2
))
self
.
assertTrue
(
np
.
allclose
(
out2_c
.
numpy
(),
np_out2
))
self
.
assertFalse
(
out0_c
.
_is_shared_buffer_with
(
out0
))
self
.
assertFalse
(
out1_c
.
_is_shared_buffer_with
(
out1
))
self
.
assertFalse
(
out2_c
.
_is_shared_buffer_with
(
out2
))
def
call_split3
(
self
):
def
call_split3
(
self
):
x_np
=
np
.
random
.
random
(
size
=
[
9
,
3
,
5
]).
astype
(
'float32'
)
x_np
=
np
.
random
.
random
(
size
=
[
9
,
3
,
5
]).
astype
(
'float32'
)
x
=
paddle
.
to_tensor
(
x_np
)
x
=
paddle
.
to_tensor
(
x_np
)
...
@@ -485,10 +462,6 @@ class TestStride(unittest.TestCase):
...
@@ -485,10 +462,6 @@ class TestStride(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
out1_c
.
numpy
(),
np_out1
))
self
.
assertTrue
(
np
.
allclose
(
out1_c
.
numpy
(),
np_out1
))
self
.
assertTrue
(
np
.
allclose
(
out2_c
.
numpy
(),
np_out2
))
self
.
assertTrue
(
np
.
allclose
(
out2_c
.
numpy
(),
np_out2
))
self
.
assertFalse
(
out0_c
.
_is_shared_buffer_with
(
out0
))
self
.
assertFalse
(
out1_c
.
_is_shared_buffer_with
(
out1
))
self
.
assertFalse
(
out2_c
.
_is_shared_buffer_with
(
out2
))
def
call_unbind
(
self
):
def
call_unbind
(
self
):
x_np
=
np
.
random
.
random
(
size
=
[
3
,
9
,
5
]).
astype
(
'float32'
)
x_np
=
np
.
random
.
random
(
size
=
[
3
,
9
,
5
]).
astype
(
'float32'
)
x
=
paddle
.
to_tensor
(
x_np
)
x
=
paddle
.
to_tensor
(
x_np
)
...
@@ -622,8 +595,6 @@ class TestStride(unittest.TestCase):
...
@@ -622,8 +595,6 @@ class TestStride(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
out_c
.
numpy
(),
np_out
))
self
.
assertTrue
(
np
.
allclose
(
out_c
.
numpy
(),
np_out
))
self
.
assertFalse
(
out_c
.
_is_shared_buffer_with
(
out
))
def
call_stride
(
self
):
def
call_stride
(
self
):
self
.
call_transpose
()
self
.
call_transpose
()
self
.
call_diagonal
()
self
.
call_diagonal
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录