Class PermutationMatrix

    • Constructor Detail

      • PermutationMatrix

        public PermutationMatrix​(int dim)
        Construct an identity permutation matrix.
        Parameters:
        dim - the matrix dimension
      • PermutationMatrix

        public PermutationMatrix​(int[] data)
        Construct a permutation matrix from an 1D double[].
        Parameters:
        data - the 1D double[] indicating the column position of the 1 in each row
        Throws:
        IllegalArgumentException - if data is not a permutation matrix
      • PermutationMatrix

        public PermutationMatrix​(PermutationMatrix P)
        Copy constructor.
        Parameters:
        P - a permutation matrix
    • Method Detail

      • deepCopy

        public PermutationMatrix deepCopy()
        Description copied from interface: DeepCopyable
        The implementation returns an instance created from this by the copy constructor of the class, or just this if the instance itself is immutable.
        Specified by:
        deepCopy in interface DeepCopyable
        Specified by:
        deepCopy in interface Matrix
        Returns:
        an independent (deep) copy of the instance
      • nRows

        public int nRows()
        Description copied from interface: Table
        Gets the number of rows. Rows count from 1.
        Specified by:
        nRows in interface Table
        Returns:
        the number of rows
      • nCols

        public int nCols()
        Description copied from interface: Table
        Gets the number of columns. Columns count from 1.
        Specified by:
        nCols in interface Table
        Returns:
        the number of columns
      • sign

        public double sign()
        Gets the sign of the permutation matrix which is also the determinant. It is +1 for an even (or 0) number of swaps and -1 for an odd number of swaps.
        Returns:
        the sign
      • swapRow

        public void swapRow​(int i1,
                            int i2)
        Swaps two rows of a permutation matrix.
        Parameters:
        i1 - row 1
        i2 - row 2
      • swapColumn

        public void swapColumn​(int j1,
                               int j2)
        Swaps two columns of a permutation matrix.
        Parameters:
        j1 - column 1
        j2 - column 2
      • moveRow2End

        public void moveRow2End​(int i)
        Swaps a row of the permutation matrix with the last row.
        Parameters:
        i - the row to be swapped with the last row
      • moveColumn2End

        public void moveColumn2End​(int j)
        Swaps a column of a permutation matrix with the last column.
        Parameters:
        j - the column to be swapped with the last column
      • getRow

        public Vector getRow​(int i)
                      throws MatrixAccessException
        Description copied from interface: Matrix
        Get the specified row in the matrix as a vector.
        Specified by:
        getRow in interface Matrix
        Parameters:
        i - the row index
        Returns:
        the vector A[i, ]
        Throws:
        MatrixAccessException - when i < 1, or when i > the number of rows
      • getColumn

        public Vector getColumn​(int j)
                         throws MatrixAccessException
        Description copied from interface: Matrix
        Get the specified column in the matrix as a vector.
        Specified by:
        getColumn in interface Matrix
        Parameters:
        j - the column index
        Returns:
        a vector A[, j]
        Throws:
        MatrixAccessException - when j < 1, or when j > the number of columns
      • rightMultiply

        public Matrix rightMultiply​(Matrix A)
        Right multiplication by P. A * P is the same as swapping columns in A according to P.
        Parameters:
        A - a matrix
        Returns:
        the matrix with the columns swapped
      • multiply

        public Vector multiply​(Vector v)
        Left multiplication by P. P * v is the same as swapping the vector entries/rows according to P.
        Specified by:
        multiply in interface Matrix
        Parameters:
        v - a column vector
        Returns:
        the vector with the rows swapped
      • multiply

        public Matrix multiply​(Matrix A)
        Left multiplication by P. P * A is the same as swapping rows in A according to P.
        Specified by:
        multiply in interface MatrixRing
        Specified by:
        multiply in interface Monoid<Matrix>
        Parameters:
        A - a matrix
        Returns:
        the matrix with the rows swapped
      • scaled

        public Matrix scaled​(double scalar)
        Description copied from interface: Matrix
        Scale this matrix, A, by a constant.
        Specified by:
        scaled in interface Matrix
        Parameters:
        scalar - a double
        Returns:
        cA
      • t

        public PermutationMatrix t()
        The transpose of a permutation matric is the same as its inverse. That is,
        P.multiply(P.t()) == P.t().multiply(P) == P.toDense().ONE()
        Specified by:
        t in interface MatrixRing
        Returns:
        a copy of itself
      • ONE

        public PermutationMatrix ONE()
        Description copied from interface: MatrixRing
        Get an identity matrix that has the same dimension as this matrix. For a non-square matrix, it zeros out the rows (columns) with index > nCols (nRows).
        Specified by:
        ONE in interface MatrixRing
        Specified by:
        ONE in interface Monoid<Matrix>
        Returns:
        an identity matrix
      • ZERO

        public Matrix ZERO()
        Description copied from interface: MatrixRing
        Get a zero matrix that has the same dimension as this matrix.
        Specified by:
        ZERO in interface AbelianGroup<Matrix>
        Specified by:
        ZERO in interface MatrixRing
        Returns:
        the 0 matrix
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object