-
Notifications
You must be signed in to change notification settings - Fork 548
Expand file tree
/
Copy pathdiagonal.cpp
More file actions
64 lines (53 loc) · 1.82 KB
/
diagonal.cpp
File metadata and controls
64 lines (53 loc) · 1.82 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 <Array.hpp>
#include <common/half.hpp>
#include <diagonal.hpp>
#include <err_cuda.hpp>
#include <kernel/diagonal.hpp>
#include <math.hpp>
#include <af/dim4.hpp>
using arrayfire::common::half;
namespace arrayfire {
namespace cuda {
template<typename T>
Array<T> diagCreate(const Array<T> &in, const int num) {
int size = in.dims()[0] + std::abs(num);
int batch = in.dims()[1];
Array<T> out = createEmptyArray<T>(dim4(size, size, batch));
kernel::diagCreate<T>(out, in, num);
return out;
}
template<typename T>
Array<T> diagExtract(const Array<T> &in, const int num) {
const dim_t *idims = in.dims().get();
dim_t size = std::min(idims[0], idims[1]) - std::abs(num);
Array<T> out = createEmptyArray<T>(dim4(size, 1, idims[2], idims[3]));
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(schar)
INSTANTIATE_DIAGONAL(uchar)
INSTANTIATE_DIAGONAL(short)
INSTANTIATE_DIAGONAL(ushort)
INSTANTIATE_DIAGONAL(half)
} // namespace cuda
} // namespace arrayfire