- 61
- 0
- 约3.38千字
- 约 8页
- 2017-09-10 发布于浙江
- 举报
稀疏矩阵及行压缩存储(CRS)
Lab 3 Why Compressed Row Storage A sparse matrix has a lot of elements of value zero. Using a two dimensional array to store a sparse matrix wastes a lot of memory. Compressed Row Storage (CRS) format only stores the nonzero elements. Using CRS format to store a sparse matrix will save a lot of memory. Compressed Row Storage val array stores the values of the nonzero elements in a row-wise fashion. col_ind array stores the corresponding column indices of the elements in the val array. E.g. col_ind[5] stores the column index of val[5]. row_ptr array stores the locations in the val array and col_ind array that start a row. //Compressed Row Storage format //for a sparse square (mSize X mSize) matrix public class CRS{ //the values of the nonzero elements of the matrix float[] val; //the column indices of the elements in val array int[] col_idx; //locations in the val and col_idx array that start a row int[] row_ptr; //the size of the matrix: the number of rows int mSize=0; //constructor that takes a sparse matrix and convert it to a CRS object CRS( float[][] matrix){... } //print the matrix in CRS format. public void printCRS(){... } //test the program public static void main(String[] args){... } } CRS( float[][] matrix){ int i, j, index; //the total number of nonzero in the matrix int totalNonZeros; //get the number of rows and columns mSize = matrix.length; //get the total number of nonzero entries in the matrix totalNonZeros = 0; for( i=0; imSize; i++){ for( j=0; jmSize; j++){ if(matrix[i][j] != 0) totalNonZeros++; } } //allocate memory for val and col_idx array val = new float[ totalNonZeros ]; col_idx = new int[ totalNonZeros ]; //allocate memory for row_ptr row_ptr = new int[ mSize+1]; row_ptr[ 0 ] = 0; //store the matrix in CRS format index = 0;// point to the next position to store the value for( i=0; imSize; i++ ){//each row for( j=0; jmSize;
您可能关注的文档
- 茶楼及空间设计要点.doc
- 茶用香花栽培和评价课程资料.doc
- 茶馆及练习题及其答案.doc
- 茶馆文化及起源和发展.doc
- 种子检验室及建设及管理.ppt
- 茶馆经营及是文化 茶馆需要及是品牌.doc
- 茶馆设计及背景分析.doc
- 种子质量及检验方法.ppt
- 草原生态保护补助奖励机制信息管理系统及使用经验.doc
- 草原上神奇及民族.doc
- 腾讯安全沙龙:红队视角下的海外SRC猎场:战略、战术与突破.pdf
- 【icap】ETS的范围扩展:设计和政策挑战.docx
- bcg -美国最高法院关于关税的裁决对你的企业意味着什么 What Does the US Supreme Court Ruling on Tariffs Mean for Your Business.pdf
- 2026届甘肃兰州市高三下学期第一次模拟考试历史试卷(扫描版,含答案).docx
- bcg -零售银行如何让人工智能代理发挥作用 How Retail Banks Can Put AI Agents to Work.pdf
- 住宅项目规范解读(GB 55038-2025) -培训 - 房地产-2025.docx
- 盘扣式脚手架工程量自动计算表 -培训 -房地产-2025.pdf
- 广东省汕头市2024-2025学年高三下学期第一次模拟考试英语学试题(含答案).docx
- 品牌研究+_+2025+CAPSE中国航司品牌榜单.pdf
- 【银河专题】如何看待豆粕内外价差关系.pdf
最近下载
- 位错线∥b screw dislocation.ppt VIP
- DQ380变速箱培训教材.pptx VIP
- 基层党组织2026年组织生活会个人五个方面对照检查自我剖析4篇.docx VIP
- 2025年重庆中考数学备考全指南(考点+真题+计划)(知识点归纳,必考知识点、真题模拟试卷及解析).docx VIP
- 卫生院胸痛救治单元建设应知应会.docx VIP
- 自考 00260《刑事诉讼法学》可打印背诵版(表格 + 高频考点 + 答题模板).docx VIP
- 强酸性阳离子交换树脂催化酯化丙烯酸和甲醇合成丙烯酸甲酯的反应动力学.pdf VIP
- 2025 年大学新闻传播学(新闻学概论)试题及答案.doc VIP
- 《“十五五”规划建议》全文解读.ppt VIP
- Unit 1 People at work 教案 课件 外研版英语四年级下册.docx VIP
原创力文档

文档评论(0)