Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
5b4d3989
Commit
5b4d3989
authored
May 02, 2018
by
Paul
Browse files
Add more tests
parent
87446fc4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
11 deletions
+69
-11
test/shape_test.cpp
test/shape_test.cpp
+58
-0
test/test.hpp
test/test.hpp
+11
-11
No files found.
test/shape_test.cpp
View file @
5b4d3989
#include <rtg/shape.hpp>
#include <rtg/shape.hpp>
#include <array>
#include <algorithm>
#include <numeric>
#include "test.hpp"
#include "test.hpp"
void
test_shape_assign
()
void
test_shape_assign
()
...
@@ -21,6 +24,7 @@ void test_shape_default()
...
@@ -21,6 +24,7 @@ void test_shape_default()
void
test_shape4
()
void
test_shape4
()
{
{
rtg
::
shape
s
{
rtg
::
shape
::
float_type
,
{
100
,
32
,
8
,
8
}};
rtg
::
shape
s
{
rtg
::
shape
::
float_type
,
{
100
,
32
,
8
,
8
}};
EXPECT
(
s
.
packed
());
EXPECT
(
s
.
type
()
==
rtg
::
shape
::
float_type
);
EXPECT
(
s
.
type
()
==
rtg
::
shape
::
float_type
);
EXPECT
(
s
.
lens
()[
0
]
==
100
);
EXPECT
(
s
.
lens
()[
0
]
==
100
);
EXPECT
(
s
.
lens
()[
1
]
==
32
);
EXPECT
(
s
.
lens
()[
1
]
==
32
);
...
@@ -32,6 +36,59 @@ void test_shape4()
...
@@ -32,6 +36,59 @@ void test_shape4()
EXPECT
(
s
.
strides
()[
3
]
==
1
);
EXPECT
(
s
.
strides
()[
3
]
==
1
);
EXPECT
(
s
.
elements
()
==
100
*
32
*
8
*
8
);
EXPECT
(
s
.
elements
()
==
100
*
32
*
8
*
8
);
EXPECT
(
s
.
bytes
()
==
100
*
32
*
8
*
8
*
sizeof
(
float
));
EXPECT
(
s
.
bytes
()
==
100
*
32
*
8
*
8
*
sizeof
(
float
));
EXPECT
(
s
.
index
({
0
,
0
,
0
,
0
})
==
0
);
EXPECT
(
s
.
index
({
0
,
0
,
0
,
1
})
==
1
);
EXPECT
(
s
.
index
({
0
,
0
,
0
,
0
})
==
s
.
index
(
0
));
EXPECT
(
s
.
index
({
0
,
0
,
0
,
1
})
==
s
.
index
(
1
));
EXPECT
(
s
.
index
({
0
,
0
,
1
,
0
})
==
s
.
index
(
8
));
EXPECT
(
s
.
index
({
0
,
1
,
0
,
0
})
==
s
.
index
(
8
*
8
));
EXPECT
(
s
.
index
({
1
,
0
,
0
,
0
})
==
s
.
index
(
8
*
8
*
32
));
EXPECT
(
s
.
index
(
0
)
==
0
);
EXPECT
(
s
.
index
(
1
)
==
1
);
EXPECT
(
s
.
index
(
8
)
==
8
);
EXPECT
(
s
.
index
(
8
*
8
)
==
8
*
8
);
EXPECT
(
s
.
index
(
8
*
8
*
32
)
==
8
*
8
*
32
);
EXPECT
(
s
.
index
(
s
.
elements
()
-
1
)
==
s
.
elements
()
-
1
);
}
void
test_shape4_nonpacked
()
{
std
::
vector
<
std
::
size_t
>
lens
=
{
100
,
32
,
8
,
8
};
std
::
array
<
std
::
size_t
,
4
>
offsets
=
{{
5
,
10
,
0
,
6
}};
std
::
array
<
std
::
size_t
,
4
>
adj_lens
=
{{
0
,
0
,
0
,
0
}};
std
::
transform
(
lens
.
begin
(),
lens
.
end
(),
offsets
.
begin
(),
adj_lens
.
begin
(),
std
::
plus
<
size_t
>
());
// adj_lens should be: { 105, 42, 8, 14 }
std
::
vector
<
std
::
size_t
>
strides
(
4
);
strides
.
back
()
=
1
;
std
::
partial_sum
(
adj_lens
.
rbegin
(),
adj_lens
.
rend
()
-
1
,
strides
.
rbegin
()
+
1
,
std
::
multiplies
<
std
::
size_t
>
());
rtg
::
shape
s
{
rtg
::
shape
::
float_type
,
lens
,
strides
};
EXPECT
(
!
s
.
packed
());
EXPECT
(
s
.
type
()
==
rtg
::
shape
::
float_type
);
EXPECT
(
s
.
lens
()[
0
]
==
100
);
EXPECT
(
s
.
lens
()[
1
]
==
32
);
EXPECT
(
s
.
lens
()[
2
]
==
8
);
EXPECT
(
s
.
lens
()[
3
]
==
8
);
EXPECT
(
s
.
strides
()[
0
]
==
4704
);
EXPECT
(
s
.
strides
()[
1
]
==
112
);
EXPECT
(
s
.
strides
()[
2
]
==
14
);
EXPECT
(
s
.
strides
()[
3
]
==
1
);
EXPECT
(
s
.
elements
()
==
100
*
32
*
8
*
8
);
EXPECT
(
s
.
bytes
()
==
sizeof
(
float
)
*
469274
);
EXPECT
(
s
.
index
(
0
)
==
0
);
EXPECT
(
s
.
index
(
1
)
==
1
);
EXPECT
(
s
.
index
({
0
,
0
,
0
,
0
})
==
0
);
EXPECT
(
s
.
index
({
0
,
0
,
0
,
1
})
==
s
.
index
(
1
));
// TODO: Fix these tests
// EXPECT(s.index({0, 0, 1, 0}) == s.index(8));
// EXPECT(s.index({0, 1, 0, 0}) == s.index(8 * 8));
// EXPECT(s.index({1, 0, 0, 0}) == s.index(8 * 8 * 32));
// EXPECT(s.index(s.elements() - 1) == 469273);
}
}
int
main
()
int
main
()
...
@@ -39,4 +96,5 @@ int main()
...
@@ -39,4 +96,5 @@ int main()
test_shape_assign
();
test_shape_assign
();
test_shape_default
();
test_shape_default
();
test_shape4
();
test_shape4
();
test_shape4_nonpacked
();
}
}
test/test.hpp
View file @
5b4d3989
...
@@ -7,15 +7,19 @@
...
@@ -7,15 +7,19 @@
#ifndef RTG_GUARD_TEST_TEST_HPP
#ifndef RTG_GUARD_TEST_TEST_HPP
#define RTG_GUARD_TEST_TEST_HPP
#define RTG_GUARD_TEST_TEST_HPP
inline
void
failed
(
const
char
*
msg
,
const
char
*
file
,
int
line
)
inline
void
failed
(
bool
b
,
const
char
*
msg
,
const
char
*
file
,
int
line
)
{
{
if
(
!
b
)
std
::
cout
<<
"FAILED: "
<<
msg
<<
": "
<<
file
<<
": "
<<
line
<<
std
::
endl
;
std
::
cout
<<
"FAILED: "
<<
msg
<<
": "
<<
file
<<
": "
<<
line
<<
std
::
endl
;
}
}
[[
gnu
::
noreturn
]]
inline
void
failed_abort
(
const
char
*
msg
,
const
char
*
file
,
int
line
)
inline
void
failed_abort
(
bool
b
,
const
char
*
msg
,
const
char
*
file
,
int
line
)
{
{
failed
(
msg
,
file
,
line
);
if
(
!
b
)
{
std
::
cout
<<
"FAILED: "
<<
msg
<<
": "
<<
file
<<
": "
<<
line
<<
std
::
endl
;
std
::
abort
();
std
::
abort
();
}
}
}
template
<
class
TLeft
,
class
TRight
>
template
<
class
TLeft
,
class
TRight
>
...
@@ -35,13 +39,9 @@ inline void expect_equality(const TLeft& left,
...
@@ -35,13 +39,9 @@ inline void expect_equality(const TLeft& left,
}
}
// NOLINTNEXTLINE
// NOLINTNEXTLINE
#define CHECK(...) \
#define CHECK(...) failed(__VA_ARGS__, #__VA_ARGS__, __FILE__, __LINE__)
if(!(__VA_ARGS__)) \
failed(#__VA_ARGS__, __FILE__, __LINE__)
// NOLINTNEXTLINE
// NOLINTNEXTLINE
#define EXPECT(...) \
#define EXPECT(...) failed_abort(__VA_ARGS__, #__VA_ARGS__, __FILE__, __LINE__)
if(!(__VA_ARGS__)) \
failed_abort(#__VA_ARGS__, __FILE__, __LINE__)
// NOLINTNEXTLINE
// NOLINTNEXTLINE
#define EXPECT_EQUAL(LEFT, RIGHT) expect_equality(LEFT, RIGHT, #LEFT, #RIGHT, __FILE__, __LINE__)
#define EXPECT_EQUAL(LEFT, RIGHT) expect_equality(LEFT, RIGHT, #LEFT, #RIGHT, __FILE__, __LINE__)
// NOLINTNEXTLINE
// NOLINTNEXTLINE
...
...
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