Class GenericMatrix<E>

  • Type Parameters:
    E - Base type for elements of the matrix.
    All Implemented Interfaces:
    MatrixI, java.io.Serializable
    Direct Known Subclasses:
    ComplexMatrix, ObjectMatrix, RationalMatrixFactory.RationalMatrix

    public class GenericMatrix<E>
    extends java.lang.Object
    implements MatrixI, java.io.Serializable
    Generic implementation of a matrix when all elements are of the base type E. Subclasses just need to provide a constructor and the setEle(int, int, Object) method. Both of these take a standard form.
            class ComplexMatrix extends GenericMatrix<Complex> {
    
                    protected ComplexMatrix(Complex[][] data) {
                            super(data);
                    }
    
                    @Override
                    public void setEle(int row, int col, Object val) throws EvaluationException {
            if(val instanceof Complex)
                this.setEleG(row, col, (Complex) val);
                    else
                throw new EvaluationException("Complex matrix setEle: element at "+row+", "+col+" should be Complex. It was "+val.toString());
                    }
                    
            }
     

    Since Jep 4.0/Extensions 2.1 fix bug with equals(Object) which did not uses Arrays.deepEquals.

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.Object[][] data  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected GenericMatrix​(java.lang.Object[][] data)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      Dimensions getDimensions()
      Gets the dimensions of the Vector or Matrix
      E getEle​(int i, int j)
      Gets an element of a matrix
      int getNCols()
      The number of columns
      int getNRows()
      The number of rows
      int hashCode()  
      void setEle​(int row, int col, java.lang.Object val)
      Set an element of a matrix
      void setEleG​(int i, int j, E val)
      Set an element of a known type E.
      java.lang.Object[][] toArray​(java.lang.Object[][] mat)
      Copies the data to an array
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • data

        protected final java.lang.Object[][] data
    • Constructor Detail

      • GenericMatrix

        protected GenericMatrix​(java.lang.Object[][] data)
        Parameters:
        data -
    • Method Detail

      • getEle

        public final E getEle​(int i,
                              int j)
        Description copied from interface: MatrixI
        Gets an element of a matrix
        Specified by:
        getEle in interface MatrixI
        Parameters:
        i - the row
        j - the column
        Returns:
        the element
      • setEleG

        public final void setEleG​(int i,
                                  int j,
                                  E val)
                           throws EvaluationException
        Set an element of a known type E. Subclasses should call this method from their setEle(int, int, Object) method.
        Parameters:
        i - index for the row (starting at 0)
        j - index for the column (starting at 0)
        val - matrix element
        Throws:
        EvaluationException
      • getNCols

        public final int getNCols()
        Description copied from interface: MatrixI
        The number of columns
        Specified by:
        getNCols in interface MatrixI
        Returns:
        number of columns
      • getNRows

        public final int getNRows()
        Description copied from interface: MatrixI
        The number of rows
        Specified by:
        getNRows in interface MatrixI
        Returns:
        number of rows
      • getDimensions

        public Dimensions getDimensions()
        Description copied from interface: MatrixI
        Gets the dimensions of the Vector or Matrix
        Specified by:
        getDimensions in interface MatrixI
        Returns:
        the dimensions
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

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

        public java.lang.Object[][] toArray​(java.lang.Object[][] mat)
                                     throws EvaluationException
        Description copied from interface: MatrixI
        Copies the data to an array
        Specified by:
        toArray in interface MatrixI
        Returns:
        mat with the elements filled in
        Throws:
        EvaluationException - if mat is not a matrix of the correct size