forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsparse.h
More file actions
367 lines (294 loc) · 12.5 KB
/
Copy pathsparse.h
File metadata and controls
367 lines (294 loc) · 12.5 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*******************************************************
* 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
********************************************************/
#pragma once
#include <af/defines.h>
#ifdef __cplusplus
namespace af
{
class array;
#if AF_API_VERSION >= 34
/**
This function converts \ref af::array of values, row indices and column
indices into a sparse array.
\note This function only create references of these arrays into the
sparse data structure and does not do deep copies.
\param[in] nRows is the number of rows in the dense matrix
\param[in] nCols is the number of columns in the dense matrix
\param[in] values is the \ref af::array containing the non-zero elements
of the matrix
\param[in] rowIdx is the row indices for the sparse array
\param[in] colIdx is the column indices for the sparse array
\param[in] stype is the storage format of the sparse array
\return \ref af::array for the sparse array
\snippet test/sparse.cpp ex_sparse_af_arrays
\ingroup sparse_func_create
*/
AFAPI array sparse(const dim_t nRows, const dim_t nCols,
const array values, const array rowIdx, const array colIdx,
const af::storage stype = AF_STORAGE_CSR);
#endif
#if AF_API_VERSION >= 34
/**
This function converts host or device arrays of values, row indices and
column indices into a sparse array on the device.
\note The rules for deep copy/shallow copy/reference are the same as for
creating a regular \ref af::array.
\param[in] nRows is the number of rows in the dense matrix
\param[in] nCols is the number of columns in the dense matrix
\param[in] nNZ is the number of non zero elements in the dense matrix
\param[in] values is the host array containing the non-zero elements
of the matrix
\param[in] rowIdx is the row indices for the sparse array
\param[in] colIdx is the column indices for the sparse array
\param[in] type is the data type for the matrix
\param[in] stype is the storage format of the sparse array
\param[in] src is \ref afHost if inputs are host arrays and \ref afDevice
if the arrays are device arrays.
\return \ref af::array for the sparse array
\snippet test/sparse.cpp ex_sparse_host_arrays
\ingroup sparse_func_create
*/
AFAPI 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 = f32, const af::storage stype = AF_STORAGE_CSR,
const af::source src = afHost);
#endif
#if AF_API_VERSION >= 34
/**
This function converts a dense \ref af::array into a sparse array.
\param[in] dense is the source dense matrix
\param[in] stype is the storage format of the sparse array
\return \ref af::array for the sparse array with the given storage type
\snippet test/sparse.cpp ex_sparse_from_dense
\ingroup sparse_func_create
*/
AFAPI array sparse(const array dense, const af::storage stype = AF_STORAGE_CSR);
#endif
#if AF_API_VERSION >= 34
/**
\param[in] in is the source sparse matrix to be converted
\param[in] destStrorage is the storage format of the output sparse array
\return \ref af::array for the sparse array with the given storage type
\ingroup sparse_func_convert_to
*/
AFAPI array sparseConvertTo(const array in, const af::storage destStrorage);
#endif
#if AF_API_VERSION >= 34
/**
\param[in] sparse is the source sparse matrix
\return dense \ref af::array from sparse
\snippet test/sparse.cpp ex_dense_from_sparse
\ingroup sparse_func_dense
*/
AFAPI array dense(const array sparse);
#endif
#if AF_API_VERSION >= 34
/**
\param[out] values stores the non-zero elements component of the sparse array
\param[out] rowIdx stores the row indices component of the sparse array
\param[out] colIdx stores the column indices component of the sparse array
\param[out] stype stores the storage type of the sparse array
\param[in] in is the input sparse matrix
\ingroup sparse_func_info
*/
AFAPI void sparseGetInfo(array &values, array &rowIdx, array &colIdx, af::storage &stype,
const array in);
#endif
#if AF_API_VERSION >= 34
/**
\param[in] in is the input sparse matrix
\return \ref af::array for the non-zero elements component of the sparse array
\ingroup sparse_func_values
*/
AFAPI array sparseGetValues(const array in);
#endif
#if AF_API_VERSION >= 34
/**
\param[in] in is the input sparse matrix
\return \ref af::array for the row indices component of the sparse array
\ingroup sparse_func_row_idx
*/
AFAPI array sparseGetRowIdx(const array in);
#endif
#if AF_API_VERSION >= 34
/**
\param[in] in is the input sparse matrix
\return \ref af::array for the column indices component of the sparse array
\ingroup sparse_func_col_idx
*/
AFAPI array sparseGetColIdx(const array in);
#endif
#if AF_API_VERSION >= 34
/**
\param[in] in is the input sparse matrix
\return the number of non-zero elements of the sparse array
\ingroup sparse_func_nnz
*/
AFAPI dim_t sparseGetNNZ(const array in);
#endif
#if AF_API_VERSION >= 34
/**
\param[in] in is the input sparse matrix
\return \ref af::storage for the storage type of the sparse array
\ingroup sparse_func_storage
*/
AFAPI af::storage sparseGetStorage(const array in);
#endif
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if AF_API_VERSION >= 34
/**
This function converts \ref af::array of values, row indices and column
indices into a sparse array.
\note This function only create references of these arrays into the
sparse data structure and does not do deep copies.
\param[out] out \ref af::array for the sparse array
\param[in] nRows is the number of rows in the dense matrix
\param[in] nCols is the number of columns in the dense matrix
\param[in] values is the \ref af_array containing the non-zero elements
of the matrix
\param[in] rowIdx is the row indices for the sparse array
\param[in] colIdx is the column indices for the sparse array
\param[in] stype is the storage format of the sparse array
\return \ref AF_SUCCESS if the execution completes properly
\ingroup sparse_func_create
*/
AFAPI af_err af_create_sparse_array(
af_array *out,
const dim_t nRows, const dim_t nCols,
const af_array values, const af_array rowIdx, const af_array colIdx,
const af_storage stype);
#endif
#if AF_API_VERSION >= 34
/**
This function converts host or device arrays of values, row indices and
column indices into a sparse array on the device.
\note The rules for deep copy/shallow copy/reference are the same as for
creating a regular \ref af::array.
\param[out] out \ref af::array for the sparse array
\param[in] nRows is the number of rows in the dense matrix
\param[in] nCols is the number of columns in the dense matrix
\param[in] nNZ is the number of non zero elements in the dense matrix
\param[in] values is the host array containing the non-zero elements
of the matrix
\param[in] rowIdx is the row indices for the sparse array
\param[in] colIdx is the column indices for the sparse array
\param[in] type is the data type for the matrix
\param[in] stype is the storage format of the sparse array
\param[in] src is \ref afHost if inputs are host arrays and \ref afDevice
if the arrays are device arrays.
\return \ref AF_SUCCESS if the execution completes properly
\ingroup sparse_func_create
*/
AFAPI af_err af_create_sparse_array_from_ptr(
af_array *out,
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 af_dtype type, const af_storage stype,
const af_source src);
#endif
#if AF_API_VERSION >= 34
/**
This function converts a dense \ref af_array into a sparse array.
\param[out] out \ref af_array for the sparse array with the given storage type
\param[in] dense is the source dense matrix
\param[in] stype is the storage format of the sparse array
\return \ref AF_SUCCESS if the execution completes properly
\ingroup sparse_func_create
*/
AFAPI af_err af_create_sparse_array_from_dense(
af_array *out, const af_array dense,
const af_storage stype);
#endif
#if AF_API_VERSION >= 34
/**
\param[out] out \ref af_array for the sparse array with the given storage type
\param[in] in is the source sparse matrix to be converted
\param[in] destStorage is the storage format of the output sparse array
\return \ref AF_SUCCESS if the execution completes properly
\ingroup sparse_func_convert_to
*/
AFAPI af_err af_sparse_convert_to(af_array *out, const af_array in,
const af_storage destStorage);
#endif
#if AF_API_VERSION >= 34
/**
\param[out] out dense \ref af_array from sparse
\param[in] sparse is the source sparse matrix
\return \ref AF_SUCCESS if the execution completes properly
\ingroup sparse_func_dense
*/
AFAPI af_err af_sparse_to_dense(af_array *out, const af_array sparse);
#endif
#if AF_API_VERSION >= 34
/**
\param[out] values stores the non-zero elements component of the sparse array
\param[out] rowIdx stores the row indices component of the sparse array
\param[out] colIdx stores the column indices component of the sparse array
\param[out] stype stores the storage type of the sparse array
\param[in] in is the input sparse matrix
\return \ref AF_SUCCESS if the execution completes properly
\ingroup sparse_func_info
*/
AFAPI af_err af_sparse_get_info(af_array *values, af_array *rowIdx, af_array *colIdx, af_storage *stype,
const af_array in);
#endif
#if AF_API_VERSION >= 34
/**
\param[out] out \ref af_array for the non-zero elements component of the sparse array
\param[in] in is the input sparse matrix
\return \ref AF_SUCCESS if the execution completes properly
\ingroup sparse_func_values
*/
AFAPI af_err af_sparse_get_values(af_array *out, const af_array in);
#endif
#if AF_API_VERSION >= 34
/**
\param[out] out \ref af_array for the row indices component of the sparse array
\param[in] in is the input sparse matrix
\return \ref AF_SUCCESS if the execution completes properly
\ingroup sparse_func_row_idx
*/
AFAPI af_err af_sparse_get_row_idx(af_array *out, const af_array in);
#endif
#if AF_API_VERSION >= 34
/**
\param[out] out \ref af_array for the column indices component of the sparse array
\param[in] in is the input sparse matrix
\return \ref AF_SUCCESS if the execution completes properly
\ingroup sparse_func_col_idx
*/
AFAPI af_err af_sparse_get_col_idx(af_array *out, const af_array in);
#endif
#if AF_API_VERSION >= 34
/**
\param[out] out the number of non-zero elements of the sparse array
\param[in] in is the input sparse matrix
\return \ref AF_SUCCESS if the execution completes properly
\ingroup sparse_func_nnz
*/
AFAPI af_err af_sparse_get_nnz(dim_t *out, const af_array in);
#endif
#if AF_API_VERSION >= 34
/**
\param[out] out contains \ref af_storage for the storage type of the sparse array
\param[in] in is the input sparse matrix
\return \ref AF_SUCCESS if the execution completes properly
\ingroup sparse_func_storage
*/
AFAPI af_err af_sparse_get_storage(af_storage *out, const af_array in);
#endif
#ifdef __cplusplus
}
#endif