实现了稀疏矩阵的生成(指定稀疏程度)、稀疏矩阵转换为CSR、从CSR中恢复出矩阵、稀疏矩阵和向量的乘法等功能。从运行结果来看,稀疏矩阵存储为CSR格式和向量相乘的运行速度快于普通矩阵向量乘法,而且稀疏程度越高,优势越明显。
#include
#include
#include
#include
typedef int dtype;
using namespace std;
void csr_to_matrix(dtype *value,dtype *colindex,dtype *rowptr,int n,int a,dtype** & M){
M=new int*[n];
for(int i=0;i
关注
打赏