Class AbstractMatrixField
- java.lang.Object
-
- com.singularsys.extensions.matrix.AbstractMatrixField
-
- All Implemented Interfaces:
FieldI
,IntegerConvertor
,MatrixFieldI
,JepComponent
,java.io.Serializable
- Direct Known Subclasses:
DoubleMatrixField
,SequenceMatrixField
public abstract class AbstractMatrixField extends java.lang.Object implements MatrixFieldI
An abstract base class for implementations of MatrixFieldI. In general theGenericMatrixField
should be used. This class is for case when the matrix does not implementGenericMatrix
such as andouble[][]
.- Since:
- Jep 3.5 / Extensions 2.0
- Author:
- Richard Morris
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected MatrixFactoryI
mf
-
Constructor Summary
Constructors Constructor Description AbstractMatrixField(MatrixFactoryI mf)
ConstructionAbstractMatrixField(MatrixFactoryI 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 java.lang.Object
add(java.lang.Object l, java.lang.Object r)
Adds two matrices or vectors.protected abstract java.lang.Object
addEle(java.lang.Object l, java.lang.Object r)
protected abstract MatrixI
addMM(MatrixI l, MatrixI r)
protected abstract VectorI
addVV(VectorI lv, VectorI rv)
Add two vectorsjava.lang.Boolean
and(java.lang.Object l, java.lang.Object r)
Logical and.protected abstract java.lang.Boolean
andEle(java.lang.Object l, java.lang.Object r)
java.lang.Object
cross(java.lang.Object l, java.lang.Object r)
Default inefficient implementation.protected java.lang.Object
crossVV(VectorI lv, VectorI rv)
Default inefficient implementation.java.lang.Object
det(java.lang.Object m)
Determinant of a matrixprotected java.lang.Object
detM(MatrixI mat)
Return the determinant of a matrix.java.lang.Object
div(java.lang.Object l, java.lang.Object r)
Divides two members of the field.protected abstract java.lang.Object
divEle(java.lang.Object l, java.lang.Object r)
protected abstract MatrixI
divMO(MatrixI l, java.lang.Object r)
protected abstract VectorI
divVO(VectorI l, java.lang.Object r)
java.lang.Object
dot(java.lang.Object l, java.lang.Object r)
The dot product of two vectorsprotected java.lang.Object
dotVV(VectorI lv, VectorI rv)
Default inefficient implementation.java.lang.Boolean
eq(java.lang.Object l, java.lang.Object r)
Equalsprotected abstract java.lang.Boolean
eqEle(java.lang.Object l, java.lang.Object r)
protected abstract java.lang.Boolean
eqMM(MatrixI l, MatrixI r)
protected abstract java.lang.Boolean
eqVV(VectorI l, VectorI r)
java.lang.Boolean
ge(java.lang.Object l, java.lang.Object r)
Greater or equal toprotected abstract java.lang.Boolean
geEle(java.lang.Object l, java.lang.Object r)
java.lang.Boolean
gt(java.lang.Object l, java.lang.Object r)
Greater thanprotected abstract java.lang.Boolean
gtEle(java.lang.Object l, java.lang.Object r)
java.lang.Object
inv(java.lang.Object l)
Returns the inverse of a square matrix.protected MatrixI
invM(MatrixI mat)
Finds the inverse of a matrix.java.lang.Boolean
le(java.lang.Object l, java.lang.Object r)
Less than or equals toprotected abstract java.lang.Boolean
leEle(java.lang.Object l, java.lang.Object r)
java.lang.Boolean
lt(java.lang.Object l, java.lang.Object r)
Less thanprotected abstract java.lang.Boolean
ltEle(java.lang.Object l, java.lang.Object r)
protected MatrixI
minor(MatrixI m, int row, int col)
Finds the minor matrix formed by excluding a row and vectorjava.lang.Object
mod(java.lang.Object l, java.lang.Object r)
The modulus of two members of the field.protected abstract java.lang.Object
modEle(java.lang.Object l, java.lang.Object r)
java.lang.Object
mul(java.lang.Object l, java.lang.Object r)
Multiplies two members of the field.protected abstract java.lang.Object
mulEle(java.lang.Object l, java.lang.Object r)
protected abstract MatrixI
mulMM(MatrixI l, MatrixI r)
protected abstract MatrixI
mulMO(MatrixI l, java.lang.Object r)
protected abstract VectorI
mulMV(MatrixI l, VectorI r)
protected void
mulRow(MatrixI m, int row, java.lang.Object mul)
In place multiply all elements of a row by a numberprotected abstract VectorI
mulVM(VectorI l, MatrixI r)
protected abstract VectorI
mulVO(VectorI l, java.lang.Object r)
protected abstract MatrixI
mulVV(VectorI l, VectorI r)
java.lang.Boolean
ne(java.lang.Object l, java.lang.Object r)
Not Equalsprotected abstract java.lang.Boolean
neEle(java.lang.Object l, java.lang.Object r)
java.lang.Object
neg(java.lang.Object l)
The negation -x of an element.protected abstract java.lang.Object
negEle(java.lang.Object l)
protected abstract MatrixI
negM(MatrixI l)
protected abstract VectorI
negV(VectorI lv)
protected abstract java.lang.Boolean
neMM(MatrixI l, MatrixI r)
protected abstract java.lang.Boolean
neVV(VectorI l, VectorI r)
java.lang.Boolean
not(java.lang.Object l)
Logical not.protected abstract java.lang.Boolean
notEle(java.lang.Object l)
java.lang.Boolean
or(java.lang.Object l, java.lang.Object r)
Logical or.protected abstract java.lang.Boolean
orEle(java.lang.Object l, java.lang.Object r)
java.lang.Object
pow(java.lang.Object l, java.lang.Object r)
The power operator.protected abstract java.lang.Object
powEle(java.lang.Object l, java.lang.Object r)
java.lang.Object
solve(java.lang.Object A, java.lang.Object B)
Solve equation A * X = Bprotected MatrixI
solveMM(MatrixI A, MatrixI b)
protected VectorI
solveMV(MatrixI A, VectorI b)
java.lang.Object
sub(java.lang.Object l, java.lang.Object r)
Subtract two members of the field.protected abstract java.lang.Object
subEle(java.lang.Object l, java.lang.Object r)
protected abstract MatrixI
subMM(MatrixI l, MatrixI r)
protected void
subtractMul(MatrixI m, int targetRow, int sourceRow, java.lang.Object mul)
In place Subtract a multiply of the source row from the targetm(t,j) = m(t,j) - mul * m(s,j)
protected abstract VectorI
subVV(VectorI lv, VectorI rv)
protected void
swapRows(MatrixI m, int i, int j)
In place swap of two rowsjava.lang.Object
trace(java.lang.Object l)
Trace of a matrixjava.lang.Object
traceM(MatrixI m)
Default inefficient implementation.java.lang.Object
trans(java.lang.Object l)
Transpose of a matrixprotected java.lang.Object
transM(MatrixI mat)
-
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
-
Methods inherited from interface com.singularsys.jep.JepComponent
getLightWeightInstance, init
-
-
-
-
Field Detail
-
mf
protected MatrixFactoryI mf
-
-
Constructor Detail
-
AbstractMatrixField
public AbstractMatrixField(MatrixFactoryI mf)
Construction- Parameters:
mf
- corresponding matrix factory
-
AbstractMatrixField
public AbstractMatrixField(MatrixFactoryI 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 java.lang.Object addEle(java.lang.Object l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
addVV
protected abstract VectorI addVV(VectorI lv, VectorI rv) throws EvaluationException
Add two vectors- Parameters:
lv
- lhs vectorrv
- rhs vector- Returns:
- the sum of the vectors
- Throws:
EvaluationException
- if the dimension do not match
-
addMM
protected abstract MatrixI addMM(MatrixI l, MatrixI r) throws EvaluationException
- Throws:
EvaluationException
-
add
public java.lang.Object add(java.lang.Object l, java.lang.Object r) throws EvaluationException
Adds two matrices or vectors. Calls eitheraddVV(VectorI, VectorI)
oraddMM(MatrixI, MatrixI)
depending on the arguments.- Specified by:
add
in interfaceFieldI
- Parameters:
l
- left hand argumentr
- right hand argument- Returns:
- the sum of the arguments if l and r are of both of type VectorI or both of type MatrixI or null otherwise.
- Throws:
EvaluationException
- on error
-
subEle
protected abstract java.lang.Object subEle(java.lang.Object l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
subVV
protected abstract VectorI subVV(VectorI lv, VectorI rv) throws EvaluationException
- Throws:
EvaluationException
-
subMM
protected abstract MatrixI subMM(MatrixI l, MatrixI r) 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
-
negEle
protected abstract java.lang.Object negEle(java.lang.Object l) throws EvaluationException
- Throws:
EvaluationException
-
negV
protected abstract VectorI negV(VectorI lv) throws EvaluationException
- Throws:
EvaluationException
-
negM
protected abstract MatrixI negM(MatrixI l) 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
-
mulEle
protected abstract java.lang.Object mulEle(java.lang.Object l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
mulVO
protected abstract VectorI mulVO(VectorI l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
mulMO
protected abstract MatrixI mulMO(MatrixI l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
mulVV
protected abstract MatrixI mulVV(VectorI l, VectorI r) throws EvaluationException
- Throws:
EvaluationException
-
mulVM
protected abstract VectorI mulVM(VectorI l, MatrixI r) throws EvaluationException
- Throws:
EvaluationException
-
mulMV
protected abstract VectorI mulMV(MatrixI l, VectorI r) throws EvaluationException
- Throws:
EvaluationException
-
mulMM
protected abstract MatrixI mulMM(MatrixI l, MatrixI r) 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
-
divEle
protected abstract java.lang.Object divEle(java.lang.Object l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
divVO
protected abstract VectorI divVO(VectorI l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
divMO
protected abstract MatrixI divMO(MatrixI l, 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
-
modEle
protected abstract java.lang.Object modEle(java.lang.Object l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
mod
public java.lang.Object mod(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:FieldI
The modulus of two members of the field.- Specified by:
mod
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
-
powEle
protected abstract java.lang.Object powEle(java.lang.Object l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
pow
public java.lang.Object pow(java.lang.Object l, java.lang.Object r) throws EvaluationException
Description copied from interface:FieldI
The power operator.- Specified by:
pow
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
-
eqEle
protected abstract java.lang.Boolean eqEle(java.lang.Object l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
eqVV
protected abstract java.lang.Boolean eqVV(VectorI l, VectorI r) throws EvaluationException
- Throws:
EvaluationException
-
eqMM
protected abstract java.lang.Boolean eqMM(MatrixI l, MatrixI r) throws EvaluationException
- 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
-
neEle
protected abstract java.lang.Boolean neEle(java.lang.Object l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
neVV
protected abstract java.lang.Boolean neVV(VectorI l, VectorI r) throws EvaluationException
- Throws:
EvaluationException
-
neMM
protected abstract java.lang.Boolean neMM(MatrixI l, MatrixI r) throws EvaluationException
- Throws:
EvaluationException
-
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
-
andEle
protected abstract java.lang.Boolean andEle(java.lang.Object l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
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
-
orEle
protected abstract java.lang.Boolean orEle(java.lang.Object l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
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
-
notEle
protected abstract java.lang.Boolean notEle(java.lang.Object l) throws EvaluationException
- Throws:
EvaluationException
-
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
-
gtEle
protected abstract java.lang.Boolean gtEle(java.lang.Object l, java.lang.Object r) 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
-
geEle
protected abstract java.lang.Boolean geEle(java.lang.Object l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
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
-
ltEle
protected abstract java.lang.Boolean ltEle(java.lang.Object l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
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
-
leEle
protected abstract java.lang.Boolean leEle(java.lang.Object l, java.lang.Object r) throws EvaluationException
- Throws:
EvaluationException
-
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
-
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
-
transM
protected java.lang.Object transM(MatrixI mat) throws EvaluationException
- Throws:
EvaluationException
-
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
-
dotVV
protected java.lang.Object dotVV(VectorI lv, VectorI rv) throws EvaluationException
Default inefficient implementation. Will only be called if vectors are of equal lengths- Parameters:
lv
- lhs vectorrv
- rhs vector- Returns:
- Throws:
EvaluationException
-
cross
public java.lang.Object cross(java.lang.Object l, java.lang.Object r) throws EvaluationException
Default inefficient implementation.- Specified by:
cross
in interfaceMatrixFieldI
- Returns:
- a vector with the cross product
- Throws:
EvaluationException
- if vectors not of length 3
-
crossVV
protected java.lang.Object crossVV(VectorI lv, VectorI rv) throws EvaluationException
Default inefficient implementation.- Throws:
EvaluationException
-
traceM
public java.lang.Object traceM(MatrixI m) throws EvaluationException
Default inefficient implementation.- Throws:
EvaluationException
-
trace
public java.lang.Object trace(java.lang.Object l) throws EvaluationException
Trace of a matrix- Specified by:
trace
in interfaceMatrixFieldI
- Parameters:
l
- the matrix- Returns:
- the trace
- Throws:
EvaluationException
-
det
public java.lang.Object det(java.lang.Object m) throws EvaluationException
Determinant of a matrix- Specified by:
det
in interfaceMatrixFieldI
- Parameters:
m
- the matrix- Returns:
- the determinant
- Throws:
EvaluationException
- if matrix is not square.
-
detM
protected java.lang.Object detM(MatrixI mat) throws EvaluationException
Return the determinant of a matrix. Does not check sizes.- Parameters:
mat
- the matrix- Returns:
- the determinant
- Throws:
EvaluationException
-
minor
protected MatrixI minor(MatrixI m, int row, int col) throws EvaluationException
Finds the minor matrix formed by excluding a row and vector- Parameters:
m
- the matrixrow
- row to removecol
- column to remove- Returns:
- new smaller matrix
- 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
-
mulRow
protected void mulRow(MatrixI m, int row, java.lang.Object mul) throws EvaluationException
In place multiply all elements of a row by a number- Parameters:
m
- the matrixrow
- the row to multiplymul
- value to multiply by- Throws:
EvaluationException
-
subtractMul
protected void subtractMul(MatrixI m, int targetRow, int sourceRow, java.lang.Object mul) throws EvaluationException
In place 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
-
invM
protected MatrixI invM(MatrixI mat) throws EvaluationException
Finds the inverse of a matrix. Default implementation uses Gauss-Jordan with partial pivoting- Parameters:
mat
-- Returns:
- Throws:
EvaluationException
- if matrix is singular
-
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(MatrixI A, MatrixI b) throws EvaluationException
- Throws:
EvaluationException
-
solveMV
protected VectorI solveMV(MatrixI A, VectorI 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
-
-