FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
arrayfire/test/gaussiankernel.cpp at master · arrayfire/arrayfire · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
arrayfire
/
arrayfire
Public
Notifications
You must be signed in to change notification settings
Fork
558
Star
4.9k
Code
Issues
292
Pull requests
26
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
arrayfire
/
test
/
gaussiankernel.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
159 lines (119 loc) · 4.35 KB
Breadcrumbs
arrayfire
/
test
/
gaussiankernel.cpp
Copy path
File metadata and controls
159 lines (119 loc) · 4.35 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
/*
******************************************************
* Copyright (c) 2015, 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/dim4.hpp
>
#
include
<
af/traits.hpp
>
#
include
<
string
>
#
include
<
vector
>
using
af::dim4;
using
std::endl;
using
std::string;
using
std::vector;
template
<
typename
T>
class
GaussianKernel
: public ::testing::Test {
public:
virtual
void
SetUp
() {}
};
//
create a list of types to be tested
typedef
::testing::Types<
float
> TestTypes;
//
register the type list
TYPED_TEST_SUITE
(GaussianKernel, TestTypes);
template
<
typename
T>
void
gaussianKernelTest
(string pFileName,
double
sigma) {
SUPPORTED_TYPE_CHECK
(T);
vector<dim4> numDims;
vector<vector<
int
>> in;
vector<vector<T>> tests;
readTestsFromFile<
int
, T>(pFileName, numDims, in, tests);
af_array outArray =
0
;
vector<
int
>
input
(in[
0
].
begin
(), in[
0
].
end
());
ASSERT_SUCCESS
(
af_gaussian_kernel
(&outArray, input[
0
], input[
1
], sigma, sigma));
dim_t
outElems =
0
;
ASSERT_SUCCESS
(
af_get_elements
(&outElems, outArray));
T *outData =
new
T[outElems];
ASSERT_SUCCESS
(
af_get_data_ptr
((
void
*)outData, outArray));
vector<T>
currGoldBar
(tests[
0
].
begin
(), tests[
0
].
end
());
size_t
nElems = currGoldBar.
size
();
ASSERT_EQ
(outElems, (
dim_t
)nElems);
for
(
size_t
elIter =
0
; elIter < nElems; ++elIter) {
ASSERT_NEAR
(currGoldBar[elIter], outData[elIter],
1.0e-3
)
<<
"
at:
"
<< elIter << endl;
}
delete[]
outData;
ASSERT_SUCCESS
(
af_release_array
(outArray));
}
TYPED_TEST
(GaussianKernel, Small1D) {
gaussianKernelTest<TypeParam>(
string
(
TEST_DIR
"
/gaussian/gauss1_7.test
"
),
0.0
);
}
TYPED_TEST
(GaussianKernel, Large1D) {
gaussianKernelTest<TypeParam>(
string
(
TEST_DIR
"
/gaussian/gauss1_15.test
"
),
0.0
);
}
TYPED_TEST
(GaussianKernel, Small1DWithSigma) {
gaussianKernelTest<TypeParam>(
string
(
TEST_DIR
"
/gaussian/gauss1_7_sigma1.test
"
),
1.0
);
}
TYPED_TEST
(GaussianKernel, SmallSmall2D) {
gaussianKernelTest<TypeParam>(
string
(
TEST_DIR
"
/gaussian/gauss2_7x7.test
"
),
0.0
);
}
TYPED_TEST
(GaussianKernel, LargeSmall2D) {
gaussianKernelTest<TypeParam>(
string
(
TEST_DIR
"
/gaussian/gauss2_15x7.test
"
),
0.0
);
}
TYPED_TEST
(GaussianKernel, LargeLarge2D) {
gaussianKernelTest<TypeParam>(
string
(
TEST_DIR
"
/gaussian/gauss2_15x15.test
"
),
0.0
);
}
TYPED_TEST
(GaussianKernel, SmallSmall2DWithSigma) {
gaussianKernelTest<TypeParam>(
string
(
TEST_DIR
"
/gaussian/gauss2_7x7_sigma1.test
"
),
1.0
);
}
//
////////////////////////////// CPP ////////////////////////////////////
//
test mean_all interface using cpp api
#
include
<
iostream
>
using
af::array;
using
af::gaussianKernel;
void
gaussianKernelTestCPP
(string pFileName,
double
sigma) {
vector<dim4> numDims;
vector<vector<
int
>> in;
vector<vector<
float
>> tests;
readTestsFromFile<
int
,
float
>(pFileName, numDims, in, tests);
vector<
int
>
input
(in[
0
].
begin
(), in[
0
].
end
());
array out =
gaussianKernel
(input[
0
], input[
1
], sigma, sigma);
dim_t
outElems = out.
elements
();
float
*outData =
new
float
[outElems];
out.
host
(outData);
vector<
float
>
currGoldBar
(tests[
0
].
begin
(), tests[
0
].
end
());
size_t
nElems = currGoldBar.
size
();
ASSERT_EQ
(outElems, (
dim_t
)nElems);
for
(
size_t
elIter =
0
; elIter < nElems; ++elIter) {
ASSERT_NEAR
(currGoldBar[elIter], outData[elIter],
1.0e-3
)
<<
"
at:
"
<< elIter << endl;
}
delete[]
outData;
}
TEST
(GaussianKernel, Small1D_CPP) {
gaussianKernelTestCPP
(
string
(
TEST_DIR
"
/gaussian/gauss1_7.test
"
),
0.0
);
}
TEST
(GaussianKernel, Small1DWithSigma_CPP) {
gaussianKernelTestCPP
(
string
(
TEST_DIR
"
/gaussian/gauss1_7_sigma1.test
"
),
1.0
);
}
TEST
(GaussianKernel, SmallSmall2D_CPP) {
gaussianKernelTestCPP
(
string
(
TEST_DIR
"
/gaussian/gauss2_7x7.test
"
),
0.0
);
}
TEST
(GaussianKernel, SmallSmall2DWithSigma_CPP) {
gaussianKernelTestCPP
(
string
(
TEST_DIR
"
/gaussian/gauss2_7x7_sigma1.test
"
),
1.0
);
}
Back
|
FazBrowse Home
|
New Git URL