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
|
/*******************************************************
* 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 <af/array.h>
#include <af/arith.h>
#include <af/data.h>
#include <af/index.h>
#include <testHelpers.hpp>
using namespace std;
using namespace af;
TEST(FlipTests, Test_flip_1D)
{
const int num = 10000;
af::array in = randu(num);
af::array out = flip(in, 0);
float *h_in = in.host<float>();
float *h_out = out.host<float>();
for (int i = 0; i < num; i++) {
ASSERT_EQ(h_in[num - i - 1], h_out[i])
<< "at (" << i << ")";
}
delete[] h_in;
delete[] h_out;
}
TEST(FlipTests, Test_flip_2D0)
{
const int nx = 200;
const int ny = 200;
af::array in = randu(nx, ny);
af::array out = flip(in, 0);
float *h_in = in.host<float>();
float *h_out = out.host<float>();
for (int j = 0; j < ny; j++) {
int off = j * nx;
for (int i = 0; i < nx; i++) {
ASSERT_EQ(h_in[off + nx - 1 - i], h_out[off + i])
<< "at (" << i << "," << j << ")";
}
}
delete[] h_in;
delete[] h_out;
}
TEST(FlipTests, Test_flip_2D1)
{
const int nx = 200;
const int ny = 200;
af::array in = randu(nx, ny);
af::array out = flip(in, 1);
float *h_in = in.host<float>();
float *h_out = out.host<float>();
for (int j = 0; j < ny; j++) {
int ioff = (ny - 1 - j) * nx;
int ooff = j * nx;
for (int i = 0; i < nx; i++) {
ASSERT_EQ(h_in[ioff + i], h_out[ooff + i])
<< "at (" << i << "," << j << ")";
}
}
delete[] h_in;
delete[] h_out;
}
TEST(FlipTests, Test_flip_1D_index)
{
const int num = 10000;
const int st = 101;
const int en = 5000;
af::array in = randu(num);
af::array tmp = in(seq(st, en));
af::array out = flip(tmp, 0);
float *h_in = in.host<float>();
float *h_out = out.host<float>();
for (int i = st; i <= en; i++) {
ASSERT_EQ(h_in[i], h_out[en - i])
<< "at (" << i << ")";
}
delete[] h_in;
delete[] h_out;
}
TEST(FlipTests, Test_flip_2D_index00)
{
const int nx = 200;
const int ny = 200;
const int st = 21;
const int en = 180;
const int nxo = (en - st + 1);
af::array in = randu(nx, ny);
af::array tmp = in(seq(st, en), span);
af::array out = flip(tmp, 0);
float *h_in = in.host<float>();
float *h_out = out.host<float>();
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[en - i + out_off])
<< "at (" << i << "," << j << ")";
}
}
delete[] h_in;
delete[] h_out;
}
TEST(FlipTests, Test_flip_2D_index01)
{
const int nx = 200;
const int ny = 200;
const int st = 21;
const int en = 180;
const int nxo = (en - st + 1);
af::array in = randu(nx, ny);
af::array tmp = in(seq(st, en), span);
af::array out = flip(tmp, 1);
float *h_in = in.host<float>();
float *h_out = out.host<float>();
for (int j = 0; j < ny; j++) {
const int in_off = (ny - 1 - 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 << ")";
}
}
delete[] h_in;
delete[] h_out;
}
TEST(FlipTests, Test_flip_2D_index10)
{
const int nx = 200;
const int ny = 200;
const int st = 21;
const int en = 180;
af::array in = randu(nx, ny);
af::array tmp = in(span, seq(st, en));
af::array out = flip(tmp, 0);
float *h_in = in.host<float>();
float *h_out = out.host<float>();
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[nx - 1 - i + in_off], h_out[i + out_off])
<< "at (" << i << "," << j << ")";
}
}
delete[] h_in;
delete[] h_out;
}
TEST(FlipTests, Test_flip_2D_index11)
{
const int nx = 200;
const int ny = 200;
const int st = 21;
const int en = 180;
af::array in = randu(nx, ny);
af::array tmp = in(span, seq(st, en));
af::array out = flip(tmp, 1);
float *h_in = in.host<float>();
float *h_out = out.host<float>();
for (int j = st; j <= en; j++) {
const int in_off = j * nx;
const int out_off = (en - j) * nx;
for (int i = 0; i < nx; i++) {
ASSERT_EQ(h_in[i + in_off], h_out[i + out_off])
<< "at (" << i << "," << j << ")";
}
}
delete[] h_in;
delete[] h_out;
}
|