Documentation of 'org.spaceroots.mantissa.linalg.Matrix' Java class
Matrix
org.spaceroots.mantissa.linalg

Class Matrix

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    GeneralMatrix, SquareMatrix


    public abstract class Matrix
    extends java.lang.Object
    implements java.io.Serializable
    This class factor all services common to matrices.

    This class is the base class of all matrix implementations, it is also the base class of the SquareMatrix class which adds methods specific to square matrices.

    This class both handles the storage of matrix elements and implements the classical operations on matrices (addition, substraction, multiplication, transposition). It relies on two protected methods (getRangeForRow(int) and getRangeForColumn(int)) to get tight loop bounds for matrices with known structures full of zeros. These methods should be implemented by derived classes to provide information about their specific shape to the general algorithms implemented by this abstract class.

    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      Matrix(int rows, int columns, double[] data)
      Simple constructor.
    • Constructor Detail

      • Matrix

        public Matrix(int rows,
                      int columns,
                      double[] data)
        Simple constructor. Build a matrix with specified elements.
        Parameters:
        rows - number of rows of the matrix
        columns - number of columns of the matrix
        data - table of the matrix elements (stored row after row)
    • Method Detail

      • duplicate

        public abstract Matrix duplicate()
        Polymorphic copy operator. This method build a new object of the same type of the instance. It is somewhat similar to the Object.clone() method, except that it has public access, it doesn't throw any specific exception and it returns a Matrix.
        See Also:
        Object.clone()
      • getRows

        public int getRows()
        Get the number of rows of the matrix.
        Returns:
        number of rows
        See Also:
        getColumns()
      • getColumns

        public int getColumns()
        Get the number of columns of the matrix.
        Returns:
        number of columns
        See Also:
        getRows()
      • getElement

        public double getElement(int i,
                                 int j)
        Get a matrix element.
        Parameters:
        i - row index, from 0 to rows - 1
        j - column index, from 0 to cols - 1
        Returns:
        value of the element
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if the indices are wrong
        See Also:
        setElement(int, int, double)
      • setElement

        public void setElement(int i,
                               int j,
                               double value)
        Set a matrix element.
        Parameters:
        i - row index, from 0 to rows - 1
        j - column index, from 0 to cols - 1
        value - value of the element
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if the indices are wrong
        See Also:
        getElement(int, int)
      • add

        public Matrix add(Matrix m)
        Add a matrix to the instance. This method adds a matrix to the instance. It returns a new matrix and does not modify the instance.
        Parameters:
        m - matrix to add
        Returns:
        a new matrix containing the result
        Throws:
        java.lang.IllegalArgumentException - if there is a dimension mismatch
      • sub

        public Matrix sub(Matrix m)
        Substract a matrix from the instance. This method substracts a matrix from the instance. It returns a new matrix and does not modify the instance.
        Parameters:
        m - matrix to substract
        Returns:
        a new matrix containing the result
        Throws:
        java.lang.IllegalArgumentException - if there is a dimension mismatch
      • mul

        public Matrix mul(Matrix m)
        Multiply the instance by a matrix. This method multiplies the instance by a matrix. It returns a new matrix and does not modify the instance.
        Parameters:
        m - matrix by which to multiply
        Returns:
        a new matrix containing the result
        Throws:
        java.lang.IllegalArgumentException - if there is a dimension mismatch
      • mul

        public Matrix mul(double a)
        Multiply the instance by a scalar. This method multiplies the instance by a scalar. It returns a new matrix and does not modify the instance.
        Parameters:
        a - scalar by which to multiply
        Returns:
        a new matrix containing the result
        See Also:
        selfMul(double)
      • selfMul

        public void selfMul(double a)
        Multiply the instance by a scalar. This method multiplies the instance by a scalar. It does modify the instance.
        Parameters:
        a - scalar by which to multiply
        See Also:
        mul(double)
      • getTranspose

        public Matrix getTranspose()
        Compute the transpose of the instance. This method transposes the instance. It returns a new matrix and does not modify the instance.
        Returns:
        a new matrix containing the result
      • toString

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

DataMelt 3.0 © DataMelt by jWork.ORG

Ads help maintain this website.