forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin.cpp
More file actions
64 lines (55 loc) · 2.23 KB
/
join.cpp
File metadata and controls
64 lines (55 loc) · 2.23 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
/*******************************************************
* 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/index.h>
#include <err_common.hpp>
#include <handle.hpp>
#include <backend.hpp>
#include <ArrayInfo.hpp>
#include <join.hpp>
using af::dim4;
using namespace detail;
template<typename Tx, typename Ty>
static inline af_array join(const int dim, const af_array first, const af_array second)
{
return getHandle(join<Tx, Ty>(dim, getArray<Tx>(first), getArray<Ty>(second)));
}
af_err af_join(af_array *out, const int dim, const af_array first, const af_array second)
{
try {
ArrayInfo finfo = getInfo(first);
ArrayInfo sinfo = getInfo(second);
af::dim4 fdims = finfo.dims();
af::dim4 sdims = sinfo.dims();
ARG_ASSERT(1, dim >= 0 && dim < 4);
ARG_ASSERT(2, finfo.getType() == sinfo.getType());
DIM_ASSERT(2, sinfo.elements() > 0);
DIM_ASSERT(3, finfo.elements() > 0);
// All dimensions except join dimension must be equal
// Compute output dims
af::dim4 odims;
for(int i = 0; i < 4; i++) {
if(i != dim) DIM_ASSERT(2, fdims[i] == sdims[i]);
}
af_array output;
switch(finfo.getType()) {
case f32: output = join<float , float >(dim, first, second); break;
case c32: output = join<cfloat , cfloat >(dim, first, second); break;
case f64: output = join<double , double >(dim, first, second); break;
case c64: output = join<cdouble, cdouble>(dim, first, second); break;
case b8: output = join<char , char >(dim, first, second); break;
case s32: output = join<int , int >(dim, first, second); break;
case u32: output = join<uint , uint >(dim, first, second); break;
case u8: output = join<uchar , uchar >(dim, first, second); break;
default: TYPE_ERROR(1, finfo.getType());
}
std::swap(*out,output);
}
CATCHALL;
return AF_SUCCESS;
}