![JAR search and dependency download from the Maven repository](/logo.png)
org.ejml.alg.dense.linsol.WrapLinearSolverBlock64 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ejml Show documentation
Show all versions of ejml Show documentation
A fast and easy to use dense matrix linear algebra library written in Java.
/*
* Copyright (c) 2009-2012, Peter Abeles. All Rights Reserved.
*
* This file is part of Efficient Java Matrix Library (EJML).
*
* EJML is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* EJML is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with EJML. If not, see .
*/
package org.ejml.alg.dense.linsol;
import org.ejml.alg.block.BlockMatrixOps;
import org.ejml.alg.block.linsol.chol.BlockCholeskyOuterSolver;
import org.ejml.data.BlockMatrix64F;
import org.ejml.data.DenseMatrix64F;
import org.ejml.factory.LinearSolver;
/**
* Wrapper that allows {@link org.ejml.factory.LinearSolver } to implements {@link org.ejml.factory.LinearSolver}. It works
* by converting {@link DenseMatrix64F} into {@link BlockMatrix64F} and calling the equivalent
* functions. Since a local copy is made all input matrices are never modified.
*
* @author Peter Abeles
*/
public class WrapLinearSolverBlock64 implements LinearSolver {
protected LinearSolver alg = new BlockCholeskyOuterSolver();
// block matrix copy of the system A matrix.
protected BlockMatrix64F blockA = new BlockMatrix64F(1,1);
// block matrix copy of B matrix passed into solve
protected BlockMatrix64F blockB = new BlockMatrix64F(1,1);
// block matrix copy of X matrix passed into solve
protected BlockMatrix64F blockX = new BlockMatrix64F(1,1);
public WrapLinearSolverBlock64( LinearSolver alg ) {
this.alg = alg;
}
/**
* Converts 'A' into a block matrix and call setA() on the block matrix solver.
*
* @param A The A matrix in the linear equation. Not modified. Reference saved.
* @return true if it can solve the system.
*/
@Override
public boolean setA(DenseMatrix64F A) {
blockA.reshape(A.numRows,A.numCols,false);
BlockMatrixOps.convert(A,blockA);
return alg.setA(blockA);
}
@Override
public double quality() {
return alg.quality();
}
/**
* Converts B and X into block matrices and calls the block matrix solve routine.
*
* @param B A matrix ℜ m × p. Not modified.
* @param X A matrix ℜ n × p, where the solution is written to. Modified.
*/
@Override
public void solve(DenseMatrix64F B, DenseMatrix64F X) {
blockB.reshape(B.numRows,B.numCols,false);
blockX.reshape(X.numRows,X.numCols,false);
BlockMatrixOps.convert(B,blockB);
alg.solve(blockB,blockX);
BlockMatrixOps.convert(blockX,X);
}
/**
* Creates a block matrix the same size as A_inv, inverts the matrix and copies the results back
* onto A_inv.
*
* @param A_inv Where the inverted matrix saved. Modified.
*/
@Override
public void invert(DenseMatrix64F A_inv) {
blockB.reshape(A_inv.numRows,A_inv.numCols,false);
alg.invert(blockB);
BlockMatrixOps.convert(blockB,A_inv);
}
@Override
public boolean modifiesA() {
return false;
}
@Override
public boolean modifiesB() {
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy