forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiagonal.cpp
More file actions
68 lines (54 loc) · 1.99 KB
/
diagonal.cpp
File metadata and controls
68 lines (54 loc) · 1.99 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 <diagonal.hpp>
#include <kernel/diagonal.hpp>
#include <Array.hpp>
#include <common/half.hpp>
#include <platform.hpp>
#include <af/defines.h>
#include <af/dim4.hpp>
#include <algorithm>
#include <cstdlib>
using common::half; // NOLINT(misc-unused-using-decls) bug in clang-tidy
using std::abs; // NOLINT(misc-unused-using-decls) bug in clang-tidy
using std::min; // NOLINT(misc-unused-using-decls) bug in clang-tidy
namespace cpu {
template<typename T>
Array<T> diagCreate(const Array<T> &in, const int num) {
int size = in.dims()[0] + abs(num);
int batch = in.dims()[1];
Array<T> out = createEmptyArray<T>(dim4(size, size, batch));
getQueue().enqueue(kernel::diagCreate<T>, out, in, num);
return out;
}
template<typename T>
Array<T> diagExtract(const Array<T> &in, const int num) {
const dim4 &idims = in.dims();
dim_t size = min(idims[0], idims[1]) - abs(num);
Array<T> out = createEmptyArray<T>(dim4(size, 1, idims[2], idims[3]));
getQueue().enqueue(kernel::diagExtract<T>, out, in, num);
return out;
}
#define INSTANTIATE_DIAGONAL(T) \
template Array<T> diagExtract<T>(const Array<T> &in, const int num); \
template Array<T> diagCreate<T>(const Array<T> &in, const int num);
INSTANTIATE_DIAGONAL(float)
INSTANTIATE_DIAGONAL(double)
INSTANTIATE_DIAGONAL(cfloat)
INSTANTIATE_DIAGONAL(cdouble)
INSTANTIATE_DIAGONAL(int)
INSTANTIATE_DIAGONAL(uint)
INSTANTIATE_DIAGONAL(intl)
INSTANTIATE_DIAGONAL(uintl)
INSTANTIATE_DIAGONAL(char)
INSTANTIATE_DIAGONAL(uchar)
INSTANTIATE_DIAGONAL(short)
INSTANTIATE_DIAGONAL(ushort)
INSTANTIATE_DIAGONAL(half)
} // namespace cpu