0

I am using parallel colt wherein I need to find the rank of a matrix. The API documentation says the following about the following about DoubleAlgebra#rank:

rank(DoubleMatrix2D A)

Returns the effective numerical rank of matrix A, obtained from Singular Value Decomposition.

But when I use it in my code, I get an IllegalArgumentException at runtime:

Exception in thread "main" java.lang.IllegalArgumentException: Matrix must be dense
    at cern.colt.matrix.tdouble.algo.DoubleProperty.checkDense(Unknown Source)
    at cern.colt.matrix.tdouble.algo.decomposition.DenseDoubleSingularValueDecomposition.<init>(Unknown Source)
    at cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra.svd(Unknown Source)
    at cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra.rank(Unknown Source)

The API doesn't mention that a matrix needs to be dense. In my IDE (I use Intellij IDEA), when I ctrl+click the method name in my code, it goes to the source, which shows

public int rank(cern.colt.matrix.tdouble.DoubleMatrix2D doubleMatrix2D) { /* compiled code */ }

Bottomline, everywhere I see the requirement for a DoubleMatrix2D object, not a DenseDoubleMatrix2D object. Any idea why the runtime exception happens?

4

1 回答 1

0

正如消息所说,它似乎确实需要一个DenseDoubleMatrix2D实例。

这是源跟踪的内容(简化为A始终保持相同的名称):

DoubleAlgebra.rank(DoubleMatrix2D A): return svd(A).rank();
  > svd(DoubleMatrix2D A): return new DenseDoubleSingularValueDecomposition(A, true, true);
    > DenseDoubleSingularValueDecomposition(): checkDense(A);

对于checkDense自己:

 public void checkDense(DoubleMatrix2D A) {
     if (!(A instanceof DenseDoubleMatrix2D) && !(A instanceof DenseColumnDoubleMatrix2D))
         throw new IllegalArgumentException("Matrix must be dense");
 }

您可以在此处查看实际的异常代码。

您可能想要做的只是使用一个实例DenseDoubleMatrix2D而不是您当前发送的任何内容。

于 2014-01-27T19:49:55.047 回答