Browse Source

Math: make {un,}pack{Half,}Into() and castInto() assertions clearer.

Say which of the two is non-contiguous, whether the source or the
destination.
pull/582/merge
Vladimír Vondruš 4 years ago
parent
commit
46e6d61803
  1. 36
      src/Magnum/Math/PackingBatch.cpp
  2. 33
      src/Magnum/Math/Test/PackingBatchTest.cpp

36
src/Magnum/Math/PackingBatch.cpp

@ -38,8 +38,10 @@ namespace {
template<class T> inline void unpackUnsignedIntoImplementation(const Corrade::Containers::StridedArrayView2D<const T>& src, const Corrade::Containers::StridedArrayView2D<Float>& dst) {
CORRADE_ASSERT(src.size() == dst.size(),
"Math::unpackInto(): wrong destination size, got" << dst.size() << "but expected" << src.size(), );
CORRADE_ASSERT(src.template isContiguous<1>() && dst.isContiguous<1>(),
"Math::unpackInto(): second view dimension is not contiguous", );
CORRADE_ASSERT(src.template isContiguous<1>(),
"Math::unpackInto(): second source view dimension is not contiguous", );
CORRADE_ASSERT(dst.isContiguous<1>(),
"Math::unpackInto(): second destination view dimension is not contiguous", );
/** @todo SSE/NEON implementations exploiting second dimension size/stride,
contiguity etc */
@ -77,8 +79,10 @@ namespace {
template<class T> inline void unpackSignedIntoImplementation(const Corrade::Containers::StridedArrayView2D<const T>& src, const Corrade::Containers::StridedArrayView2D<Float>& dst) {
CORRADE_ASSERT(src.size() == dst.size(),
"Math::unpackInto(): wrong destination size, got" << dst.size() << "but expected" << src.size(), );
CORRADE_ASSERT(src.template isContiguous<1>() && dst.isContiguous<1>(),
"Math::unpackInto(): second view dimension is not contiguous", );
CORRADE_ASSERT(src.template isContiguous<1>(),
"Math::unpackInto(): second source view dimension is not contiguous", );
CORRADE_ASSERT(dst.isContiguous<1>(),
"Math::unpackInto(): second destination view dimension is not contiguous", );
/** @todo SSE/NEON implementations exploiting second dimension size/stride,
contiguity etc */
@ -119,8 +123,10 @@ namespace {
template<class T> inline void packIntoImplementation(const Corrade::Containers::StridedArrayView2D<const Float>& src, const Corrade::Containers::StridedArrayView2D<T>& dst) {
CORRADE_ASSERT(src.size() == dst.size(),
"Math::packInto(): wrong destination size, got" << dst.size() << "but expected" << src.size(), );
CORRADE_ASSERT(src.isContiguous<1>() && dst.template isContiguous<1>(),
"Math::packInto(): second view dimension is not contiguous", );
CORRADE_ASSERT(src.isContiguous<1>(),
"Math::packInto(): second source view dimension is not contiguous", );
CORRADE_ASSERT(dst.template isContiguous<1>(),
"Math::packInto(): second destination view dimension is not contiguous", );
/** @todo SSE/NEON implementations exploiting second dimension size/stride,
contiguity etc */
@ -167,8 +173,10 @@ namespace {
template<class T, class U> inline void castIntoImplementation(const Corrade::Containers::StridedArrayView2D<const T>& src, const Corrade::Containers::StridedArrayView2D<U>& dst) {
CORRADE_ASSERT(src.size() == dst.size(),
"Math::castInto(): wrong destination size, got" << dst.size() << "but expected" << src.size(), );
CORRADE_ASSERT(src.template isContiguous<1>() && dst.template isContiguous<1>(),
"Math::castInto(): second view dimension is not contiguous", );
CORRADE_ASSERT(src.template isContiguous<1>(),
"Math::castInto(): second source view dimension is not contiguous", );
CORRADE_ASSERT(dst.template isContiguous<1>(),
"Math::castInto(): second destination view dimension is not contiguous", );
/** @todo SSE/NEON implementations exploiting second dimension size/stride,
contiguity etc */
@ -401,8 +409,10 @@ static_assert(sizeof(HalfBaseTable) + sizeof(HalfShiftTable) == 1536,
void unpackHalfInto(const Corrade::Containers::StridedArrayView2D<const UnsignedShort>& src, const Corrade::Containers::StridedArrayView2D<Float>& dst) {
CORRADE_ASSERT(src.size() == dst.size(),
"Math::unpackHalfInto(): wrong destination size, got" << dst.size() << "but expected" << src.size(), );
CORRADE_ASSERT(src.isContiguous<1>() && dst.isContiguous<1>(),
"Math::unpackHalfInto(): second view dimension is not contiguous", );
CORRADE_ASSERT(src.isContiguous<1>(),
"Math::unpackHalfInto(): second source view dimension is not contiguous", );
CORRADE_ASSERT(dst.isContiguous<1>(),
"Math::unpackHalfInto(): second destination view dimension is not contiguous", );
/* Caching values to avoid inline function calls in debug builds */
const char* srcPtr = reinterpret_cast<const char*>(src.data());
@ -426,8 +436,10 @@ void unpackHalfInto(const Corrade::Containers::StridedArrayView2D<const Unsigned
void packHalfInto(const Corrade::Containers::StridedArrayView2D<const Float>& src, const Corrade::Containers::StridedArrayView2D<UnsignedShort>& dst) {
CORRADE_ASSERT(src.size() == dst.size(),
"Math::packHalfInto(): wrong destination size, got" << dst.size() << "but expected" << src.size(), );
CORRADE_ASSERT(src.isContiguous<1>() && dst.isContiguous<1>(),
"Math::packHalfInto(): second view dimension is not contiguous", );
CORRADE_ASSERT(src.isContiguous<1>(),
"Math::packHalfInto(): second source view dimension is not contiguous", );
CORRADE_ASSERT(dst.isContiguous<1>(),
"Math::packHalfInto(): second destination view dimension is not contiguous", );
/* Caching values to avoid inline function calls in debug builds */
const char* srcPtr = reinterpret_cast<const char*>(src.data());

33
src/Magnum/Math/Test/PackingBatchTest.cpp

@ -145,6 +145,7 @@ typedef Math::Vector2<Float> Vector2;
typedef Math::Vector2<UnsignedInt> Vector2ui;
typedef Math::Vector2<Int> Vector2i;
typedef Math::Vector3<Float> Vector3;
typedef Math::Vector4<UnsignedShort> Vector4us;
typedef Math::Vector4<Float> Vector4;
void PackingBatchTest::unpackUnsignedByte() {
@ -641,12 +642,18 @@ template<class T> void PackingBatchTest::assertionsPackUnpack() {
CORRADE_SKIP_IF_NO_ASSERT();
Math::Vector2<T> data[2]{};
Math::Vector4<T> dataNonContiguous[2]{};
Vector2 resultWrongCount[1]{};
Vector2 result[2]{};
Vector3 resultWrongVectorSize[2]{};
Vector4 resultNonContiguous[2]{};
auto src = Corrade::Containers::arrayCast<2, T>(
Corrade::Containers::arrayView(data));
auto srcNonContiguous = Corrade::Containers::arrayCast<2, T>(
Corrade::Containers::arrayView(dataNonContiguous)).every({1, 2});
auto dst = Corrade::Containers::arrayCast<2, Float>(
Corrade::Containers::arrayView(result));
auto dstWrongCount = Corrade::Containers::arrayCast<2, Float>(
Corrade::Containers::arrayView(resultWrongCount));
auto dstWrongVectorSize = Corrade::Containers::arrayCast<2, Float>(
@ -659,28 +666,38 @@ template<class T> void PackingBatchTest::assertionsPackUnpack() {
unpackInto(src, dstWrongCount);
unpackInto(src, dstWrongVectorSize);
unpackInto(src, dstNotContiguous);
unpackInto(srcNonContiguous, dst);
packInto(dstWrongCount, src);
packInto(dstWrongVectorSize, src);
packInto(dstNotContiguous, src);
packInto(dst, srcNonContiguous);
CORRADE_COMPARE(out.str(),
"Math::unpackInto(): wrong destination size, got {1, 2} but expected {2, 2}\n"
"Math::unpackInto(): wrong destination size, got {2, 3} but expected {2, 2}\n"
"Math::unpackInto(): second view dimension is not contiguous\n"
"Math::unpackInto(): second destination view dimension is not contiguous\n"
"Math::unpackInto(): second source view dimension is not contiguous\n"
"Math::packInto(): wrong destination size, got {2, 2} but expected {1, 2}\n"
"Math::packInto(): wrong destination size, got {2, 2} but expected {2, 3}\n"
"Math::packInto(): second view dimension is not contiguous\n");
"Math::packInto(): second source view dimension is not contiguous\n"
"Math::packInto(): second destination view dimension is not contiguous\n");
}
void PackingBatchTest::assertionsPackUnpackHalf() {
CORRADE_SKIP_IF_NO_ASSERT();
Vector2us data[2]{};
Vector4us dataNonContiguous[2]{};
Vector2 result[2]{};
Vector2 resultWrongCount[1]{};
Vector3 resultWrongVectorSize[2]{};
Vector4 resultNonContiguous[2]{};
auto src = Corrade::Containers::arrayCast<2, UnsignedShort>(
Corrade::Containers::arrayView(data));
auto srcNonContiguous = Corrade::Containers::arrayCast<2, UnsignedShort>(
Corrade::Containers::arrayView(dataNonContiguous)).every({1, 2});
auto dst = Corrade::Containers::arrayCast<2, Float>(
Corrade::Containers::arrayView(result));
auto dstWrongCount = Corrade::Containers::arrayCast<2, Float>(
Corrade::Containers::arrayView(resultWrongCount));
auto dstWrongVectorSize = Corrade::Containers::arrayCast<2, Float>(
@ -693,16 +710,20 @@ void PackingBatchTest::assertionsPackUnpackHalf() {
unpackHalfInto(src, dstWrongCount);
unpackHalfInto(src, dstWrongVectorSize);
unpackHalfInto(src, dstNotContiguous);
unpackHalfInto(srcNonContiguous, dst);
packHalfInto(dstWrongCount, src);
packHalfInto(dstWrongVectorSize, src);
packHalfInto(dstNotContiguous, src);
packHalfInto(dst, srcNonContiguous);
CORRADE_COMPARE(out.str(),
"Math::unpackHalfInto(): wrong destination size, got {1, 2} but expected {2, 2}\n"
"Math::unpackHalfInto(): wrong destination size, got {2, 3} but expected {2, 2}\n"
"Math::unpackHalfInto(): second view dimension is not contiguous\n"
"Math::unpackHalfInto(): second destination view dimension is not contiguous\n"
"Math::unpackHalfInto(): second source view dimension is not contiguous\n"
"Math::packHalfInto(): wrong destination size, got {2, 2} but expected {1, 2}\n"
"Math::packHalfInto(): wrong destination size, got {2, 2} but expected {2, 3}\n"
"Math::packHalfInto(): second view dimension is not contiguous\n");
"Math::packHalfInto(): second source view dimension is not contiguous\n"
"Math::packHalfInto(): second destination view dimension is not contiguous\n");
}
template<class U, class T> void PackingBatchTest::assertionsCast() {
@ -735,10 +756,10 @@ template<class U, class T> void PackingBatchTest::assertionsCast() {
CORRADE_COMPARE(out.str(),
"Math::castInto(): wrong destination size, got {1, 2} but expected {2, 2}\n"
"Math::castInto(): wrong destination size, got {2, 3} but expected {2, 2}\n"
"Math::castInto(): second view dimension is not contiguous\n"
"Math::castInto(): second destination view dimension is not contiguous\n"
"Math::castInto(): wrong destination size, got {2, 2} but expected {1, 2}\n"
"Math::castInto(): wrong destination size, got {2, 2} but expected {2, 3}\n"
"Math::castInto(): second view dimension is not contiguous\n");
"Math::castInto(): second source view dimension is not contiguous\n");
}
}}}}

Loading…
Cancel
Save