开发者

Visiting all entries of Sparse Matrix in the org.apache.commons.math.linear package

I see 2 implementations of sparse matrix in this package.

  1. OpenMapRealMatrix
  2. SparseFieldMatrix

Both are documented as "Sparse matrix implementation based on an open addressed map".

Do you know what are the diffrences between the two? als开发者_开发技巧o, what's the best way to iterate over all entries in a fast way (which means, iterating over the non zero elements).

Thanks!


SparseFieldMatrix is simply an interface that is implemented by the class OpenMapRealMatrix.

To walk the entries most efficiently see walkInOptimizedOrder overloads, depending on what you need to do on the iteration. You need to give these methods a Visitor instance which then handles the iteration. See this example when you require read-only access to each element.

It's not clear to me from this documentation how the iteration works for the sparse matrix you wish to use. It says that you would visit all entries but whether that means only the non-zero ones or not, I cannot be sure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜