Fix a lot of ref issues reagrding extarction, rvalueness and proper use of temporary memory.
This commit is contained in:
parent
d5c41bf43e
commit
379d77ebef
50 changed files with 2945 additions and 1397 deletions
|
|
@ -5,12 +5,13 @@
|
|||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
TTS_CASE_TPL("Chains of extraction",
|
||||
rotgen::tests::types)<typename T, typename O>(
|
||||
tts::type<tts::types<T, O>>)
|
||||
#include "unit/tests.hpp"
|
||||
|
||||
TTS_CASE_TPL("Chains of extraction", rotgen::tests::types)
|
||||
|
||||
<typename T, typename O>(tts::type<tts::types<T, O>>)
|
||||
{
|
||||
constexpr int N = 8;
|
||||
auto a = rotgen::matrix<T, N, N, O::value>::Random();
|
||||
|
|
@ -44,6 +45,9 @@ TTS_CASE_TPL("Chains of extraction",
|
|||
setConstant(bbbb, 0.125);
|
||||
|
||||
TTS_EQUAL(a(3, 3), 0.125);
|
||||
|
||||
bool verbose = ::tts::arguments()[{"--verbose"}];
|
||||
if (verbose) std::cout << a << "\n\n";
|
||||
};
|
||||
|
||||
auto ref_extract(rotgen::ref<rotgen::matrix<float>> m)
|
||||
|
|
@ -66,9 +70,10 @@ TTS_CASE("Extraction of ref/ref const")
|
|||
for (rotgen::Index r = 0; r < 3; r++)
|
||||
for (rotgen::Index c = 0; c < 4; c++) TTS_EQUAL(m(r, c), 1.f);
|
||||
|
||||
auto sliced = ref_cextract(m);
|
||||
rotgen::extract(m, 3, 4, 4, 3) =
|
||||
rotgen::setConstant<rotgen::matrix<float, 4, 3>>(5);
|
||||
auto sliced = ref_cextract(m);
|
||||
|
||||
for (rotgen::Index r = 0; r < 4; r++)
|
||||
for (rotgen::Index c = 0; c < 3; c++) TTS_EQUAL(sliced(r, c), 5.f);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@
|
|||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
#include "unit/tests.hpp"
|
||||
#include <iostream>
|
||||
|
||||
TTS_CASE_TPL("outer_stride<0> interactions",
|
||||
|
|
@ -54,49 +55,3 @@ TTS_CASE_TPL("outer_stride<0> interactions",
|
|||
TTS_EQUAL(dp, sp);
|
||||
}
|
||||
};
|
||||
|
||||
void process_ref(rotgen::ref<rotgen::matrix<float> const>) {}
|
||||
|
||||
void process_ref(rotgen::ref<rotgen::matrix<double> const>) {}
|
||||
|
||||
void process_ref(
|
||||
rotgen::ref<
|
||||
rotgen::
|
||||
matrix<float, rotgen::Dynamic, rotgen::Dynamic, rotgen::RowMajor> const>)
|
||||
{
|
||||
}
|
||||
|
||||
void process_ref(
|
||||
rotgen::ref<
|
||||
rotgen::
|
||||
matrix<double, rotgen::Dynamic, rotgen::Dynamic, rotgen::RowMajor> const>)
|
||||
{
|
||||
}
|
||||
|
||||
TTS_CASE_TPL("Extraction of outer_stride<?> blocks",
|
||||
rotgen::tests::types)<typename T, typename O>(
|
||||
tts::type<tts::types<T, O>>)
|
||||
{
|
||||
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
|
||||
|
||||
if constexpr (O::value == rotgen::ColMajor)
|
||||
{
|
||||
T padded[] = {1, 2, 3, 4, 99, 5, 6, 7, 8, 99, 9, 10, 11, 12};
|
||||
rotgen::map<mat_t, 0, rotgen::outer_stride<5>> sp(&padded[0], 4, 3);
|
||||
rotgen::map<mat_t, 0, rotgen::outer_stride<>> dp(&padded[0], 4, 3,
|
||||
rotgen::outer_stride(5));
|
||||
|
||||
TTS_EXPECT_COMPILES(sp, { process_ref(extract(sp, 0, 0, 3, 2)); });
|
||||
TTS_EXPECT_COMPILES(dp, { process_ref(extract(dp, 0, 0, 3, 2)); });
|
||||
}
|
||||
else
|
||||
{
|
||||
T padded[] = {1, 2, 3, 99, 4, 5, 6, 99, 7, 8, 9, 99, 10, 11, 12};
|
||||
rotgen::map<mat_t, 0, rotgen::outer_stride<4>> sp(&padded[0], 4, 3);
|
||||
rotgen::map<mat_t, 0, rotgen::outer_stride<>> dp(&padded[0], 4, 3,
|
||||
rotgen::outer_stride(4));
|
||||
|
||||
TTS_EXPECT_COMPILES(sp, { process_ref(extract(sp, 0, 0, 3, 2)); });
|
||||
TTS_EXPECT_COMPILES(dp, { process_ref(extract(dp, 0, 0, 3, 2)); });
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@
|
|||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
#include "unit/tests.hpp"
|
||||
|
||||
template<int size = rotgen::Dynamic,
|
||||
typename Scalar = float,
|
||||
int maxSize = size>
|
||||
|
|
@ -63,3 +64,34 @@ TTS_CASE("Reference of reference check")
|
|||
TTS_EQUAL(v2[0], sum2);
|
||||
TTS_EQUAL(v3[0], sum3);
|
||||
};
|
||||
|
||||
int f(rotgen::ref<rotgen::matrix<float, 1, 3, rotgen::RowMajor>>)
|
||||
{
|
||||
return +2;
|
||||
}
|
||||
|
||||
template<int N>
|
||||
int g(rotgen::ref<rotgen::matrix<float, -1, N, rotgen::ColMajor>>)
|
||||
{
|
||||
return +1;
|
||||
}
|
||||
|
||||
template<int N>
|
||||
int g(rotgen::ref<rotgen::matrix<float, -1, N, rotgen::RowMajor>>)
|
||||
requires(N > 1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
TTS_CASE("Reference overload on stroage order check")
|
||||
{
|
||||
rotgen::matrix<float> mat_dyn(1, 3);
|
||||
rotgen::matrix<float, -1, 3, rotgen::ColMajor> mat_col(1, 3);
|
||||
rotgen::matrix<float, -1, 3, rotgen::RowMajor> mat_row(1, 3);
|
||||
|
||||
TTS_EQUAL(f(mat_dyn), +2);
|
||||
|
||||
TTS_EQUAL(g<3>(mat_dyn), +1);
|
||||
TTS_EQUAL(g<3>(mat_col), +1);
|
||||
TTS_EQUAL(g<3>(mat_row), -1);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue