parent
87d4bc0585
commit
c8fb0f476c
6 changed files with 220 additions and 69 deletions
146
test/unit/map/strides.cpp
Normal file
146
test/unit/map/strides.cpp
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/rotgen.hpp>
|
||||
#include <vector>
|
||||
#include <Eigen/Core>
|
||||
|
||||
auto generate_data(int rows, int cols)
|
||||
{
|
||||
std::vector<float> buffer(rows * cols * 3);
|
||||
|
||||
for (size_t i = 0; i < buffer.size(); ++i)
|
||||
buffer[i] = static_cast<float>(1+i);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
template<int O>
|
||||
using r_mat_t = rotgen::matrix<float,rotgen::Dynamic,rotgen::Dynamic,O>;
|
||||
|
||||
template<int O>
|
||||
using e_mat_t = Eigen::Matrix<float,Eigen::Dynamic,Eigen::Dynamic,O>;
|
||||
|
||||
template<typename M, typename S = rotgen::stride> using r_map_t = rotgen::map<M,0,S>;
|
||||
template<typename M, typename S = Eigen::Stride<0,0>> using e_map_t = Eigen::Map<M,0,S>;
|
||||
|
||||
TTS_CASE("Validate Column Major Map with regular stride behavior")
|
||||
{
|
||||
auto rows = 3;
|
||||
auto cols = 4;
|
||||
auto buffer = generate_data(rows,cols);
|
||||
|
||||
r_map_t<r_mat_t<rotgen::ColMajor>> r_map(buffer.data(), rows, cols);
|
||||
|
||||
TTS_EQUAL(r_map.innerStride(), 1);
|
||||
TTS_EQUAL(r_map.outerStride(), 3);
|
||||
|
||||
e_map_t<e_mat_t<Eigen::ColMajor>> e_map(buffer.data(), rows, cols);
|
||||
|
||||
for(std::ptrdiff_t r=0;r<rows;r++)
|
||||
for(std::ptrdiff_t c=0;c<cols;c++)
|
||||
TTS_EQUAL(r_map(r,c), e_map(r,c));
|
||||
};
|
||||
|
||||
TTS_CASE("Validate Column Major Map with specific outer stride behavior")
|
||||
{
|
||||
auto rows = 3;
|
||||
auto cols = 4;
|
||||
auto buffer = generate_data(rows,cols);
|
||||
|
||||
r_map_t<r_mat_t<rotgen::ColMajor>, rotgen::outer_stride<>>
|
||||
r_map(buffer.data(), rows, cols, rotgen::outer_stride(rows + 1));
|
||||
|
||||
TTS_EQUAL(r_map.innerStride(), 1);
|
||||
TTS_EQUAL(r_map.outerStride() , 4);
|
||||
|
||||
e_map_t<e_mat_t<Eigen::ColMajor>, Eigen::OuterStride<>>
|
||||
e_map(buffer.data(), rows, cols, Eigen::OuterStride<>(rows + 1));
|
||||
|
||||
for(std::ptrdiff_t r=0;r<rows;r++)
|
||||
for(std::ptrdiff_t c=0;c<cols;c++)
|
||||
TTS_EQUAL(r_map(r,c), e_map(r,c));
|
||||
};
|
||||
|
||||
TTS_CASE("Validate Column Major Map with specific inner stride behavior")
|
||||
{
|
||||
auto rows = 3;
|
||||
auto cols = 4;
|
||||
auto buffer = generate_data(rows,cols);
|
||||
|
||||
r_map_t<r_mat_t<rotgen::ColMajor>>
|
||||
r_map(buffer.data(), rows, cols, rotgen::stride(rows, 2));
|
||||
|
||||
TTS_EQUAL(r_map.innerStride(), 2);
|
||||
TTS_EQUAL(r_map.outerStride() , 3);
|
||||
|
||||
e_map_t<e_mat_t<Eigen::ColMajor>,Eigen::Stride<Eigen::Dynamic,Eigen::Dynamic>>
|
||||
e_map(buffer.data(), rows, cols, Eigen::Stride<Eigen::Dynamic,Eigen::Dynamic>(rows,2));
|
||||
|
||||
for(std::ptrdiff_t r=0;r<rows;r++)
|
||||
for(std::ptrdiff_t c=0;c<cols;c++)
|
||||
TTS_EQUAL(r_map(r,c), e_map(r,c));
|
||||
};
|
||||
|
||||
TTS_CASE("Validate Row Major Map with regular stride behavior")
|
||||
{
|
||||
auto rows = 3;
|
||||
auto cols = 4;
|
||||
auto buffer = generate_data(rows,cols);
|
||||
|
||||
r_map_t<r_mat_t<rotgen::RowMajor>> r_map(buffer.data(), rows, cols);
|
||||
|
||||
TTS_EQUAL(r_map.innerStride(), 1);
|
||||
TTS_EQUAL(r_map.outerStride(), 4);
|
||||
|
||||
e_map_t<e_mat_t<Eigen::RowMajor>> e_map(buffer.data(), rows, cols);
|
||||
|
||||
for(std::ptrdiff_t r=0;r<rows;r++)
|
||||
for(std::ptrdiff_t c=0;c<cols;c++)
|
||||
TTS_EQUAL(r_map(r,c), e_map(r,c));
|
||||
};
|
||||
|
||||
TTS_CASE("Validate Row Major Map with specific outer stride behavior")
|
||||
{
|
||||
auto rows = 3;
|
||||
auto cols = 4;
|
||||
auto buffer = generate_data(rows,cols);
|
||||
|
||||
r_map_t<r_mat_t<rotgen::RowMajor>, rotgen::outer_stride<>>
|
||||
r_map(buffer.data(), rows, cols, rotgen::outer_stride(cols + 1));
|
||||
|
||||
TTS_EQUAL(r_map.innerStride(), 1);
|
||||
TTS_EQUAL(r_map.outerStride() , 5);
|
||||
|
||||
e_map_t<e_mat_t<Eigen::RowMajor>, Eigen::OuterStride<>>
|
||||
e_map(buffer.data(), rows, cols, Eigen::OuterStride<>(cols + 1));
|
||||
|
||||
for(std::ptrdiff_t r=0;r<rows;r++)
|
||||
for(std::ptrdiff_t c=0;c<cols;c++)
|
||||
TTS_EQUAL(r_map(r,c), e_map(r,c));
|
||||
};
|
||||
|
||||
TTS_CASE("Validate Row Major Map with specific inner stride behavior")
|
||||
{
|
||||
auto rows = 3;
|
||||
auto cols = 4;
|
||||
auto buffer = generate_data(rows,cols);
|
||||
|
||||
r_map_t<r_mat_t<rotgen::RowMajor>,rotgen::stride>
|
||||
r_map(buffer.data(), rows, cols, rotgen::stride(2, cols));
|
||||
|
||||
TTS_EQUAL(r_map.innerStride(), 4);
|
||||
TTS_EQUAL(r_map.outerStride() , 2);
|
||||
|
||||
e_map_t<e_mat_t<Eigen::RowMajor>,Eigen::Stride<Eigen::Dynamic,Eigen::Dynamic>>
|
||||
e_map(buffer.data(), rows, cols, Eigen::Stride<Eigen::Dynamic,Eigen::Dynamic>(2,cols));
|
||||
|
||||
for(std::ptrdiff_t r=0;r<rows;r++)
|
||||
for(std::ptrdiff_t c=0;c<cols;c++)
|
||||
TTS_EQUAL(r_map(r,c), e_map(r,c));
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue