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 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 MatrixE
getEle(int i, int j)
Gets an element of a matrixint
getNCols()
The number of columnsint
getNRows()
The number of rowsint
hashCode()
void
setEle(int row, int col, java.lang.Object val)
Set an element of a matrixvoid
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 arrayjava.lang.String
toString()
-
-
-
Method Detail
-
getEle
public final E getEle(int i, int j)
Description copied from interface:MatrixI
Gets an element of a matrix
-
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 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 EvaluationException
Description copied from interface:MatrixI
Set an element of a matrix- Specified by:
setEle
in interfaceMatrixI
val
- value to set- Throws:
EvaluationException
-
getNCols
public final int getNCols()
Description copied from interface:MatrixI
The number of columns
-
getNRows
public final int getNRows()
Description copied from interface:MatrixI
The number of rows
-
getDimensions
public Dimensions getDimensions()
Description copied from interface:MatrixI
Gets the dimensions of the Vector or Matrix- Specified by:
getDimensions
in interfaceMatrixI
- Returns:
- the dimensions
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.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 interfaceMatrixI
- Returns:
- mat with the elements filled in
- Throws:
EvaluationException
- if mat is not a matrix of the correct size
-
-