solver rework + refactor
This commit is contained in:
@@ -7,29 +7,29 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
Matrix::Matrix(std::size_t lignes, std::size_t colonnes) : m_Raws(lignes), m_Columns(colonnes) {
|
||||
Matrix::Matrix(std::size_t a_Raws, std::size_t a_Columns) : m_Raws(a_Raws), m_Columns(a_Columns) {
|
||||
m_Data.resize(m_Raws * m_Columns);
|
||||
}
|
||||
|
||||
Matrix::Matrix(std::size_t lignes, std::size_t colonnes, std::initializer_list<Element>&& initList) :
|
||||
m_Raws(lignes), m_Columns(colonnes) {
|
||||
m_Data = initList;
|
||||
Matrix::Matrix(std::size_t a_Raws, std::size_t a_Columns, std::initializer_list<Element>&& a_Elements) :
|
||||
m_Raws(a_Raws), m_Columns(a_Columns) {
|
||||
m_Data = a_Elements;
|
||||
m_Data.resize(m_Raws * m_Columns);
|
||||
}
|
||||
|
||||
Matrix Matrix::operator*(const Matrix& other) const {
|
||||
if (m_Columns != other.m_Raws) {
|
||||
Matrix Matrix::operator*(const Matrix& a_Other) const {
|
||||
if (m_Columns != a_Other.m_Raws) {
|
||||
std::cerr << "Mutiplication impossible car la dimensions des matrices est incompatible" << std::endl;
|
||||
return {};
|
||||
}
|
||||
|
||||
Matrix result(m_Raws, other.m_Columns);
|
||||
Matrix result(m_Raws, a_Other.m_Columns);
|
||||
|
||||
for (std::size_t i = 0; i < m_Raws; ++i) {
|
||||
for (std::size_t j = 0; j < other.m_Columns; ++j) {
|
||||
for (std::size_t j = 0; j < a_Other.m_Columns; ++j) {
|
||||
Element sum = 0;
|
||||
for (std::size_t k = 0; k < m_Columns; k++) {
|
||||
sum += at(i, k) * other.at(k, j);
|
||||
sum += at(i, k) * a_Other.at(k, j);
|
||||
}
|
||||
result.at(i, j) = sum;
|
||||
}
|
||||
@@ -47,35 +47,35 @@ void Matrix::Transpose() {
|
||||
*this = result;
|
||||
}
|
||||
|
||||
Matrix Matrix::Identity(std::size_t taille) {
|
||||
Matrix id {taille, taille};
|
||||
for (std::size_t i = 0; i < taille; i++) {
|
||||
for (std::size_t j = i; j < taille; j++) {
|
||||
Matrix Matrix::Identity(std::size_t a_Size) {
|
||||
Matrix id {a_Size, a_Size};
|
||||
for (std::size_t i = 0; i < a_Size; i++) {
|
||||
for (std::size_t j = i; j < a_Size; j++) {
|
||||
id.at(i, j) = (i == j);
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
Matrix Matrix::ColumnVector(std::initializer_list<Element>&& initList) {
|
||||
Matrix result {initList.size(), 1};
|
||||
Matrix Matrix::ColumnVector(std::initializer_list<Element>&& a_Elements) {
|
||||
Matrix result {a_Elements.size(), 1};
|
||||
|
||||
result.m_Data = initList;
|
||||
result.m_Data = a_Elements;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix Matrix::RawVector(std::initializer_list<Element>&& initList) {
|
||||
Matrix result {1, initList.size()};
|
||||
Matrix Matrix::RawVector(std::initializer_list<Element>&& a_Elements) {
|
||||
Matrix result {1, a_Elements.size()};
|
||||
|
||||
result.m_Data = initList;
|
||||
result.m_Data = a_Elements;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Matrix::Augment(const Matrix& droite) {
|
||||
assert(droite.m_Raws == m_Raws);
|
||||
Matrix temp {m_Raws, m_Columns + droite.m_Columns};
|
||||
void Matrix::Augment(const Matrix& a_Right) {
|
||||
assert(a_Right.m_Raws == m_Raws);
|
||||
Matrix temp {m_Raws, m_Columns + a_Right.m_Columns};
|
||||
|
||||
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||
for (std::size_t j = 0; j < m_Columns; j++) {
|
||||
@@ -84,49 +84,49 @@ void Matrix::Augment(const Matrix& droite) {
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||
for (std::size_t j = 0; j < droite.m_Columns; j++) {
|
||||
temp.at(i, j + m_Columns) = droite.at(i, j);
|
||||
for (std::size_t j = 0; j < a_Right.m_Columns; j++) {
|
||||
temp.at(i, j + m_Columns) = a_Right.at(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
*this = temp;
|
||||
}
|
||||
|
||||
Matrix Matrix::operator+(const Matrix& other) const {
|
||||
assert(GetColumnCount() == other.GetColumnCount() && GetRawCount() == other.GetRawCount());
|
||||
Matrix Matrix::operator+(const Matrix& a_Other) const {
|
||||
assert(GetColumnCount() == a_Other.GetColumnCount() && GetRawCount() == a_Other.GetRawCount());
|
||||
|
||||
Matrix result = *this;
|
||||
|
||||
for (std::size_t i = 0; i < GetRawCount(); i++) {
|
||||
for (std::size_t j = 0; j < GetColumnCount(); j++) {
|
||||
result.at(i, j) += other.at(i, j);
|
||||
result.at(i, j) += a_Other.at(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix Matrix::operator-(const Matrix& other) const {
|
||||
assert(GetColumnCount() == other.GetColumnCount() && GetRawCount() == other.GetRawCount());
|
||||
Matrix Matrix::operator-(const Matrix& a_Other) const {
|
||||
assert(GetColumnCount() == a_Other.GetColumnCount() && GetRawCount() == a_Other.GetRawCount());
|
||||
|
||||
Matrix result = *this;
|
||||
|
||||
for (std::size_t i = 0; i < GetRawCount(); i++) {
|
||||
for (std::size_t j = 0; j < GetColumnCount(); j++) {
|
||||
result.at(i, j) -= other.at(i, j);
|
||||
result.at(i, j) -= a_Other.at(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Matrix::operator==(const Matrix& other) const {
|
||||
if (m_Raws != other.m_Raws || m_Columns != other.m_Columns)
|
||||
bool Matrix::operator==(const Matrix& a_Other) const {
|
||||
if (m_Raws != a_Other.m_Raws || m_Columns != a_Other.m_Columns)
|
||||
return false;
|
||||
|
||||
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||
for (std::size_t j = 0; j < m_Columns; j++) {
|
||||
if (!IsEqualZero(at(i, j) - other.at(i, j)))
|
||||
if (!IsEqualZero(at(i, j) - a_Other.at(i, j)))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -134,12 +134,12 @@ bool Matrix::operator==(const Matrix& other) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
Matrix::Element& Matrix::at(std::size_t ligne, std::size_t colonne) {
|
||||
return m_Data[ligne * m_Columns + colonne];
|
||||
Matrix::Element& Matrix::at(std::size_t a_Raw, std::size_t a_Column) {
|
||||
return m_Data[a_Raw * m_Columns + a_Column];
|
||||
}
|
||||
|
||||
Matrix::Element Matrix::at(std::size_t ligne, std::size_t colonne) const {
|
||||
return m_Data[ligne * m_Columns + colonne];
|
||||
Matrix::Element Matrix::at(std::size_t a_Raw, std::size_t a_Column) const {
|
||||
return m_Data[a_Raw * m_Columns + a_Column];
|
||||
}
|
||||
|
||||
std::size_t Matrix::GetRawCount() const {
|
||||
@@ -150,14 +150,15 @@ std::size_t Matrix::GetColumnCount() const {
|
||||
return m_Columns;
|
||||
}
|
||||
|
||||
Matrix Matrix::SubMatrix(std::size_t origine_ligne, std::size_t origine_colonne, std::size_t ligne, std::size_t colonne) const {
|
||||
assert(m_Raws >= origine_ligne + ligne && m_Columns >= origine_colonne + colonne);
|
||||
Matrix Matrix::SubMatrix(
|
||||
std::size_t a_RawOrigin, std::size_t a_ColumnOrigin, std::size_t a_RawCount, std::size_t a_ColumnCount) const {
|
||||
assert(m_Raws >= a_RawOrigin + a_RawCount && m_Columns >= a_ColumnOrigin + a_ColumnCount);
|
||||
|
||||
Matrix result {ligne, colonne};
|
||||
Matrix result {a_RawCount, a_ColumnCount};
|
||||
|
||||
for (std::size_t i = 0; i < ligne; i++) {
|
||||
for (std::size_t j = 0; j < colonne; j++) {
|
||||
result.at(i, j) = at(i + origine_ligne, j + origine_colonne);
|
||||
for (std::size_t i = 0; i < result.GetRawCount(); i++) {
|
||||
for (std::size_t j = 0; j < result.GetColumnCount(); j++) {
|
||||
result.at(i, j) = at(i + a_RawOrigin, j + a_ColumnOrigin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user