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

Function af_sparse_convert_to

src/api/c/sparse.cpp:346–392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344}
345
346af_err af_sparse_convert_to(af_array *out, const af_array in,
347 const af_storage destStorage) {
348 try {
349 // Handle dense case
350 const ArrayInfo &info = getInfo(in, false);
351 if (!info.isSparse()) { // If input is dense
352 return af_create_sparse_array_from_dense(out, in, destStorage);
353 }
354
355 af_array output = nullptr;
356
357 const SparseArrayBase &base = getSparseArrayBase(in);
358
359 // Dense not allowed as input -> Should never happen with
360 // SparseArrayBase CSC is currently not supported
361 ARG_ASSERT(1, base.getStorage() != AF_STORAGE_DENSE &&
362 base.getStorage() != AF_STORAGE_CSC);
363
364 // Conversion to and from CSC is not supported
365 ARG_ASSERT(2, destStorage != AF_STORAGE_CSC);
366
367 if (base.getStorage() == destStorage) {
368 // Return a reference
369 AF_CHECK(af_retain_array(out, in));
370 return AF_SUCCESS;
371 }
372
373 switch (base.getType()) {
374 case f32:
375 output = sparseConvertStorage<float>(in, destStorage);
376 break;
377 case f64:
378 output = sparseConvertStorage<double>(in, destStorage);
379 break;
380 case c32:
381 output = sparseConvertStorage<cfloat>(in, destStorage);
382 break;
383 case c64:
384 output = sparseConvertStorage<cdouble>(in, destStorage);
385 break;
386 default: AF_ERROR("Output storage type is not valid", AF_ERR_ARG);
387 }
388 std::swap(*out, output);
389 }
390 CATCHALL;
391 return AF_SUCCESS;
392}
393
394af_err af_sparse_to_dense(af_array *out, const af_array in) {
395 try {

Callers 2

TESTFunction · 0.50
sparseConvertToFunction · 0.50

Calls 6

swapFunction · 0.85
isSparseMethod · 0.80
getStorageMethod · 0.80
af_retain_arrayFunction · 0.70
getTypeMethod · 0.45

Tested by

no test coverage detected