Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a sparse matrix using SparseMatrix's CSC constructor resulted in LU decomposition failure #37

Open
H-Dynamite opened this issue Dec 22, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@H-Dynamite
Copy link

Describe the current behavior

Using SparseMatrix (int rowCount, int columnCount, int [] columnStart, int [] rowIndicators, double [] values) causes LU decomposition to fail

error log:

Exception in thread "main" com.powsybl.math.matrix.MatrixException: klu_analyze error KLU_INVALID
at com.powsybl.math.matrix.SparseLUDecomposition.init(Native Method)
at com.powsybl.math.matrix.SparseLUDecomposition.init(SparseLUDecomposition.java:49)
at com.powsybl.math.matrix.SparseLUDecomposition.(SparseLUDecomposition.java:43)
at com.powsybl.math.matrix.SparseMatrix.decomposeLU(SparseMatrix.java:330)
at com.powsybl.math.matrix.SparseMatrixTest.main(SparseMatrixTest.java:121)

Describe the expected behavior

Expected decomposition successful

Describe the steps

SparseMatrix a =new SparseMatrix(2, 2, 2);
a.add(0, 0, 1d);
a.add(1, 0, 1d);
a.add(0, 1, 1d);
SparseMatrix m = new SparseMatrix(a.getRowCount(), a.getColumnCount(), a.getColumnStart(), a.getRowIndices(), a.getValues());
LUDecomposition decomposition = m.decomposeLU();

Problem solving:

This issue is caused by the variable "currentColumn" not being assigned during initialization

SparseMatrix(int rowCount, int columnCount, int[] columnStart, int[] rowIndices, double[] values) {
    this.rowCount = rowCount;
    this.columnCount = columnCount;
    this.columnStart = Objects.requireNonNull(columnStart);
    this.currentColumn = values.length;//Initialize here
    columnValueCount = new int[columnCount];
    this.rowIndices = new TIntArrayListHack(Objects.requireNonNull(rowIndices));
    this.values = new TDoubleArrayListHack(Objects.requireNonNull(values));
    fillColumnValueCount(this.columnCount, this.columnStart, columnValueCount, this.values);
}

}

Environment

powsybl-core 6.2.0-SNAPSHOT

Relevant Log Output

No response

Extra Information

No response

@H-Dynamite H-Dynamite added the bug Something isn't working label Dec 22, 2023
@geofjamg
Copy link
Member

Thanks for reporting this issue. I will open a PR on core repo.
Is your original need to copy an existing sparse matrix or build a sparse matrix from provided arrays ?

@H-Dynamite
Copy link
Author

I initially wanted to use arrays to quickly construct a sparse matrix for testing the performance of KLU. Surprisingly, the decomposition speed of KLU is very fast. I am grateful that we have developed such a great library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants