format project
This commit is contained in:
@@ -7,6 +7,8 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
|||||||
PointerAlignment: Left
|
PointerAlignment: Left
|
||||||
SortIncludes: true
|
SortIncludes: true
|
||||||
SpacesBeforeTrailingComments: 2
|
SpacesBeforeTrailingComments: 2
|
||||||
|
SeparateDefinitionBlocks: Always
|
||||||
|
SpaceBeforeCpp11BracedList: true
|
||||||
UseTab: Always
|
UseTab: Always
|
||||||
MaxEmptyLinesToKeep: 5
|
MaxEmptyLinesToKeep: 5
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ Matrix::Matrix(const std::string& fileNameInput) {
|
|||||||
Matrix::Matrix(std::size_t lignes, std::size_t colonnes) : m_Lignes(lignes), m_Colonnes(colonnes) {
|
Matrix::Matrix(std::size_t lignes, std::size_t colonnes) : m_Lignes(lignes), m_Colonnes(colonnes) {
|
||||||
m_Data.resize(m_Lignes * m_Colonnes);
|
m_Data.resize(m_Lignes * m_Colonnes);
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix::Matrix(std::size_t lignes, std::size_t colonnes, std::initializer_list<long double>&& initList) :
|
Matrix::Matrix(std::size_t lignes, std::size_t colonnes, std::initializer_list<long double>&& initList) :
|
||||||
m_Lignes(lignes), m_Colonnes(colonnes) {
|
m_Lignes(lignes), m_Colonnes(colonnes) {
|
||||||
m_Data = initList;
|
m_Data = initList;
|
||||||
@@ -69,7 +70,7 @@ void Matrix::Insert() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::Save(const std::string& fileName) {
|
void Matrix::Save(const std::string& fileName) {
|
||||||
std::ofstream out{fileName};
|
std::ofstream out {fileName};
|
||||||
if (!out) {
|
if (!out) {
|
||||||
std::cerr << "Impossible de sauvegarder la matrice !\n";
|
std::cerr << "Impossible de sauvegarder la matrice !\n";
|
||||||
return;
|
return;
|
||||||
@@ -78,7 +79,7 @@ void Matrix::Save(const std::string& fileName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::Load(const std::string& filename) {
|
void Matrix::Load(const std::string& filename) {
|
||||||
std::ifstream in{filename};
|
std::ifstream in {filename};
|
||||||
if (!in) {
|
if (!in) {
|
||||||
std::cerr << "Impossible de charger la matrice !\n";
|
std::cerr << "Impossible de charger la matrice !\n";
|
||||||
return;
|
return;
|
||||||
@@ -87,7 +88,7 @@ void Matrix::Load(const std::string& filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::Transpose() {
|
void Matrix::Transpose() {
|
||||||
Matrix result{m_Colonnes, m_Lignes};
|
Matrix result {m_Colonnes, m_Lignes};
|
||||||
for (std::size_t i = 0; i < m_Lignes; i++) {
|
for (std::size_t i = 0; i < m_Lignes; i++) {
|
||||||
for (std::size_t j = 0; j < m_Colonnes; j++) {
|
for (std::size_t j = 0; j < m_Colonnes; j++) {
|
||||||
result.at(j, i) = at(i, j);
|
result.at(j, i) = at(i, j);
|
||||||
@@ -106,7 +107,7 @@ void Matrix::Identity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Matrix Matrix::Identity(std::size_t taille) {
|
Matrix Matrix::Identity(std::size_t taille) {
|
||||||
Matrix id{taille, taille};
|
Matrix id {taille, taille};
|
||||||
id.Identity();
|
id.Identity();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -126,7 +127,7 @@ bool Matrix::IsInversed() const {
|
|||||||
|
|
||||||
void Matrix::Augmenter(const Matrix& droite) {
|
void Matrix::Augmenter(const Matrix& droite) {
|
||||||
assert(droite.m_Lignes == m_Lignes);
|
assert(droite.m_Lignes == m_Lignes);
|
||||||
Matrix temp{m_Lignes, m_Colonnes + droite.m_Colonnes};
|
Matrix temp {m_Lignes, m_Colonnes + droite.m_Colonnes};
|
||||||
|
|
||||||
for (std::size_t i = 0; i < m_Lignes; i++) {
|
for (std::size_t i = 0; i < m_Lignes; i++) {
|
||||||
for (std::size_t j = 0; j < m_Colonnes; j++) {
|
for (std::size_t j = 0; j < m_Colonnes; j++) {
|
||||||
@@ -245,7 +246,7 @@ std::size_t Matrix::GetColumnCount() const {
|
|||||||
|
|
||||||
Matrix Matrix::SubMatrix(std::size_t origine_ligne, std::size_t origine_colonne, std::size_t ligne, std::size_t colonne) const {
|
Matrix Matrix::SubMatrix(std::size_t origine_ligne, std::size_t origine_colonne, std::size_t ligne, std::size_t colonne) const {
|
||||||
assert(m_Lignes >= ligne && m_Colonnes >= colonne);
|
assert(m_Lignes >= ligne && m_Colonnes >= colonne);
|
||||||
Matrix result{ligne, colonne};
|
Matrix result {ligne, colonne};
|
||||||
|
|
||||||
for (std::size_t i = 0; i < ligne; i++) {
|
for (std::size_t i = 0; i < ligne; i++) {
|
||||||
for (std::size_t j = 0; j < colonne; j++) {
|
for (std::size_t j = 0; j < colonne; j++) {
|
||||||
|
|||||||
2
src/NR.h
2
src/NR.h
@@ -7,6 +7,8 @@ class NR {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
NR() : m_Numerator(0), m_Denominator(1) {}
|
NR() : m_Numerator(0), m_Denominator(1) {}
|
||||||
|
|
||||||
NR(int entier) : m_Numerator(entier), m_Denominator(1) {}
|
NR(int entier) : m_Numerator(entier), m_Denominator(1) {}
|
||||||
|
|
||||||
NR(int numerator, int denominator) : m_Numerator(numerator), m_Denominator(denominator) {}
|
NR(int numerator, int denominator) : m_Numerator(numerator), m_Denominator(denominator) {}
|
||||||
};
|
};
|
||||||
@@ -29,7 +29,7 @@ VectAffine Solver::SystemeTriangulaire() const {
|
|||||||
Matrix mat = m_Matrix;
|
Matrix mat = m_Matrix;
|
||||||
mat.GaussJordan(true);
|
mat.GaussJordan(true);
|
||||||
|
|
||||||
Solver solver{mat.SubMatrix(0, 0, mat.GetRawCount(), mat.GetColumnCount() - 1)};
|
Solver solver {mat.SubMatrix(0, 0, mat.GetRawCount(), mat.GetColumnCount() - 1)};
|
||||||
|
|
||||||
Vect noyau = solver.Noyau();
|
Vect noyau = solver.Noyau();
|
||||||
Matrix origin = mat.SubMatrix(0, mat.GetColumnCount() - 1, mat.GetRawCount(), 1);
|
Matrix origin = mat.SubMatrix(0, mat.GetColumnCount() - 1, mat.GetRawCount(), 1);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class Solver {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Solver(const Matrix& mat);
|
Solver(const Matrix& mat);
|
||||||
|
|
||||||
~Solver() {}
|
~Solver() {}
|
||||||
|
|
||||||
Vect Image() const;
|
Vect Image() const;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ Matrix Vect::GetLinearSystem() const {
|
|||||||
Matrix vect = m_Data;
|
Matrix vect = m_Data;
|
||||||
vect.Transpose();
|
vect.Transpose();
|
||||||
|
|
||||||
Solver solver{vect};
|
Solver solver {vect};
|
||||||
vect = solver.Noyau().m_Data;
|
vect = solver.Noyau().m_Data;
|
||||||
vect.Transpose();
|
vect.Transpose();
|
||||||
return vect;
|
return vect;
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ class Vect {
|
|||||||
void Simplify();
|
void Simplify();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class VectAffine {
|
class VectAffine {
|
||||||
private:
|
private:
|
||||||
Vect m_Base;
|
Vect m_Base;
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ void test() {
|
|||||||
mat.Print();
|
mat.Print();
|
||||||
// mat.Save("matrice4x4echelonne.mat"); */
|
// mat.Save("matrice4x4echelonne.mat"); */
|
||||||
|
|
||||||
Matrix mat2{"matrice4x4.mat"};
|
Matrix mat2 {"matrice4x4.mat"};
|
||||||
mat2.Print();
|
mat2.Print();
|
||||||
|
|
||||||
Solver solver{mat2};
|
Solver solver {mat2};
|
||||||
|
|
||||||
Vect image = solver.Image();
|
Vect image = solver.Image();
|
||||||
Vect noyau = solver.Noyau();
|
Vect noyau = solver.Noyau();
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
#error "Il faut être en debug mode ! xmake f -m debug"
|
#error "Il faut être en debug mode ! xmake f -m debug"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct Test{
|
struct Test {
|
||||||
Matrix mat;
|
Matrix mat;
|
||||||
Matrix res;
|
Matrix res;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::vector<Test> TEST_MATRICES = {
|
static const std::vector<Test> TEST_MATRICES = {
|
||||||
@@ -35,9 +35,9 @@ static const std::vector<Test> TEST_MATRICES = {
|
|||||||
|
|
||||||
void test() {
|
void test() {
|
||||||
for (Test test : TEST_MATRICES) {
|
for (Test test : TEST_MATRICES) {
|
||||||
test.mat.GaussJordan(true);
|
test.mat.GaussJordan(true);
|
||||||
assert(test.mat == test.res);
|
assert(test.mat == test.res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|||||||
@@ -14,15 +14,15 @@ int main() {
|
|||||||
|
|
||||||
std::cout << "Opening " << fileName << " ...\n";
|
std::cout << "Opening " << fileName << " ...\n";
|
||||||
|
|
||||||
std::ifstream in{fileName};
|
std::ifstream in {fileName};
|
||||||
|
|
||||||
Matrix mat{1, 1}, imageMat{1, 1}, noyauMat{1, 1};
|
Matrix mat {1, 1}, imageMat {1, 1}, noyauMat {1, 1};
|
||||||
in >> mat >> imageMat >> noyauMat;
|
in >> mat >> imageMat >> noyauMat;
|
||||||
|
|
||||||
Vect image{imageMat};
|
Vect image {imageMat};
|
||||||
Vect noyau{noyauMat};
|
Vect noyau {noyauMat};
|
||||||
|
|
||||||
Solver solver{mat};
|
Solver solver {mat};
|
||||||
|
|
||||||
assert(solver.Image() == image);
|
assert(solver.Image() == image);
|
||||||
assert(solver.Noyau() == noyau);
|
assert(solver.Noyau() == noyau);
|
||||||
|
|||||||
Reference in New Issue
Block a user