test_class.file: singa-mathematics/src/test/java/bio/singa/mathematics/algorithms/matrix/LUDecompositionTest.java
test_class.identifier: LUDecompositionTest
test_case.body: @Test
      void shouldFindRowEcholonFromTwoByThree() {
          Matrix matrix = new RegularMatrix(new double[][]{{2, 3}, {0, 1}, {4, -1}});
          Matrix expected = new RegularMatrix(new double[][]{{4, -1}, {0, 7.0 / 2.0}, {0, 0}});
          Matrix actual = LUDecomposition.calculateRowEchelonMatrix(matrix);
          assertMatrixEquals(expected, actual, 0.0);
      }
test_case.class_method_signature: LUDecompositionTest.shouldFindRowEcholonFromTwoByThree()
test_case.full_signature: @Test void shouldFindRowEcholonFromTwoByThree()
test_case.identifier: shouldFindRowEcholonFromTwoByThree
test_case.invocations: calculateRowEchelonMatrix assertMatrixEquals
test_case.modifiers: @Test
test_case.parameters: ()
test_case.return: void
test_case.signature: void shouldFindRowEcholonFromTwoByThree()
focal_class.file: singa-mathematics/src/main/java/bio/singa/mathematics/algorithms/matrix/LUDecomposition.java
focal_class.identifier: LUDecomposition
focal_class.class_method_signature: LUDecomposition.calculateRowEchelonMatrix(Matrix originalMatrix)
focal_class.full_signature: public static Matrix calculateRowEchelonMatrix(Matrix originalMatrix)
focal_class.identifier: calculateRowEchelonMatrix
focal_class.modifiers: public static
focal_class.parameters: (Matrix originalMatrix)
focal_class.return: Matrix
focal_class.signature: Matrix calculateRowEchelonMatrix(Matrix originalMatrix)
focal_class.class_method_signature: LUDecomposition.getRowWithAbsoluteMaximalElementAtIndex(List<Vector> matrixRows, int index, int startIndex)
focal_class.full_signature: private static int getRowWithAbsoluteMaximalElementAtIndex(List<Vector> matrixRows, int index, int startIndex)
focal_class.identifier: getRowWithAbsoluteMaximalElementAtIndex
focal_class.modifiers: private static
focal_class.parameters: (List<Vector> matrixRows, int index, int startIndex)
focal_class.return: int
focal_class.signature: int getRowWithAbsoluteMaximalElementAtIndex(List<Vector> matrixRows, int index, int startIndex)
focal_class.class_method_signature: LUDecomposition.getRank(Matrix matrix)
focal_class.full_signature: public static int getRank(Matrix matrix)
focal_class.identifier: getRank
focal_class.modifiers: public static
focal_class.parameters: (Matrix matrix)
focal_class.return: int
focal_class.signature: int getRank(Matrix matrix)
focal_method.body: public static Matrix calculateRowEchelonMatrix(Matrix originalMatrix) {
          List<Vector> matrixRows = Matrices.divideIntoRows(originalMatrix);
          for (int iteration = 0; iteration < Math.min(originalMatrix.getColumnDimension(), originalMatrix.getRowDimension()); iteration++) {
              // this row is the zero
              // FIXME: this can fail if the very first row is zero
              if (matrixRows.get(iteration).isZero()) {
                  continue;
              }
              // search for vector with largest absolute value in the current iteration
              int pivotIndex = getRowWithAbsoluteMaximalElementAtIndex(matrixRows, iteration, iteration);
              // if this element is zero
              if (matrixRows.get(pivotIndex).getElement(iteration) == 0) {
                  // no decomposition possible
                  throw new IllegalStateException("The given matrix is singular - no LU decomposition possible.");
              }
              // swap those rows in the row list
              Collections.swap(matrixRows, iteration, pivotIndex);
              // start factor calculation
              for (int row = iteration + 1; row < originalMatrix.getRowDimension(); row++) {
                  if (matrixRows.get(iteration).getElement(iteration) != 0) {
                      double[] newRowValues = new double[originalMatrix.getColumnDimension()];
                      // calculate division factor
                      double factor = matrixRows.get(row).getElement(iteration) / matrixRows.get(iteration).getElement(iteration);
                      for (int column = iteration + 1; column < originalMatrix.getColumnDimension(); column++) {
                          // subtract and scale by factor
                          newRowValues[column] = matrixRows.get(row).getElement(column) - matrixRows.get(iteration).getElement(column) * factor;
                      }
                      newRowValues[iteration] = 0;
                      matrixRows.set(row, new RegularVector(newRowValues));
                  }
              }
  
          }
          return Matrices.assembleMatrixFromRows(matrixRows);
      }
focal_method.class_method_signature: LUDecomposition.calculateRowEchelonMatrix(Matrix originalMatrix)
focal_method.full_signature: public static Matrix calculateRowEchelonMatrix(Matrix originalMatrix)
focal_method.identifier: calculateRowEchelonMatrix
focal_method.invocations: divideIntoRows min getColumnDimension getRowDimension isZero get getRowWithAbsoluteMaximalElementAtIndex getElement get swap getRowDimension getElement get getColumnDimension getElement get getElement get getColumnDimension getElement get getElement get set assembleMatrixFromRows
focal_method.modifiers: public static
focal_method.parameters: (Matrix originalMatrix)
focal_method.return: Matrix
focal_method.signature: Matrix calculateRowEchelonMatrix(Matrix originalMatrix)