http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/linear/FieldLUDecomposition.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/linear/FieldLUDecomposition.java b/src/main/java/org/apache/commons/math3/linear/FieldLUDecomposition.java deleted file mode 100644 index 4aa80ed..0000000 --- a/src/main/java/org/apache/commons/math3/linear/FieldLUDecomposition.java +++ /dev/null @@ -1,444 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.commons.math3.linear; - -import org.apache.commons.math3.Field; -import org.apache.commons.math3.FieldElement; -import org.apache.commons.math3.exception.DimensionMismatchException; -import org.apache.commons.math3.util.MathArrays; - -/** - * Calculates the LUP-decomposition of a square matrix. - * <p>The LUP-decomposition of a matrix A consists of three matrices - * L, U and P that satisfy: PA = LU, L is lower triangular, and U is - * upper triangular and P is a permutation matrix. All matrices are - * m×m.</p> - * <p>Since {@link FieldElement field elements} do not provide an ordering - * operator, the permutation matrix is computed here only in order to avoid - * a zero pivot element, no attempt is done to get the largest pivot - * element.</p> - * <p>This class is based on the class with similar name from the - * <a href="http://math.nist.gov/javanumerics/jama/">JAMA</a> library.</p> - * <ul> - * <li>a {@link #getP() getP} method has been added,</li> - * <li>the {@code det} method has been renamed as {@link #getDeterminant() - * getDeterminant},</li> - * <li>the {@code getDoublePivot} method has been removed (but the int based - * {@link #getPivot() getPivot} method has been kept),</li> - * <li>the {@code solve} and {@code isNonSingular} methods have been replaced - * by a {@link #getSolver() getSolver} method and the equivalent methods - * provided by the returned {@link DecompositionSolver}.</li> - * </ul> - * - * @param <T> the type of the field elements - * @see <a href="http://mathworld.wolfram.com/LUDecomposition.html">MathWorld</a> - * @see <a href="http://en.wikipedia.org/wiki/LU_decomposition">Wikipedia</a> - * @since 2.0 (changed to concrete class in 3.0) - */ -public class FieldLUDecomposition<T extends FieldElement<T>> { - - /** Field to which the elements belong. */ - private final Field<T> field; - - /** Entries of LU decomposition. */ - private T[][] lu; - - /** Pivot permutation associated with LU decomposition. */ - private int[] pivot; - - /** Parity of the permutation associated with the LU decomposition. */ - private boolean even; - - /** Singularity indicator. */ - private boolean singular; - - /** Cached value of L. */ - private FieldMatrix<T> cachedL; - - /** Cached value of U. */ - private FieldMatrix<T> cachedU; - - /** Cached value of P. */ - private FieldMatrix<T> cachedP; - - /** - * Calculates the LU-decomposition of the given matrix. - * @param matrix The matrix to decompose. - * @throws NonSquareMatrixException if matrix is not square - */ - public FieldLUDecomposition(FieldMatrix<T> matrix) { - if (!matrix.isSquare()) { - throw new NonSquareMatrixException(matrix.getRowDimension(), - matrix.getColumnDimension()); - } - - final int m = matrix.getColumnDimension(); - field = matrix.getField(); - lu = matrix.getData(); - pivot = new int[m]; - cachedL = null; - cachedU = null; - cachedP = null; - - // Initialize permutation array and parity - for (int row = 0; row < m; row++) { - pivot[row] = row; - } - even = true; - singular = false; - - // Loop over columns - for (int col = 0; col < m; col++) { - - T sum = field.getZero(); - - // upper - for (int row = 0; row < col; row++) { - final T[] luRow = lu[row]; - sum = luRow[col]; - for (int i = 0; i < row; i++) { - sum = sum.subtract(luRow[i].multiply(lu[i][col])); - } - luRow[col] = sum; - } - - // lower - int nonZero = col; // permutation row - for (int row = col; row < m; row++) { - final T[] luRow = lu[row]; - sum = luRow[col]; - for (int i = 0; i < col; i++) { - sum = sum.subtract(luRow[i].multiply(lu[i][col])); - } - luRow[col] = sum; - - if (lu[nonZero][col].equals(field.getZero())) { - // try to select a better permutation choice - ++nonZero; - } - } - - // Singularity check - if (nonZero >= m) { - singular = true; - return; - } - - // Pivot if necessary - if (nonZero != col) { - T tmp = field.getZero(); - for (int i = 0; i < m; i++) { - tmp = lu[nonZero][i]; - lu[nonZero][i] = lu[col][i]; - lu[col][i] = tmp; - } - int temp = pivot[nonZero]; - pivot[nonZero] = pivot[col]; - pivot[col] = temp; - even = !even; - } - - // Divide the lower elements by the "winning" diagonal elt. - final T luDiag = lu[col][col]; - for (int row = col + 1; row < m; row++) { - final T[] luRow = lu[row]; - luRow[col] = luRow[col].divide(luDiag); - } - } - - } - - /** - * Returns the matrix L of the decomposition. - * <p>L is a lower-triangular matrix</p> - * @return the L matrix (or null if decomposed matrix is singular) - */ - public FieldMatrix<T> getL() { - if ((cachedL == null) && !singular) { - final int m = pivot.length; - cachedL = new Array2DRowFieldMatrix<T>(field, m, m); - for (int i = 0; i < m; ++i) { - final T[] luI = lu[i]; - for (int j = 0; j < i; ++j) { - cachedL.setEntry(i, j, luI[j]); - } - cachedL.setEntry(i, i, field.getOne()); - } - } - return cachedL; - } - - /** - * Returns the matrix U of the decomposition. - * <p>U is an upper-triangular matrix</p> - * @return the U matrix (or null if decomposed matrix is singular) - */ - public FieldMatrix<T> getU() { - if ((cachedU == null) && !singular) { - final int m = pivot.length; - cachedU = new Array2DRowFieldMatrix<T>(field, m, m); - for (int i = 0; i < m; ++i) { - final T[] luI = lu[i]; - for (int j = i; j < m; ++j) { - cachedU.setEntry(i, j, luI[j]); - } - } - } - return cachedU; - } - - /** - * Returns the P rows permutation matrix. - * <p>P is a sparse matrix with exactly one element set to 1.0 in - * each row and each column, all other elements being set to 0.0.</p> - * <p>The positions of the 1 elements are given by the {@link #getPivot() - * pivot permutation vector}.</p> - * @return the P rows permutation matrix (or null if decomposed matrix is singular) - * @see #getPivot() - */ - public FieldMatrix<T> getP() { - if ((cachedP == null) && !singular) { - final int m = pivot.length; - cachedP = new Array2DRowFieldMatrix<T>(field, m, m); - for (int i = 0; i < m; ++i) { - cachedP.setEntry(i, pivot[i], field.getOne()); - } - } - return cachedP; - } - - /** - * Returns the pivot permutation vector. - * @return the pivot permutation vector - * @see #getP() - */ - public int[] getPivot() { - return pivot.clone(); - } - - /** - * Return the determinant of the matrix. - * @return determinant of the matrix - */ - public T getDeterminant() { - if (singular) { - return field.getZero(); - } else { - final int m = pivot.length; - T determinant = even ? field.getOne() : field.getZero().subtract(field.getOne()); - for (int i = 0; i < m; i++) { - determinant = determinant.multiply(lu[i][i]); - } - return determinant; - } - } - - /** - * Get a solver for finding the A × X = B solution in exact linear sense. - * @return a solver - */ - public FieldDecompositionSolver<T> getSolver() { - return new Solver<T>(field, lu, pivot, singular); - } - - /** Specialized solver. */ - private static class Solver<T extends FieldElement<T>> implements FieldDecompositionSolver<T> { - - /** Field to which the elements belong. */ - private final Field<T> field; - - /** Entries of LU decomposition. */ - private final T[][] lu; - - /** Pivot permutation associated with LU decomposition. */ - private final int[] pivot; - - /** Singularity indicator. */ - private final boolean singular; - - /** - * Build a solver from decomposed matrix. - * @param field field to which the matrix elements belong - * @param lu entries of LU decomposition - * @param pivot pivot permutation associated with LU decomposition - * @param singular singularity indicator - */ - private Solver(final Field<T> field, final T[][] lu, - final int[] pivot, final boolean singular) { - this.field = field; - this.lu = lu; - this.pivot = pivot; - this.singular = singular; - } - - /** {@inheritDoc} */ - public boolean isNonSingular() { - return !singular; - } - - /** {@inheritDoc} */ - public FieldVector<T> solve(FieldVector<T> b) { - try { - return solve((ArrayFieldVector<T>) b); - } catch (ClassCastException cce) { - - final int m = pivot.length; - if (b.getDimension() != m) { - throw new DimensionMismatchException(b.getDimension(), m); - } - if (singular) { - throw new SingularMatrixException(); - } - - // Apply permutations to b - final T[] bp = MathArrays.buildArray(field, m); - for (int row = 0; row < m; row++) { - bp[row] = b.getEntry(pivot[row]); - } - - // Solve LY = b - for (int col = 0; col < m; col++) { - final T bpCol = bp[col]; - for (int i = col + 1; i < m; i++) { - bp[i] = bp[i].subtract(bpCol.multiply(lu[i][col])); - } - } - - // Solve UX = Y - for (int col = m - 1; col >= 0; col--) { - bp[col] = bp[col].divide(lu[col][col]); - final T bpCol = bp[col]; - for (int i = 0; i < col; i++) { - bp[i] = bp[i].subtract(bpCol.multiply(lu[i][col])); - } - } - - return new ArrayFieldVector<T>(field, bp, false); - - } - } - - /** Solve the linear equation A × X = B. - * <p>The A matrix is implicit here. It is </p> - * @param b right-hand side of the equation A × X = B - * @return a vector X such that A × X = B - * @throws DimensionMismatchException if the matrices dimensions do not match. - * @throws SingularMatrixException if the decomposed matrix is singular. - */ - public ArrayFieldVector<T> solve(ArrayFieldVector<T> b) { - final int m = pivot.length; - final int length = b.getDimension(); - if (length != m) { - throw new DimensionMismatchException(length, m); - } - if (singular) { - throw new SingularMatrixException(); - } - - // Apply permutations to b - final T[] bp = MathArrays.buildArray(field, m); - for (int row = 0; row < m; row++) { - bp[row] = b.getEntry(pivot[row]); - } - - // Solve LY = b - for (int col = 0; col < m; col++) { - final T bpCol = bp[col]; - for (int i = col + 1; i < m; i++) { - bp[i] = bp[i].subtract(bpCol.multiply(lu[i][col])); - } - } - - // Solve UX = Y - for (int col = m - 1; col >= 0; col--) { - bp[col] = bp[col].divide(lu[col][col]); - final T bpCol = bp[col]; - for (int i = 0; i < col; i++) { - bp[i] = bp[i].subtract(bpCol.multiply(lu[i][col])); - } - } - - return new ArrayFieldVector<T>(bp, false); - } - - /** {@inheritDoc} */ - public FieldMatrix<T> solve(FieldMatrix<T> b) { - final int m = pivot.length; - if (b.getRowDimension() != m) { - throw new DimensionMismatchException(b.getRowDimension(), m); - } - if (singular) { - throw new SingularMatrixException(); - } - - final int nColB = b.getColumnDimension(); - - // Apply permutations to b - final T[][] bp = MathArrays.buildArray(field, m, nColB); - for (int row = 0; row < m; row++) { - final T[] bpRow = bp[row]; - final int pRow = pivot[row]; - for (int col = 0; col < nColB; col++) { - bpRow[col] = b.getEntry(pRow, col); - } - } - - // Solve LY = b - for (int col = 0; col < m; col++) { - final T[] bpCol = bp[col]; - for (int i = col + 1; i < m; i++) { - final T[] bpI = bp[i]; - final T luICol = lu[i][col]; - for (int j = 0; j < nColB; j++) { - bpI[j] = bpI[j].subtract(bpCol[j].multiply(luICol)); - } - } - } - - // Solve UX = Y - for (int col = m - 1; col >= 0; col--) { - final T[] bpCol = bp[col]; - final T luDiag = lu[col][col]; - for (int j = 0; j < nColB; j++) { - bpCol[j] = bpCol[j].divide(luDiag); - } - for (int i = 0; i < col; i++) { - final T[] bpI = bp[i]; - final T luICol = lu[i][col]; - for (int j = 0; j < nColB; j++) { - bpI[j] = bpI[j].subtract(bpCol[j].multiply(luICol)); - } - } - } - - return new Array2DRowFieldMatrix<T>(field, bp, false); - - } - - /** {@inheritDoc} */ - public FieldMatrix<T> getInverse() { - final int m = pivot.length; - final T one = field.getOne(); - FieldMatrix<T> identity = new Array2DRowFieldMatrix<T>(field, m, m); - for (int i = 0; i < m; ++i) { - identity.setEntry(i, i, one); - } - return solve(identity); - } - } -}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/linear/FieldMatrix.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/linear/FieldMatrix.java b/src/main/java/org/apache/commons/math3/linear/FieldMatrix.java deleted file mode 100644 index 1048887..0000000 --- a/src/main/java/org/apache/commons/math3/linear/FieldMatrix.java +++ /dev/null @@ -1,816 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.commons.math3.linear; - - -import org.apache.commons.math3.Field; -import org.apache.commons.math3.FieldElement; -import org.apache.commons.math3.exception.DimensionMismatchException; -import org.apache.commons.math3.exception.NoDataException; -import org.apache.commons.math3.exception.NotPositiveException; -import org.apache.commons.math3.exception.NotStrictlyPositiveException; -import org.apache.commons.math3.exception.NullArgumentException; -import org.apache.commons.math3.exception.NumberIsTooSmallException; -import org.apache.commons.math3.exception.OutOfRangeException; - -/** - * Interface defining field-valued matrix with basic algebraic operations. - * <p> - * Matrix element indexing is 0-based -- e.g., <code>getEntry(0, 0)</code> - * returns the element in the first row, first column of the matrix.</p> - * - * @param <T> the type of the field elements - */ -public interface FieldMatrix<T extends FieldElement<T>> extends AnyMatrix { - /** - * Get the type of field elements of the matrix. - * - * @return the type of field elements of the matrix. - */ - Field<T> getField(); - - /** - * Create a new FieldMatrix<T> of the same type as the instance with - * the supplied row and column dimensions. - * - * @param rowDimension the number of rows in the new matrix - * @param columnDimension the number of columns in the new matrix - * @return a new matrix of the same type as the instance - * @throws NotStrictlyPositiveException if row or column dimension is not - * positive. - * @since 2.0 - */ - FieldMatrix<T> createMatrix(final int rowDimension, final int columnDimension) - throws NotStrictlyPositiveException; - - /** - * Make a (deep) copy of this. - * - * @return a copy of this matrix. - */ - FieldMatrix<T> copy(); - - /** - * Compute the sum of this and m. - * - * @param m Matrix to be added. - * @return {@code this} + {@code m}. - * @throws MatrixDimensionMismatchException if {@code m} is not the same - * size as {@code this} matrix. - */ - FieldMatrix<T> add(FieldMatrix<T> m) throws MatrixDimensionMismatchException; - - /** - * Subtract {@code m} from this matrix. - * - * @param m Matrix to be subtracted. - * @return {@code this} - {@code m}. - * @throws MatrixDimensionMismatchException if {@code m} is not the same - * size as {@code this} matrix. - */ - FieldMatrix<T> subtract(FieldMatrix<T> m) throws MatrixDimensionMismatchException; - - /** - * Increment each entry of this matrix. - * - * @param d Value to be added to each entry. - * @return {@code d} + {@code this}. - */ - FieldMatrix<T> scalarAdd(T d); - - /** - * Multiply each entry by {@code d}. - * - * @param d Value to multiply all entries by. - * @return {@code d} * {@code this}. - */ - FieldMatrix<T> scalarMultiply(T d); - - /** - * Postmultiply this matrix by {@code m}. - * - * @param m Matrix to postmultiply by. - * @return {@code this} * {@code m}. - * @throws DimensionMismatchException if the number of columns of - * {@code this} matrix is not equal to the number of rows of matrix - * {@code m}. - */ - FieldMatrix<T> multiply(FieldMatrix<T> m) throws DimensionMismatchException; - - /** - * Premultiply this matrix by {@code m}. - * - * @param m Matrix to premultiply by. - * @return {@code m} * {@code this}. - * @throws DimensionMismatchException if the number of columns of {@code m} - * differs from the number of rows of {@code this} matrix. - */ - FieldMatrix<T> preMultiply(FieldMatrix<T> m) throws DimensionMismatchException; - - /** - * Returns the result multiplying this with itself <code>p</code> times. - * Depending on the type of the field elements, T, instability for high - * powers might occur. - * - * @param p raise this to power p - * @return this^p - * @throws NotPositiveException if {@code p < 0} - * @throws NonSquareMatrixException if {@code this matrix} is not square - */ - FieldMatrix<T> power(final int p) throws NonSquareMatrixException, - NotPositiveException; - - /** - * Returns matrix entries as a two-dimensional array. - * - * @return a 2-dimensional array of entries. - */ - T[][] getData(); - - /** - * Get a submatrix. Rows and columns are indicated - * counting from 0 to n - 1. - * - * @param startRow Initial row index - * @param endRow Final row index (inclusive) - * @param startColumn Initial column index - * @param endColumn Final column index (inclusive) - * @return the matrix containing the data of the specified rows and columns. - * @throws NumberIsTooSmallException is {@code endRow < startRow} of - * {@code endColumn < startColumn}. - * @throws OutOfRangeException if the indices are not valid. - */ - FieldMatrix<T> getSubMatrix(int startRow, int endRow, int startColumn, int endColumn) - throws NumberIsTooSmallException, OutOfRangeException; - - /** - * Get a submatrix. Rows and columns are indicated - * counting from 0 to n - 1. - * - * @param selectedRows Array of row indices. - * @param selectedColumns Array of column indices. - * @return the matrix containing the data in the - * specified rows and columns. - * @throws NoDataException if {@code selectedRows} or - * {@code selectedColumns} is empty - * @throws NullArgumentException if {@code selectedRows} or - * {@code selectedColumns} is {@code null}. - * @throws OutOfRangeException if row or column selections are not valid. - */ - FieldMatrix<T> getSubMatrix(int[] selectedRows, int[] selectedColumns) - throws NoDataException, NullArgumentException, OutOfRangeException; - - /** - * Copy a submatrix. Rows and columns are indicated - * counting from 0 to n-1. - * - * @param startRow Initial row index. - * @param endRow Final row index (inclusive). - * @param startColumn Initial column index. - * @param endColumn Final column index (inclusive). - * @param destination The arrays where the submatrix data should be copied - * (if larger than rows/columns counts, only the upper-left part will be used). - * @throws MatrixDimensionMismatchException if the dimensions of - * {@code destination} do not match those of {@code this}. - * @throws NumberIsTooSmallException is {@code endRow < startRow} of - * {@code endColumn < startColumn}. - * @throws OutOfRangeException if the indices are not valid. - * @exception IllegalArgumentException if the destination array is too small. - */ - void copySubMatrix(int startRow, int endRow, int startColumn, int endColumn, - T[][] destination) - throws MatrixDimensionMismatchException, NumberIsTooSmallException, - OutOfRangeException; - - /** - * Copy a submatrix. Rows and columns are indicated - * counting from 0 to n - 1. - * - * @param selectedRows Array of row indices. - * @param selectedColumns Array of column indices. - * @param destination Arrays where the submatrix data should be copied - * (if larger than rows/columns counts, only the upper-left part will be used) - * @throws MatrixDimensionMismatchException if the dimensions of - * {@code destination} do not match those of {@code this}. - * @throws NoDataException if {@code selectedRows} or - * {@code selectedColumns} is empty - * @throws NullArgumentException if {@code selectedRows} or - * {@code selectedColumns} is {@code null}. - * @throws OutOfRangeException if the indices are not valid. - */ - void copySubMatrix(int[] selectedRows, int[] selectedColumns, T[][] destination) - throws MatrixDimensionMismatchException, NoDataException, NullArgumentException, - OutOfRangeException; - - /** - * Replace the submatrix starting at {@code (row, column)} using data in the - * input {@code subMatrix} array. Indexes are 0-based. - * <p> - * Example:<br> - * Starting with - * - * <pre> - * 1 2 3 4 - * 5 6 7 8 - * 9 0 1 2 - * </pre> - * - * and <code>subMatrix = {{3, 4} {5,6}}</code>, invoking - * <code>setSubMatrix(subMatrix,1,1))</code> will result in - * - * <pre> - * 1 2 3 4 - * 5 3 4 8 - * 9 5 6 2 - * </pre> - * - * </p> - * - * @param subMatrix Array containing the submatrix replacement data. - * @param row Row coordinate of the top-left element to be replaced. - * @param column Column coordinate of the top-left element to be replaced. - * @throws OutOfRangeException if {@code subMatrix} does not fit into this - * matrix from element in {@code (row, column)}. - * @throws NoDataException if a row or column of {@code subMatrix} is empty. - * @throws DimensionMismatchException if {@code subMatrix} is not - * rectangular (not all rows have the same length). - * @throws NullArgumentException if {@code subMatrix} is {@code null}. - * @since 2.0 - */ - void setSubMatrix(T[][] subMatrix, int row, int column) - throws DimensionMismatchException, OutOfRangeException, - NoDataException, NullArgumentException; - - /** - * Get the entries in row number {@code row} - * as a row matrix. - * - * @param row Row to be fetched. - * @return a row matrix. - * @throws OutOfRangeException if the specified row index is invalid. - */ - FieldMatrix<T> getRowMatrix(int row) throws OutOfRangeException; - - /** - * Set the entries in row number {@code row} - * as a row matrix. - * - * @param row Row to be set. - * @param matrix Row matrix (must have one row and the same number - * of columns as the instance). - * @throws OutOfRangeException if the specified row index is invalid. - * @throws MatrixDimensionMismatchException - * if the matrix dimensions do not match one instance row. - */ - void setRowMatrix(int row, FieldMatrix<T> matrix) - throws MatrixDimensionMismatchException, OutOfRangeException; - - /** - * Get the entries in column number {@code column} - * as a column matrix. - * - * @param column Column to be fetched. - * @return a column matrix. - * @throws OutOfRangeException if the specified column index is invalid. - */ - FieldMatrix<T> getColumnMatrix(int column) throws OutOfRangeException; - - /** - * Set the entries in column number {@code column} - * as a column matrix. - * - * @param column Column to be set. - * @param matrix column matrix (must have one column and the same - * number of rows as the instance). - * @throws OutOfRangeException if the specified column index is invalid. - * @throws MatrixDimensionMismatchException if the matrix dimensions do - * not match one instance column. - */ - void setColumnMatrix(int column, FieldMatrix<T> matrix) - throws MatrixDimensionMismatchException, OutOfRangeException; - - /** - * Get the entries in row number {@code row} - * as a vector. - * - * @param row Row to be fetched - * @return a row vector. - * @throws OutOfRangeException if the specified row index is invalid. - */ - FieldVector<T> getRowVector(int row) throws OutOfRangeException; - - /** - * Set the entries in row number {@code row} - * as a vector. - * - * @param row Row to be set. - * @param vector row vector (must have the same number of columns - * as the instance). - * @throws OutOfRangeException if the specified row index is invalid. - * @throws MatrixDimensionMismatchException if the vector dimension does not - * match one instance row. - */ - void setRowVector(int row, FieldVector<T> vector) - throws MatrixDimensionMismatchException, OutOfRangeException; - - /** - * Returns the entries in column number {@code column} - * as a vector. - * - * @param column Column to be fetched. - * @return a column vector. - * @throws OutOfRangeException if the specified column index is invalid. - */ - FieldVector<T> getColumnVector(int column) throws OutOfRangeException; - - /** - * Set the entries in column number {@code column} - * as a vector. - * - * @param column Column to be set. - * @param vector Column vector (must have the same number of rows - * as the instance). - * @throws OutOfRangeException if the specified column index is invalid. - * @throws MatrixDimensionMismatchException if the vector dimension does not - * match one instance column. - */ - void setColumnVector(int column, FieldVector<T> vector) - throws MatrixDimensionMismatchException, OutOfRangeException; - - /** - * Get the entries in row number {@code row} as an array. - * - * @param row Row to be fetched. - * @return array of entries in the row. - * @throws OutOfRangeException if the specified row index is not valid. - */ - T[] getRow(int row) throws OutOfRangeException; - - /** - * Set the entries in row number {@code row} - * as a row matrix. - * - * @param row Row to be set. - * @param array Row matrix (must have the same number of columns as - * the instance). - * @throws OutOfRangeException if the specified row index is invalid. - * @throws MatrixDimensionMismatchException if the array size does not match - * one instance row. - */ - void setRow(int row, T[] array) throws MatrixDimensionMismatchException, - OutOfRangeException; - - /** - * Get the entries in column number {@code col} as an array. - * - * @param column the column to be fetched - * @return array of entries in the column - * @throws OutOfRangeException if the specified column index is not valid. - */ - T[] getColumn(int column) throws OutOfRangeException; - - /** - * Set the entries in column number {@code column} - * as a column matrix. - * - * @param column the column to be set - * @param array column array (must have the same number of rows as the instance) - * @throws OutOfRangeException if the specified column index is invalid. - * @throws MatrixDimensionMismatchException if the array size does not match - * one instance column. - */ - void setColumn(int column, T[] array) throws MatrixDimensionMismatchException, - OutOfRangeException; - - /** - * Returns the entry in the specified row and column. - * - * @param row row location of entry to be fetched - * @param column column location of entry to be fetched - * @return matrix entry in row,column - * @throws OutOfRangeException if the row or column index is not valid. - */ - T getEntry(int row, int column) throws OutOfRangeException; - - /** - * Set the entry in the specified row and column. - * - * @param row row location of entry to be set - * @param column column location of entry to be set - * @param value matrix entry to be set in row,column - * @throws OutOfRangeException if the row or column index is not valid. - * @since 2.0 - */ - void setEntry(int row, int column, T value) throws OutOfRangeException; - - /** - * Change an entry in the specified row and column. - * - * @param row Row location of entry to be set. - * @param column Column location of entry to be set. - * @param increment Value to add to the current matrix entry in - * {@code (row, column)}. - * @throws OutOfRangeException if the row or column index is not valid. - * @since 2.0 - */ - void addToEntry(int row, int column, T increment) throws OutOfRangeException; - - /** - * Change an entry in the specified row and column. - * - * @param row Row location of entry to be set. - * @param column Column location of entry to be set. - * @param factor Multiplication factor for the current matrix entry - * in {@code (row,column)} - * @throws OutOfRangeException if the row or column index is not valid. - * @since 2.0 - */ - void multiplyEntry(int row, int column, T factor) throws OutOfRangeException; - - /** - * Returns the transpose of this matrix. - * - * @return transpose matrix - */ - FieldMatrix<T> transpose(); - - /** - * Returns the <a href="http://mathworld.wolfram.com/MatrixTrace.html"> - * trace</a> of the matrix (the sum of the elements on the main diagonal). - * - * @return trace - * @throws NonSquareMatrixException if the matrix is not square. - */ - T getTrace() throws NonSquareMatrixException; - - /** - * Returns the result of multiplying this by the vector {@code v}. - * - * @param v the vector to operate on - * @return {@code this * v} - * @throws DimensionMismatchException if the number of columns of - * {@code this} matrix is not equal to the size of the vector {@code v}. - */ - T[] operate(T[] v) throws DimensionMismatchException; - - /** - * Returns the result of multiplying this by the vector {@code v}. - * - * @param v the vector to operate on - * @return {@code this * v} - * @throws DimensionMismatchException if the number of columns of - * {@code this} matrix is not equal to the size of the vector {@code v}. - */ - FieldVector<T> operate(FieldVector<T> v) throws DimensionMismatchException; - - /** - * Returns the (row) vector result of premultiplying this by the vector - * {@code v}. - * - * @param v the row vector to premultiply by - * @return {@code v * this} - * @throws DimensionMismatchException if the number of rows of {@code this} - * matrix is not equal to the size of the vector {@code v} - */ - T[] preMultiply(T[] v) throws DimensionMismatchException; - - /** - * Returns the (row) vector result of premultiplying this by the vector - * {@code v}. - * - * @param v the row vector to premultiply by - * @return {@code v * this} - * @throws DimensionMismatchException if the number of rows of {@code this} - * matrix is not equal to the size of the vector {@code v} - */ - FieldVector<T> preMultiply(FieldVector<T> v) throws DimensionMismatchException; - - /** - * Visit (and possibly change) all matrix entries in row order. - * <p>Row order starts at upper left and iterating through all elements - * of a row from left to right before going to the leftmost element - * of the next row.</p> - * @param visitor visitor used to process all matrix entries - * @see #walkInRowOrder(FieldMatrixPreservingVisitor) - * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @return the value returned by {@link FieldMatrixChangingVisitor#end()} at the end - * of the walk - */ - T walkInRowOrder(FieldMatrixChangingVisitor<T> visitor); - - /** - * Visit (but don't change) all matrix entries in row order. - * <p>Row order starts at upper left and iterating through all elements - * of a row from left to right before going to the leftmost element - * of the next row.</p> - * @param visitor visitor used to process all matrix entries - * @see #walkInRowOrder(FieldMatrixChangingVisitor) - * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @return the value returned by {@link FieldMatrixPreservingVisitor#end()} at the end - * of the walk - */ - T walkInRowOrder(FieldMatrixPreservingVisitor<T> visitor); - - /** - * Visit (and possibly change) some matrix entries in row order. - * <p>Row order starts at upper left and iterating through all elements - * of a row from left to right before going to the leftmost element - * of the next row.</p> - * @param visitor visitor used to process all matrix entries - * @param startRow Initial row index - * @param endRow Final row index (inclusive) - * @param startColumn Initial column index - * @param endColumn Final column index - * @throws OutOfRangeException if the indices are not valid. - * @throws NumberIsTooSmallException if {@code endRow < startRow} or - * {@code endColumn < startColumn}. - * @see #walkInRowOrder(FieldMatrixChangingVisitor) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @return the value returned by {@link FieldMatrixChangingVisitor#end()} at the end - * of the walk - */ - T walkInRowOrder(FieldMatrixChangingVisitor<T> visitor, - int startRow, int endRow, int startColumn, int endColumn) - throws OutOfRangeException, NumberIsTooSmallException; - - /** - * Visit (but don't change) some matrix entries in row order. - * <p>Row order starts at upper left and iterating through all elements - * of a row from left to right before going to the leftmost element - * of the next row.</p> - * @param visitor visitor used to process all matrix entries - * @param startRow Initial row index - * @param endRow Final row index (inclusive) - * @param startColumn Initial column index - * @param endColumn Final column index - * @throws OutOfRangeException if the indices are not valid. - * @throws NumberIsTooSmallException if {@code endRow < startRow} or - * {@code endColumn < startColumn}. - * @see #walkInRowOrder(FieldMatrixChangingVisitor) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor) - * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @return the value returned by {@link FieldMatrixPreservingVisitor#end()} at the end - * of the walk - */ - T walkInRowOrder(FieldMatrixPreservingVisitor<T> visitor, - int startRow, int endRow, int startColumn, int endColumn) - throws OutOfRangeException, NumberIsTooSmallException; - - /** - * Visit (and possibly change) all matrix entries in column order. - * <p>Column order starts at upper left and iterating through all elements - * of a column from top to bottom before going to the topmost element - * of the next column.</p> - * @param visitor visitor used to process all matrix entries - * @see #walkInRowOrder(FieldMatrixChangingVisitor) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor) - * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @return the value returned by {@link FieldMatrixChangingVisitor#end()} at the end - * of the walk - */ - T walkInColumnOrder(FieldMatrixChangingVisitor<T> visitor); - - /** - * Visit (but don't change) all matrix entries in column order. - * <p>Column order starts at upper left and iterating through all elements - * of a column from top to bottom before going to the topmost element - * of the next column.</p> - * @param visitor visitor used to process all matrix entries - * @see #walkInRowOrder(FieldMatrixChangingVisitor) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor) - * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @return the value returned by {@link FieldMatrixPreservingVisitor#end()} at the end - * of the walk - */ - T walkInColumnOrder(FieldMatrixPreservingVisitor<T> visitor); - - /** - * Visit (and possibly change) some matrix entries in column order. - * <p>Column order starts at upper left and iterating through all elements - * of a column from top to bottom before going to the topmost element - * of the next column.</p> - * @param visitor visitor used to process all matrix entries - * @param startRow Initial row index - * @param endRow Final row index (inclusive) - * @param startColumn Initial column index - * @param endColumn Final column index - * @throws NumberIsTooSmallException if {@code endRow < startRow} or - * {@code endColumn < startColumn}. - * @throws OutOfRangeException if the indices are not valid. - * @see #walkInRowOrder(FieldMatrixChangingVisitor) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor) - * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @return the value returned by {@link FieldMatrixChangingVisitor#end()} at the end - * of the walk - */ - T walkInColumnOrder(FieldMatrixChangingVisitor<T> visitor, - int startRow, int endRow, int startColumn, int endColumn) - throws NumberIsTooSmallException, OutOfRangeException; - - /** - * Visit (but don't change) some matrix entries in column order. - * <p>Column order starts at upper left and iterating through all elements - * of a column from top to bottom before going to the topmost element - * of the next column.</p> - * @param visitor visitor used to process all matrix entries - * @param startRow Initial row index - * @param endRow Final row index (inclusive) - * @param startColumn Initial column index - * @param endColumn Final column index - * @throws NumberIsTooSmallException if {@code endRow < startRow} or - * {@code endColumn < startColumn}. - * @throws OutOfRangeException if the indices are not valid. - * @see #walkInRowOrder(FieldMatrixChangingVisitor) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor) - * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @return the value returned by {@link FieldMatrixPreservingVisitor#end()} at the end - * of the walk - */ - T walkInColumnOrder(FieldMatrixPreservingVisitor<T> visitor, - int startRow, int endRow, int startColumn, int endColumn) - throws NumberIsTooSmallException, OutOfRangeException; - - /** - * Visit (and possibly change) all matrix entries using the fastest possible order. - * <p>The fastest walking order depends on the exact matrix class. It may be - * different from traditional row or column orders.</p> - * @param visitor visitor used to process all matrix entries - * @see #walkInRowOrder(FieldMatrixChangingVisitor) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor) - * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @return the value returned by {@link FieldMatrixChangingVisitor#end()} at the end - * of the walk - */ - T walkInOptimizedOrder(FieldMatrixChangingVisitor<T> visitor); - - /** - * Visit (but don't change) all matrix entries using the fastest possible order. - * <p>The fastest walking order depends on the exact matrix class. It may be - * different from traditional row or column orders.</p> - * @param visitor visitor used to process all matrix entries - * @see #walkInRowOrder(FieldMatrixChangingVisitor) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor) - * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @return the value returned by {@link FieldMatrixPreservingVisitor#end()} at the end - * of the walk - */ - T walkInOptimizedOrder(FieldMatrixPreservingVisitor<T> visitor); - - /** - * Visit (and possibly change) some matrix entries using the fastest possible order. - * <p>The fastest walking order depends on the exact matrix class. It may be - * different from traditional row or column orders.</p> - * @param visitor visitor used to process all matrix entries - * @param startRow Initial row index - * @param endRow Final row index (inclusive) - * @param startColumn Initial column index - * @param endColumn Final column index (inclusive) - * @throws NumberIsTooSmallException if {@code endRow < startRow} or - * {@code endColumn < startColumn}. - * @throws OutOfRangeException if the indices are not valid. - * @see #walkInRowOrder(FieldMatrixChangingVisitor) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor) - * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @return the value returned by {@link FieldMatrixChangingVisitor#end()} at the end - * of the walk - */ - T walkInOptimizedOrder(FieldMatrixChangingVisitor<T> visitor, - int startRow, int endRow, int startColumn, int endColumn) - throws NumberIsTooSmallException, OutOfRangeException; - - /** - * Visit (but don't change) some matrix entries using the fastest possible order. - * <p>The fastest walking order depends on the exact matrix class. It may be - * different from traditional row or column orders.</p> - * @param visitor visitor used to process all matrix entries - * @param startRow Initial row index - * @param endRow Final row index (inclusive) - * @param startColumn Initial column index - * @param endColumn Final column index (inclusive) - * @throws NumberIsTooSmallException if {@code endRow < startRow} or - * {@code endColumn < startColumn}. - * @throws OutOfRangeException if the indices are not valid. - * @see #walkInRowOrder(FieldMatrixChangingVisitor) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor) - * @see #walkInRowOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInRowOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor) - * @see #walkInColumnOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @see #walkInColumnOrder(FieldMatrixPreservingVisitor, int, int, int, int) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixPreservingVisitor) - * @see #walkInOptimizedOrder(FieldMatrixChangingVisitor, int, int, int, int) - * @return the value returned by {@link FieldMatrixPreservingVisitor#end()} at the end - * of the walk - */ - T walkInOptimizedOrder(FieldMatrixPreservingVisitor<T> visitor, - int startRow, int endRow, int startColumn, int endColumn) - throws NumberIsTooSmallException, OutOfRangeException; -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/linear/FieldMatrixChangingVisitor.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/linear/FieldMatrixChangingVisitor.java b/src/main/java/org/apache/commons/math3/linear/FieldMatrixChangingVisitor.java deleted file mode 100644 index d510cd0..0000000 --- a/src/main/java/org/apache/commons/math3/linear/FieldMatrixChangingVisitor.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.commons.math3.linear; - -import org.apache.commons.math3.FieldElement; - -/** - * Interface defining a visitor for matrix entries. - * - * @param <T> the type of the field elements - * @since 2.0 - */ -public interface FieldMatrixChangingVisitor<T extends FieldElement<?>> { - /** - * Start visiting a matrix. - * <p>This method is called once before any entry of the matrix is visited.</p> - * @param rows number of rows of the matrix - * @param columns number of columns of the matrix - * @param startRow Initial row index - * @param endRow Final row index (inclusive) - * @param startColumn Initial column index - * @param endColumn Final column index (inclusive) - */ - void start(int rows, int columns, - int startRow, int endRow, int startColumn, int endColumn); - - /** - * Visit one matrix entry. - * @param row row index of the entry - * @param column column index of the entry - * @param value current value of the entry - * @return the new value to be set for the entry - */ - T visit(int row, int column, T value); - - /** - * End visiting a matrix. - * <p>This method is called once after all entries of the matrix have been visited.</p> - * @return the value that the <code>walkInXxxOrder</code> must return - */ - T end(); -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/linear/FieldMatrixPreservingVisitor.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/linear/FieldMatrixPreservingVisitor.java b/src/main/java/org/apache/commons/math3/linear/FieldMatrixPreservingVisitor.java deleted file mode 100644 index 8db2e3a..0000000 --- a/src/main/java/org/apache/commons/math3/linear/FieldMatrixPreservingVisitor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.commons.math3.linear; - -import org.apache.commons.math3.FieldElement; - -/** - * Interface defining a visitor for matrix entries. - * - * @param <T> the type of the field elements - * @since 2.0 - */ -public interface FieldMatrixPreservingVisitor<T extends FieldElement<?>> { - /** - * Start visiting a matrix. - * <p>This method is called once before any entry of the matrix is visited.</p> - * @param rows number of rows of the matrix - * @param columns number of columns of the matrix - * @param startRow Initial row index - * @param endRow Final row index (inclusive) - * @param startColumn Initial column index - * @param endColumn Final column index (inclusive) - */ - void start(int rows, int columns, - int startRow, int endRow, int startColumn, int endColumn); - - /** - * Visit one matrix entry. - * @param row row index of the entry - * @param column column index of the entry - * @param value current value of the entry - */ - void visit(int row, int column, T value); - - /** - * End visiting a matrix. - * <p>This method is called once after all entries of the matrix have been visited.</p> - * @return the value that the <code>walkInXxxOrder</code> must return - */ - T end(); -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/linear/FieldVector.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/linear/FieldVector.java b/src/main/java/org/apache/commons/math3/linear/FieldVector.java deleted file mode 100644 index 2161e81..0000000 --- a/src/main/java/org/apache/commons/math3/linear/FieldVector.java +++ /dev/null @@ -1,298 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.linear; - -import org.apache.commons.math3.Field; -import org.apache.commons.math3.FieldElement; -import org.apache.commons.math3.exception.DimensionMismatchException; -import org.apache.commons.math3.exception.MathArithmeticException; -import org.apache.commons.math3.exception.NotPositiveException; -import org.apache.commons.math3.exception.NullArgumentException; -import org.apache.commons.math3.exception.OutOfRangeException; - -/** - * Interface defining a field-valued vector with basic algebraic operations. - * <p> - * vector element indexing is 0-based -- e.g., <code>getEntry(0)</code> - * returns the first element of the vector. - * </p> - * <p> - * The various <code>mapXxx</code> and <code>mapXxxToSelf</code> methods operate - * on vectors element-wise, i.e. they perform the same operation (adding a scalar, - * applying a function ...) on each element in turn. The <code>mapXxx</code> - * versions create a new vector to hold the result and do not change the instance. - * The <code>mapXxxToSelf</code> versions use the instance itself to store the - * results, so the instance is changed by these methods. In both cases, the result - * vector is returned by the methods, this allows to use the <i>fluent API</i> - * style, like this: - * </p> - * <pre> - * RealVector result = v.mapAddToSelf(3.0).mapTanToSelf().mapSquareToSelf(); - * </pre> - * <p> - * Note that as almost all operations on {@link FieldElement} throw {@link - * NullArgumentException} when operating on a null element, it is the responsibility - * of <code>FieldVector</code> implementations to make sure no null elements - * are inserted into the vector. This must be done in all constructors and - * all setters. - * <p> - * - * @param <T> the type of the field elements - * @since 2.0 - */ -public interface FieldVector<T extends FieldElement<T>> { - - /** - * Get the type of field elements of the vector. - * @return type of field elements of the vector - */ - Field<T> getField(); - - /** - * Returns a (deep) copy of this. - * @return vector copy - */ - FieldVector<T> copy(); - - /** - * Compute the sum of {@code this} and {@code v}. - * @param v vector to be added - * @return {@code this + v} - * @throws DimensionMismatchException if {@code v} is not the same size as {@code this} - */ - FieldVector<T> add(FieldVector<T> v) throws DimensionMismatchException; - - /** - * Compute {@code this} minus {@code v}. - * @param v vector to be subtracted - * @return {@code this - v} - * @throws DimensionMismatchException if {@code v} is not the same size as {@code this} - */ - FieldVector<T> subtract(FieldVector<T> v) throws DimensionMismatchException; - - /** - * Map an addition operation to each entry. - * @param d value to be added to each entry - * @return {@code this + d} - * @throws NullArgumentException if {@code d} is {@code null}. - */ - FieldVector<T> mapAdd(T d) throws NullArgumentException; - - /** - * Map an addition operation to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @param d value to be added to each entry - * @return for convenience, return {@code this} - * @throws NullArgumentException if {@code d} is {@code null}. - */ - FieldVector<T> mapAddToSelf(T d) throws NullArgumentException; - - /** - * Map a subtraction operation to each entry. - * @param d value to be subtracted to each entry - * @return {@code this - d} - * @throws NullArgumentException if {@code d} is {@code null} - */ - FieldVector<T> mapSubtract(T d) throws NullArgumentException; - - /** - * Map a subtraction operation to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @param d value to be subtracted to each entry - * @return for convenience, return {@code this} - * @throws NullArgumentException if {@code d} is {@code null} - */ - FieldVector<T> mapSubtractToSelf(T d) throws NullArgumentException; - - /** - * Map a multiplication operation to each entry. - * @param d value to multiply all entries by - * @return {@code this * d} - * @throws NullArgumentException if {@code d} is {@code null}. - */ - FieldVector<T> mapMultiply(T d) throws NullArgumentException; - - /** - * Map a multiplication operation to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @param d value to multiply all entries by - * @return for convenience, return {@code this} - * @throws NullArgumentException if {@code d} is {@code null}. - */ - FieldVector<T> mapMultiplyToSelf(T d) throws NullArgumentException; - - /** - * Map a division operation to each entry. - * @param d value to divide all entries by - * @return {@code this / d} - * @throws NullArgumentException if {@code d} is {@code null}. - * @throws MathArithmeticException if {@code d} is zero. - */ - FieldVector<T> mapDivide(T d) - throws NullArgumentException, MathArithmeticException; - - /** - * Map a division operation to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @param d value to divide all entries by - * @return for convenience, return {@code this} - * @throws NullArgumentException if {@code d} is {@code null}. - * @throws MathArithmeticException if {@code d} is zero. - */ - FieldVector<T> mapDivideToSelf(T d) - throws NullArgumentException, MathArithmeticException; - - /** - * Map the 1/x function to each entry. - * @return a vector containing the result of applying the function to each entry. - * @throws MathArithmeticException if one of the entries is zero. - */ - FieldVector<T> mapInv() throws MathArithmeticException; - - /** - * Map the 1/x function to each entry. - * <p>The instance <strong>is</strong> changed by this method.</p> - * @return for convenience, return {@code this} - * @throws MathArithmeticException if one of the entries is zero. - */ - FieldVector<T> mapInvToSelf() throws MathArithmeticException; - - /** - * Element-by-element multiplication. - * @param v vector by which instance elements must be multiplied - * @return a vector containing {@code this[i] * v[i]} for all {@code i} - * @throws DimensionMismatchException if {@code v} is not the same size as {@code this} - */ - FieldVector<T> ebeMultiply(FieldVector<T> v) - throws DimensionMismatchException; - - /** - * Element-by-element division. - * @param v vector by which instance elements must be divided - * @return a vector containing {@code this[i] / v[i]} for all {@code i} - * @throws DimensionMismatchException if {@code v} is not the same size as {@code this} - * @throws MathArithmeticException if one entry of {@code v} is zero. - */ - FieldVector<T> ebeDivide(FieldVector<T> v) - throws DimensionMismatchException, MathArithmeticException; - - /** - * Returns vector entries as a T array. - * @return T array of entries - * @deprecated as of 3.1, to be removed in 4.0. Please use the {@link #toArray()} method instead. - */ - @Deprecated - T[] getData(); - - /** - * Compute the dot product. - * @param v vector with which dot product should be computed - * @return the scalar dot product of {@code this} and {@code v} - * @throws DimensionMismatchException if {@code v} is not the same size as {@code this} - */ - T dotProduct(FieldVector<T> v) throws DimensionMismatchException; - - /** - * Find the orthogonal projection of this vector onto another vector. - * @param v vector onto which {@code this} must be projected - * @return projection of {@code this} onto {@code v} - * @throws DimensionMismatchException if {@code v} is not the same size as {@code this} - * @throws MathArithmeticException if {@code v} is the null vector. - */ - FieldVector<T> projection(FieldVector<T> v) - throws DimensionMismatchException, MathArithmeticException; - - /** - * Compute the outer product. - * @param v vector with which outer product should be computed - * @return the matrix outer product between instance and v - */ - FieldMatrix<T> outerProduct(FieldVector<T> v); - - /** - * Returns the entry in the specified index. - * - * @param index Index location of entry to be fetched. - * @return the vector entry at {@code index}. - * @throws OutOfRangeException if the index is not valid. - * @see #setEntry(int, FieldElement) - */ - T getEntry(int index) throws OutOfRangeException; - - /** - * Set a single element. - * @param index element index. - * @param value new value for the element. - * @throws OutOfRangeException if the index is not valid. - * @see #getEntry(int) - */ - void setEntry(int index, T value) throws OutOfRangeException; - - /** - * Returns the size of the vector. - * @return size - */ - int getDimension(); - - /** - * Construct a vector by appending a vector to this vector. - * @param v vector to append to this one. - * @return a new vector - */ - FieldVector<T> append(FieldVector<T> v); - - /** - * Construct a vector by appending a T to this vector. - * @param d T to append. - * @return a new vector - */ - FieldVector<T> append(T d); - - /** - * Get a subvector from consecutive elements. - * @param index index of first element. - * @param n number of elements to be retrieved. - * @return a vector containing n elements. - * @throws OutOfRangeException if the index is not valid. - * @throws NotPositiveException if the number of elements if not positive. - */ - FieldVector<T> getSubVector(int index, int n) - throws OutOfRangeException, NotPositiveException; - - /** - * Set a set of consecutive elements. - * @param index index of first element to be set. - * @param v vector containing the values to set. - * @throws OutOfRangeException if the index is not valid. - */ - void setSubVector(int index, FieldVector<T> v) throws OutOfRangeException; - - /** - * Set all elements to a single value. - * @param value single value to set for all elements - */ - void set(T value); - - /** - * Convert the vector to a T array. - * <p>The array is independent from vector data, it's elements - * are copied.</p> - * @return array containing a copy of vector elements - */ - T[] toArray(); - -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/linear/FieldVectorChangingVisitor.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/linear/FieldVectorChangingVisitor.java b/src/main/java/org/apache/commons/math3/linear/FieldVectorChangingVisitor.java deleted file mode 100644 index b1589b1..0000000 --- a/src/main/java/org/apache/commons/math3/linear/FieldVectorChangingVisitor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.linear; - -import org.apache.commons.math3.FieldElement; - -/** - * This interface defines a visitor for the entries of a vector. Visitors - * implementing this interface may alter the entries of the vector being - * visited. - * - * @param <T> the type of the field elements - * @since 3.3 - */ -public interface FieldVectorChangingVisitor<T extends FieldElement<?>> { - /** - * Start visiting a vector. This method is called once, before any entry - * of the vector is visited. - * - * @param dimension the size of the vector - * @param start the index of the first entry to be visited - * @param end the index of the last entry to be visited (inclusive) - */ - void start(int dimension, int start, int end); - - /** - * Visit one entry of the vector. - * - * @param index the index of the entry being visited - * @param value the value of the entry being visited - * @return the new value of the entry being visited - */ - T visit(int index, T value); - - /** - * End visiting a vector. This method is called once, after all entries of - * the vector have been visited. - * - * @return the value returned after visiting all entries - */ - T end(); -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/linear/FieldVectorPreservingVisitor.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/linear/FieldVectorPreservingVisitor.java b/src/main/java/org/apache/commons/math3/linear/FieldVectorPreservingVisitor.java deleted file mode 100644 index bc09bda..0000000 --- a/src/main/java/org/apache/commons/math3/linear/FieldVectorPreservingVisitor.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.linear; - -import org.apache.commons.math3.FieldElement; - -/** - * This interface defines a visitor for the entries of a vector. Visitors - * implementing this interface do not alter the entries of the vector being - * visited. - * - * @param <T> the type of the field elements - * @since 3.3 - */ -public interface FieldVectorPreservingVisitor<T extends FieldElement<?>> { - /** - * Start visiting a vector. This method is called once, before any entry - * of the vector is visited. - * - * @param dimension the size of the vector - * @param start the index of the first entry to be visited - * @param end the index of the last entry to be visited (inclusive) - */ - void start(int dimension, int start, int end); - - /** - * Visit one entry of the vector. - * - * @param index the index of the entry being visited - * @param value the value of the entry being visited - */ - void visit(int index, T value); - - /** - * End visiting a vector. This method is called once, after all entries of - * the vector have been visited. - * - * @return the value returned after visiting all entries - */ - T end(); -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/linear/HessenbergTransformer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/linear/HessenbergTransformer.java b/src/main/java/org/apache/commons/math3/linear/HessenbergTransformer.java deleted file mode 100644 index 8fefc09..0000000 --- a/src/main/java/org/apache/commons/math3/linear/HessenbergTransformer.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.commons.math3.linear; - -import org.apache.commons.math3.util.FastMath; -import org.apache.commons.math3.util.Precision; - -/** - * Class transforming a general real matrix to Hessenberg form. - * <p>A m × m matrix A can be written as the product of three matrices: A = P - * × H × P<sup>T</sup> with P an orthogonal matrix and H a Hessenberg - * matrix. Both P and H are m × m matrices.</p> - * <p>Transformation to Hessenberg form is often not a goal by itself, but it is an - * intermediate step in more general decomposition algorithms like - * {@link EigenDecomposition eigen decomposition}. This class is therefore - * intended for internal use by the library and is not public. As a consequence - * of this explicitly limited scope, many methods directly returns references to - * internal arrays, not copies.</p> - * <p>This class is based on the method orthes in class EigenvalueDecomposition - * from the <a href="http://math.nist.gov/javanumerics/jama/">JAMA</a> library.</p> - * - * @see <a href="http://mathworld.wolfram.com/HessenbergDecomposition.html">MathWorld</a> - * @see <a href="http://en.wikipedia.org/wiki/Householder_transformation">Householder Transformations</a> - * @since 3.1 - */ -class HessenbergTransformer { - /** Householder vectors. */ - private final double householderVectors[][]; - /** Temporary storage vector. */ - private final double ort[]; - /** Cached value of P. */ - private RealMatrix cachedP; - /** Cached value of Pt. */ - private RealMatrix cachedPt; - /** Cached value of H. */ - private RealMatrix cachedH; - - /** - * Build the transformation to Hessenberg form of a general matrix. - * - * @param matrix matrix to transform - * @throws NonSquareMatrixException if the matrix is not square - */ - public HessenbergTransformer(final RealMatrix matrix) { - if (!matrix.isSquare()) { - throw new NonSquareMatrixException(matrix.getRowDimension(), - matrix.getColumnDimension()); - } - - final int m = matrix.getRowDimension(); - householderVectors = matrix.getData(); - ort = new double[m]; - cachedP = null; - cachedPt = null; - cachedH = null; - - // transform matrix - transform(); - } - - /** - * Returns the matrix P of the transform. - * <p>P is an orthogonal matrix, i.e. its inverse is also its transpose.</p> - * - * @return the P matrix - */ - public RealMatrix getP() { - if (cachedP == null) { - final int n = householderVectors.length; - final int high = n - 1; - final double[][] pa = new double[n][n]; - - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) { - pa[i][j] = (i == j) ? 1 : 0; - } - } - - for (int m = high - 1; m >= 1; m--) { - if (householderVectors[m][m - 1] != 0.0) { - for (int i = m + 1; i <= high; i++) { - ort[i] = householderVectors[i][m - 1]; - } - - for (int j = m; j <= high; j++) { - double g = 0.0; - - for (int i = m; i <= high; i++) { - g += ort[i] * pa[i][j]; - } - - // Double division avoids possible underflow - g = (g / ort[m]) / householderVectors[m][m - 1]; - - for (int i = m; i <= high; i++) { - pa[i][j] += g * ort[i]; - } - } - } - } - - cachedP = MatrixUtils.createRealMatrix(pa); - } - return cachedP; - } - - /** - * Returns the transpose of the matrix P of the transform. - * <p>P is an orthogonal matrix, i.e. its inverse is also its transpose.</p> - * - * @return the transpose of the P matrix - */ - public RealMatrix getPT() { - if (cachedPt == null) { - cachedPt = getP().transpose(); - } - - // return the cached matrix - return cachedPt; - } - - /** - * Returns the Hessenberg matrix H of the transform. - * - * @return the H matrix - */ - public RealMatrix getH() { - if (cachedH == null) { - final int m = householderVectors.length; - final double[][] h = new double[m][m]; - for (int i = 0; i < m; ++i) { - if (i > 0) { - // copy the entry of the lower sub-diagonal - h[i][i - 1] = householderVectors[i][i - 1]; - } - - // copy upper triangular part of the matrix - for (int j = i; j < m; ++j) { - h[i][j] = householderVectors[i][j]; - } - } - cachedH = MatrixUtils.createRealMatrix(h); - } - - // return the cached matrix - return cachedH; - } - - /** - * Get the Householder vectors of the transform. - * <p>Note that since this class is only intended for internal use, it returns - * directly a reference to its internal arrays, not a copy.</p> - * - * @return the main diagonal elements of the B matrix - */ - double[][] getHouseholderVectorsRef() { - return householderVectors; - } - - /** - * Transform original matrix to Hessenberg form. - * <p>Transformation is done using Householder transforms.</p> - */ - private void transform() { - final int n = householderVectors.length; - final int high = n - 1; - - for (int m = 1; m <= high - 1; m++) { - // Scale column. - double scale = 0; - for (int i = m; i <= high; i++) { - scale += FastMath.abs(householderVectors[i][m - 1]); - } - - if (!Precision.equals(scale, 0)) { - // Compute Householder transformation. - double h = 0; - for (int i = high; i >= m; i--) { - ort[i] = householderVectors[i][m - 1] / scale; - h += ort[i] * ort[i]; - } - final double g = (ort[m] > 0) ? -FastMath.sqrt(h) : FastMath.sqrt(h); - - h -= ort[m] * g; - ort[m] -= g; - - // Apply Householder similarity transformation - // H = (I - u*u' / h) * H * (I - u*u' / h) - - for (int j = m; j < n; j++) { - double f = 0; - for (int i = high; i >= m; i--) { - f += ort[i] * householderVectors[i][j]; - } - f /= h; - for (int i = m; i <= high; i++) { - householderVectors[i][j] -= f * ort[i]; - } - } - - for (int i = 0; i <= high; i++) { - double f = 0; - for (int j = high; j >= m; j--) { - f += ort[j] * householderVectors[i][j]; - } - f /= h; - for (int j = m; j <= high; j++) { - householderVectors[i][j] -= f * ort[j]; - } - } - - ort[m] = scale * ort[m]; - householderVectors[m][m - 1] = scale * g; - } - } - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/linear/IllConditionedOperatorException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/linear/IllConditionedOperatorException.java b/src/main/java/org/apache/commons/math3/linear/IllConditionedOperatorException.java deleted file mode 100644 index 3285f68..0000000 --- a/src/main/java/org/apache/commons/math3/linear/IllConditionedOperatorException.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.linear; - -import org.apache.commons.math3.exception.MathIllegalArgumentException; -import org.apache.commons.math3.exception.util.LocalizedFormats; - -/** - * An exception to be thrown when the condition number of a - * {@link RealLinearOperator} is too high. - * - * @since 3.0 - */ -public class IllConditionedOperatorException - extends MathIllegalArgumentException { - /** Serializable version Id. */ - private static final long serialVersionUID = -7883263944530490135L; - - /** - * Creates a new instance of this class. - * - * @param cond An estimate of the condition number of the offending linear - * operator. - */ - public IllConditionedOperatorException(final double cond) { - super(LocalizedFormats.ILL_CONDITIONED_OPERATOR, cond); - } -}