fix: fix coo to csr tranfer bug
This commit is contained in:
@@ -15,9 +15,7 @@
|
||||
#include <Eigen/Sparse>
|
||||
#include <Spectra/GenEigsSolver.h>
|
||||
#include <Spectra/MatOp/SparseGenMatProd.h>
|
||||
#include <Eigen/Core>
|
||||
#include <Eigen/SparseCore>
|
||||
#include <Eigen/Eigenvalues>
|
||||
|
||||
|
||||
namespace Recon
|
||||
{
|
||||
@@ -86,34 +84,47 @@ namespace Recon
|
||||
int * xIdxs = new int[M.getRowVector().getDataSize()];
|
||||
std::copy(M.getRowVector().getData(),M.getRowVector().getData()+M.getRowVector().getDataSize(),xIdxs);
|
||||
Aurora::Matrix values = M.getValVector();
|
||||
size_t cols = M.getM(), rows = M.getN();
|
||||
size_t rows = M.getM(), cols = M.getN();
|
||||
int nz = std::max(M.getColVector().getDataSize(),std::max(M.getRowVector().getDataSize(),M.getValVector().getDataSize()));
|
||||
sparse_matrix_t A;
|
||||
sparse_matrix_t csrA;
|
||||
mkl_sparse_s_create_coo(&A, sparse_index_base_t::SPARSE_INDEX_BASE_ZERO, rows, cols, nz, yIdxs, xIdxs,values.getData());
|
||||
mkl_sparse_convert_csr(A, sparse_operation_t::SPARSE_OPERATION_NON_TRANSPOSE, &csrA);
|
||||
int n_rows,n_cols;
|
||||
int *rows_start,*rows_end,*col_indx;
|
||||
float * csrValues;
|
||||
|
||||
mkl_sparse_s_create_coo(&A, sparse_index_base_t::SPARSE_INDEX_BASE_ZERO, rows,cols, nz, xIdxs,yIdxs,values.getData());
|
||||
// csr transpose means csc, 行列互换
|
||||
mkl_sparse_convert_csr(A, sparse_operation_t::SPARSE_OPERATION_TRANSPOSE, &csrA);
|
||||
|
||||
//export csc matrix , row->col, col->row
|
||||
int nRows = 0;
|
||||
int nCols = 0;
|
||||
int *cscColStart,*cscColEnd,*cscRowIdx;
|
||||
float * cscValues;
|
||||
sparse_index_base_t index;
|
||||
mkl_sparse_s_export_csr(csrA, &index, &n_rows, &n_cols, &rows_start, &rows_end, &col_indx, &csrValues);
|
||||
mkl_sparse_s_export_csr(csrA, &index, &nCols, &nRows, &cscColStart, &cscColEnd, &cscRowIdx, &cscValues);
|
||||
|
||||
//free A & temp input index
|
||||
mkl_sparse_destroy(A);
|
||||
delete [] xIdxs;
|
||||
delete [] yIdxs;
|
||||
|
||||
int *row_idx = new int[n_rows+1];
|
||||
std::copy(rows_start,rows_start+n_rows,row_idx);
|
||||
row_idx[n_rows] = rows_end[n_rows-1];
|
||||
// add last unit to cols
|
||||
int *cscColIdx = new int[nCols+1];
|
||||
std::copy(cscColStart,cscColEnd+nCols,cscColIdx);
|
||||
cscColIdx[nCols] = nz;
|
||||
|
||||
// prepare other input
|
||||
float* bData = b.getData();
|
||||
// std::copy(b.getData(),b.getData()+b.getDataSize(),bData);
|
||||
size_t bDims[3]={(size_t)b.getDimSize(0),(size_t)b.getDimSize(1),(size_t)b.getDimSize(2)};
|
||||
size_t rdims[3] = {(size_t)dims[0], (size_t)dims[1], (size_t)dims[2]};
|
||||
bool pagelocked = false;
|
||||
auto result = TVALGPU( col_indx, row_idx, csrValues, M.getM(), M.getN(), nz, bData, bDims, rdims, opt, device, false);
|
||||
|
||||
//call TVAL
|
||||
auto result = TVALGPU( cscRowIdx,cscColIdx, cscValues, M.getM(), M.getN(), nz, bData, bDims, rdims, opt, device, false);
|
||||
|
||||
// free csrA, cscColStart, cscColEnd, cscRowIdx, cscValues will free with it
|
||||
mkl_sparse_destroy(csrA);
|
||||
delete [] row_idx;
|
||||
//delete [] bData;
|
||||
//free cscColIdx
|
||||
delete [] cscColIdx;
|
||||
|
||||
return Aurora::Matrix::fromRawData(result.data, result.dims[0],result.dims[1],result.dims[2]);
|
||||
// return Aurora::Matrix();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user