forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhere.cpp
More file actions
51 lines (46 loc) · 1.4 KB
/
where.cpp
File metadata and controls
51 lines (46 loc) · 1.4 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
/*******************************************************
* 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 <complex>
#include <af/dim4.hpp>
#include <af/algorithm.h>
#include <err_common.hpp>
#include <handle.hpp>
#include <ops.hpp>
#include <where.hpp>
#include <backend.hpp>
using af::dim4;
using namespace detail;
template<typename T>
static inline af_array where(const af_array in)
{
// Making it more explicit that the output is uint
return getHandle<uint>(where<T>(getArray<T>(in)));
}
af_err af_where(af_array *idx, const af_array in)
{
try {
af_dtype type = getInfo(in).getType();
af_array res;
switch(type) {
case f32: res = where<float >(in); break;
case f64: res = where<double >(in); break;
case c32: res = where<cfloat >(in); break;
case c64: res = where<cdouble>(in); break;
case s32: res = where<int >(in); break;
case u32: res = where<uint >(in); break;
case u8 : res = where<uchar >(in); break;
case b8 : res = where<char >(in); break;
default:
TYPE_ERROR(1, type);
}
std::swap(*idx, res);
}
CATCHALL
return AF_SUCCESS;
}