forked from hunter-packages/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsat.cpp
More file actions
59 lines (49 loc) · 1.8 KB
/
sat.cpp
File metadata and controls
59 lines (49 loc) · 1.8 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
/*******************************************************
* 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 <af/defines.h>
#include <af/image.h>
#include <handle.hpp>
#include <err_common.hpp>
#include <scan.hpp>
using af::dim4;
using namespace detail;
template<typename To, typename Ti>
static af_array sat(const af_array& in)
{
const Array<To> input = castArray<To>(in);
Array<To> hprefix_scan = scan<af_add_t, To, To>(input, 0);
Array<To> vprefix_scan = scan<af_add_t, To, To>(hprefix_scan, 1);
return getHandle<To>(vprefix_scan);
}
af_err af_sat(af_array* out, const af_array in)
{
try{
ArrayInfo info = getInfo(in);
const dim4 dims = info.dims();
ARG_ASSERT(1, (dims.ndims() >= 2));
af_dtype inputType = info.getType();
af_array output = 0;
switch(inputType) {
case f64: output = sat<double, double>(in); break;
case f32: output = sat<float , float >(in); break;
case s32: output = sat<int , int >(in); break;
case u32: output = sat<uint , uint >(in); break;
case b8: output = sat<int , char >(in); break;
case u8: output = sat<uint , uchar >(in); break;
case s64: output = sat<intl , intl >(in); break;
case u64: output = sat<uintl , uintl >(in); break;
case s16: output = sat<int , short >(in); break;
case u16: output = sat<uint , ushort>(in); break;
default: TYPE_ERROR(1, inputType);
}
std::swap(*out, output);
}
CATCHALL;
return AF_SUCCESS;
}