[ARITHMETICS][TESTS] used auto init_fn instead of std::function for the function called to initialize teh matrix
This commit is contained in:
parent
b206f40372
commit
bf343703fa
1 changed files with 10 additions and 12 deletions
|
|
@ -10,8 +10,7 @@
|
||||||
#include "tts.hpp"
|
#include "tts.hpp"
|
||||||
|
|
||||||
template <typename MatrixType>
|
template <typename MatrixType>
|
||||||
void test_matrix_scalar_multiplication(std::size_t rows, std::size_t cols, double scalar,
|
void test_matrix_scalar_multiplication(std::size_t rows, std::size_t cols, double scalar, auto init_fn)
|
||||||
const std::function<void(MatrixType &, std::size_t, std::size_t)>& init_fn)
|
|
||||||
{
|
{
|
||||||
MatrixType a(rows, cols);
|
MatrixType a(rows, cols);
|
||||||
MatrixType ref(rows, cols);
|
MatrixType ref(rows, cols);
|
||||||
|
|
@ -33,8 +32,7 @@ void test_matrix_scalar_multiplication(std::size_t rows, std::size_t cols, doubl
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MatrixType>
|
template <typename MatrixType>
|
||||||
void test_matrix_scalar_division(std::size_t rows, std::size_t cols, double scalar,
|
void test_matrix_scalar_division(std::size_t rows, std::size_t cols, double scalar, auto init_fn)
|
||||||
const std::function<void(MatrixType &, std::size_t, std::size_t)>& init_fn)
|
|
||||||
{
|
{
|
||||||
MatrixType a(rows, cols);
|
MatrixType a(rows, cols);
|
||||||
MatrixType ref(rows, cols);
|
MatrixType ref(rows, cols);
|
||||||
|
|
@ -53,8 +51,8 @@ void test_matrix_scalar_division(std::size_t rows, std::size_t cols, double scal
|
||||||
TTS_EQUAL(a, ref);
|
TTS_EQUAL(a, ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MatrixType, typename InitA, typename InitB>
|
template <typename MatrixType>
|
||||||
void test_matrix_multiplication(std::size_t n, std::size_t m, std::size_t p, InitA&& a_init_fn, InitB&& b_init_fn)
|
void test_matrix_multiplication(std::size_t n, std::size_t m, std::size_t p, auto a_init_fn, auto b_init_fn)
|
||||||
{
|
{
|
||||||
MatrixType a(n, m);
|
MatrixType a(n, m);
|
||||||
MatrixType b(m, p);
|
MatrixType b(m, p);
|
||||||
|
|
@ -81,8 +79,8 @@ void test_matrix_multiplication(std::size_t n, std::size_t m, std::size_t p, Ini
|
||||||
TTS_EQUAL(a, ref);
|
TTS_EQUAL(a, ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MatrixType, typename InitA, typename InitB>
|
template <typename MatrixType>
|
||||||
void test_matrix_addition(std::size_t rows, std::size_t cols, InitA&& a_init_fn, InitB&& b_init_fn)
|
void test_matrix_addition(std::size_t rows, std::size_t cols, auto a_init_fn, auto b_init_fn)
|
||||||
{
|
{
|
||||||
MatrixType a(rows, cols);
|
MatrixType a(rows, cols);
|
||||||
MatrixType b(rows, cols);
|
MatrixType b(rows, cols);
|
||||||
|
|
@ -104,8 +102,8 @@ void test_matrix_addition(std::size_t rows, std::size_t cols, InitA&& a_init_fn,
|
||||||
TTS_EQUAL(a, ref);
|
TTS_EQUAL(a, ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MatrixType, typename InitA, typename InitB>
|
template <typename MatrixType>
|
||||||
void test_matrix_substraction(std::size_t rows, std::size_t cols, InitA&& a_init_fn, InitB&& b_init_fn)
|
void test_matrix_substraction(std::size_t rows, std::size_t cols, auto a_init_fn, auto b_init_fn)
|
||||||
{
|
{
|
||||||
MatrixType a(rows, cols);
|
MatrixType a(rows, cols);
|
||||||
MatrixType b(rows, cols);
|
MatrixType b(rows, cols);
|
||||||
|
|
@ -252,14 +250,14 @@ TTS_CASE("Matrix addition with zero matrix")
|
||||||
[](auto& mat, std::size_t r, std::size_t c) { mat(r, c) = 0; });
|
[](auto& mat, std::size_t r, std::size_t c) { mat(r, c) = 0; });
|
||||||
};
|
};
|
||||||
|
|
||||||
TTS_CASE("Matrix substraction")
|
TTS_CASE("Matrix subtraction")
|
||||||
{
|
{
|
||||||
test_matrix_substraction<rotgen::matrix<double>>(3, 4,
|
test_matrix_substraction<rotgen::matrix<double>>(3, 4,
|
||||||
[](auto& mat, std::size_t r, std::size_t c) { mat(r, c) = 6.78*r - 5.2*c - 0.01; },
|
[](auto& mat, std::size_t r, std::size_t c) { mat(r, c) = 6.78*r - 5.2*c - 0.01; },
|
||||||
[](auto& mat, std::size_t r, std::size_t c) { mat(r, c) = 3.1*r + 33.456*c*c; });
|
[](auto& mat, std::size_t r, std::size_t c) { mat(r, c) = 3.1*r + 33.456*c*c; });
|
||||||
};
|
};
|
||||||
|
|
||||||
TTS_CASE("Matrix substraction with zero matrix")
|
TTS_CASE("Matrix subtraction with zero matrix")
|
||||||
{
|
{
|
||||||
test_matrix_substraction<rotgen::matrix<double>>(3, 4,
|
test_matrix_substraction<rotgen::matrix<double>>(3, 4,
|
||||||
[](auto& mat, std::size_t r, std::size_t c) { mat(r, c) = r + c*c*c*c - 56.6; },
|
[](auto& mat, std::size_t r, std::size_t c) { mat(r, c) = r + c*c*c*c - 56.6; },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue