Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
9658f49b
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
9658f49b
编写于
3月 14, 2023
作者:
J
JYChen
提交者:
GitHub
3月 14, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix UT when np >= 1.23 (#51466)
* fix UT when np >= 1.24 * optimize decription of this change
上级
9cd99f7e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
5 deletion
+35
-5
python/paddle/fluid/tests/unittests/test_var_base.py
python/paddle/fluid/tests/unittests/test_var_base.py
+15
-2
python/paddle/fluid/tests/unittests/test_variable.py
python/paddle/fluid/tests/unittests/test_variable.py
+20
-3
未找到文件。
python/paddle/fluid/tests/unittests/test_var_base.py
浏览文件 @
9658f49b
...
...
@@ -952,9 +952,22 @@ class TestVarBase(unittest.TestCase):
array
=
np
.
arange
(
120
).
reshape
([
6
,
5
,
4
])
x
=
paddle
.
to_tensor
(
array
)
py_idx
=
[[
0
,
2
,
0
,
1
,
3
],
[
0
,
0
,
1
,
2
,
0
]]
# note(chenjianye):
# Non-tuple sequence for multidimensional indexing is supported in numpy < 1.23.
# For List case, the outermost `[]` will be treated as tuple `()` in version less than 1.23,
# which is used to wrap index elements for multiple axes.
# And from 1.23, this will be treat as a whole and only works on one axis.
#
# e.g. x[[[0],[1]]] == x[([0],[1])] == x[[0],[1]] (in version < 1.23)
# x[[[0],[1]]] == x[array([[0],[1]])] (in version >= 1.23)
#
# Here, we just modify the code to remove the impact of numpy version changes,
# changing x[[[0],[1]]] to x[tuple([[0],[1]])] == x[([0],[1])] == x[[0],[1]].
# Whether the paddle behavior in this case will change is still up for debate.
idx
=
[
paddle
.
to_tensor
(
py_idx
[
0
]),
paddle
.
to_tensor
(
py_idx
[
1
])]
np
.
testing
.
assert_array_equal
(
x
[
idx
].
numpy
(),
array
[
py_idx
])
np
.
testing
.
assert_array_equal
(
x
[
py_idx
].
numpy
(),
array
[
py_idx
])
np
.
testing
.
assert_array_equal
(
x
[
idx
].
numpy
(),
array
[
tuple
(
py_idx
)
])
np
.
testing
.
assert_array_equal
(
x
[
py_idx
].
numpy
(),
array
[
tuple
(
py_idx
)
])
# case2:
tensor_x
=
paddle
.
to_tensor
(
np
.
zeros
(
12
).
reshape
(
2
,
6
).
astype
(
np
.
float32
)
...
...
python/paddle/fluid/tests/unittests/test_variable.py
浏览文件 @
9658f49b
...
...
@@ -596,6 +596,19 @@ class TestVariableSlice(unittest.TestCase):
class
TestListIndex
(
unittest
.
TestCase
):
# note(chenjianye):
# Non-tuple sequence for multidimensional indexing is supported in numpy < 1.23.
# For List case, the outermost `[]` will be treated as tuple `()` in version less than 1.23,
# which is used to wrap index elements for multiple axes.
# And from 1.23, this will be treat as a whole and only works on one axis.
#
# e.g. x[[[0],[1]]] == x[([0],[1])] == x[[0],[1]] (in version < 1.23)
# x[[[0],[1]]] == x[array([[0],[1]])] (in version >= 1.23)
#
# Here, we just modify the code to remove the impact of numpy version changes,
# changing x[[[0],[1]]] to x[tuple([[0],[1]])] == x[([0],[1])] == x[[0],[1]].
# Whether the paddle behavior in this case will change is still up for debate.
def
setUp
(
self
):
np
.
random
.
seed
(
2022
)
...
...
@@ -637,7 +650,7 @@ class TestListIndex(unittest.TestCase):
exe
.
run
(
paddle
.
static
.
default_startup_program
())
fetch_list
=
[
y
.
name
]
getitem_np
=
array
[
index_mod
]
getitem_np
=
array
[
tuple
(
index_mod
)
]
getitem_pp
=
exe
.
run
(
prog
,
feed
=
{
x
.
name
:
array
},
fetch_list
=
fetch_list
)
...
...
@@ -659,7 +672,7 @@ class TestListIndex(unittest.TestCase):
pt
=
paddle
.
to_tensor
(
array
)
index_mod
=
(
index
%
(
array
.
shape
[
-
1
])).
tolist
()
try
:
getitem_np
=
array
[
index_mod
]
getitem_np
=
array
[
tuple
(
index_mod
)
]
except
:
with
self
.
assertRaises
(
ValueError
):
...
...
@@ -844,8 +857,12 @@ class TestListIndex(unittest.TestCase):
exe
.
run
(
paddle
.
static
.
default_startup_program
())
fetch_list
=
[
y
.
name
]
array2
=
array
.
copy
()
try
:
index
=
(
tuple
(
index
)
if
isinstance
(
index
,
list
)
and
isinstance
(
index
[
0
],
list
)
else
index
)
array2
[
index
]
=
value_np
except
:
with
self
.
assertRaises
(
ValueError
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录