Class JMatrix

    • Constructor Detail

      • JMatrix

        public JMatrix​(double[][] A)
        Constructor.
        Parameters:
        A - the array of matrix.
      • JMatrix

        public JMatrix​(double[] A)
        Constructor of a column vector/matrix with given array as the internal storage.
        Parameters:
        A - the array of column vector.
      • JMatrix

        public JMatrix​(int rows,
                       int cols)
        Constructor of all-zero matrix.
      • JMatrix

        public JMatrix​(int rows,
                       int cols,
                       double value)
        Constructor. Fill the matrix with given value.
      • JMatrix

        public JMatrix​(int rows,
                       int cols,
                       double[] value)
        Constructor.
        Parameters:
        value - the array of matrix values arranged in column major format
    • Method Detail

      • isSymmetric

        public boolean isSymmetric()
        Description copied from interface: Matrix
        Returns true if the matrix is symmetric.
        Specified by:
        isSymmetric in interface Matrix
      • setSymmetric

        public void setSymmetric​(boolean symmetric)
        Description copied from interface: Matrix
        Sets if the matrix is symmetric. It is the caller's responability to make sure if the matrix symmetric. Also the matrix won't update this property if the matrix values are changed.
        Specified by:
        setSymmetric in interface Matrix
      • data

        public double[] data()
        Description copied from interface: DenseMatrix
        Returns the array of storing the matrix.
        Specified by:
        data in interface DenseMatrix
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • nrows

        public int nrows()
        Description copied from interface: Matrix
        Returns the number of rows.
        Specified by:
        nrows in interface Matrix
      • ncols

        public int ncols()
        Description copied from interface: Matrix
        Returns the number of columns.
        Specified by:
        ncols in interface Matrix
      • ld

        public int ld()
        Description copied from interface: DenseMatrix
        The LDA (and LDB, LDC, etc.) parameter in BLAS is effectively the stride of the matrix as it is laid out in linear memory. It is perfectly valid to have an LDA value which is larger than the leading dimension of the matrix which is being operated on. Typical cases where it is either useful or necessary to use a larger LDA value are when you are operating on a sub matrix from a larger dense matrix, and when hardware or algorithms offer performance advantages when storage is padded to round multiples of some optimal size (cache lines or GPU memory transaction size, or load balance in multiprocessor implementations, for example).
        Specified by:
        ld in interface DenseMatrix
        Returns:
        the leading dimension
      • get

        public double get​(int i,
                          int j)
        Description copied from interface: Matrix
        Returns the entry value at row i and column j.
        Specified by:
        get in interface Matrix
      • set

        public double set​(int i,
                          int j,
                          double x)
        Description copied from interface: DenseMatrix
        Set the entry value at row i and column j.
        Specified by:
        set in interface DenseMatrix
      • add

        public double add​(int i,
                          int j,
                          double x)
        Description copied from interface: DenseMatrix
        A[i][j] += x
        Specified by:
        add in interface DenseMatrix
      • sub

        public double sub​(int i,
                          int j,
                          double x)
        Description copied from interface: DenseMatrix
        A[i][j] -= x
        Specified by:
        sub in interface DenseMatrix
      • mul

        public double mul​(int i,
                          int j,
                          double x)
        Description copied from interface: DenseMatrix
        A[i][j] *= x
        Specified by:
        mul in interface DenseMatrix
      • div

        public double div​(int i,
                          int j,
                          double x)
        Description copied from interface: DenseMatrix
        A[i][j] /= x
        Specified by:
        div in interface DenseMatrix
      • add

        public JMatrix add​(double x)
        Description copied from interface: DenseMatrix
        In place element-wise addition A = A + x
        Specified by:
        add in interface DenseMatrix
      • sub

        public JMatrix sub​(double x)
        Description copied from interface: DenseMatrix
        In place element-wise subtraction A = A - x
        Specified by:
        sub in interface DenseMatrix
      • mul

        public JMatrix mul​(double x)
        Description copied from interface: DenseMatrix
        In place element-wise multiplication A = A * x
        Specified by:
        mul in interface DenseMatrix
      • div

        public JMatrix div​(double x)
        Description copied from interface: DenseMatrix
        In place element-wise division A = A / x
        Specified by:
        div in interface DenseMatrix
      • sum

        public double sum()
        Description copied from interface: DenseMatrix
        Returns the sum of all elements in the matrix.
        Specified by:
        sum in interface DenseMatrix
        Returns:
        the sum of all elements.
      • ax

        public double[] ax​(double[] x,
                           double[] y)
        Description copied from interface: Matrix
        y = A * x
        Specified by:
        ax in interface Matrix
        Returns:
        y
      • axpy

        public double[] axpy​(double[] x,
                             double[] y)
        Description copied from interface: Matrix
        y = A * x + y
        Specified by:
        axpy in interface Matrix
        Returns:
        y
      • axpy

        public double[] axpy​(double[] x,
                             double[] y,
                             double b)
        Description copied from interface: Matrix
        y = A * x + b * y
        Specified by:
        axpy in interface Matrix
        Returns:
        y
      • atx

        public double[] atx​(double[] x,
                            double[] y)
        Description copied from interface: Matrix
        y = A' * x
        Specified by:
        atx in interface Matrix
        Returns:
        y
      • atxpy

        public double[] atxpy​(double[] x,
                              double[] y)
        Description copied from interface: Matrix
        y = A' * x + y
        Specified by:
        atxpy in interface Matrix
        Returns:
        y
      • atxpy

        public double[] atxpy​(double[] x,
                              double[] y,
                              double b)
        Description copied from interface: Matrix
        y = A' * x + b * y
        Specified by:
        atxpy in interface Matrix
        Returns:
        y
      • lu

        public LU lu()
        LU decomposition is computed by a "left-looking", dot-product, Crout/Doolittle algorithm.
        Specified by:
        lu in interface DenseMatrix
      • cholesky

        public Cholesky cholesky()
        Cholesky decomposition for symmetric and positive definite matrix. Only the lower triangular part will be used in the decomposition.
        Specified by:
        cholesky in interface DenseMatrix
        Throws:
        java.lang.IllegalArgumentException - if the matrix is not positive definite.
      • qr

        public QR qr()
        QR Decomposition is computed by Householder reflections.
        Specified by:
        qr in interface DenseMatrix
      • svd

        public SVD svd()
        Description copied from interface: DenseMatrix
        Returns the singular value decomposition. Note that the input matrix will hold U on output.
        Specified by:
        svd in interface DenseMatrix
      • eig

        public double[] eig()
        Description copied from interface: DenseMatrix
        Returns the eigen values in an array of size 2N. The first half and second half of returned array contain the real and imaginary parts, respectively, of the computed eigenvalues.
        Specified by:
        eig in interface DenseMatrix
      • eigen

        public EVD eigen()
        Description copied from interface: DenseMatrix
        Returns the eigen value decomposition. Note that the input matrix will be overwritten on output.
        Specified by:
        eigen in interface DenseMatrix
      • sort

        protected static void sort​(double[] d,
                                   double[] e)
        Sort eigenvalues.
      • sort

        protected static void sort​(double[] d,
                                   double[] e,
                                   DenseMatrix V)
        Sort eigenvalues and eigenvectors.