java.lang.Object
com.singularsys.extensions.matrix.externalmat.ExternalMatrixField<M,V>
- Type Parameters:
M- type on Matrix usedV- type of Vector usedImplementations should provide implementations of
addMM(M l,M r),addVV(V l,V r)etc. It can be assumed that the arguments of these methods are of correct sizes.
- All Implemented Interfaces:
FieldI,IntegerConvertor,MatrixFieldI,JepComponent,Serializable
public abstract class ExternalMatrixField<M extends MatrixI,V extends VectorI>
extends Object
implements MatrixFieldI
Base class for MatrixField implementations with external matrix libraries.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionExternalMatrixField(ExternalMatrixFactory<M, V> mf, FieldI baseField) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionAdds two matrices or vectors.protected ObjectAdds two elements which are not vectors or matrices.protected abstract MAdd two matrices.protected abstract VAdd two vectors.Logical and.protected Booleanprotected MGiven that the argument is of type MatrixI cast to the type M.protected VGiven that the argument is of type VectorI cast to the type V.Cross product of two vectorsprotected abstract VCross product of two 3D vectorsDeterminant of a matrixprotected abstract ObjectReturn the determinant of a matrix.Divides two members of the field.protected Objectprotected abstract MDivide a matrix by a scalarprotected abstract VDivide a vector by a scalarThe dot product of two vectorsprotected abstract ObjectDot or inner product of two vectorsTry to convert argument to base type of elements of Vector/Matrix.Equalsprotected Booleanprotected abstract BooleanTest if two matrices are equal.protected abstract BooleanTest if two vectors are equal.Greater or equal toprotected BooleanGreater thanprotected BooleanReturns the inverse of a square matrix.protected abstract MFinds the inverse of a matrix.Less than or equals toprotected BooleanLess thanprotected BooleanThe modulus of two members of the field.protected ObjectMultiplies two members of the field.protected Objectprotected abstract MMultiply matrix by matrixprotected abstract MMultiply matrix by scalarprotected abstract VMultiply matrix by column-vectorprotected abstract VMultiply row-vector by matrixprotected abstract VMultiply a vector by a scalarprotected abstract MOuter product of two vectorsNot Equalsprotected BooleanThe negation -x of an element.protected Objectprotected abstract Mprotected abstract Vprotected abstract BooleanTest if two matrices are not equal.protected abstract BooleanTest if two vectors are not-equal.Logical not.protected BooleanLogical or.protected BooleanDefault power method only works for scalars.protected ObjectSolve equation A * X = Bprotected abstract MSolve the matrix equation A * M = Bprotected abstract VSolve the matrix equation A * v = BSubtract two members of the field.protected Objectprotected abstract Mprotected abstract VReturns the trace of a matrix.abstract ObjectTrace of a matrixTranspose of a matrixprotected abstract ObjectTranspose of a matrixTranspose of a vector.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.singularsys.extensions.field.IntegerConvertor
convertFromInt, convertToIntMethods inherited from interface com.singularsys.jep.JepComponent
getLightWeightInstance, init
-
Constructor Details
-
ExternalMatrixField
Constructor.- Parameters:
mf- corresponding MatrixFieldbaseField- field used to compute operations of the base field
-
-
Method Details
-
castM
Given that the argument is of type MatrixI cast to the type M.- Parameters:
m- the argument- Returns:
- argument cast to desired type
-
castV
Given that the argument is of type VectorI cast to the type V.- Parameters:
v- the argument- Returns:
- argument cast to desired type
-
addEle
Adds two elements which are not vectors or matrices. By default the base field is used to implement this method, but it could be overwritten.- Parameters:
l- lhsr- rhs- Returns:
- the sum
- Throws:
EvaluationException- where necessary
-
addVV
Add two vectors. Arguments are guaranteed to be the same size.- Parameters:
lv- lhs vectorrv- rhs vector- Returns:
- the sum of the vectors
- Throws:
EvaluationException
-
addMM
Add two matrices. Arguments are guaranteed to be the same size.- Parameters:
l- lhs matrixr- rhs matrix- Returns:
- the sum of the matrices
- Throws:
EvaluationException
-
add
Adds two matrices or vectors. Calls eitheraddVV(VectorI, VectorI),addMM(MatrixI, MatrixI)oraddEle(Object, Object)depending on the arguments.- Specified by:
addin interfaceFieldI- Parameters:
l- lhsr- rhs- 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- if sizes do not match or attempts to add object of other types
-
elementValue
Try to convert argument to base type of elements of Vector/Matrix. CallsMatrixFactoryI.elementValue(Object)to check base value is correct type.- Parameters:
o- item to convert- Returns:
- o
- Throws:
EvaluationException- if the argument is a vector or matrix
-
subEle
- Throws:
EvaluationException
-
subVV
- Throws:
EvaluationException
-
subMM
- Throws:
EvaluationException
-
sub
Description copied from interface:FieldISubtract two members of the field.- Specified by:
subin 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
- Throws:
EvaluationException
-
negV
- Throws:
EvaluationException
-
negM
- Throws:
EvaluationException
-
neg
Description copied from interface:FieldIThe negation -x of an element.- Specified by:
negin interfaceFieldI- Parameters:
l- the argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
mulEle
- Throws:
EvaluationException
-
mulVO
Multiply a vector by a scalar- Parameters:
l- vectorr- scalar- Returns:
- produce
- Throws:
EvaluationException
-
mulMO
Multiply matrix by scalar- Parameters:
l- matrixr- scalar- Returns:
- product
- Throws:
EvaluationException
-
mulVV
Outer product of two vectors- Parameters:
l- column-vectorr- row-vector- Returns:
- matrix whose size if size(l) x size(r)
- Throws:
EvaluationException
-
mulVM
Multiply row-vector by matrix- Parameters:
l- lhs row vectorr- rhs matrix- Returns:
- a vector
- Throws:
EvaluationException
-
mulMV
Multiply matrix by column-vector- Parameters:
l- lhs matrixr- rhs column-vector- Returns:
- a vector
- Throws:
EvaluationException
-
mulMM
Multiply matrix by matrix- Parameters:
l- lhs matrixr- rhs matrix- Returns:
- a matrix
- Throws:
EvaluationException
-
mul
Description copied from interface:FieldIMultiplies two members of the field.- Specified by:
mulin 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
- Throws:
EvaluationException
-
divVO
Divide a vector by a scalar- Parameters:
l- vectorr- scalar- Returns:
- product
- Throws:
EvaluationException
-
divMO
Divide a matrix by a scalar- Parameters:
l- matrixr- scalar- Returns:
- product
- Throws:
EvaluationException
-
div
Description copied from interface:FieldIDivides two members of the field.- Specified by:
divin 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
- Throws:
EvaluationException
-
mod
Description copied from interface:FieldIThe modulus of two members of the field.- Specified by:
modin 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
- Throws:
EvaluationException
-
pow
Default power method only works for scalars. Can be overwritten for other behaviour.- Specified by:
powin interfaceFieldI- Parameters:
l- lhsr- rhs- Returns:
- l^r
- Throws:
EvaluationException- By default throw if either argument is a matrix or vector
-
eqEle
- Throws:
EvaluationException
-
eqVV
Test if two vectors are equal. It can be assumed the sizes are equal.- Parameters:
l- lhsr- rhs- Returns:
- True or False
- Throws:
EvaluationException
-
eqMM
Test if two matrices are equal. It can be assumed the sizes are equal.- Parameters:
l- lhsr- rhs- Returns:
- True or False
- Throws:
EvaluationException
-
eq
Description copied from interface:FieldIEquals- Specified by:
eqin 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
- Throws:
EvaluationException
-
neVV
Test if two vectors are not-equal. It can be assumed the sizes are equal.- Parameters:
l- lhsr- rhs- Returns:
- True or False
- Throws:
EvaluationException
-
neMM
Test if two matrices are not equal. It can be assumed the sizes are equal.- Parameters:
l- lhsr- rhs- Returns:
- True or False
- Throws:
EvaluationException
-
ne
Description copied from interface:FieldINot Equals- Specified by:
nein 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
- Throws:
EvaluationException
-
and
Description copied from interface:FieldILogical and.- Specified by:
andin 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
-
orEle
- Throws:
EvaluationException
-
or
Description copied from interface:FieldILogical or.- Specified by:
orin 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
- Throws:
EvaluationException
-
not
Description copied from interface:FieldILogical not.- Specified by:
notin interfaceFieldI- Parameters:
l- argument- Returns:
- an object representing the result or null if it can not be evaluated.
- Throws:
EvaluationException- on error
-
gtEle
- Throws:
EvaluationException
-
gt
Description copied from interface:FieldIGreater than- Specified by:
gtin 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
- Throws:
EvaluationException
-
ge
Description copied from interface:FieldIGreater or equal to- Specified by:
gein 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
- Throws:
EvaluationException
-
lt
Description copied from interface:FieldILess than- Specified by:
ltin 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
- Throws:
EvaluationException
-
le
Description copied from interface:FieldILess than or equals to- Specified by:
lein 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
Description copied from interface:MatrixFieldITranspose of a matrix- Specified by:
transin interfaceMatrixFieldI- Parameters:
l- the matrix- Returns:
- a matrix containing the transpose
- Throws:
EvaluationException
-
transV
Transpose of a vector. Default implementation is just to inefficiently return a copy of the vector.- Parameters:
l- a vector- Returns:
- a new vector
- Throws:
EvaluationException- if necessary
-
transM
Transpose of a matrix- Parameters:
mat- a matrix- Returns:
- it transpose
- Throws:
EvaluationException
-
dot
Description copied from interface:MatrixFieldIThe dot product of two vectors- Specified by:
dotin interfaceMatrixFieldI- Parameters:
l-r-- Returns:
- the dot product if both arguments are vectors, null otherwise.
- Throws:
EvaluationException
-
dotVV
Dot or inner product of two vectors- Parameters:
lv- lhs vectorrv- rhs vector- Returns:
- value of scalar product
- Throws:
EvaluationException
-
cross
Cross product of two vectors- Specified by:
crossin interfaceMatrixFieldI- Parameters:
l- lhs vectorr- rhs vector- Returns:
- value of scalar product
- Throws:
EvaluationException- if either argument is not a 3D vector
-
crossVV
Cross product of two 3D vectors- Parameters:
lv- left-hand side vectorrv- right-hand side vector- Returns:
- their cross product
- Throws:
EvaluationException- if necessary
-
traceM
Trace of a matrix- Parameters:
m- the matrix- Returns:
- the trace
- Throws:
EvaluationException
-
trace
Description copied from interface:MatrixFieldIReturns the trace of a matrix.- Specified by:
tracein interfaceMatrixFieldI- Parameters:
l- the matrix- Returns:
- the trace
- Throws:
EvaluationException
-
det
Determinant of a matrix- Specified by:
detin interfaceMatrixFieldI- Parameters:
m- the matrix- Returns:
- the determinant
- Throws:
EvaluationException- if matrix is not square.
-
detM
Return the determinant of a matrix.- Parameters:
mat- the matrix- Returns:
- the determinant
- Throws:
EvaluationException- on error
-
invM
Finds the inverse of a matrix. Default implementation uses Gauss-Jordan with partial pivoting- Parameters:
mat- the matrix- Returns:
- its inverse
- Throws:
EvaluationException- if matrix is singular
-
inv
Description copied from interface:MatrixFieldIReturns the inverse of a square matrix.- Specified by:
invin interfaceMatrixFieldI- Parameters:
l- the matrix- Returns:
- the trace
- Throws:
EvaluationException- if matrix is not square or is singular
-
solveMM
Solve the matrix equation A * M = B- Parameters:
A- matrixB- matrix- Returns:
- matrix M
- Throws:
EvaluationException
-
solveMV
Solve the matrix equation A * v = B- Parameters:
A- matrixb- vector- Returns:
- vector v
- Throws:
EvaluationException
-
solve
Description copied from interface:MatrixFieldISolve equation A * X = B- Specified by:
solvein 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
-