Package org.ojalgo.matrix
Class BasicMatrix<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- java.lang.Object
-
- org.ojalgo.matrix.BasicMatrix<N,M>
-
- All Implemented Interfaces:
Group
,Group.Additive<M>
,NormedVectorSpace<M,N>
,Operation
,Operation.Addition<M>
,Operation.Multiplication<M>
,Operation.Subtraction<M>
,ScalarOperation
,ScalarOperation.Addition<M,N>
,ScalarOperation.Division<M,N>
,ScalarOperation.Multiplication<M,N>
,ScalarOperation.Subtraction<M,N>
,VectorSpace<M,N>
,Matrix2D<N,M>
,Provider2D
,Provider2D.Condition
,Provider2D.Determinant<N>
,Provider2D.Eigenpairs
,Provider2D.Hermitian
,Provider2D.Inverse<M>
,Provider2D.Rank
,Provider2D.Solution<M>
,Provider2D.Symmetric
,Provider2D.Trace<N>
,Access1D<N>
,Access1D.Aggregatable<N>
,Access2D<N>
,Access2D.Aggregatable<N>
,Access2D.Collectable<N,TransformableRegion<N>>
,Operate2D<N,M>
,Structure1D
,Structure2D
,Structure2D.Logical<Access2D<N>,M>
,Structure2D.ReducibleTo1D<M>
,NumberContext.Enforceable<M>
- Direct Known Subclasses:
MatrixC128
,MatrixH256
,MatrixQ128
,MatrixR032
,MatrixR064
,MatrixR128
public abstract class BasicMatrix<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>> extends java.lang.Object implements Matrix2D<N,M>, Structure2D.ReducibleTo1D<M>, NumberContext.Enforceable<M>, Access2D.Collectable<N,TransformableRegion<N>>, Provider2D.Inverse<M>, Provider2D.Condition, Provider2D.Rank, Provider2D.Symmetric, Provider2D.Hermitian, Provider2D.Trace<N>, Provider2D.Determinant<N>, Provider2D.Solution<M>, Provider2D.Eigenpairs, Structure2D.Logical<Access2D<N>,M>, Operate2D<N,M>
A base class for, easy to use, immutable (thread safe) matrices with a rich feature set. This class handles a lot of complexity, and makes choices, for you. If you want more control, and to be exposed to all the implementation details, then look at the various interfaces/classes in the org.ojalgo.matrix.store and org.ojalgo.matrix.decomposition packages.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.ojalgo.structure.Access2D
Access2D.Aggregatable<N extends java.lang.Comparable<N>>, Access2D.Collectable<N extends java.lang.Comparable<N>,R extends Mutate2D>, Access2D.ColumnView<N extends java.lang.Comparable<N>>, Access2D.ElementView<N extends java.lang.Comparable<N>>, Access2D.RowView<N extends java.lang.Comparable<N>>, Access2D.SelectionView<N extends java.lang.Comparable<N>>, Access2D.Sliceable<N extends java.lang.Comparable<N>>, Access2D.Visitable<N extends java.lang.Comparable<N>>
-
Nested classes/interfaces inherited from interface org.ojalgo.algebra.Group
Group.Additive<T>, Group.Multiplicative<T>
-
Nested classes/interfaces inherited from interface org.ojalgo.algebra.Operation
Operation.Addition<T>, Operation.Division<T>, Operation.Multiplication<T>, Operation.Subtraction<T>
-
Nested classes/interfaces inherited from interface org.ojalgo.matrix.Provider2D
Provider2D.Condition, Provider2D.Determinant<N extends java.lang.Comparable<N>>, Provider2D.Eigenpairs, Provider2D.Hermitian, Provider2D.Inverse<M>, Provider2D.Rank, Provider2D.Solution<M>, Provider2D.Symmetric, Provider2D.Trace<N extends java.lang.Comparable<N>>
-
Nested classes/interfaces inherited from interface org.ojalgo.algebra.ScalarOperation
ScalarOperation.Addition<T,N extends java.lang.Comparable<N>>, ScalarOperation.Division<T,N extends java.lang.Comparable<N>>, ScalarOperation.Multiplication<T,N extends java.lang.Comparable<N>>, ScalarOperation.Subtraction<T,N extends java.lang.Comparable<N>>
-
Nested classes/interfaces inherited from interface org.ojalgo.structure.Structure1D
Structure1D.BasicMapper<T>, Structure1D.IndexMapper<T>, Structure1D.IntIndex, Structure1D.Logical<S extends Structure1D,B extends Structure1D.Logical<S,B>>, Structure1D.LongIndex, Structure1D.LoopCallback
-
Nested classes/interfaces inherited from interface org.ojalgo.structure.Structure2D
Structure2D.IntRowColumn, Structure2D.Logical<S extends Structure2D,B extends Structure2D.Logical<S,B>>, Structure2D.LongRowColumn, Structure2D.ReducibleTo1D<R extends Structure1D>, Structure2D.Reshapable, Structure2D.RowColumnKey<R,C>, Structure2D.RowColumnMapper<R,C>
-
-
Field Summary
Fields Modifier and Type Field Description private static NumberContext
EQUALS
private MatrixDecomposition<N>
myDecomposition
private PhysicalStore.Factory<N,?>
myFactory
private int
myHashCode
private java.lang.Boolean
myHermitian
private java.lang.Boolean
mySPD
private MatrixStore<N>
myStore
private ElementsSupplier<N>
mySupplier
private java.lang.Boolean
mySymmetric
-
Constructor Summary
Constructors Constructor Description BasicMatrix(PhysicalStore.Factory<N,?> factory, ElementsSupplier<N> supplier)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description M
above(long numberOfRows)
M
above(Access2D<N> above)
M
above(Access2D<N>... above)
M
add(double scalarAddend)
M
add(M addend)
M
add(N scalarAddend)
N
aggregateColumn(long row, long col, Aggregator aggregator)
N
aggregateDiagonal(long row, long col, Aggregator aggregator)
N
aggregateRange(long first, long limit, Aggregator aggregator)
N
aggregateRow(long row, long col, Aggregator aggregator)
M
below(long numberOfRows)
M
below(Access2D<N> below)
M
below(Access2D<N>... below)
M
bidiagonal(boolean upper)
static <M extends BasicMatrix<?,M>>
doublecalculateFrobeniusNorm(M matrix)
The Frobenius norm is the square root of the sum of the squares of each element, or the square root of the sum of the square of the singular values.static <M extends BasicMatrix<?,M>>
doublecalculateInfinityNorm(M matrix)
static <M extends BasicMatrix<?,M>>
doublecalculateOneNorm(M matrix)
M
column(int column)
M
column(long column)
M
columns(int... columns)
A selection (re-ordering) of columns.M
columns(long... columns)
M
conjugate()
This method will (most likely) be moved to some other interface in the future! Just have to figure out where it fits...abstract DenseMutator2D<N,M>
copy()
The returned instance can have its elements mutated in various ways, while the size/shape is fixed.long
count()
count() == countRows() * countColumns()long
countColumns()
Only need to implement if the structure may contain more than Integer.MAX_VALUE elements.long
countRows()
Only need to implement if the structure may contain more than Integer.MAX_VALUE elements.M
diagonal()
M
diagonally(Access2D<N>... diagonally)
M
divide(double scalarDivisor)
M
divide(N scalarDivisor)
double
doubleValue(int row, int col)
Extracts one element of this matrix as a double.double
doubleValue(long index)
M
enforce(NumberContext context)
boolean
equals(java.lang.Object other)
true if "other" is anAccess2D
of the same size/shape and the elements are equal to high precision (12 significant digits).M
get()
Deprecated.v50 No need for this!N
get(long index)
N
get(long row, long col)
int
getColDim()
double
getCondition()
Matrix condition (2-norm)private Provider2D.Condition
getConditionProvider()
N
getDeterminant()
private Provider2D.Determinant<N>
getDeterminantProvider()
java.util.List<Eigenvalue.Eigenpair>
getEigenpairs()
private Provider2D.Eigenpairs
getEigenpairsProvider()
private Provider2D.Inverse<java.util.Optional<MatrixStore<N>>>
getInverseProvider(boolean safe)
int
getRank()
The rank of a matrix is the (maximum) number of linearly independent rows or columns it contains.private Provider2D.Rank
getRankProvider()
int
getRowDim()
private Provider2D.Solution<java.util.Optional<MatrixStore<N>>>
getSolutionProvider(boolean safe, Access2D<?> rhs)
N
getTrace()
The sum of the diagonal elements.int
hashCode()
M
hermitian(boolean upper)
Similar toStructure2D.Logical.symmetric(boolean)
but in addition the mirrored elements are conjugated.M
hessenberg(boolean upper)
long
indexOfLargest()
M
invert()
About inverting matrices:boolean
isHermitian()
boolean
isSmall(double comparedTo)
boolean
isSymmetric()
M
left(long numberOfColumns)
M
left(Access2D<N> left)
M
left(Access2D<N>... left)
M
limits(long rowLimit, long columnLimit)
Setting either limit to < 0 is interpreted as "no limit" (useful when you only want to limit either the rows or columns, and don't know the size of the other)M
logical()
Deprecated.v50 No need for this!M
multiply(double scalarMultiplicand)
M
multiply(M multiplicand)
M
multiply(N scalarMultiplicand)
M
negate()
The additive inverse of this.(package private) abstract Cholesky<N>
newCholesky(Structure2D typical)
(package private) abstract DeterminantTask<N>
newDeterminantTask(Structure2D template)
(package private) abstract Eigenvalue<N>
newEigenvalue(Structure2D typical)
(package private) abstract M
newInstance(ElementsSupplier<N> store)
(package private) abstract InverterTask<N>
newInverterTask(Structure2D template)
(package private) abstract LDL<N>
newLDL(Structure2D typical)
(package private) LDU<N>
newLDU(Structure2D typical)
(package private) abstract LU<N>
newLU(Structure2D typical)
(package private) abstract QR<N>
newQR(Structure2D typical)
(package private) abstract SingularValue<N>
newSingularValue(Structure2D typical)
(package private) abstract SolverTask<N>
newSolverTask(Structure2D templateBody, Structure2D templateRHS)
double
norm()
The Frobenius norm is the square root of the sum of the squares of each element, or the square root of the sum of the square of the singular values.M
offsets(long rowOffset, long columnOffset)
M
onAll(double left, BinaryFunction<N> operator)
M
onAll(N left, BinaryFunction<N> operator)
M
onAll(BinaryFunction<N> operator, double right)
M
onAll(BinaryFunction<N> operator, N right)
M
onAll(ParameterFunction<N> operator, int parameter)
M
onAll(UnaryFunction<N> operator)
M
onAny(Transformation2D<N> operator)
M
onColumns(BinaryFunction<N> operator, Access1D<N> right)
M
onColumns(Access1D<N> left, BinaryFunction<N> operator)
M
onCompatible(BinaryFunction<N> operator, Access2D<N> right)
M
onCompatible(Access2D<N> left, BinaryFunction<N> operator)
M
onMatching(BinaryFunction<N> operator, Access2D<N> right)
M
onMatching(Access2D<N> left, BinaryFunction<N> operator)
M
onRows(BinaryFunction<N> operator, Access1D<N> right)
M
onRows(Access1D<N> left, BinaryFunction<N> operator)
M
power(int power)
Multiply by itselfpower
times.M
reduceColumns(Aggregator aggregator)
M
reduceRows(Aggregator aggregator)
M
repeat(int rowsRepetitions, int columnsRepetitions)
Will repeat this structure creating a new structure with a multiple of rows and columns.M
right(long numberOfColumns)
M
right(Access2D<N> right)
M
right(Access2D<N>... right)
M
row(int row)
M
row(long row)
M
rows(int... rows)
A selection (re-ordering) of rows.M
rows(long... rows)
M
select(int[] rows, int[] columns)
M
select(long[] rows, long[] columns)
Creates a view of the underlying data structure of only the selected elements.M
signum()
this == this.signum().multiply(this.norm())
int
size()
size() == getRowDim() * getColDim()M
solve(Access2D<?> rhs)
This method solves a system of linear equations: [this][X]=[rhs].(package private) MatrixStore<N>
store()
M
subtract(double scalarSubtrahend)
M
subtract(M subtrahend)
M
subtract(N scalarSubtrahend)
M
superimpose(long row, long col, Access2D<N> matrix)
(package private) ElementsSupplier<N>
supplier()
void
supplyTo(TransformableRegion<N> receiver)
M
symmetric(boolean upper)
Defines a symmetricStructure2D
(matrix) by mirroring one half (diagonally) on the other.Scalar<N>
toScalar(int row, int col)
Extracts one element of this matrix as a Scalar.java.lang.String
toString()
M
transpose()
Transposes this matrix.M
triangular(boolean upper, boolean assumeOne)
M
tridiagonal()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.ojalgo.structure.Access1D
asCollectable1D, asKeyed1D, axpy, dot, select, supplyTo, toRawCopy1D
-
Methods inherited from interface org.ojalgo.structure.Access1D.Aggregatable
aggregateAll
-
Methods inherited from interface org.ojalgo.structure.Access2D
asCollectable2D, asKeyed2D, byteValue, byteValue, byteValue, byteValue, columns, doubleValue, doubleValue, elements, floatValue, floatValue, floatValue, floatValue, intValue, intValue, intValue, intValue, longValue, longValue, longValue, longValue, nonzeros, rows, shortValue, shortValue, shortValue, shortValue, toRawCopy2D
-
Methods inherited from interface org.ojalgo.structure.Access2D.Aggregatable
aggregateColumn, aggregateDiagonal, aggregateRow, reduceColumns, reduceRows
-
Methods inherited from interface org.ojalgo.structure.Access2D.Collectable
collect
-
Methods inherited from interface org.ojalgo.algebra.ScalarOperation.Addition
add
-
Methods inherited from interface org.ojalgo.algebra.ScalarOperation.Division
divide
-
Methods inherited from interface org.ojalgo.algebra.ScalarOperation.Multiplication
multiply
-
Methods inherited from interface org.ojalgo.algebra.ScalarOperation.Subtraction
subtract
-
Methods inherited from interface org.ojalgo.structure.Structure2D
firstInColumn, firstInRow, getMaxDim, getMinDim, isEmpty, isFat, isScalar, isSquare, isTall, isVector, limitOfColumn, limitOfRow
-
Methods inherited from interface org.ojalgo.structure.Structure2D.Logical
superimpose
-
-
-
-
Field Detail
-
EQUALS
private static final NumberContext EQUALS
-
myDecomposition
private transient MatrixDecomposition<N extends java.lang.Comparable<N>> myDecomposition
-
myFactory
private final PhysicalStore.Factory<N extends java.lang.Comparable<N>,?> myFactory
-
myHashCode
private transient int myHashCode
-
myHermitian
private transient java.lang.Boolean myHermitian
-
mySPD
private transient java.lang.Boolean mySPD
-
myStore
private MatrixStore<N extends java.lang.Comparable<N>> myStore
-
mySupplier
private final ElementsSupplier<N extends java.lang.Comparable<N>> mySupplier
-
mySymmetric
private transient java.lang.Boolean mySymmetric
-
-
Constructor Detail
-
BasicMatrix
BasicMatrix(PhysicalStore.Factory<N,?> factory, ElementsSupplier<N> supplier)
-
-
Method Detail
-
calculateFrobeniusNorm
public static <M extends BasicMatrix<?,M>> double calculateFrobeniusNorm(M matrix)
The Frobenius norm is the square root of the sum of the squares of each element, or the square root of the sum of the square of the singular values.- Returns:
- The matrix' Frobenius norm
-
calculateInfinityNorm
public static <M extends BasicMatrix<?,M>> double calculateInfinityNorm(M matrix)
- Returns:
- The inf-norm or maximum row sum
-
calculateOneNorm
public static <M extends BasicMatrix<?,M>> double calculateOneNorm(M matrix)
- Returns:
- The 1-norm or maximum column sum
-
above
public M above(Access2D<N>... above)
- Specified by:
above
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
above
public M above(Access2D<N> above)
- Specified by:
above
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
above
public M above(long numberOfRows)
- Specified by:
above
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
add
public M add(double scalarAddend)
- Specified by:
add
in interfaceScalarOperation.Addition<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Returns:
this + scalarAddend
.
-
add
public M add(M addend)
- Specified by:
add
in interfaceOperation.Addition<N extends java.lang.Comparable<N>>
- Parameters:
addend
- What to add- Returns:
this + addend
-
add
public M add(N scalarAddend)
- Specified by:
add
in interfaceScalarOperation.Addition<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Returns:
this + scalarAddend
.
-
aggregateColumn
public N aggregateColumn(long row, long col, Aggregator aggregator)
- Specified by:
aggregateColumn
in interfaceAccess2D.Aggregatable<N extends java.lang.Comparable<N>>
-
aggregateDiagonal
public N aggregateDiagonal(long row, long col, Aggregator aggregator)
- Specified by:
aggregateDiagonal
in interfaceAccess2D.Aggregatable<N extends java.lang.Comparable<N>>
-
aggregateRange
public N aggregateRange(long first, long limit, Aggregator aggregator)
- Specified by:
aggregateRange
in interfaceAccess1D.Aggregatable<N extends java.lang.Comparable<N>>
-
aggregateRow
public N aggregateRow(long row, long col, Aggregator aggregator)
- Specified by:
aggregateRow
in interfaceAccess2D.Aggregatable<N extends java.lang.Comparable<N>>
-
below
public M below(Access2D<N>... below)
- Specified by:
below
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
below
public M below(Access2D<N> below)
- Specified by:
below
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
below
public M below(long numberOfRows)
- Specified by:
below
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
bidiagonal
public M bidiagonal(boolean upper)
- Specified by:
bidiagonal
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
column
public M column(int column)
- Specified by:
column
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- See Also:
Structure2D.Logical.columns(int[])
-
column
public M column(long column)
- Specified by:
column
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- See Also:
Structure2D.Logical.columns(int[])
-
columns
public M columns(int... columns)
Description copied from interface:Structure2D.Logical
A selection (re-ordering) of columns. Note that it's ok to reference the same base column more than once, and any negative column reference/index will translate to a column of zeros. The number of columns in the resulting matrix is the same as the number of elements in the columns index array.
-
columns
public M columns(long... columns)
- Specified by:
columns
in interfaceAccess2D<N extends java.lang.Comparable<N>>
- Specified by:
columns
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- See Also:
Structure2D.Logical.columns(int[])
-
conjugate
public M conjugate()
Description copied from interface:VectorSpace
This method will (most likely) be moved to some other interface in the future! Just have to figure out where it fits...
The conjugate transpose of a matrix and/or the conjugate of a scalar/field like ComplexNumber or Quaternion.
The conjugate transpose of a real matrix is simply its transpose.
- Specified by:
conjugate
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Specified by:
conjugate
in interfaceVectorSpace<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
copy
public abstract DenseMutator2D<N,M> copy()
The returned instance can have its elements mutated in various ways, while the size/shape is fixed.- Returns:
- A fully mutable matrix builder with the elements initially set to a copy of this matrix – always creates a full dense copy.
- See Also:
logical()
-
count
public long count()
Description copied from interface:Structure2D
count() == countRows() * countColumns()- Specified by:
count
in interfaceStructure1D
- Specified by:
count
in interfaceStructure2D
-
countColumns
public long countColumns()
Description copied from interface:Structure2D
Only need to implement if the structure may contain more than Integer.MAX_VALUE elements.- Specified by:
countColumns
in interfaceStructure2D
- Returns:
- The number of columns
-
countRows
public long countRows()
Description copied from interface:Structure2D
Only need to implement if the structure may contain more than Integer.MAX_VALUE elements.- Specified by:
countRows
in interfaceStructure2D
- Returns:
- The number of rows
-
diagonal
public M diagonal()
- Specified by:
diagonal
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Returns:
- A diagonal matrix (main diagonal only)
-
diagonally
public M diagonally(Access2D<N>... diagonally)
- Specified by:
diagonally
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
divide
public M divide(double scalarDivisor)
- Specified by:
divide
in interfaceScalarOperation.Division<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Returns:
this / scalarDivisor
.
-
divide
public M divide(N scalarDivisor)
- Specified by:
divide
in interfaceScalarOperation.Division<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Returns:
this / scalarDivisor
.
-
doubleValue
public double doubleValue(int row, int col)
Description copied from interface:Access2D
Extracts one element of this matrix as a double.- Specified by:
doubleValue
in interfaceAccess2D<N extends java.lang.Comparable<N>>
- Parameters:
row
- A row index.col
- A column index.- Returns:
- One matrix element
-
doubleValue
public double doubleValue(long index)
- Specified by:
doubleValue
in interfaceAccess1D<N extends java.lang.Comparable<N>>
- Specified by:
doubleValue
in interfaceAccess2D<N extends java.lang.Comparable<N>>
-
enforce
public M enforce(NumberContext context)
- Specified by:
enforce
in interfaceNumberContext.Enforceable<N extends java.lang.Comparable<N>>
-
equals
public boolean equals(java.lang.Object other)
true if "other" is anAccess2D
of the same size/shape and the elements are equal to high precision (12 significant digits).- Overrides:
equals
in classjava.lang.Object
-
get
@Deprecated public M get()
Deprecated.v50 No need for this!
-
get
public N get(long index)
-
get
public N get(long row, long col)
-
getColDim
public int getColDim()
- Specified by:
getColDim
in interfaceStructure2D
- Returns:
- The number of columns
-
getCondition
public double getCondition()
Matrix condition (2-norm)- Specified by:
getCondition
in interfaceProvider2D.Condition
- Returns:
- ratio of largest to smallest singular value.
-
getDeterminant
public N getDeterminant()
- Specified by:
getDeterminant
in interfaceProvider2D.Determinant<N extends java.lang.Comparable<N>>
- Returns:
- The matrix' determinant.
-
getEigenpairs
public java.util.List<Eigenvalue.Eigenpair> getEigenpairs()
- Specified by:
getEigenpairs
in interfaceProvider2D.Eigenpairs
-
getRank
public int getRank()
The rank of a matrix is the (maximum) number of linearly independent rows or columns it contains. It is also equal to the number of nonzero singular values of the matrix.- Specified by:
getRank
in interfaceProvider2D.Rank
- Returns:
- The matrix' rank.
- See Also:
MatrixDecomposition.RankRevealing
-
getRowDim
public int getRowDim()
- Specified by:
getRowDim
in interfaceStructure2D
- Returns:
- The number of rows
-
getTrace
public N getTrace()
The sum of the diagonal elements.- Specified by:
getTrace
in interfaceProvider2D.Trace<N extends java.lang.Comparable<N>>
- Returns:
- The matrix' trace.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
hermitian
public M hermitian(boolean upper)
Description copied from interface:Structure2D.Logical
Similar toStructure2D.Logical.symmetric(boolean)
but in addition the mirrored elements are conjugated.- Specified by:
hermitian
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
hessenberg
public M hessenberg(boolean upper)
- Specified by:
hessenberg
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
indexOfLargest
public long indexOfLargest()
- Specified by:
indexOfLargest
in interfaceAccess1D.Aggregatable<N extends java.lang.Comparable<N>>
-
invert
public M invert()
About inverting matrices:
- "right inverse": [this][right inverse]=[I]. You may calculate it using solve(Access2D).
- "left inverse": [left inverse][this]=[I]. You may calculate it using solve(Access2D) and transposing.
- "generalised inverse": [this][generalised inverse][this]=[this]. Note that if [this] is singular or non-square, then [generalised inverse] is not unique.
- "pseudoinverse": The generalised inverse (there are typically/possibly many) with the smallest frobenius norm is called the (Moore-Penrose) pseudoinverse. You may calculate it using the QR or SingularValue decompositions.
- "inverse":
- If [left inverse]=[right inverse] then it is also [inverse].
- If [this] is square and has full rank then the [generalised inverse] is unique, with the [pseudoinverse] given, and equal to [inverse].
- Specified by:
invert
in interfaceProvider2D.Inverse<N extends java.lang.Comparable<N>>
- Returns:
- The "best possible" inverse....
-
isHermitian
public boolean isHermitian()
- Specified by:
isHermitian
in interfaceProvider2D.Hermitian
-
isSmall
public boolean isSmall(double comparedTo)
- Specified by:
isSmall
in interfaceNormedVectorSpace<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Parameters:
comparedTo
- What to compare with- Returns:
- true if this is small compared to the magnitude of the input reference value.
-
isSymmetric
public boolean isSymmetric()
- Specified by:
isSymmetric
in interfaceProvider2D.Symmetric
-
left
public M left(Access2D<N>... left)
- Specified by:
left
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
left
public M left(Access2D<N> left)
- Specified by:
left
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
left
public M left(long numberOfColumns)
- Specified by:
left
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
limits
public M limits(long rowLimit, long columnLimit)
Description copied from interface:Structure2D.Logical
Setting either limit to < 0 is interpreted as "no limit" (useful when you only want to limit either the rows or columns, and don't know the size of the other)- Specified by:
limits
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
logical
@Deprecated public final M logical()
Deprecated.v50 No need for this!
-
multiply
public M multiply(double scalarMultiplicand)
- Specified by:
multiply
in interfaceScalarOperation.Multiplication<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Returns:
this * scalarMultiplicand
.
-
multiply
public M multiply(M multiplicand)
- Specified by:
multiply
in interfaceOperation.Multiplication<N extends java.lang.Comparable<N>>
- Parameters:
multiplicand
- The multiplicand- Returns:
this * multiplicand
.
-
multiply
public M multiply(N scalarMultiplicand)
- Specified by:
multiply
in interfaceScalarOperation.Multiplication<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Returns:
this * multiplicand
.
-
negate
public M negate()
Description copied from interface:Group.Additive
The additive inverse of this.- Specified by:
negate
in interfaceGroup.Additive<N extends java.lang.Comparable<N>>
- Returns:
-this
.
-
norm
public double norm()
The Frobenius norm is the square root of the sum of the squares of each element, or the square root of the sum of the square of the singular values. This definition fits the requirements of NormedVectorSpace.norm().- Specified by:
norm
in interfaceNormedVectorSpace<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Returns:
- The matrix' Frobenius norm
-
offsets
public M offsets(long rowOffset, long columnOffset)
- Specified by:
offsets
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
onAll
public M onAll(BinaryFunction<N> operator, double right)
-
onAll
public M onAll(BinaryFunction<N> operator, N right)
-
onAll
public M onAll(double left, BinaryFunction<N> operator)
-
onAll
public M onAll(N left, BinaryFunction<N> operator)
-
onAll
public M onAll(ParameterFunction<N> operator, int parameter)
-
onAll
public M onAll(UnaryFunction<N> operator)
-
onAny
public M onAny(Transformation2D<N> operator)
-
onColumns
public M onColumns(Access1D<N> left, BinaryFunction<N> operator)
-
onColumns
public M onColumns(BinaryFunction<N> operator, Access1D<N> right)
-
onCompatible
public M onCompatible(Access2D<N> left, BinaryFunction<N> operator)
- Specified by:
onCompatible
in interfaceOperate2D<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
onCompatible
public M onCompatible(BinaryFunction<N> operator, Access2D<N> right)
- Specified by:
onCompatible
in interfaceOperate2D<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
onMatching
public M onMatching(Access2D<N> left, BinaryFunction<N> operator)
- Specified by:
onMatching
in interfaceOperate2D<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
onMatching
public M onMatching(BinaryFunction<N> operator, Access2D<N> right)
- Specified by:
onMatching
in interfaceOperate2D<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
onRows
public M onRows(Access1D<N> left, BinaryFunction<N> operator)
-
onRows
public M onRows(BinaryFunction<N> operator, Access1D<N> right)
-
power
public M power(int power)
Description copied from interface:Operation.Multiplication
Multiply by itselfpower
times.- Specified by:
power
in interfaceOperation.Multiplication<N extends java.lang.Comparable<N>>
-
reduceColumns
public M reduceColumns(Aggregator aggregator)
- Specified by:
reduceColumns
in interfaceStructure2D.ReducibleTo1D<N extends java.lang.Comparable<N>>
-
reduceRows
public M reduceRows(Aggregator aggregator)
- Specified by:
reduceRows
in interfaceStructure2D.ReducibleTo1D<N extends java.lang.Comparable<N>>
-
repeat
public M repeat(int rowsRepetitions, int columnsRepetitions)
Description copied from interface:Structure2D.Logical
Will repeat this structure creating a new structure with a multiple of rows and columns.- Specified by:
repeat
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Parameters:
rowsRepetitions
- The number of times to repeat the rowscolumnsRepetitions
- The number of times to repeat the columns- Returns:
- The builder
-
right
public M right(Access2D<N>... right)
- Specified by:
right
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
right
public M right(Access2D<N> right)
- Specified by:
right
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
right
public M right(long numberOfColumns)
- Specified by:
right
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
row
public M row(int row)
- Specified by:
row
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- See Also:
Structure2D.Logical.rows(int[])
-
row
public M row(long row)
- Specified by:
row
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- See Also:
Structure2D.Logical.rows(int[])
-
rows
public M rows(int... rows)
Description copied from interface:Structure2D.Logical
A selection (re-ordering) of rows. Note that it's ok to reference the same base row more than once, and any negative row reference/index will translate to a row of zeros. The number of rows in the resulting matrix is the same as the number of elements in the rows index array.
-
rows
public M rows(long... rows)
- Specified by:
rows
in interfaceAccess2D<N extends java.lang.Comparable<N>>
- Specified by:
rows
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- See Also:
Structure2D.Logical.rows(int[])
-
select
public M select(int[] rows, int[] columns)
-
select
public M select(long[] rows, long[] columns)
Description copied from interface:Access2D
Creates a view of the underlying data structure of only the selected elements. If either the rows or columns input arguments are null or empty arrays, then that transaltes to all rows and/or columns.
-
signum
public M signum()
Description copied from interface:NormedVectorSpace
this == this.signum().multiply(this.norm())
- Specified by:
signum
in interfaceNormedVectorSpace<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Returns:
- A unit "vector"
-
size
public int size()
Description copied from interface:Structure2D
size() == getRowDim() * getColDim()- Specified by:
size
in interfaceStructure1D
- Specified by:
size
in interfaceStructure2D
-
solve
public M solve(Access2D<?> rhs)
This method solves a system of linear equations: [this][X]=[rhs]. A combination of columns in [this] should produce a column(s) in [rhs]. It is ok for [rhs] to have more than 1 column.
- If the problem is over-qualified an approximate solution is returned.
- If the problem is under-qualified one possible solution is returned.
Remember that: [X][this]=[rhs] is equivalent to [this]T[X]T=[rhs]T
- Specified by:
solve
in interfaceProvider2D.Solution<N extends java.lang.Comparable<N>>
- Parameters:
rhs
- The right hand side of the equation.- Returns:
- The solution, [X].
-
subtract
public M subtract(double scalarSubtrahend)
- Specified by:
subtract
in interfaceScalarOperation.Subtraction<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Returns:
this - scalarSubtrahend
.
-
subtract
public M subtract(M subtrahend)
- Specified by:
subtract
in interfaceOperation.Subtraction<N extends java.lang.Comparable<N>>
- Parameters:
subtrahend
- The subtrahend- Returns:
this - subtrahend
.
-
subtract
public M subtract(N scalarSubtrahend)
- Specified by:
subtract
in interfaceScalarOperation.Subtraction<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Returns:
this - scalarSubtrahend
.
-
superimpose
public M superimpose(long row, long col, Access2D<N> matrix)
- Specified by:
superimpose
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
supplyTo
public void supplyTo(TransformableRegion<N> receiver)
- Specified by:
supplyTo
in interfaceAccess2D.Collectable<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
symmetric
public M symmetric(boolean upper)
Description copied from interface:Structure2D.Logical
Defines a symmetricStructure2D
(matrix) by mirroring one half (diagonally) on the other.- Specified by:
symmetric
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Parameters:
upper
- From where are the elements read?
-
toScalar
public Scalar<N> toScalar(int row, int col)
Description copied from interface:Matrix2D
Extracts one element of this matrix as a Scalar.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
transpose
public M transpose()
Transposes this matrix. For complex matrices conjugate() and transpose() are NOT EQUAL.- Specified by:
transpose
in interfaceMatrix2D<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Specified by:
transpose
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
- Returns:
- A matrix that is the transpose of this matrix.
- See Also:
conjugate()
-
triangular
public M triangular(boolean upper, boolean assumeOne)
- Specified by:
triangular
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
tridiagonal
public M tridiagonal()
- Specified by:
tridiagonal
in interfaceStructure2D.Logical<N extends java.lang.Comparable<N>,M extends BasicMatrix<N,M>>
-
getConditionProvider
private Provider2D.Condition getConditionProvider()
-
getDeterminantProvider
private Provider2D.Determinant<N> getDeterminantProvider()
-
getEigenpairsProvider
private Provider2D.Eigenpairs getEigenpairsProvider()
-
getInverseProvider
private Provider2D.Inverse<java.util.Optional<MatrixStore<N>>> getInverseProvider(boolean safe)
-
getRankProvider
private Provider2D.Rank getRankProvider()
-
getSolutionProvider
private Provider2D.Solution<java.util.Optional<MatrixStore<N>>> getSolutionProvider(boolean safe, Access2D<?> rhs)
-
newCholesky
abstract Cholesky<N> newCholesky(Structure2D typical)
-
newDeterminantTask
abstract DeterminantTask<N> newDeterminantTask(Structure2D template)
-
newEigenvalue
abstract Eigenvalue<N> newEigenvalue(Structure2D typical)
-
newInstance
abstract M newInstance(ElementsSupplier<N> store)
-
newInverterTask
abstract InverterTask<N> newInverterTask(Structure2D template)
-
newLDL
abstract LDL<N> newLDL(Structure2D typical)
-
newLDU
final LDU<N> newLDU(Structure2D typical)
-
newLU
abstract LU<N> newLU(Structure2D typical)
-
newQR
abstract QR<N> newQR(Structure2D typical)
-
newSingularValue
abstract SingularValue<N> newSingularValue(Structure2D typical)
-
newSolverTask
abstract SolverTask<N> newSolverTask(Structure2D templateBody, Structure2D templateRHS)
-
store
MatrixStore<N> store()
-
supplier
ElementsSupplier<N> supplier()
-
-