caca
All checks were successful
Linux arm64 / Build (push) Successful in 41m33s

This commit is contained in:
2024-05-14 19:00:04 +02:00
parent a135df2e96
commit 8c004b64ed
13 changed files with 2512 additions and 26 deletions

View File

@@ -2,6 +2,12 @@
#include "Matrix.h"
#include "test_assert.h"
#include <chrono>
#include <iostream>
static constexpr int MATRIX_MAX_SIZE = 300;
static constexpr int EXECUTION_COUNT = 1;
struct Test {
Matrix mat;
Matrix res;
@@ -30,6 +36,22 @@ static const std::vector<Test> TEST_MATRICES = {
}}}
};
static unsigned int GetRandomInt() {
return rand() % MATRIX_MAX_SIZE + 1;
}
static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
Matrix matrix {a_Raw, a_Column};
for (std::size_t i = 0; i < matrix.GetRawCount(); i++) {
for (std::size_t j = 0; j < matrix.GetColumnCount(); j++) {
matrix.at(i, j) = GetRandomInt();
}
}
return matrix;
}
void test() {
for (Test test : TEST_MATRICES) {
Gauss::GaussJordan(test.mat, true, true);
@@ -37,7 +59,26 @@ void test() {
}
}
void gaussTest() {
auto start = std::chrono::system_clock::now();
for (int i = 0; i < EXECUTION_COUNT; i++) {
Matrix mat = GetRandomMatrix(500, 500);
Gauss::GaussJordan(mat, false, false);
}
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
std::cout << "\tgauss jordan elapsed time : " << elapsed_seconds.count() << "s" << std::endl;
}
void speedTest() {
gaussTest();
// gaussColumnTest();
}
int main(int argc, char** argv) {
test();
speedTest();
return 0;
}

109
test/test_plot.cpp Normal file
View File

@@ -0,0 +1,109 @@
#include <algorithm>
#include <chrono>
#include <cmath>
#include <execution>
#include <future>
#include <matplot/matplot.h>
#include "Gauss.h"
#include "Matrix.h"
#include "Solver.h"
static constexpr int EXECUTION_COUNT = 100;
static constexpr int MATRIX_MAX_SIZE = 300;
static unsigned int GetRandomInt() {
return rand() % MATRIX_MAX_SIZE + 1;
}
static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
Matrix matrix {a_Raw, a_Column};
for (std::size_t i = 0; i < matrix.GetRawCount(); i++) {
for (std::size_t j = 0; j < matrix.GetColumnCount(); j++) {
matrix.at(i, j) = GetRandomInt();
}
}
return matrix;
}
std::vector<double> GaussJordan(const std::vector<double>& x) {
std::vector<double> y;
std::for_each(x.begin(), x.end(), [&y](double size) {
auto start = std::chrono::system_clock::now();
for (int j = 0; j < EXECUTION_COUNT; j++) {
Matrix mat = GetRandomMatrix(size, size);
Gauss::GaussJordan(mat, false, false);
}
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
std::cout << "S " << size << "\n";
y.push_back(elapsed_seconds.count() / static_cast<double>(EXECUTION_COUNT));
});
return y;
}
std::vector<double> GaussJordanReduite(const std::vector<double>& x) {
std::vector<double> y;
std::for_each(x.begin(), x.end(), [&y](double size) {
auto start = std::chrono::system_clock::now();
for (int j = 0; j < EXECUTION_COUNT; j++) {
Matrix mat = GetRandomMatrix(size, size);
Gauss::GaussJordan(mat, true, false);
}
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
std::cout << "R " << size << "\n";
y.push_back(elapsed_seconds.count() / static_cast<double>(EXECUTION_COUNT));
});
return y;
}
int main() {
srand(time(0));
int start = 1;
std::vector<double> x = matplot::linspace(start, MATRIX_MAX_SIZE, MATRIX_MAX_SIZE - start + 1);
//std::vector<double> x = {5000};
std::vector<double> y, y1, y2, y3;
// y2.resize(x.size());
{
auto result1 = std::async(std::launch::async, &GaussJordan, x);
auto result2 = std::async(std::launch::async, &GaussJordanReduite, x);
y = result1.get();
y1 = result2.get();
}
std::cout << "Fini !\n";
// std::transform(x.begin(), x.end(), y2.begin(), [](double x) { return 1.0 / (100.0 * 100.0) * 0.6 * x * x; });
matplot::title("Echelonnage de matrices");
matplot::xlabel("Taille des matrices");
matplot::ylabel("Temps d'exécution (s)");
matplot::hold(matplot::on);
matplot::plot(x, y);
matplot::plot(x, y1);
auto l = matplot::legend({"Echelonnage non réduit", "Echelonnage réduit", "Echelonnage non réduit normalisé", "Echelonnage réduit normalisé"});
l->location(matplot::legend::general_alignment::topleft);
matplot::show();
return 0;
}

View File

@@ -16,6 +16,16 @@ static int GetRandomInt() {
return rand() % 11 - 5;
}
#define print_time(i) \
end = std::chrono::system_clock::now(); \
elapsed_seconds = end - start; \
std::cout << "elapsed time " << i << " : " << elapsed_seconds.count() << "s" << std::endl; \
start = std::chrono::system_clock::now()
static unsigned int GetRandomSize() {
return rand() % MATRIX_MAX_SIZE + 1;
}
static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
Matrix matrix {a_Raw, a_Column};
@@ -29,34 +39,57 @@ static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
}
static bool Test() {
Matrix matrix = GetRandomMatrix(rand() % MATRIX_MAX_SIZE + 1, rand() % MATRIX_MAX_SIZE + 1);
auto start = std::chrono::system_clock::now();
auto begin = start;
auto end = start;
std::chrono::duration<double> elapsed_seconds = end - start;
for (std::size_t i = 0; i < matrix.GetRawCount(); i++) {
for (std::size_t j = 0; j < matrix.GetColumnCount(); j++) {
matrix.at(i, j) = GetRandomInt();
}
}
std::cout << "Begin\n";
Matrix matrix = GetRandomMatrix(GetRandomSize(), GetRandomSize());
print_time(1);
Matrix copy = matrix;
Vect kernel = solver.Kernel(std::move(copy));
print_time(2);
Matrix nullVector {matrix.GetRawCount(), 1};
nullVector.Fill(0.0);
for (std::size_t i = 0; i < kernel.GetCardinal(); i++) {
test_assert(matrix * kernel.GetVector(i) == nullVector);
Matrix result = matrix * kernel.GetVector(i);
if(!(result == nullVector)) {
test_assert(false);
}
}
print_time(3);
for (std::size_t i = 0; i < KERNEL_CHECKS; i++) {
Matrix vector = GetRandomMatrix(kernel.GetDimension(), 1);
test_assert(kernel.IsElementOf(vector) == (matrix * vector == nullVector));
}
Vect kernel2 = solver.Kernel(kernel.GetLinearSystem());
print_time(4);
Matrix linearSystem = kernel.GetLinearSystem();
print_time(5);
Vect kernel2 = solver.Kernel(std::move(linearSystem));
test_assert(kernel == kernel2);
print_time(6);
elapsed_seconds = end - begin;
std::cout << "final elapsed time: " << elapsed_seconds.count() << "s" << std::endl;
std::cout << "End\n";
return true;
}
@@ -69,6 +102,7 @@ int main() {
for (int i = 0; i < EXECUTION_COUNT; i++) {
auto handle = std::async(std::launch::async, &Test);
results.push_back(std::move(handle));
// Test();
}
for (auto& result : results) {