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
71 lines (62 loc) · 2.1 KB
/
flip.cpp
File metadata and controls
71 lines (62 loc) · 2.1 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
/*******************************************************
* 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 <Array.hpp>
#include <backend.hpp>
#include <common/half.hpp>
#include <common/indexing_helpers.hpp>
#include <handle.hpp>
#include <af/array.h>
#include <af/data.h>
#include <cassert>
using af::dim4;
using common::flip;
using common::half;
using detail::Array;
using detail::cdouble;
using detail::cfloat;
using detail::intl;
using detail::uchar;
using detail::uintl;
using detail::ushort;
using std::swap;
template<typename T>
static inline af_array flip(const af_array in, const unsigned dim) {
return getHandle(
flip(getArray<T>(in), {dim == 0, dim == 1, dim == 2, dim == 3}));
}
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 f16: out = flip<half>(in, dim); break;
case f32: out = flip<float>(in, dim); break;
case c32: out = flip<cfloat>(in, dim); break;
case f64: out = flip<double>(in, dim); break;
case c64: out = flip<cdouble>(in, dim); break;
case b8: out = flip<char>(in, dim); break;
case s32: out = flip<int>(in, dim); break;
case u32: out = flip<unsigned>(in, dim); break;
case s64: out = flip<intl>(in, dim); break;
case u64: out = flip<uintl>(in, dim); break;
case s16: out = flip<short>(in, dim); break;
case u16: out = flip<ushort>(in, dim); break;
case u8: out = flip<uchar>(in, dim); break;
default: TYPE_ERROR(1, in_type);
}
swap(*result, out);
}
CATCHALL
return AF_SUCCESS;
}