Class GenericMatrix<E>

java.lang.Object
com.singularsys.extensions.matrix.genericmat.GenericMatrix<E>
Type Parameters:
E - Base type for elements of the matrix.
All Implemented Interfaces:
MatrixI, Serializable
Direct Known Subclasses:
ComplexMatrix, ObjectMatrix, RationalMatrixFactory.RationalMatrix

public class GenericMatrix<E> extends Object implements MatrixI, 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:
  • Field Details

    • data

      protected final Object[][] data
  • Constructor Details

    • GenericMatrix

      protected GenericMatrix(Object[][] data)
      Parameters:
      data -
  • Method Details

    • getEle

      public final E getEle(int i, int j) throws EvaluationException
      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
      Throws:
      EvaluationException - if the index is out of range. Since Jep 4.1 extensions 2.2 this now throws an EvaluationException
    • 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
    • setEle

      public void setEle(int row, int col, Object val) throws EvaluationException
      Description copied from interface: MatrixI
      Set an element of a matrix
      Specified by:
      setEle in interface MatrixI
      Parameters:
      row -
      col -
      val - value to set
      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(Object obj)
      Overrides:
      equals in class Object
    • hashCode

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

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

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