Class GenericMatrixField<E>
- java.lang.Object
-
- com.singularsys.extensions.matrix.genericmat.GenericMatrixField<E>
-
- Type Parameters:
E
- Type of an individual element.Subclasses should implement the methods
addEle(Object, Object)
to add elements of the base field.
- All Implemented Interfaces:
FieldI
,IntegerConvertor
,MatrixFieldI
,JepComponent
,java.io.Serializable
- Direct Known Subclasses:
ComplexMatrixField
,FieldMatrixField
,GenericFieldMatrixField
,SimpleMatrixField
public abstract class GenericMatrixField<E> extends java.lang.Object implements MatrixFieldI
A Generic matrix field providing default implementations for all operations. Sub classes just need to provide implementations ofaddEle(Object, Object)
etc.- Author:
- Richard Morris
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected GenericMatrixFactory<E>
mf
-
Constructor Summary
Constructors Constructor Description GenericMatrixField(GenericMatrixFactory<E> mf)
Standard constructor.GenericMatrixField(GenericMatrixFactory<E> mf, boolean skipElements)
Constructor where operations on the base field can be switched off.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected GenericMatrix<E>
add(GenericMatrix<E> lm, GenericMatrix<E> rm)
protected GenericVector<E>
add(GenericVector<E> lv, GenericVector<E> rv)
java.lang.Object
add(java.lang.Object l, java.lang.Object r)
Add two members of the field.protected abstract E
addEle(E l, E r)
Adds two elements of the vector/matrixjava.lang.Boolean
and(java.lang.Object l, java.lang.Object r)
Logical and.protected abstract java.lang.Boolean
andEle(E l, E r)
protected E
calcSize(E ele)
Get the current "size" of an elementprotected boolean
cmpSize(E size, E max)
Compare current "size" to maximum.java.lang.Object
cross(GenericVector<E> lv, GenericVector<E> rv)
java.lang.Object
cross(java.lang.Object l, java.lang.Object r)
The cross product of two vectorsprotected E
det(GenericMatrix<E> l)
java.lang.Object
det(java.lang.Object l)
The determinant of a matrixprotected GenericMatrix<E>
div(GenericMatrix<E> lm, java.lang.Object r)
protected GenericVector<E>
div(GenericVector<E> lv, java.lang.Object r)
java.lang.Object
div(java.lang.Object l, java.lang.Object r)
Divides two members of the field.protected abstract E
divEle(E l, E r)
protected E
dot(GenericVector<E> lv, GenericVector<E> rv)
java.lang.Object
dot(java.lang.Object l, java.lang.Object r)
The dot product of two vectorsprotected boolean
eq(GenericMatrix<E> lm, GenericMatrix<E> rm)
protected boolean
eq(GenericVector<E> lv, GenericVector<E> rv)
java.lang.Boolean
eq(java.lang.Object l, java.lang.Object r)
Equalsprotected abstract java.lang.Boolean
eqEle(E l, E r)
java.lang.Boolean
ge(java.lang.Object l, java.lang.Object r)
Greater or equal toprotected abstract java.lang.Boolean
geEle(E l, E r)
JepComponent
getLightWeightInstance()
Gets a light-weight instance suitable for using in multiple threads.abstract E
getOne()
Get the multiplicative identity for this field.abstract E
getZero()
Get the additive identity for this fieldjava.lang.Boolean
gt(java.lang.Object l, java.lang.Object r)
Greater thanprotected abstract java.lang.Boolean
gtEle(E l, E r)
void
init(Jep jep)
Initialize the component.java.lang.Object
inv(java.lang.Object l)
Returns the inverse of a square matrix.protected GenericMatrix<E>
invMat(GenericMatrix<E> mat)
java.lang.Boolean
le(java.lang.Object l, java.lang.Object r)
Less than or equals toprotected abstract java.lang.Boolean
leEle(E l, E r)
java.lang.Boolean
lt(java.lang.Object l, java.lang.Object r)
Less thanprotected abstract java.lang.Boolean
ltEle(E l, E r)
protected GenericMatrix<E>
minor(GenericMatrix<E> l, int row, int col)
Creates the matrix of minors by excluding one row and one columnjava.lang.Object
mod(java.lang.Object l, java.lang.Object r)
Mod operation not defined for matricesprotected abstract E
modEle(E l, E r)
protected GenericMatrix<E>
mul(GenericMatrix<E> lm, GenericMatrix<E> rm)
protected GenericVector<E>
mul(GenericMatrix<E> lm, GenericVector<E> rv)
protected GenericMatrix<E>
mul(GenericMatrix<E> lm, java.lang.Object r)
protected GenericVector<E>
mul(GenericVector<E> lv, GenericMatrix<E> rm)
protected GenericMatrix<E>
mul(GenericVector<E> lv, GenericVector<E> rv)
protected GenericVector<E>
mul(GenericVector<E> lv, java.lang.Object r)
java.lang.Object
mul(java.lang.Object l, java.lang.Object r)
Multiplies two members of the field.protected abstract E
mulEle(E l, E r)
java.lang.Boolean
ne(java.lang.Object l, java.lang.Object r)
Not Equalsprotected abstract java.lang.Boolean
neEle(E l, E r)
protected GenericMatrix<E>
neg(GenericMatrix<E> lm)
protected GenericVector<E>
neg(GenericVector<E> lv)
java.lang.Object
neg(java.lang.Object l)
The negation -x of an element.protected abstract E
negEle(E l)
java.lang.Boolean
not(java.lang.Object l)
Logical not.protected abstract java.lang.Boolean
notEle(E l)
java.lang.Boolean
or(java.lang.Object l, java.lang.Object r)
Logical or.protected abstract java.lang.Boolean
orEle(E l, E r)
java.lang.Object
pow(java.lang.Object l, java.lang.Object r)
Pow operation not defined for matricesprotected abstract E
powEle(E l, E r)
java.lang.Object
solve(java.lang.Object A, java.lang.Object B)
Solve equation A * X = Bprotected MatrixI
solveMM(GenericMatrix<E> A, GenericMatrix<E> b)
protected VectorI
solveMV(GenericMatrix<E> A, GenericVector<E> b)
protected GenericMatrix<E>
sub(GenericMatrix<E> lm, GenericMatrix<E> rm)
protected GenericVector<E>
sub(GenericVector<E> lv, GenericVector<E> rv)
java.lang.Object
sub(java.lang.Object l, java.lang.Object r)
Subtract two members of the field.protected abstract E
subEle(E l, E r)
protected void
subtractMul(GenericMatrix<E> m, int targetRow, int sourceRow, E mul)
Subtract a multiply of the source row from the targetm(t,j) = m(t,j) - mul * m(s,j)
protected void
swapRows(MatrixI m, int i, int j)
In place swap of two rowsjava.lang.Object
trace(GenericMatrix<E> l)
java.lang.Object
trace(java.lang.Object l)
Returns the trace of a matrix.protected GenericMatrix<E>
trans(GenericMatrix<E> l)
java.lang.Object
trans(java.lang.Object l)
Transpose of a matrix-
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.field.implementations.IntegerConvertor
convertFromInt, convertToInt
-
-
-
-
Field Detail
-
mf
protected GenericMatrixFactory<E> mf
-
-
Constructor Detail
-
GenericMatrixField
public GenericMatrixField(GenericMatrixFactory<E> mf)
Standard constructor.- Parameters:
mf
- The factory used to generate matrices
-
GenericMatrixField
public GenericMatrixField(GenericMatrixFactory<E> mf, boolean skipElements)
Constructor where operations on the base field can be switched off. By default the add operator will add vectors/matrices over a base field and also add elements in that field. So it will calculate (2,3)+(4,5) but also 6+7. Setting skipElements to true means that it will calculate (2,3)+(4,5) but return null if given 6+7. This will need to be specified by some other field. Its not intended to use this constructor but left here for case where it is needed.- Parameters:
mf
- The factory used to generate matricesskipElements
- whether to skip operations on the base elements
-
-
Method Detail
-
addEle
protected abstract E addEle(E l, E r) throws EvaluationException
Adds two elements of the vector/matrix- Parameters:
l
- lhs elementr
- rhs element- Returns:
- their sum
- Throws:
EvaluationException
-
subEle
protected abstract E subEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
negEle
protected abstract E negEle(E l) throws EvaluationException
- Throws:
EvaluationException
-
mulEle
protected abstract E mulEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
modEle
protected abstract E modEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
divEle
protected abstract E divEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
powEle
protected abstract E powEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
eqEle
protected abstract java.lang.Boolean eqEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
neEle
protected abstract java.lang.Boolean neEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
ltEle
protected abstract java.lang.Boolean ltEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
leEle
protected abstract java.lang.Boolean leEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
gtEle
protected abstract java.lang.Boolean gtEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
geEle
protected abstract java.lang.Boolean geEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
andEle
protected abstract java.lang.Boolean andEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
orEle
protected abstract java.lang.Boolean orEle(E l, E r) throws EvaluationException
- Throws:
EvaluationException
-
notEle
protected abstract java.lang.Boolean notEle(E l) throws EvaluationException
- Throws:
EvaluationException
-
add
public java.lang.Object add(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:FieldI
Add two members of the field.- Specified by:
add
in interfaceFieldI
- Parameters:
l
- left hand argumentr
- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException
- on error
-
add
protected GenericVector<E> add(GenericVector<E> lv, GenericVector<E> rv) throws EvaluationException
- Throws:
EvaluationException
-
add
protected GenericMatrix<E> add(GenericMatrix<E> lm, GenericMatrix<E> rm) throws EvaluationException
- Throws:
EvaluationException
-
sub
public java.lang.Object sub(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:FieldI
Subtract two members of the field.- Specified by:
sub
in interfaceFieldI
- Parameters:
l
- left hand argumentr
- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException
- on error
-
sub
protected GenericMatrix<E> sub(GenericMatrix<E> lm, GenericMatrix<E> rm) throws EvaluationException
- Throws:
EvaluationException
-
sub
protected GenericVector<E> sub(GenericVector<E> lv, GenericVector<E> rv) throws EvaluationException
- Throws:
EvaluationException
-
neg
public java.lang.Object neg(java.lang.Object l) throws EvaluationException
Description copied from interface:FieldI
The negation -x of an element.- Specified by:
neg
in interfaceFieldI
- Parameters:
l
- the argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException
- on error
-
neg
protected GenericMatrix<E> neg(GenericMatrix<E> lm) throws EvaluationException
- Throws:
EvaluationException
-
neg
protected GenericVector<E> neg(GenericVector<E> lv) throws EvaluationException
- Throws:
EvaluationException
-
mul
public java.lang.Object mul(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:FieldI
Multiplies two members of the field.- Specified by:
mul
in interfaceFieldI
- Parameters:
l
- left hand argumentr
- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException
- on error
-
mul
protected GenericMatrix<E> mul(GenericMatrix<E> lm, GenericMatrix<E> rm) throws EvaluationException
- Throws:
EvaluationException
-
mul
protected GenericVector<E> mul(GenericMatrix<E> lm, GenericVector<E> rv) throws EvaluationException
- Throws:
EvaluationException
-
mul
protected GenericVector<E> mul(GenericVector<E> lv, GenericMatrix<E> rm) throws EvaluationException
- Throws:
EvaluationException
-
mul
protected GenericMatrix<E> mul(GenericVector<E> lv, GenericVector<E> rv) throws EvaluationException
- Throws:
EvaluationException
-
mul
protected GenericMatrix<E> mul(GenericMatrix<E> lm, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
mul
protected GenericVector<E> mul(GenericVector<E> lv, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
div
public java.lang.Object div(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:FieldI
Divides two members of the field.- Specified by:
div
in interfaceFieldI
- Parameters:
l
- left hand argumentr
- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException
- on error
-
div
protected GenericVector<E> div(GenericVector<E> lv, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
div
protected GenericMatrix<E> div(GenericMatrix<E> lm, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
mod
public java.lang.Object mod(java.lang.Object l, java.lang.Object r) throws EvaluationException
Mod operation not defined for matrices- Specified by:
mod
in interfaceFieldI
- Parameters:
l
- left hand argumentr
- right hand argument- Returns:
- null
- Throws:
EvaluationException
-
pow
public java.lang.Object pow(java.lang.Object l, java.lang.Object r) throws EvaluationException
Pow operation not defined for matrices- Specified by:
pow
in interfaceFieldI
- Parameters:
l
- left hand argumentr
- right hand argument- Returns:
- null
- Throws:
EvaluationException
-
eq
public java.lang.Boolean eq(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:FieldI
Equals- Specified by:
eq
in interfaceFieldI
- Parameters:
l
- left hand argumentr
- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException
- on error
-
ne
public java.lang.Boolean ne(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:FieldI
Not Equals- Specified by:
ne
in interfaceFieldI
- Parameters:
l
- left hand argumentr
- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException
- on error
-
eq
protected boolean eq(GenericMatrix<E> lm, GenericMatrix<E> rm) throws EvaluationException
- Throws:
EvaluationException
-
eq
protected boolean eq(GenericVector<E> lv, GenericVector<E> rv) throws EvaluationException
- Throws:
EvaluationException
-
gt
public java.lang.Boolean gt(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:FieldI
Greater than- Specified by:
gt
in interfaceFieldI
- Parameters:
l
- left hand argumentr
- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException
- on error
-
ge
public java.lang.Boolean ge(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:FieldI
Greater or equal to- Specified by:
ge
in interfaceFieldI
- Parameters:
l
- left hand argumentr
- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException
- on error
-
lt
public java.lang.Boolean lt(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:FieldI
Less than- Specified by:
lt
in interfaceFieldI
- Parameters:
l
- left hand argumentr
- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException
- on error
-
le
public java.lang.Boolean le(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:FieldI
Less than or equals to- Specified by:
le
in interfaceFieldI
- Parameters:
l
- left hand argumentr
- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException
- on error
-
and
public java.lang.Boolean and(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:FieldI
Logical and.- Specified by:
and
in interfaceFieldI
- Parameters:
l
- left hand argument implimentationr
- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException
- on error
-
or
public java.lang.Boolean or(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:FieldI
Logical or.- Specified by:
or
in interfaceFieldI
- Parameters:
l
- left hand argumentr
- right hand argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException
- on error
-
not
public java.lang.Boolean not(java.lang.Object l) throws EvaluationException
Description copied from interface:FieldI
Logical not.- Specified by:
not
in interfaceFieldI
- Parameters:
l
- argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException
- on error
-
det
public java.lang.Object det(java.lang.Object l) throws EvaluationException
Description copied from interface:MatrixFieldI
The determinant of a matrix- Specified by:
det
in interfaceMatrixFieldI
- Returns:
- the determinant of mat if it is a matrix
- Throws:
EvaluationException
-
det
protected E det(GenericMatrix<E> l) throws EvaluationException
- Throws:
EvaluationException
-
trace
public java.lang.Object trace(java.lang.Object l) throws EvaluationException
Description copied from interface:MatrixFieldI
Returns the trace of a matrix.- Specified by:
trace
in interfaceMatrixFieldI
- Parameters:
l
- the matrix- Returns:
- the trace
- Throws:
EvaluationException
-
trace
public java.lang.Object trace(GenericMatrix<E> l) throws EvaluationException
- Throws:
EvaluationException
-
minor
protected GenericMatrix<E> minor(GenericMatrix<E> l, int row, int col) throws EvaluationException
Creates the matrix of minors by excluding one row and one column- Parameters:
l
-row
- the row to excludecol
- the column to exclude- Returns:
- matrix of minors
- Throws:
EvaluationException
-
trans
public java.lang.Object trans(java.lang.Object l) throws EvaluationException
Description copied from interface:MatrixFieldI
Transpose of a matrix- Specified by:
trans
in interfaceMatrixFieldI
- Parameters:
l
- the matrix- Returns:
- a matrix containing the transpose
- Throws:
EvaluationException
-
trans
protected GenericMatrix<E> trans(GenericMatrix<E> l)
-
dot
public java.lang.Object dot(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:MatrixFieldI
The dot product of two vectors- Specified by:
dot
in interfaceMatrixFieldI
- Returns:
- the dot product if both arguments are vectors, null otherwise.
- Throws:
EvaluationException
-
dot
protected E dot(GenericVector<E> lv, GenericVector<E> rv) throws EvaluationException
- Throws:
EvaluationException
-
cross
public java.lang.Object cross(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:MatrixFieldI
The cross product of two vectors- Specified by:
cross
in interfaceMatrixFieldI
- Returns:
- a vector with the cross product
- Throws:
EvaluationException
- if either vectors not of length 3
-
cross
public java.lang.Object cross(GenericVector<E> lv, GenericVector<E> rv) throws EvaluationException
- Throws:
EvaluationException
-
swapRows
protected void swapRows(MatrixI m, int i, int j) throws EvaluationException
In place swap of two rows- Parameters:
m
- matrixi
- index of first rowj
- index of second row- Throws:
EvaluationException
-
subtractMul
protected void subtractMul(GenericMatrix<E> m, int targetRow, int sourceRow, E mul) throws EvaluationException
Subtract a multiply of the source row from the targetm(t,j) = m(t,j) - mul * m(s,j)
- Parameters:
m
-targetRow
-sourceRow
-mul
-- Throws:
EvaluationException
-
getZero
public abstract E getZero()
Description copied from interface:FieldI
Get the additive identity for this field
-
getOne
public abstract E getOne()
Description copied from interface:FieldI
Get the multiplicative identity for this field.
-
invMat
protected GenericMatrix<E> invMat(GenericMatrix<E> mat) throws EvaluationException
- Throws:
EvaluationException
-
calcSize
protected E calcSize(E ele) throws EvaluationException
Get the current "size" of an element- Parameters:
ele
-- Returns:
- Throws:
EvaluationException
-
cmpSize
protected boolean cmpSize(E size, E max) throws EvaluationException
Compare current "size" to maximum.- Parameters:
size
- currentmax
- maximum- Returns:
- true is size > max
- Throws:
EvaluationException
-
inv
public java.lang.Object inv(java.lang.Object l) throws EvaluationException
Description copied from interface:MatrixFieldI
Returns the inverse of a square matrix.- Specified by:
inv
in interfaceMatrixFieldI
- Parameters:
l
- the matrix- Returns:
- the trace
- Throws:
EvaluationException
- if matrix is not square or is singular
-
solveMM
protected MatrixI solveMM(GenericMatrix<E> A, GenericMatrix<E> b) throws EvaluationException
- Throws:
EvaluationException
-
solveMV
protected VectorI solveMV(GenericMatrix<E> A, GenericVector<E> b) throws EvaluationException
- Throws:
EvaluationException
-
solve
public java.lang.Object solve(java.lang.Object A, java.lang.Object B) throws EvaluationException
Description copied from interface:MatrixFieldI
Solve equation A * X = B- Specified by:
solve
in interfaceMatrixFieldI
- Parameters:
A
- a square matrixB
- either a vector or matrix with same number of rows as A- Returns:
- a vector or matrix solving equations
- Throws:
EvaluationException
- if matrix is not square or is singular
-
init
public void init(Jep jep)
Description copied from interface:JepComponent
Initialize 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:
init
in interfaceJepComponent
- Parameters:
jep
- the current Jep instance
-
getLightWeightInstance
public JepComponent getLightWeightInstance()
Description copied from interface:JepComponent
Gets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstance
in interfaceJepComponent
- Returns:
- either an new instance, null or 'this'.
-
-