Class GenericMatrixFactory<E>
- java.lang.Object
-
- com.singularsys.extensions.matrix.genericmat.GenericMatrixFactory<E>
-
- Type Parameters:
E- Base type of elements for the matrices or vectors
- All Implemented Interfaces:
MatrixFactoryI,JepComponent,java.io.Serializable
- Direct Known Subclasses:
ComplexMatrixFactory,ObjectMatrixFactory,RationalMatrixFactory
public class GenericMatrixFactory<E> extends java.lang.Object implements MatrixFactoryI
An abstract matrix factory for vectors and matrices over a specific type such as Object or Complex.A typical implementation for Complex numbers would be
public class ComplexMatrixFactory extends GenericMatrixFactory<ComplexMatrix,ComplexVector,Complex> { private static final long serialVersionUID = 340L; public ComplexMatrixFactory() { super(new Complex(0.0,0.0),new Complex(1.0,0.0)); } @Override public Complex[][] buildDataArray(int rows, int cols) { return new Complex[rows][cols]; } @Override public Complex[] buildDataArray(int len) { return new Complex[len]; } @Override public Complex elementValue(Object o) { if(o instanceof Complex) return (Complex) o; return null; } @Override public ComplexMatrix newMatrixG(Complex[][] data) { return new ComplexMatrix(data); } @Override public ComplexVector newVectorG(Complex[] data) { return new ComplexVector(data); } @Override public ComplexMatrix cast(MatrixI m) { return (ComplexMatrix) m; } @Override public ComplexVector cast(VectorI v) { return (ComplexVector) v; } public 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 should be either Complex or Matrix, it was "+val.toString()); } } public class ComplexVector extends GenericVector<Complex> { public ComplexVector(Complex[] data) { super(data); } @Override public void setEle(int index, Object val) throws EvaluationException { if(val instanceof Complex) this.setEleG(index, (Complex) val); else throw new EvaluationException("Complex vector setEle: element should be either Complex or Matrix, it was "+val.toString()); } } }- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description GenericMatrixFactory(GenericField<E> f)GenericMatrixFactory(E zero, E one)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object[]buildDataArray(int len)Build a data array.protected java.lang.Object[][]buildDataArray(int rows, int cols)Build a data array.protected GenericMatrix<E>cast(MatrixI m)A typical implementation will just usereturn (GenericMatrix<E>) m;protected GenericVector<E>cast(VectorI v)A typical implementation will just usereturn (V) v;EelementValue(java.lang.Object o)Convert the element o to type E.JepComponentgetLightWeightInstance()Returns this.EgetONE()The element representing 1.GenericMatrix<E>identity(int size)Create an square identity matrixGenericMatrix<E>identity(int rows, int cols)Create an identity matrix.voidinit(Jep jep)Initialize the component.GenericMatrix<E>newMatrix(java.lang.Object[][] data)Subclasses do not need to implement this method.GenericMatrix<E>newMatrixUnchecked(java.lang.Object[][] data)GenericVector<E>newVector(java.lang.Object... data)Subclasses do not need to implement this method.GenericVector<E>newVectorUnchecked(java.lang.Object[] data)protected EzeroEement()The element representing 0.GenericMatrix<E>zeroMat(int size)GenericMatrix<E>zeroMat(int rows, int cols)Create an zero matrix.GenericMatrix<E>zeroMat(Dimensions dimensions)Create a matrix with zero elementsGenericVector<E>zeroVec(int size)Create a vector with zeros-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.singularsys.extensions.matrix.MatrixFactoryI
zeroVec
-
-
-
-
Constructor Detail
-
GenericMatrixFactory
public GenericMatrixFactory(GenericField<E> f)
- Parameters:
f- base field to uses
-
-
Method Detail
-
elementValue
public E elementValue(java.lang.Object o) throws EvaluationException
Convert the element o to type E. A typical implementation will just usepublic abstract E elementValue(Object o) { if(o instance of E) return (E) o; return null; }- Specified by:
elementValuein interfaceMatrixFactoryI- Parameters:
o- value to convert- Returns:
- the value cast to type E or null if the type cannot be converted.
- Throws:
EvaluationException
-
cast
protected GenericMatrix<E> cast(MatrixI m)
A typical implementation will just usereturn (GenericMatrix<E>) m;- Parameters:
m- the matrix to cast- Returns:
- a matrix of type GenericMatrix<E> = GenericMatrix<E>
-
cast
protected GenericVector<E> cast(VectorI v)
A typical implementation will just usereturn (V) v;- Parameters:
v- the vector to cast- Returns:
- a vector of type V = GenericVector<E>
-
zeroEement
protected E zeroEement()
The element representing 0.
-
getONE
public E getONE()
The element representing 1.
-
buildDataArray
protected java.lang.Object[][] buildDataArray(int rows, int cols)Build a data array. A typical concrete implementation will just usereturn new E[rows][cols].- Parameters:
rows- number of rowscols- number of cols- Returns:
- the array.
-
buildDataArray
protected java.lang.Object[] buildDataArray(int len)
Build a data array. A typical concrete implementation will just usereturn new E[rows][len].- Parameters:
len- number of elements- Returns:
- the array.
-
newMatrixUnchecked
public GenericMatrix<E> newMatrixUnchecked(java.lang.Object[][] data)
-
newMatrix
public GenericMatrix<E> newMatrix(java.lang.Object[][] data) throws EvaluationException
Subclasses do not need to implement this method.- Specified by:
newMatrixin interfaceMatrixFactoryI- Returns:
- a new MatrixI the precise type depends on the implementing class
- Throws:
EvaluationException
-
newVectorUnchecked
public GenericVector<E> newVectorUnchecked(java.lang.Object[] data)
-
newVector
public GenericVector<E> newVector(java.lang.Object... data) throws EvaluationException
Subclasses do not need to implement this method.- Specified by:
newVectorin interfaceMatrixFactoryI- Returns:
- a new VectorI the precise type depends on the implementing class
- Throws:
EvaluationException
-
identity
public GenericMatrix<E> identity(int size) throws EvaluationException
Description copied from interface:MatrixFactoryICreate an square identity matrix- Specified by:
identityin interfaceMatrixFactoryI- Parameters:
size- size- Returns:
- a size by size identity matrix
- Throws:
EvaluationException
-
identity
public GenericMatrix<E> identity(int rows, int cols) throws EvaluationException
Description copied from interface:MatrixFactoryICreate an identity matrix.- Specified by:
identityin interfaceMatrixFactoryI- Returns:
- a rows by cols identity matrix
- Throws:
EvaluationException
-
zeroMat
public GenericMatrix<E> zeroMat(int size) throws EvaluationException
- Throws:
EvaluationException
-
zeroMat
public GenericMatrix<E> zeroMat(int rows, int cols) throws EvaluationException
Description copied from interface:MatrixFactoryICreate an zero matrix.- Specified by:
zeroMatin interfaceMatrixFactoryI- Returns:
- a rows by cols matrix
- Throws:
EvaluationException
-
zeroMat
public GenericMatrix<E> zeroMat(Dimensions dimensions) throws EvaluationException
Description copied from interface:MatrixFactoryICreate a matrix with zero elements- Specified by:
zeroMatin interfaceMatrixFactoryI- Parameters:
dimensions- dimensions specifying the size of a matrix.- Returns:
- a matrix filled with zeros
- Throws:
EvaluationException- if the dimensions are not of order 2
-
zeroVec
public GenericVector<E> zeroVec(int size) throws EvaluationException
Description copied from interface:MatrixFactoryICreate a vector with zeros- Specified by:
zeroVecin interfaceMatrixFactoryI- Returns:
- a vector of zeros
- Throws:
EvaluationException
-
init
public void init(Jep jep)
Description copied from interface:JepComponentInitialize the component. This methods is called whenever a component is added to Jep. Hence it allows components to keep track of the other components they may rely on.- Specified by:
initin interfaceJepComponent- Parameters:
jep- the current Jep instance
-
getLightWeightInstance
public JepComponent getLightWeightInstance()
Returns this.- Specified by:
getLightWeightInstancein interfaceJepComponent- Returns:
- either an new instance, null or 'this'.
-
-