View Javadoc
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    * Demonstrate the COLT Matrix must be sparse problem.
7    * <p>
8    * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
9    * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
10   * <p>
11   * $LastChangedDate: 2015-08-30 00:16:51 +0200 (Sun, 30 Aug 2015) $, @version $Revision: 1329 $, by $Author: averbraeck $,
12   * initial version Aug 26, 2014 <br>
13   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
14   */
15  public final class SparseMatrixProblem
16  {
17      /**
18       * This class should never be instantiated.
19       */
20      private SparseMatrixProblem()
21      {
22          // This class should never be instantiated.
23      }
24  
25      /**
26       * Execute the demo.
27       * @param args String[]; not used
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  }