1 import cern.colt.matrix.tfloat.FloatMatrix2D;
2 import cern.colt.matrix.tfloat.algo.SparseFloatAlgebra;
3 import cern.colt.matrix.tfloat.impl.SparseFloatMatrix2D;
4
5
6
7
8
9
10
11
12
13
14
15 public final class SparseMatrixProblem
16 {
17
18
19
20 private SparseMatrixProblem()
21 {
22
23 }
24
25
26
27
28
29 public static void main(final String[] args)
30 {
31 float[][] values = {{1, 2, 3}, {3, 5, 7}, {5, 10, 0}};
32 Float determinant = null;
33
34 FloatMatrix2D floatMatrix2D = new SparseFloatMatrix2D(values.length, values[0].length);
35 for (int row = 0; row < values.length; row++)
36 {
37 for (int column = 0; column < values[row].length; column++)
38 {
39 floatMatrix2D.set(row, column, values[row][column]);
40 }
41 }
42 System.out.println("matrix: " + floatMatrix2D.toString());
43 System.out.println("calling SparseFloatAlgebra().det(this.matrixSI)");
44 try
45 {
46 determinant = new SparseFloatAlgebra().det(floatMatrix2D);
47 }
48 catch (IllegalArgumentException exception)
49 {
50 exception.printStackTrace();
51 }
52 System.out.println("determinant is " + determinant + " (should be 15.0)");
53 }
54 }