FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
arrayfire/test/fast.cpp at master · AMD-Ecosystem/arrayfire · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
AMD-Ecosystem
/
arrayfire
Public
forked from
arrayfire/arrayfire
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
arrayfire
/
test
/
fast.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
241 lines (195 loc) · 8.1 KB
Breadcrumbs
arrayfire
/
test
/
fast.cpp
Copy path
File metadata and controls
241 lines (195 loc) · 8.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
*******************************************************
*/
#
include
<
arrayfire.h
>
#
include
<
gtest/gtest.h
>
#
include
<
testHelpers.hpp
>
#
include
<
af/compatible.h
>
#
include
<
af/dim4.hpp
>
#
include
<
af/traits.hpp
>
#
include
<
cmath
>
#
include
<
string
>
#
include
<
typeinfo
>
#
include
<
vector
>
using
af::dim4;
using
std::abs;
using
std::endl;
using
std::string;
using
std::vector;
typedef
struct
{
float
f[
5
];
}
feat_t
;
static
bool
feat_cmp
(
feat_t
i,
feat_t
j) {
for
(
int
k =
0
; k <
5
; k++)
if
(i.
f
[k] != j.
f
[k])
return
(i.
f
[k] < j.
f
[k]);
return
false
;
}
static
void
array_to_feat
(vector<
feat_t
> &feat,
float
*x,
float
*y,
float
*score,
float
*orientation,
float
*size,
unsigned
nfeat) {
feat.
resize
(nfeat);
for
(
unsigned
i =
0
; i < feat.
size
(); i++) {
feat[i].
f
[
0
] = x[i];
feat[i].
f
[
1
] = y[i];
feat[i].
f
[
2
] = score[i];
feat[i].
f
[
3
] = orientation[i];
feat[i].
f
[
4
] = size[i];
}
}
template
<
typename
T>
class
FloatFAST
: public ::testing::Test {
public:
virtual
void
SetUp
() {}
};
template
<
typename
T>
class
FixedFAST
: public ::testing::Test {
public:
virtual
void
SetUp
() {}
};
typedef
::testing::Types<
float
,
double
> FloatTestTypes;
typedef
::testing::Types<
int
,
unsigned
,
short
, ushort, schar> FixedTestTypes;
TYPED_TEST_SUITE
(FloatFAST, FloatTestTypes);
TYPED_TEST_SUITE
(FixedFAST, FixedTestTypes);
template
<
typename
T>
void
fastTest
(string pTestFile,
bool
nonmax) {
SUPPORTED_TYPE_CHECK
(T);
IMAGEIO_ENABLED_CHECK
();
vector<dim4> inDims;
vector<string> inFiles;
vector<vector<
float
>> gold;
readImageTests
(pTestFile, inDims, inFiles, gold);
size_t
testCount = inDims.
size
();
for
(
size_t
testId =
0
; testId < testCount; ++testId) {
dim_t
nElems =
0
;
af_array inArray_f32 =
0
;
af_array inArray =
0
;
af_features out;
inFiles[testId].
insert
(
0
,
string
(
TEST_DIR
"
/fast/
"
));
ASSERT_SUCCESS
(
af_load_image
(&inArray_f32, inFiles[testId].
c_str
(),
false
));
ASSERT_SUCCESS
(conv_image<T>(&inArray, inArray_f32));
ASSERT_SUCCESS
(
af_fast
(&out, inArray,
20
.
0f
,
9
, nonmax,
0
.
05f
,
3
));
dim_t
n =
0
;
af_array x, y, score, orientation, size;
ASSERT_SUCCESS
(
af_get_features_num
(&n, out));
ASSERT_SUCCESS
(
af_get_features_xpos
(&x, out));
ASSERT_SUCCESS
(
af_get_features_ypos
(&y, out));
ASSERT_SUCCESS
(
af_get_features_score
(&score, out));
ASSERT_SUCCESS
(
af_get_features_orientation
(&orientation, out));
ASSERT_SUCCESS
(
af_get_features_size
(&size, out));
ASSERT_SUCCESS
(
af_get_elements
(&nElems, x));
float
*outX =
new
float
[gold[
0
].
size
()];
float
*outY =
new
float
[gold[
1
].
size
()];
float
*outScore =
new
float
[gold[
2
].
size
()];
float
*outOrientation =
new
float
[gold[
3
].
size
()];
float
*outSize =
new
float
[gold[
4
].
size
()];
ASSERT_SUCCESS
(
af_get_data_ptr
((
void
*)outX, x));
ASSERT_SUCCESS
(
af_get_data_ptr
((
void
*)outY, y));
ASSERT_SUCCESS
(
af_get_data_ptr
((
void
*)outScore, score));
ASSERT_SUCCESS
(
af_get_data_ptr
((
void
*)outOrientation, orientation));
ASSERT_SUCCESS
(
af_get_data_ptr
((
void
*)outSize, size));
vector<
feat_t
> out_feat;
array_to_feat
(out_feat, outX, outY, outScore, outOrientation, outSize,
n);
vector<
feat_t
> gold_feat;
array_to_feat
(gold_feat, &gold[
0
].
front
(), &gold[
1
].
front
(),
&gold[
2
].
front
(), &gold[
3
].
front
(), &gold[
4
].
front
(),
gold[
0
].
size
());
std::sort
(out_feat.
begin
(), out_feat.
end
(), feat_cmp);
std::sort
(gold_feat.
begin
(), gold_feat.
end
(), feat_cmp);
for
(
int
elIter =
0
; elIter < (
int
)nElems; elIter++) {
ASSERT_EQ
(out_feat[elIter].
f
[
0
], gold_feat[elIter].
f
[
0
])
<<
"
at:
"
<< elIter << endl;
ASSERT_EQ
(out_feat[elIter].
f
[
1
], gold_feat[elIter].
f
[
1
])
<<
"
at:
"
<< elIter << endl;
ASSERT_LE
(
fabs
(out_feat[elIter].
f
[
2
] - gold_feat[elIter].
f
[
2
]),
1e-3
)
<<
"
at:
"
<< elIter << endl;
ASSERT_EQ
(out_feat[elIter].
f
[
3
], gold_feat[elIter].
f
[
3
])
<<
"
at:
"
<< elIter << endl;
ASSERT_EQ
(out_feat[elIter].
f
[
4
], gold_feat[elIter].
f
[
4
])
<<
"
at:
"
<< elIter << endl;
}
ASSERT_SUCCESS
(
af_release_array
(inArray));
ASSERT_SUCCESS
(
af_release_array
(inArray_f32));
ASSERT_SUCCESS
(
af_release_features
(out));
delete[]
outX;
delete[]
outY;
delete[]
outScore;
delete[]
outOrientation;
delete[]
outSize;
}
}
#
define
FLOAT_FAST_INIT
(
desc, image, nonmax
) \
TYPED_TEST
(FloatFAST, desc) { \
UNSUPPORTED_BACKEND
(
AF_BACKEND_ONEAPI
); \
fastTest<TypeParam>(
string
(
TEST_DIR
"
/fast/
"
#image
"
_float.test
"
), \
nonmax); \
}
#
define
FIXED_FAST_INIT
(
desc, image, nonmax
) \
TYPED_TEST
(FixedFAST, desc) { \
UNSUPPORTED_BACKEND
(
AF_BACKEND_ONEAPI
); \
fastTest<TypeParam>(
string
(
TEST_DIR
"
/fast/
"
#image
"
_fixed.test
"
), \
nonmax); \
}
FLOAT_FAST_INIT
(square, square,
false
);
FLOAT_FAST_INIT
(square_nonmax, square_nonmax,
true
);
FIXED_FAST_INIT
(square, square,
false
);
FIXED_FAST_INIT
(square_nonmax, square_nonmax,
true
);
//
///////////////////////////////// CPP ////////////////////////////////
using
af::array;
using
af::features;
using
af::loadImage;
TEST
(FloatFAST,
CPP
) {
UNSUPPORTED_BACKEND
(
AF_BACKEND_ONEAPI
);
IMAGEIO_ENABLED_CHECK
();
vector<dim4> inDims;
vector<string> inFiles;
vector<vector<
float
>> gold;
readImageTests
(
string
(
TEST_DIR
"
/fast/square_nonmax_float.test
"
), inDims,
inFiles, gold);
inFiles[
0
].
insert
(
0
,
string
(
TEST_DIR
"
/fast/
"
));
array in =
loadImage
(inFiles[
0
].
c_str
(),
false
);
features out =
fast
(in,
20
.
0f
,
9
,
true
,
0
.
05f
,
3
);
float
*outX =
new
float
[gold[
0
].
size
()];
float
*outY =
new
float
[gold[
1
].
size
()];
float
*outScore =
new
float
[gold[
2
].
size
()];
float
*outOrientation =
new
float
[gold[
3
].
size
()];
float
*outSize =
new
float
[gold[
4
].
size
()];
out.
getX
().
host
(outX);
out.
getY
().
host
(outY);
out.
getScore
().
host
(outScore);
out.
getOrientation
().
host
(outOrientation);
out.
getSize
().
host
(outSize);
vector<
feat_t
> out_feat;
array_to_feat
(out_feat, outX, outY, outScore, outOrientation, outSize,
out.
getNumFeatures
());
vector<
feat_t
> gold_feat;
array_to_feat
(gold_feat, &gold[
0
].
front
(), &gold[
1
].
front
(),
&gold[
2
].
front
(), &gold[
3
].
front
(), &gold[
4
].
front
(),
gold[
0
].
size
());
std::sort
(out_feat.
begin
(), out_feat.
end
(), feat_cmp);
std::sort
(gold_feat.
begin
(), gold_feat.
end
(), feat_cmp);
for
(
unsigned
elIter =
0
; elIter < out.
getNumFeatures
(); elIter++) {
ASSERT_EQ
(out_feat[elIter].
f
[
0
], gold_feat[elIter].
f
[
0
])
<<
"
at:
"
<< elIter << endl;
ASSERT_EQ
(out_feat[elIter].
f
[
1
], gold_feat[elIter].
f
[
1
])
<<
"
at:
"
<< elIter << endl;
ASSERT_LE
(
fabs
(out_feat[elIter].
f
[
2
] - gold_feat[elIter].
f
[
2
]),
1e-3
)
<<
"
at:
"
<< elIter << endl;
ASSERT_EQ
(out_feat[elIter].
f
[
3
], gold_feat[elIter].
f
[
3
])
<<
"
at:
"
<< elIter << endl;
ASSERT_EQ
(out_feat[elIter].
f
[
4
], gold_feat[elIter].
f
[
4
])
<<
"
at:
"
<< elIter << endl;
}
delete[]
outX;
delete[]
outY;
delete[]
outScore;
delete[]
outOrientation;
delete[]
outSize;
}
Back
|
FazBrowse Home
|
New Git URL