In-place matrix packing

This commit is contained in:
Pavel Kirienko
2014-07-03 12:56:33 +04:00
parent 4098d8694d
commit 154dcd105c
3 changed files with 123 additions and 0 deletions
@@ -648,6 +648,36 @@ public:
packSquareMatrixImpl<const ScalarType*>(src_row_major);
}
/**
* Fills this array as a packed square matrix in place.
*/
void packSquareMatrix()
{
if (this->size() == MaxSize)
{
ValueType matrix[MaxSize];
for (unsigned i = 0; i < MaxSize; i++)
{
matrix[i] = this->at(i);
}
packSquareMatrix(matrix);
}
else if (this->size() == 0)
{
; // Nothing to do - leave the matrix empty
}
else
{
#if UAVCAN_EXCEPTIONS
throw std::out_of_range("uavcan::Array::packSquareMatrix()");
#else
assert(0);
this->clear();
#endif
}
}
/**
* Fills this array as a packed square matrix from any container that implements the methods begin() and size().
*/
@@ -683,6 +713,21 @@ public:
unpackSquareMatrixImpl<ScalarType*>(dst_row_major);
}
/**
* Reconstructs full matrix in place.
*/
void unpackSquareMatrix()
{
ValueType matrix[MaxSize];
unpackSquareMatrix(matrix);
this->clear();
for (unsigned i = 0; i < MaxSize; i++)
{
this->push_back(matrix[i]);
}
}
/**
* Reconstructs full matrix, result will be saved into container that implements begin() and size().
*/
@@ -147,6 +147,12 @@ template <> struct UAVCAN_EXPORT CompileTimeIntSqrt<36> { enum { Result = 6 }; }
template <> struct UAVCAN_EXPORT CompileTimeIntSqrt<49> { enum { Result = 7 }; };
template <> struct UAVCAN_EXPORT CompileTimeIntSqrt<64> { enum { Result = 8 }; };
template <> struct UAVCAN_EXPORT CompileTimeIntSqrt<81> { enum { Result = 9 }; };
template <> struct UAVCAN_EXPORT CompileTimeIntSqrt<100> { enum { Result = 10 }; };
template <> struct UAVCAN_EXPORT CompileTimeIntSqrt<121> { enum { Result = 11 }; };
template <> struct UAVCAN_EXPORT CompileTimeIntSqrt<144> { enum { Result = 12 }; };
template <> struct UAVCAN_EXPORT CompileTimeIntSqrt<169> { enum { Result = 13 }; };
template <> struct UAVCAN_EXPORT CompileTimeIntSqrt<196> { enum { Result = 14 }; };
template <> struct UAVCAN_EXPORT CompileTimeIntSqrt<256> { enum { Result = 16 }; };
/**
* Replacement for std::copy(..)