
org.ojalgo.matrix.decomposition.LU Maven / Gradle / Ivy
/*
* Copyright 1997-2024 Optimatika
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.ojalgo.matrix.decomposition;
import org.ojalgo.array.PlainArray;
import org.ojalgo.matrix.store.MatrixStore;
import org.ojalgo.scalar.ComplexNumber;
import org.ojalgo.scalar.Quadruple;
import org.ojalgo.scalar.Quaternion;
import org.ojalgo.scalar.RationalNumber;
import org.ojalgo.structure.Access2D;
import org.ojalgo.type.context.NumberContext;
/**
* LU: [A] = [L][U]
*
* Decomposes [this] into [L] and [U] (with pivot order information in an int[]) where:
*
*
* - [L] is a unit lower (left) triangular matrix. It has the same number of rows as [this], and ones on the
* diagonal.
* - [U] is an upper (right) triangular matrix. It has the same number of columns as [this].
* - [this] = [L][U] (with reordered rows according to the pivot order)
*
*
* Note: The number of columns in [L] and the number of rows in [U] is not specified by this interface.
*
*
* The LU decomposition always exists - the compute method should always succeed - even for non-square and/or
* singular matrices. The primary use of the LU decomposition is in the solution of systems of simultaneous
* linear equations. That will, however, only work for square non-singular matrices.
*
*
* @author apete
*/
public interface LU> extends LDU, MatrixDecomposition.Pivoting {
interface Factory> extends MatrixDecomposition.Factory> {
}
Factory C128 = typical -> new LUDecomposition.C128();
Factory H256 = typical -> new LUDecomposition.H256();
Factory Q128 = typical -> new LUDecomposition.Q128();
Factory R064 = typical -> {
if (512L < typical.countColumns() && typical.count() <= PlainArray.MAX_SIZE) {
return new LUDecomposition.R064();
} else {
return new RawLU();
}
};
Factory R128 = typical -> new LUDecomposition.R128();
static > boolean equals(final MatrixStore matrix, final LU decomposition, final NumberContext context) {
MatrixStore tmpL = decomposition.getL();
MatrixStore tmpU = decomposition.getU();
int[] tmpPivotOrder = decomposition.getPivotOrder();
return Access2D.equals(matrix.rows(tmpPivotOrder), tmpL.multiply(tmpU), context);
}
MatrixStore getL();
/**
* http://en.wikipedia.org/wiki/Row_echelon_form
*
* This is the same as [D][U]. Together with the pivotOrder and [L] this constitutes an alternative, more
* compact, way to express the decomposition.
*
* @see #getPivotOrder()
* @see #getL()
*/
MatrixStore getU();
@Override
default MatrixStore reconstruct() {
MatrixStore mtrxL = this.getL();
MatrixStore mtrxU = this.getU();
int[] reversePivotOrder = this.getReversePivotOrder();
return mtrxL.multiply(mtrxU).rows(reversePivotOrder);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy