E
- Base type of elements for the matrices or vectorspublic class GenericMatrixFactory<E> extends java.lang.Object implements MatrixFactoryI
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()); } } }
Constructor and Description |
---|
GenericMatrixFactory(E zero,
E one) |
GenericMatrixFactory(GenericField<E> f) |
Modifier and Type | Method and 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 use
return (GenericMatrix<E>) m; |
protected GenericVector<E> |
cast(VectorI v)
A typical implementation will just use
return (V) v; |
E |
elementValue(java.lang.Object o)
Convert the element o to type E.
|
JepComponent |
getLightWeightInstance()
Gets a light-weight instance suitable for using in multiple threads.
|
E |
getONE()
The element representing 1.
|
GenericMatrix<E> |
identity(int size)
Create an square identity matrix
|
GenericMatrix<E> |
identity(int rows,
int cols)
Create an identity matrix.
|
void |
init(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 E |
zeroEement()
The element representing 0.
|
GenericMatrix<E> |
zeroMat(Dimensions dimensions)
Create a matrix with zero elements
|
GenericMatrix<E> |
zeroMat(int size) |
GenericMatrix<E> |
zeroMat(int rows,
int cols)
Create an zero matrix.
|
GenericVector<E> |
zeroVec(int size)
Create a vector with zeros
|
public GenericMatrixFactory(GenericField<E> f)
f
- base field to usespublic E elementValue(java.lang.Object o) throws EvaluationException
public abstract E elementValue(Object o) { if(o instance of E) return (E) o; return null; }
elementValue
in interface MatrixFactoryI
o
- value to convertEvaluationException
protected GenericMatrix<E> cast(MatrixI m)
return (GenericMatrix<E>) m;
m
- the matrix to castprotected GenericVector<E> cast(VectorI v)
return (V) v;
v
- the vector to castprotected E zeroEement()
public E getONE()
protected java.lang.Object[][] buildDataArray(int rows, int cols)
return new E[rows][cols]
.rows
- number of rowscols
- number of colsprotected java.lang.Object[] buildDataArray(int len)
return new E[rows][len]
.len
- number of elementspublic GenericMatrix<E> newMatrixUnchecked(java.lang.Object[][] data)
public GenericMatrix<E> newMatrix(java.lang.Object[][] data) throws EvaluationException
newMatrix
in interface MatrixFactoryI
EvaluationException
public GenericVector<E> newVectorUnchecked(java.lang.Object[] data)
public GenericVector<E> newVector(java.lang.Object... data) throws EvaluationException
newVector
in interface MatrixFactoryI
EvaluationException
public GenericMatrix<E> identity(int size) throws EvaluationException
MatrixFactoryI
identity
in interface MatrixFactoryI
size
- sizeEvaluationException
public GenericMatrix<E> identity(int rows, int cols) throws EvaluationException
MatrixFactoryI
identity
in interface MatrixFactoryI
EvaluationException
public GenericMatrix<E> zeroMat(int size) throws EvaluationException
EvaluationException
public GenericMatrix<E> zeroMat(int rows, int cols) throws EvaluationException
MatrixFactoryI
zeroMat
in interface MatrixFactoryI
EvaluationException
public GenericMatrix<E> zeroMat(Dimensions dimensions) throws EvaluationException
MatrixFactoryI
zeroMat
in interface MatrixFactoryI
dimensions
- dimensions specifying the size of a matrix.EvaluationException
- if the dimensions are not of order 2public GenericVector<E> zeroVec(int size) throws EvaluationException
MatrixFactoryI
zeroVec
in interface MatrixFactoryI
EvaluationException
public void init(Jep jep)
JepComponent
init
in interface JepComponent
jep
- the current Jep instancepublic JepComponent getLightWeightInstance()
JepComponent
getLightWeightInstance
in interface JepComponent
Copyright © 2018 Singular Systems http://www.singularsys.com/jep