Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jerrrrry
infinicore
Commits
615e2e25
Commit
615e2e25
authored
Mar 14, 2025
by
YdrMaster
Committed by
PanZezhong
Mar 14, 2025
Browse files
issue/68/fix: 添加测例
Signed-off-by:
YdrMaster
<
ydrml@hotmail.com
>
parent
2966666c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
11 deletions
+9
-11
src/utils-test/test_rearrange.cc
src/utils-test/test_rearrange.cc
+9
-11
No files found.
src/utils-test/test_rearrange.cc
View file @
615e2e25
...
...
@@ -45,28 +45,26 @@ size_t check_equal(
return
fails
;
}
int
test_transpose_2d
()
{
std
::
vector
<
size_t
>
shape
=
{
3
,
5
};
std
::
vector
<
ptrdiff_t
>
strides_a
=
{
5
,
1
};
std
::
vector
<
ptrdiff_t
>
strides_b
=
{
1
,
3
};
int
test_transpose_any
(
size_t
index
,
std
::
vector
<
size_t
>
shape
,
std
::
vector
<
ptrdiff_t
>
strides_a
,
std
::
vector
<
ptrdiff_t
>
strides_b
)
{
auto
numel
=
std
::
accumulate
(
shape
.
begin
(),
shape
.
end
(),
(
size_t
)
1
,
std
::
multiplies
<
size_t
>
());
std
::
vector
<
float
>
a
(
numel
);
std
::
vector
<
float
>
b
(
numel
);
for
(
size_t
i
=
0
;
i
<
numel
;
i
++
)
{
a
[
i
]
=
(
float
)
i
/
numel
;
}
utils
::
rearrange
(
b
.
data
(),
a
.
data
(),
shape
.
data
(),
strides_b
.
data
(),
strides_a
.
data
(),
2
,
sizeof
(
float
));
if
(
check_equal
<
float
>
(
a
.
data
(),
b
.
data
(),
shape
,
strides_a
,
strides_b
))
{
utils
::
rearrange
(
b
.
data
(),
a
.
data
(),
shape
.
data
(),
strides_b
.
data
(),
strides_a
.
data
(),
shape
.
size
(),
sizeof
(
float
));
auto
fails
=
check_equal
<
float
>
(
a
.
data
(),
b
.
data
(),
shape
,
strides_a
,
strides_b
);
if
(
fails
>
0
)
{
std
::
cout
<<
"test_transpose "
<<
index
<<
" failed"
<<
std
::
endl
;
return
1
;
}
else
{
std
::
cout
<<
"test_transpose_2d passed"
<<
std
::
endl
;
std
::
cout
<<
"test_transpose "
<<
index
<<
" passed"
<<
std
::
endl
;
return
0
;
}
return
0
;
}
int
test_rearrange
()
{
return
test_transpose_2d
();
return
test_transpose_any
(
1
,
{
3
,
5
},
{
5
,
1
},
{
1
,
3
})
+
test_transpose_any
(
2
,
{
1
,
2048
},
{
2048
,
1
},
{
2048
,
1
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment