| 301 | } |
| 302 | |
| 303 | af_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 | |
| 346 | af_err af_sparse_convert_to(af_array *out, const af_array in, |
| 347 | const af_storage destStorage) { |
no test coverage detected