improve random_kernel test
All checks were successful
Linux arm64 / Build (push) Successful in 1m25s
All checks were successful
Linux arm64 / Build (push) Successful in 1m25s
This commit is contained in:
@@ -72,6 +72,12 @@ class Matrix {
|
||||
*/
|
||||
void Augment(const Matrix& a_Right);
|
||||
|
||||
/**
|
||||
* \brief Affecte tous les coefficients de la matrice à un élément
|
||||
* \param a_Element L'élément à affecter
|
||||
*/
|
||||
void Fill(Element a_Element);
|
||||
|
||||
/**
|
||||
* \brief Retourne la sous-matrice spécifiée
|
||||
* \param a_RawOrigin L'indice de la première ligne de la matrice à récupérer
|
||||
|
||||
@@ -18,10 +18,7 @@ Matrix::Matrix(std::size_t a_Raws, std::size_t a_Columns, std::initializer_list<
|
||||
}
|
||||
|
||||
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 {};
|
||||
}
|
||||
assert(m_Columns == a_Other.m_Raws);
|
||||
|
||||
Matrix result(m_Raws, a_Other.m_Columns);
|
||||
|
||||
@@ -73,6 +70,14 @@ Matrix Matrix::RawVector(std::initializer_list<Element>&& a_Elements) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void Matrix::Fill(Element a_Element) {
|
||||
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||
for (std::size_t j = 0; j < m_Columns; j++) {
|
||||
at(i, j) = a_Element;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Matrix::Augment(const Matrix& a_Right) {
|
||||
assert(a_Right.m_Raws == m_Raws);
|
||||
Matrix temp {m_Raws, m_Columns + a_Right.m_Columns};
|
||||
@@ -121,8 +126,7 @@ Matrix Matrix::operator-(const Matrix& a_Other) const {
|
||||
}
|
||||
|
||||
bool Matrix::operator==(const Matrix& a_Other) const {
|
||||
if (m_Raws != a_Other.m_Raws || m_Columns != a_Other.m_Columns)
|
||||
return false;
|
||||
assert(m_Raws == a_Other.m_Raws && m_Columns == a_Other.m_Columns);
|
||||
|
||||
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||
for (std::size_t j = 0; j < m_Columns; j++) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <vector>
|
||||
|
||||
static constexpr int EXECUTION_COUNT = 100;
|
||||
static constexpr int KERNEL_CHECKS = 100;
|
||||
static constexpr int MATRIX_MAX_SIZE = 100;
|
||||
|
||||
static const Solver solver;
|
||||
@@ -14,8 +15,8 @@ static unsigned int GetRandomInt() {
|
||||
return rand() % MATRIX_MAX_SIZE + 1;
|
||||
}
|
||||
|
||||
static void Test() {
|
||||
Matrix matrix {GetRandomInt(), GetRandomInt()};
|
||||
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++) {
|
||||
@@ -23,10 +24,36 @@ static void Test() {
|
||||
}
|
||||
}
|
||||
|
||||
Vect vect1 = solver.Kernel(matrix);
|
||||
Vect vect2 = solver.Kernel(vect1.GetLinearSystem());
|
||||
return matrix;
|
||||
}
|
||||
|
||||
assert(vect1 == vect2);
|
||||
static void Test() {
|
||||
Matrix matrix = GetRandomMatrix(GetRandomInt(), GetRandomInt());
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Vect kernel = solver.Kernel(matrix);
|
||||
|
||||
Matrix nullVector {matrix.GetRawCount(), 1};
|
||||
nullVector.Fill(0.0);
|
||||
|
||||
for (std::size_t i = 0; i < kernel.GetCardinal(); i++) {
|
||||
assert(matrix * kernel.GetVector(i) == nullVector);
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < KERNEL_CHECKS; i++) {
|
||||
Matrix vector = GetRandomMatrix(kernel.GetDimension(), 1);
|
||||
|
||||
assert(kernel.IsElementOf(vector) == (matrix * vector == nullVector));
|
||||
}
|
||||
|
||||
Vect kernel2 = solver.Kernel(kernel.GetLinearSystem());
|
||||
|
||||
assert(kernel == kernel2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
Reference in New Issue
Block a user