我正在附加用于求解稀疏矩阵的代码,但似乎花费了太多时间来求解方程。请告诉我我是否做错了什么。
Code 1:
//given to the below function
//int[] row_inds, int[] col_inds, double[] vals, double[] x, double[] b;
value=49152;
Matrix A= new CCSMatrix(value,value);
for(i=0;i<value;i++){
A.set(row_inds[i], col_inds[i], val[i]);
}
Vector B = new BasicVector(b);
GaussianSolver solvers=new GaussianSolver(A);
Vector Y=solvers.solve(B, LinearAlgebra.SPARSE_FACTORY);
for (i = 0; i < Y.length(); i++) {
x[i]=Y.get(i);
}
Code 2:
//given to the below function
//int[] row_inds, int[] col_inds, double[] vals, double[] x, double[] b;
value=49152;
Matrix A= new CCSMatrix(value,value);
for(i=0;i<value;i++){
A.set(row_inds[i], col_inds[i], val[i]);
}
Vector B = new BasicVector(b);
LinearSystemSolver solver = A.withSolver(LinearAlgebra.FORWARD_BACK_SUBSTITUTION);
Vector X = solver.solve(B, LinearAlgebra.SPARSE_FACTORY);
System.out.println("solved for vector X");
for (i = 0; i < X.length(); i++) {
x[i]=X.get(i);
}
LA4J中有一个性能错误。它已在上一个版本中修复。现在应该正常工作(尤其是对于低密度的稀疏矩阵)。