-
Notifications
You must be signed in to change notification settings - Fork 550
Expand file tree
/
Copy pathshift.cpp
More file actions
68 lines (59 loc) · 2.24 KB
/
shift.cpp
File metadata and controls
68 lines (59 loc) · 2.24 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
/*******************************************************
* 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 <backend.hpp>
#include <common/ArrayInfo.hpp>
#include <common/err_common.hpp>
#include <handle.hpp>
#include <shift.hpp>
#include <af/data.h>
using detail::cdouble;
using detail::cfloat;
using detail::intl;
using detail::schar;
using detail::uchar;
using detail::uint;
using detail::uintl;
using detail::ushort;
template<typename T>
static inline af_array shift(const af_array in, const int sdims[4]) {
return getHandle(shift<T>(getArray<T>(in), sdims));
}
af_err af_shift(af_array *out, const af_array in, const int sdims[4]) {
try {
const ArrayInfo &info = getInfo(in);
af_dtype type = info.getType();
if (info.ndims() == 0) { return af_retain_array(out, in); }
DIM_ASSERT(1, info.elements() > 0);
af_array output;
switch (type) {
case f32: output = shift<float>(in, sdims); break;
case c32: output = shift<cfloat>(in, sdims); break;
case f64: output = shift<double>(in, sdims); break;
case c64: output = shift<cdouble>(in, sdims); break;
case b8: output = shift<char>(in, sdims); break;
case s32: output = shift<int>(in, sdims); break;
case u32: output = shift<uint>(in, sdims); break;
case s64: output = shift<intl>(in, sdims); break;
case u64: output = shift<uintl>(in, sdims); break;
case s16: output = shift<short>(in, sdims); break;
case u16: output = shift<ushort>(in, sdims); break;
case s8: output = shift<schar>(in, sdims); break;
case u8: output = shift<uchar>(in, sdims); break;
default: TYPE_ERROR(1, type);
}
std::swap(*out, output);
}
CATCHALL;
return AF_SUCCESS;
}
af_err af_shift(af_array *out, const af_array in, const int x, const int y,
const int z, const int w) {
const int sdims[] = {x, y, z, w};
return af_shift(out, in, sdims);
}