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,Serializable
- Direct Known Subclasses:
ComplexMatrixFactory,ObjectMatrixFactory,RationalMatrixFactory
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:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Object[]buildDataArray(int len) Build a data array.protected Object[][]buildDataArray(int rows, int cols) Build a data array.protected GenericMatrix<E> A typical implementation will just usereturn (GenericMatrix<E>) m;protected GenericVector<E> A typical implementation will just usereturn (V) v;Return a copy of the matrix.Return a copy of the vector.duplicateGM(GenericMatrix<E> gm) Convert the element o to type E.Returns this.getONE()The element representing 1.identity(int size) Create a square identity matrixidentity(int rows, int cols) Create an identity matrix.voidInitialize the component.Subclasses do not need to implement this method.newMatrixUnchecked(Object[][] data) Subclasses do not need to implement this method.newVector(Collection<?> set) Create a new VectorI from a collection.newVectorUnchecked(Object[] data) protected EThe element representing 0.zeroMat(int size) zeroMat(int rows, int cols) Create an zero matrix.zeroMat(Dimensions dimensions) Create a matrix with zero elementszeroVec(int size) Create a vector with zerosMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.singularsys.extensions.matrix.MatrixFactoryI
zeroVec
-
Field Details
-
ZERO
-
ONE
-
-
Constructor Details
-
GenericMatrixFactory
- Parameters:
f- base field to uses
-
GenericMatrixFactory
-
-
Method Details
-
elementValue
Convert the element o to type E. A typical implementation will just usepublic abstract E elementValue(Object o) { if(o instanceof 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.
-
cast
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
A typical implementation will just usereturn (V) v;- Parameters:
v- the vector to cast- Returns:
- a vector of type V = GenericVector<E>
-
zeroElement
The element representing 0. -
getONE
The element representing 1. -
buildDataArray
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
Build a data array. A typical concrete implementation will just usereturn new E[rows][len].- Parameters:
len- number of elements- Returns:
- the array.
-
newMatrixUnchecked
-
newMatrix
Subclasses do not need to implement this method.- Specified by:
newMatrixin interfaceMatrixFactoryI- Parameters:
data-- Returns:
- a new MatrixI the precise type depends on the implementing class
- Throws:
EvaluationException
-
newVectorUnchecked
-
newVector
Subclasses do not need to implement this method.- Specified by:
newVectorin interfaceMatrixFactoryI- Parameters:
data-- Returns:
- a new VectorI the precise type depends on the implementing class
- Throws:
EvaluationException
-
newVector
Description copied from interface:MatrixFactoryICreate a new VectorI from a collection. Default implementation simple callsnewVector(set.toArray()). Implementing classes can override this method to provide more efficient implementations.- Specified by:
newVectorin interfaceMatrixFactoryI- Parameters:
set- any collection including Lists.- Returns:
- a new vector
- Throws:
EvaluationException
-
identity
Description copied from interface:MatrixFactoryICreate a square identity matrix- Specified by:
identityin interfaceMatrixFactoryI- Parameters:
size- size- Returns:
- a size by size identity matrix
- Throws:
EvaluationException
-
identity
Description copied from interface:MatrixFactoryICreate an identity matrix.- Specified by:
identityin interfaceMatrixFactoryI- Parameters:
rows-cols-- Returns:
- a
rowsbycolsidentity matrix
-
zeroMat
- Throws:
EvaluationException
-
zeroMat
Description copied from interface:MatrixFactoryICreate an zero matrix.- Specified by:
zeroMatin interfaceMatrixFactoryI- Parameters:
rows-cols-- Returns:
- a rows by cols matrix
-
zeroMat
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
Description copied from interface:MatrixFactoryICreate a vector with zeros- Specified by:
zeroVecin interfaceMatrixFactoryI- Parameters:
size-- Returns:
- a vector of zeros
-
init
Description copied from interface:JepComponentInitialize the component. This method 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
Returns this.- Specified by:
getLightWeightInstancein interfaceJepComponent- Returns:
- either a new instance, null or 'this'.
-
duplicateGV
-
duplicateGM
-
duplicate
Description copied from interface:MatrixFactoryIReturn a copy of the matrix. Default implementation is a little inefficient creating a temporary data array.- Specified by:
duplicatein interfaceMatrixFactoryI- Parameters:
mat- matrix to copy- Returns:
- a copy
- Throws:
EvaluationException
-
duplicate
Description copied from interface:MatrixFactoryIReturn a copy of the vector. Default implementation is a little inefficient.- Specified by:
duplicatein interfaceMatrixFactoryI- Parameters:
mat- vector to copy- Returns:
- a copy
- Throws:
EvaluationException
-