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

Function af_create_sparse_array_from_dense

src/api/c/sparse.cpp:303–344  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

301}
302
303af_err af_create_sparse_array_from_dense(af_array *out, const af_array in,
304 const af_storage stype) {
305 try {
306 // Checks:
307 // stype is within acceptable range
308 // values is of floating point type
309
310 const ArrayInfo &info = getInfo(in);
311
312 if (!(stype == AF_STORAGE_CSR || stype == AF_STORAGE_CSC ||
313 stype == AF_STORAGE_COO)) {
314 AF_ERROR("Storage type is out of range/unsupported", AF_ERR_ARG);
315 }
316
317 // Only matrices allowed
318 DIM_ASSERT(1, info.ndims() == 2);
319
320 TYPE_ASSERT(info.isFloating());
321
322 af_array output = 0;
323
324 switch (info.getType()) {
325 case f32:
326 output = createSparseArrayFromDense<float>(in, stype);
327 break;
328 case f64:
329 output = createSparseArrayFromDense<double>(in, stype);
330 break;
331 case c32:
332 output = createSparseArrayFromDense<cfloat>(in, stype);
333 break;
334 case c64:
335 output = createSparseArrayFromDense<cdouble>(in, stype);
336 break;
337 default: TYPE_ERROR(1, info.getType());
338 }
339 std::swap(*out, output);
340 }
341 CATCHALL;
342
343 return AF_SUCCESS;
344}
345
346af_err af_sparse_convert_to(af_array *out, const af_array in,
347 const af_storage destStorage) {

Callers 3

af_sparse_convert_toFunction · 0.70
sparse.cppFile · 0.50
sparseFunction · 0.50

Calls 4

swapFunction · 0.85
isFloatingMethod · 0.80
ndimsMethod · 0.45
getTypeMethod · 0.45

Tested by

no test coverage detected