Implement fixed size options for rotgen containers
See merge request oss/rotgen!11
This commit is contained in:
parent
8e545dd51a
commit
2084874b1b
39 changed files with 1247 additions and 323 deletions
|
|
@ -6,18 +6,18 @@
|
|||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/matrix.hpp>
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
template <typename MatrixType>
|
||||
void test_matrix_operations(std::size_t rows, std::size_t cols, auto a_init_fn, auto b_init_fn, auto ops, auto self_ops)
|
||||
void test_matrix_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto b_init_fn, auto ops, auto self_ops)
|
||||
{
|
||||
MatrixType a(rows, cols);
|
||||
MatrixType b(rows, cols);
|
||||
MatrixType ref(rows, cols);
|
||||
|
||||
for (std::size_t r = 0; r < rows; ++r)
|
||||
for (rotgen::Index r = 0; r < rows; ++r)
|
||||
{
|
||||
for (std::size_t c = 0; c < cols; ++c)
|
||||
for (rotgen::Index c = 0; c < cols; ++c)
|
||||
{
|
||||
a(r,c) = a_init_fn(r, c);
|
||||
b(r,c) = b_init_fn(r, c);
|
||||
|
|
@ -28,17 +28,20 @@ void test_matrix_operations(std::size_t rows, std::size_t cols, auto a_init_fn,
|
|||
TTS_EQUAL(ops(a, b), ref);
|
||||
self_ops(a,b);
|
||||
TTS_EQUAL(a, ref);
|
||||
|
||||
TTS_EXPECT(verify_rotgen_reentrance(ops(a, b)));
|
||||
TTS_EXPECT(verify_rotgen_reentrance(self_ops(a, b)));
|
||||
}
|
||||
|
||||
template <typename MatrixType>
|
||||
void test_scalar_operations(std::size_t rows, std::size_t cols, auto a_init_fn, auto s, auto ops, auto self_ops)
|
||||
void test_scalar_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto s, auto ops, auto self_ops)
|
||||
{
|
||||
MatrixType a(rows, cols);
|
||||
MatrixType ref(rows, cols);
|
||||
|
||||
for (std::size_t r = 0; r < rows; ++r)
|
||||
for (rotgen::Index r = 0; r < rows; ++r)
|
||||
{
|
||||
for (std::size_t c = 0; c < cols; ++c)
|
||||
for (rotgen::Index c = 0; c < cols; ++c)
|
||||
{
|
||||
a(r,c) = a_init_fn(r, c);
|
||||
ref(r, c) = ops(a(r,c),s);
|
||||
|
|
@ -48,17 +51,20 @@ void test_scalar_operations(std::size_t rows, std::size_t cols, auto a_init_fn,
|
|||
TTS_EQUAL(ops(a, s), ref);
|
||||
self_ops(a,s);
|
||||
TTS_EQUAL(a, ref);
|
||||
|
||||
TTS_EXPECT(verify_rotgen_reentrance(ops(a, s)));
|
||||
TTS_EXPECT(verify_rotgen_reentrance(self_ops(a, s)));
|
||||
}
|
||||
|
||||
template <typename MatrixType>
|
||||
void test_scalar_multiplications(std::size_t rows, std::size_t cols, auto fn, auto s)
|
||||
void test_scalar_multiplications(rotgen::Index rows, rotgen::Index cols, auto fn, auto s)
|
||||
{
|
||||
MatrixType a(rows, cols);
|
||||
MatrixType ref(rows, cols);
|
||||
|
||||
for (std::size_t r = 0; r < rows; ++r)
|
||||
for (rotgen::Index r = 0; r < rows; ++r)
|
||||
{
|
||||
for (std::size_t c = 0; c < cols; ++c)
|
||||
for (rotgen::Index c = 0; c < cols; ++c)
|
||||
{
|
||||
a(r,c) = fn(r, c);
|
||||
ref(r, c) = a(r,c) * s;
|
||||
|
|
@ -69,34 +75,39 @@ void test_scalar_multiplications(std::size_t rows, std::size_t cols, auto fn, au
|
|||
TTS_EQUAL(s * a, ref);
|
||||
a *= s;
|
||||
TTS_EQUAL(a, ref);
|
||||
|
||||
TTS_EXPECT(verify_rotgen_reentrance(a*s));
|
||||
TTS_EXPECT(verify_rotgen_reentrance(s*a));
|
||||
TTS_EXPECT(verify_rotgen_reentrance(a*=s));
|
||||
}
|
||||
|
||||
template <typename MatrixType>
|
||||
void test_matrix_multiplication(std::size_t rows, std::size_t cols, auto a_init_fn, auto b_init_fn)
|
||||
void test_matrix_multiplication(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto b_init_fn)
|
||||
{
|
||||
MatrixType a(rows, cols);
|
||||
MatrixType b(cols, rows);
|
||||
MatrixType ref(rows, rows);
|
||||
|
||||
for (std::size_t r = 0; r < a.rows(); ++r)
|
||||
for (std::size_t c = 0; c < a.cols(); ++c)
|
||||
for (rotgen::Index r = 0; r < a.rows(); ++r)
|
||||
for (rotgen::Index c = 0; c < a.cols(); ++c)
|
||||
a(r,c) = a_init_fn(r, c);
|
||||
|
||||
for (std::size_t r = 0; r < b.rows(); ++r)
|
||||
for (std::size_t c = 0; c < b.cols(); ++c)
|
||||
for (rotgen::Index r = 0; r < b.rows(); ++r)
|
||||
for (rotgen::Index c = 0; c < b.cols(); ++c)
|
||||
b(r,c) = b_init_fn(r, c);
|
||||
|
||||
for (std::size_t i = 0; i < a.rows(); ++i)
|
||||
for (rotgen::Index i = 0; i < a.rows(); ++i)
|
||||
{
|
||||
for (std::size_t j = 0; j < b.cols(); ++j)
|
||||
for (rotgen::Index j = 0; j < b.cols(); ++j)
|
||||
{
|
||||
ref(i, j) = 0;
|
||||
for (std::size_t k = 0; k < a.cols(); ++k)
|
||||
for (rotgen::Index k = 0; k < a.cols(); ++k)
|
||||
ref(i, j) += a(i, k) * b(k, j);
|
||||
}
|
||||
}
|
||||
|
||||
TTS_EQUAL(a * b, ref);
|
||||
TTS_EXPECT(verify_rotgen_reentrance(a*b));
|
||||
}
|
||||
|
||||
// Basic initializers
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue