MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / af_create_sparse_array_from_ptr

Function af_create_sparse_array_from_ptr

src/api/c/sparse.cpp:249–301  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247}
248
249af_err af_create_sparse_array_from_ptr(
250 af_array *out, const dim_t nRows, const dim_t nCols, const dim_t nNZ,
251 const void *const values, const int *const rowIdx, const int *const colIdx,
252 const af_dtype type, const af_storage stype, const af_source source) {
253 try {
254 // Checks:
255 // rowIdx and colIdx arrays are of s32 type
256 // values is of floating point type
257 // if COO, rowIdx, colIdx and values should have same dims
258 // if CRS, colIdx and values should have same dims, rowIdx.dims = nRows
259 // if CRC, rowIdx and values should have same dims, colIdx.dims = nCols
260 // stype is within acceptable range
261 // type is floating type
262 if (!(stype == AF_STORAGE_CSR || stype == AF_STORAGE_CSC ||
263 stype == AF_STORAGE_COO)) {
264 AF_ERROR("Storage type is out of range/unsupported", AF_ERR_ARG);
265 }
266
267 TYPE_ASSERT(type == f32 || type == f64 || type == c32 || type == c64);
268
269 af_array output = nullptr;
270
271 dim4 dims(nRows, nCols);
272
273 switch (type) {
274 case f32:
275 output = createSparseArrayFromPtr<float>(
276 dims, nNZ, static_cast<const float *>(values), rowIdx,
277 colIdx, stype, source);
278 break;
279 case f64:
280 output = createSparseArrayFromPtr<double>(
281 dims, nNZ, static_cast<const double *>(values), rowIdx,
282 colIdx, stype, source);
283 break;
284 case c32:
285 output = createSparseArrayFromPtr<cfloat>(
286 dims, nNZ, static_cast<const cfloat *>(values), rowIdx,
287 colIdx, stype, source);
288 break;
289 case c64:
290 output = createSparseArrayFromPtr<cdouble>(
291 dims, nNZ, static_cast<const cdouble *>(values), rowIdx,
292 colIdx, stype, source);
293 break;
294 default: TYPE_ERROR(1, type);
295 }
296 std::swap(*out, output);
297 }
298 CATCHALL;
299
300 return AF_SUCCESS;
301}
302
303af_err af_create_sparse_array_from_dense(af_array *out, const af_array in,
304 const af_storage stype) {

Callers 3

af_copy_arrayFunction · 0.70
TYPED_TESTFunction · 0.50
sparseFunction · 0.50

Calls 1

swapFunction · 0.85

Tested by

no test coverage detected