forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflip.cpp
More file actions
78 lines (64 loc) · 2.26 KB
/
flip.cpp
File metadata and controls
78 lines (64 loc) · 2.26 KB
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
/*******************************************************
* 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 <cassert>
#include <vector>
#include <Array.hpp>
#include <backend.hpp>
#include <common/ArrayInfo.hpp>
#include <common/err_common.hpp>
#include <handle.hpp>
#include <lookup.hpp>
#include <af/array.h>
#include <af/data.h>
#include <af/index.h>
#include <af/seq.h>
using namespace detail;
using std::swap;
using std::vector;
template<typename T>
static af_array flipArray(const af_array in, const unsigned dim) {
const Array<T> &input = getArray<T>(in);
vector<af_seq> index(4);
for (int i = 0; i < 4; i++) { index[i] = af_span; }
// Reverse "dim"
dim4 in_dims = input.dims();
af_seq s = {(double)(in_dims[dim] - 1), 0, -1};
index[dim] = s;
Array<T> dst = createSubArray(input, index);
return getHandle(dst);
}
af_err af_flip(af_array *result, const af_array in, const unsigned dim) {
af_array out;
try {
const ArrayInfo &in_info = getInfo(in);
if (in_info.ndims() <= dim) {
*result = retain(in);
return AF_SUCCESS;
}
af_dtype in_type = in_info.getType();
switch (in_type) {
case f32: out = flipArray<float>(in, dim); break;
case c32: out = flipArray<cfloat>(in, dim); break;
case f64: out = flipArray<double>(in, dim); break;
case c64: out = flipArray<cdouble>(in, dim); break;
case b8: out = flipArray<char>(in, dim); break;
case s32: out = flipArray<int>(in, dim); break;
case u32: out = flipArray<unsigned>(in, dim); break;
case s64: out = flipArray<intl>(in, dim); break;
case u64: out = flipArray<uintl>(in, dim); break;
case s16: out = flipArray<short>(in, dim); break;
case u16: out = flipArray<ushort>(in, dim); break;
case u8: out = flipArray<uchar>(in, dim); break;
default: TYPE_ERROR(1, in_type);
}
swap(*result, out);
}
CATCHALL
return AF_SUCCESS;
}