-
Notifications
You must be signed in to change notification settings - Fork 549
Expand file tree
/
Copy pathsparse.cpp
More file actions
104 lines (92 loc) · 3.4 KB
/
sparse.cpp
File metadata and controls
104 lines (92 loc) · 3.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*******************************************************
* 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/array.h>
#include <af/sparse.h>
#include "error.hpp"
namespace af {
array sparse(const dim_t nRows, const dim_t nCols,
const array values, // NOLINT(performance-unnecessary-value-param)
const array rowIdx, // NOLINT(performance-unnecessary-value-param)
const array colIdx, // NOLINT(performance-unnecessary-value-param)
const af::storage stype) {
af_array out = 0;
AF_THROW(af_create_sparse_array(&out, nRows, nCols, values.get(),
rowIdx.get(), colIdx.get(), stype));
return array(out);
}
array sparse(const dim_t nRows, const dim_t nCols, const dim_t nNZ,
const void* const values, const int* const rowIdx,
const int* const colIdx, const dtype type, const af::storage stype,
const af::source src) {
af_array out = 0;
AF_THROW(af_create_sparse_array_from_ptr(&out, nRows, nCols, nNZ, values,
rowIdx, colIdx, type, stype, src));
return array(out);
}
// NOLINTNEXTLINE(performance-unnecessary-value-param)
array sparse(const array dense, const af::storage stype) {
af_array out = 0;
AF_THROW(af_create_sparse_array_from_dense(&out, dense.get(), stype));
return array(out);
}
// NOLINTNEXTLINE(performance-unnecessary-value-param)
array sparseConvertTo(const array in, const af::storage stype) {
af_array out = 0;
AF_THROW(af_sparse_convert_to(&out, in.get(), stype));
return array(out);
}
// NOLINTNEXTLINE(performance-unnecessary-value-param)
array dense(const array sparse) {
af_array out = 0;
AF_THROW(af_sparse_to_dense(&out, sparse.get()));
return array(out);
}
void sparseGetInfo(
array& values, array& rowIdx, array& colIdx, storage& stype,
const array in) { // NOLINT(performance-unnecessary-value-param)
af_array values_ = 0, rowIdx_ = 0, colIdx_ = 0;
af_storage stype_ = AF_STORAGE_DENSE;
AF_THROW(
af_sparse_get_info(&values_, &rowIdx_, &colIdx_, &stype_, in.get()));
values = array(values_);
rowIdx = array(rowIdx_);
colIdx = array(colIdx_);
stype = stype_;
}
// NOLINTNEXTLINE(performance-unnecessary-value-param)
array sparseGetValues(const array in) {
af_array out = 0;
AF_THROW(af_sparse_get_values(&out, in.get()));
return array(out);
}
// NOLINTNEXTLINE(performance-unnecessary-value-param)
array sparseGetRowIdx(const array in) {
af_array out = 0;
AF_THROW(af_sparse_get_row_idx(&out, in.get()));
return array(out);
}
// NOLINTNEXTLINE(performance-unnecessary-value-param)
array sparseGetColIdx(const array in) {
af_array out = 0;
AF_THROW(af_sparse_get_col_idx(&out, in.get()));
return array(out);
}
// NOLINTNEXTLINE(performance-unnecessary-value-param)
dim_t sparseGetNNZ(const array in) {
dim_t out = 0;
AF_THROW(af_sparse_get_nnz(&out, in.get()));
return out;
}
// NOLINTNEXTLINE(performance-unnecessary-value-param)
af::storage sparseGetStorage(const array in) {
af::storage out;
AF_THROW(af_sparse_get_storage(&out, in.get()));
return out;
}
} // namespace af