FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
arrayfire/test/flat.cpp at master · arrayfire/arrayfire · GitHub
arrayfire
arrayfire
Repository navigation
Code
Issues
292
(292)
Pull requests
39
(39)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
arrayfire
/
test
/
flat.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
136 lines (108 loc) · 3.17 KB
Breadcrumbs
arrayfire
/
test
/
flat.cpp
Copy path
File metadata and controls
136 lines (108 loc) · 3.17 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
/*
******************************************************
* 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
<
gtest/gtest.h
>
#
include
<
testHelpers.hpp
>
#
include
<
af/arith.h
>
#
include
<
af/array.h
>
#
include
<
af/data.h
>
#
include
<
af/device.h
>
#
include
<
af/random.h
>
#
include
<
vector
>
using
af::array;
using
af::dim4;
using
af::flat;
using
af::freeHost;
using
af::randu;
using
af::seq;
using
af::span;
using
std::vector;
TEST
(FlatTests, Test_flat_1D) {
const
int
num =
10000
;
array in =
randu
(num);
array out =
flat
(in);
ASSERT_ARRAYS_EQ
(in, out);
}
TEST
(FlatTests, Test_flat_2D_Half) {
if
(
noHalfTests
(
f16
))
return
;
const
int
num =
10
;
array in =
randu
(num, num,
f16
);
array out =
flat
(in);
vector<half_float::half>
gold
(num * num);
in.
host
(&gold[
0
]);
ASSERT_VEC_ARRAY_EQ
(gold,
dim4
(num * num), out);
}
TEST
(FlatTests, Test_flat_2D) {
const
int
nx =
200
;
const
int
ny =
200
;
array in =
randu
(nx, ny);
array out =
flat
(in);
vector<
float
>
h_in_flat
(in.
elements
());
in.
host
(h_in_flat.
data
());
dim4 h_in_flat_dims =
dim4
(nx * ny);
ASSERT_VEC_ARRAY_EQ
(h_in_flat, h_in_flat_dims, out);
}
TEST
(FlatTests, Test_flat_1D_index) {
const
int
num =
10000
;
const
int
st =
101
;
const
int
en =
5000
;
array in =
randu
(num);
array tmp =
in
(
seq
(st, en));
array out =
flat
(tmp);
float
*h_in = in.
host
<
float
>();
float
*h_out = out.
host
<
float
>();
//
TODO: Use ASSERT_ARRAYS_EQUAL
for
(
int
i = st; i <= en; i++) {
ASSERT_EQ
(h_in[i], h_out[i - st]); }
freeHost
(h_in);
freeHost
(h_out);
}
TEST
(FlatTests, Test_flat_2D_index0) {
const
int
nx =
200
;
const
int
ny =
200
;
const
int
st =
21
;
const
int
en =
180
;
const
int
nxo = (en - st +
1
);
array in =
randu
(nx, ny);
array tmp =
in
(
seq
(st, en), span);
array out =
flat
(tmp);
float
*h_in = in.
host
<
float
>();
float
*h_out = out.
host
<
float
>();
//
TODO: Use ASSERT_ARRAYS_EQUAL
for
(
int
j =
0
; j < ny; j++) {
const
int
in_off = j * nx;
const
int
out_off = j * nxo;
for
(
int
i = st; i <= en; i++) {
ASSERT_EQ
(h_in[i + in_off], h_out[i - st + out_off])
<<
"
at (
"
<< i <<
"
,
"
<< j <<
"
)
"
;
}
}
freeHost
(h_in);
freeHost
(h_out);
}
TEST
(FlatTests, Test_flat_2D_index1) {
const
int
nx =
200
;
const
int
ny =
200
;
const
int
st =
21
;
const
int
en =
180
;
array in =
randu
(nx, ny);
array tmp =
in
(span,
seq
(st, en));
array out =
flat
(tmp);
float
*h_in = in.
host
<
float
>();
float
*h_out = out.
host
<
float
>();
//
TODO: Use ASSERT_ARRAYS_EQUAL
for
(
int
j = st; j <= en; j++) {
const
int
in_off = j * nx;
const
int
out_off = (j - st) * nx;
for
(
int
i =
0
; i < nx; i++) {
ASSERT_EQ
(h_in[i + in_off], h_out[i + out_off])
<<
"
at (
"
<< i <<
"
,
"
<< j <<
"
)
"
;
}
}
freeHost
(h_in);
freeHost
(h_out);
}
Back
|
FazBrowse Home
|
New Git URL