It seems like, as the message says, it really does need a DenseDoubleMatrix2D
instance.
Here's what the source traces through (simplified with A
kept the same name throughout):
DoubleAlgebra.rank(DoubleMatrix2D A): return svd(A).rank();
> svd(DoubleMatrix2D A): return new DenseDoubleSingularValueDecomposition(A, true, true);
> DenseDoubleSingularValueDecomposition(): checkDense(A);
For checkDense
itself:
public void checkDense(DoubleMatrix2D A) {
if (!(A instanceof DenseDoubleMatrix2D) && !(A instanceof DenseColumnDoubleMatrix2D))
throw new IllegalArgumentException("Matrix must be dense");
}
You can see the actual exception code here.
What you probably want to do is just use an instance of DenseDoubleMatrix2D
instead of whatever you're currently sending in.