solver move matricies
This commit is contained in:
@@ -2,37 +2,38 @@
|
||||
|
||||
#include "Gauss.h"
|
||||
|
||||
Vect Solver::Image(const Matrix& a_Matrix) const {
|
||||
Matrix result = a_Matrix;
|
||||
result.Transpose();
|
||||
Gauss::GaussJordan(result, true, true);
|
||||
result.Transpose();
|
||||
return {result};
|
||||
Vect Solver::Image(Matrix&& a_Matrix) const {
|
||||
a_Matrix.Transpose();
|
||||
Gauss::GaussJordan(a_Matrix, true, true);
|
||||
a_Matrix.Transpose();
|
||||
return {a_Matrix};
|
||||
}
|
||||
|
||||
// https://en.wikipedia.org/wiki/Kernel_(linear_algebra)#Computation_by_Gaussian_elimination
|
||||
Vect Solver::Kernel(const Matrix& a_Matrix) const {
|
||||
Matrix result = a_Matrix;
|
||||
result.Transpose();
|
||||
result.Augment(Matrix::Identity(result.GetRawCount()));
|
||||
Gauss::GaussJordan(result, true, true);
|
||||
result.Transpose();
|
||||
Vect Solver::Kernel(Matrix&& a_Matrix) const {
|
||||
std::size_t matrixRawCount = a_Matrix.GetRawCount();
|
||||
std::size_t matrixColumnCount = a_Matrix.GetColumnCount();
|
||||
|
||||
a_Matrix.Transpose();
|
||||
a_Matrix.Augment(Matrix::Identity(a_Matrix.GetRawCount()));
|
||||
Gauss::GaussJordan(a_Matrix, true, true);
|
||||
a_Matrix.Transpose();
|
||||
|
||||
// nombre de colonnes non nulles
|
||||
std::size_t origine_colonne = Vect(result.SubMatrix(0, 0, a_Matrix.GetRawCount(), a_Matrix.GetColumnCount())).GetCardinal();
|
||||
std::size_t origine_colonne = Vect(a_Matrix.SubMatrix(0, 0, matrixRawCount, matrixColumnCount)).GetCardinal();
|
||||
|
||||
return {result.SubMatrix(a_Matrix.GetRawCount(), origine_colonne, result.GetRawCount() - a_Matrix.GetRawCount(),
|
||||
result.GetColumnCount() - origine_colonne)};
|
||||
return {a_Matrix.SubMatrix(matrixRawCount, origine_colonne, a_Matrix.GetRawCount() - matrixRawCount,
|
||||
a_Matrix.GetColumnCount() - origine_colonne)};
|
||||
}
|
||||
|
||||
VectAffine Solver::RectangularSystem(const Matrix& a_MatrixA, const Matrix& a_VectorB) const {
|
||||
VectAffine Solver::RectangularSystem(Matrix&& a_MatrixA, const Matrix& a_VectorB) const {
|
||||
Matrix mat = a_MatrixA;
|
||||
mat.Augment(a_VectorB);
|
||||
Gauss::GaussJordan(mat, true, true);
|
||||
|
||||
Solver solver;
|
||||
|
||||
Vect noyau = solver.Kernel(a_MatrixA);
|
||||
Vect noyau = solver.Kernel(std::move(a_MatrixA));
|
||||
Matrix origin = mat.SubMatrix(0, mat.GetColumnCount() - 1, mat.GetRawCount(), 1);
|
||||
|
||||
// on rajoute des 0 si il faut
|
||||
@@ -49,6 +50,6 @@ VectAffine Solver::RectangularSystem(const Matrix& a_MatrixA, const Matrix& a_Ve
|
||||
return {noyau, fullOrigin};
|
||||
}
|
||||
|
||||
std::size_t Solver::Rank(const Matrix& a_Matrix) const {
|
||||
return Image(a_Matrix).GetCardinal();
|
||||
std::size_t Solver::Rank(Matrix&& a_Matrix) const {
|
||||
return Image(std::move(a_Matrix)).GetCardinal();
|
||||
}
|
||||
|
||||
@@ -75,9 +75,9 @@ Matrix Vect::GetLinearSystem() const {
|
||||
vect.Transpose();
|
||||
|
||||
Solver solver;
|
||||
vect = solver.Kernel(vect).m_Data;
|
||||
vect.Transpose();
|
||||
return vect;
|
||||
Matrix result = solver.Kernel(std::move(vect)).m_Data;
|
||||
result.Transpose();
|
||||
return result;
|
||||
}
|
||||
|
||||
std::size_t Vect::GetDimension() const {
|
||||
|
||||
@@ -25,8 +25,8 @@ void test() {
|
||||
|
||||
Solver solver;
|
||||
|
||||
Vect image = solver.Image(mat2);
|
||||
Vect noyau = solver.Kernel(mat2);
|
||||
Vect image = solver.Image(Matrix{mat2});
|
||||
Vect noyau = solver.Kernel(Matrix{mat2});
|
||||
|
||||
std::cout << "\tImage :\n";
|
||||
Print(image);
|
||||
|
||||
Reference in New Issue
Block a user