MTL4学习笔记1 矩阵的一些知识
MTL4学习笔记1--矩阵的一些知识2010-07-14 21:15MTL(Matrix Template Library)矩阵模板库,据说可以超越fortan的C++矩阵计算的库,
极有可能成为下一代C++标准库的部分。可是他的资料实在是太少了。学习中
摘抄了部分MTL4官方文档的内容,写了翻译和自己的理解。希望可以丰富下搜索引擎,^_^,写错了,欢迎批评,觉得太粗糙的,笑笑即可--我不是搞程序的,^_^
1.dense matrices稠密矩阵默认是row-major(dense matrices are by default row-major)不明白row_major和col_row什么意思dense2D
float,matrix:parameters tag:col_major B(10,10);dense2D double
A(10,10);不过不影响引用关系2.A[2][4]将被内部转化为A(2,3)Matrix elements can be accessed by a(i,j)or in the more familiar form
a[i][j].The second form is internally transformed into the first one
at compile time这一转化不会造成太大的编译时间消耗。3.单独访问每一个
元素只对稠密矩阵有效。(Please notice that overwriting single matrix elements is only defined for dense matrix type.)但是The MTL4
approach lies somewhere between.Sparse matrices can be either
written(inserted)or read.However,there can be multiple insertion phases.稀疏矩阵的操作参见:4.给一个矩阵赋值一个整数时,将使矩阵的对角线元素全部成为这个元素,这一操作对非方阵有效,(矩阵默认初始化为全零)
这一设计的目的是为了使向量运算得到简化:y=alpha*x;//将等价与A=alpha;//alpha赋给对角线元素y=A*x;//old before revision
identity matrix是什么意思6843,considered it erroneous to store anon-zero scalar to anon-square matrix.旧版本认为这是一个错误。5.A=0,可以用来clear任意矩阵,全部清零。
6.Dense matrices with arecursively designed memory layout can be defined with the type morton_dense:
7pressed2D稀疏矩阵Matrix ais stored as compressed row
storage(CRS).Its assigned values correspond to adiscretized Laplace
operator.不支持单独改变和添加元素给稀疏矩阵。To change or insert
single elements of acompressed matrix is not supported.this would result in an unbearable performance burden CRS下会忍无可忍的性能下降。但是CCS模式(compressed column storage)可以将一个标量赋值给整个矩阵。例如://CCS matrix compressed2D float,matrix:parameters tag:
col_major B(10,10);//Assign the identity matrix times 3to BB=3;
8.unsigned r=num_rows(A);//返回行数unsigned c=num_cols(A);//返
回列数unsigned s=size(A);//返回总数assert(s==r*c);