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

Function sparseConvertDenseToStorage

src/backend/cpu/sparse.cpp:42–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40
41template<typename T, af_storage stype>
42SparseArray<T> sparseConvertDenseToStorage(const Array<T> &in) {
43 if (stype == AF_STORAGE_CSR) {
44 uint nNZ = getScalar<uint>(reduce_all<af_notzero_t, T, uint>(in));
45
46 auto sparse = createEmptySparseArray<T>(in.dims(), nNZ, stype);
47 sparse.eval();
48
49 Array<T> values = sparse.getValues();
50 Array<int> rowIdx = sparse.getRowIdx();
51 Array<int> colIdx = sparse.getColIdx();
52
53 getQueue().enqueue(kernel::dense2csr<T>, values, rowIdx, colIdx, in);
54
55 return sparse;
56 } else if (stype == AF_STORAGE_COO) {
57 auto nonZeroIdx = cast<int, uint>(where<T>(in));
58
59 dim_t nNZ = nonZeroIdx.elements();
60
61 auto cnst = createValueArray<int>(dim4(nNZ), in.dims()[0]);
62
63 auto rowIdx =
64 arithOp<int, af_mod_t>(nonZeroIdx, cnst, nonZeroIdx.dims());
65 auto colIdx =
66 arithOp<int, af_div_t>(nonZeroIdx, cnst, nonZeroIdx.dims());
67
68 Array<T> values = copyArray<T>(in);
69 values.modDims(dim4(values.elements()));
70 values = lookup<T, int>(values, nonZeroIdx, 0);
71
72 return createArrayDataSparseArray<T>(in.dims(), values, rowIdx, colIdx,
73 stype);
74 } else {
75 AF_ERROR("CPU Backend only supports Dense to CSR or COO",
76 AF_ERR_NOT_SUPPORTED);
77 }
78}
79
80template<typename T, af_storage stype>
81Array<T> sparseConvertStorageToDense(const SparseArray<T> &in) {

Callers

nothing calls this directly

Calls 7

dim4Class · 0.70
getQueueFunction · 0.50
dimsMethod · 0.45
evalMethod · 0.45
enqueueMethod · 0.45
elementsMethod · 0.45
modDimsMethod · 0.45

Tested by

no test coverage detected