SparseArray<T> sparseConvertStorageToStorage(const SparseArray<T> &in) { // Dummy function // TODO finish this function when support is required AF_ERROR("CPU Backend only supports Dense to CSR or COO", AF_ERR_NOT_SUPPORTED); in.eval(); SparseArray<T> dense = createEmptySparseArray<T>(in.dims(), (int)in.getNNZ(), dest); return dense; }
Array<T> sparseConvertStorageToDense(const SparseArray<T> &in_) { // MKL only has dns<->csr. // CSR <-> CSC is only supported if input is square if(stype == AF_STORAGE_CSC) AF_ERROR("CPU Backend only supports Dense to CSR or COO", AF_ERR_NOT_SUPPORTED); in_.eval(); Array<T> dense_ = createValueArray<T>(in_.dims(), scalar<T>(0)); dense_.eval(); auto func = [=] (Array<T> dense, const SparseArray<T> in) { // Read: https://software.intel.com/en-us/node/520848 // But job description is incorrect with regards to job[1] // 0 implies row major and 1 implies column major int j1 = 1, j2 = 0; const int job[] = {1, j1, j2, 2, (int)dense.elements(), 1}; const int M = dense.dims()[0]; const int N = dense.dims()[1]; int ldd = dense.strides()[1]; int info = 0; Array<T > values = in.getValues(); Array<int> rowIdx = in.getRowIdx(); Array<int> colIdx = in.getColIdx(); // Have to mess up all const correctness because MKL dnscsr function // is bidirectional and has input/output on all pointers dnscsr_func<T>()( job, &M, &N, reinterpret_cast<ptr_type<T>>(dense.get()), &ldd, reinterpret_cast<ptr_type<T>>(const_cast<T*>(values.get())), const_cast<int*>(colIdx.get()), const_cast<int*>(rowIdx.get()), &info); }; getQueue().enqueue(func, dense_, in_); if(stype == AF_STORAGE_CSR) return dense_; else AF_ERROR("CPU Backend only supports Dense to CSR or COO", AF_ERR_NOT_SUPPORTED); return dense_; }
Array<T> sparseConvertCOOToDense(const SparseArray<T> &in) { in.eval(); Array<T> dense = createValueArray<T>(in.dims(), scalar<T>(0)); dense.eval(); const Array<T> values = in.getValues(); const Array<int> rowIdx = in.getRowIdx(); const Array<int> colIdx = in.getColIdx(); getQueue().enqueue(kernel::coo2dense<T>, dense, values, rowIdx, colIdx); return dense; }
Array<T> sparseConvertStorageToDense(const SparseArray<T> &in_) { in_.eval(); Array<T> dense_ = createValueArray<T>(in_.dims(), scalar<T>(0)); dense_.eval(); auto func = [=] (Array<T> dense, const SparseArray<T> in) { Array<T > values = in.getValues(); Array<int> rowIdx = in.getRowIdx(); Array<int> colIdx = in.getColIdx(); kernel::csr_dense<T>()(dense, values, rowIdx, colIdx); }; getQueue().enqueue(func, dense_, in_); if(stype == AF_STORAGE_CSR) return dense_; else AF_ERROR("CPU Backend only supports Dense to CSR or COO", AF_ERR_NOT_SUPPORTED); return dense_; }