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,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 thesetEle(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 protectedGenericMatrix(java.lang.Object[][] data)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)DimensionsgetDimensions()Gets the dimensions of the Vector or MatrixEgetEle(int i, int j)Gets an element of a matrixintgetNCols()The number of columnsintgetNRows()The number of rowsinthashCode()voidsetEle(int row, int col, java.lang.Object val)Set an element of a matrixvoidsetEleG(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 arrayjava.lang.StringtoString()
-
-
-
Method Detail
-
getEle
public final E getEle(int i, int j)
Description copied from interface:MatrixIGets an element of a matrix
-
setEleG
public final void setEleG(int i, int j, E val) throws EvaluationExceptionSet an element of a known type E. Subclasses should call this method from theirsetEle(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, java.lang.Object val) throws EvaluationExceptionDescription copied from interface:MatrixISet an element of a matrix- Specified by:
setElein interfaceMatrixIval- value to set- Throws:
EvaluationException
-
getNCols
public final int getNCols()
Description copied from interface:MatrixIThe number of columns
-
getNRows
public final int getNRows()
Description copied from interface:MatrixIThe number of rows
-
getDimensions
public Dimensions getDimensions()
Description copied from interface:MatrixIGets the dimensions of the Vector or Matrix- Specified by:
getDimensionsin interfaceMatrixI- Returns:
- the dimensions
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toArray
public java.lang.Object[][] toArray(java.lang.Object[][] mat) throws EvaluationExceptionDescription copied from interface:MatrixICopies the data to an array- Specified by:
toArrayin interfaceMatrixI- Returns:
- mat with the elements filled in
- Throws:
EvaluationException- if mat is not a matrix of the correct size
-
-