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

Function sparseConvertDenseToCOO

src/backend/opencl/sparse.cpp:37–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35// However, template specialization is not allowed
36template<typename T>
37SparseArray<T> sparseConvertDenseToCOO(const Array<T> &in) {
38 in.eval();
39
40 Array<uint> nonZeroIdx_ = where<T>(in);
41 Array<int> nonZeroIdx = cast<int, uint>(nonZeroIdx_);
42
43 dim_t nNZ = nonZeroIdx.elements();
44
45 Array<int> constDim = createValueArray<int>(dim4(nNZ), in.dims()[0]);
46 constDim.eval();
47
48 Array<int> rowIdx =
49 arithOp<int, af_mod_t>(nonZeroIdx, constDim, nonZeroIdx.dims());
50 Array<int> colIdx =
51 arithOp<int, af_div_t>(nonZeroIdx, constDim, nonZeroIdx.dims());
52
53 Array<T> values = copyArray<T>(in);
54 values = modDims(values, dim4(values.elements()));
55 values = lookup<T, int>(values, nonZeroIdx, 0);
56
57 return createArrayDataSparseArray<T>(in.dims(), values, rowIdx, colIdx,
58 AF_STORAGE_COO);
59}
60
61template<typename T, af_storage stype>
62SparseArray<T> sparseConvertDenseToStorage(const Array<T> &in_) {

Callers

nothing calls this directly

Calls 5

dim4Class · 0.50
modDimsFunction · 0.50
evalMethod · 0.45
elementsMethod · 0.45
dimsMethod · 0.45

Tested by

no test coverage detected