Implements unary resize and conservativeResize
See merge request oss/rotgen!25
This commit is contained in:
parent
c6316f9bc9
commit
a864e2cf96
5 changed files with 47 additions and 9 deletions
|
|
@ -94,8 +94,12 @@ namespace rotgen
|
||||||
inline constexpr bool storage_status =
|
inline constexpr bool storage_status =
|
||||||
[]()
|
[]()
|
||||||
{
|
{
|
||||||
// Actual static size
|
// Actual static size - vector 1xN
|
||||||
if(Rows > 0 && Cols > 0) return (Rows*Cols) <= max_static_size;
|
if(Rows == 1 && Cols == -1) return true;
|
||||||
|
// Actual static size - vector Nx1
|
||||||
|
else if(Rows == -1 && Cols == 1) return true;
|
||||||
|
// Actual static size - matrix
|
||||||
|
else if(Rows > 0 && Cols > 0) return (Rows*Cols) <= max_static_size;
|
||||||
// Dynamic size but static Max Size
|
// Dynamic size but static Max Size
|
||||||
else if(MaxRows > 0 && MaxCols > 0) return (MaxRows*MaxCols) <= max_static_size;
|
else if(MaxRows > 0 && MaxCols > 0) return (MaxRows*MaxCols) <= max_static_size;
|
||||||
// Everything dynamic already
|
// Everything dynamic already
|
||||||
|
|
|
||||||
|
|
@ -107,11 +107,23 @@ namespace rotgen
|
||||||
parent::resize(new_rows, new_cols);
|
parent::resize(new_rows, new_cols);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resize(int new_size) requires(IsVectorAtCompileTime && (Rows == -1 || Cols == -1))
|
||||||
|
{
|
||||||
|
if constexpr(Rows == -1) parent::resize(new_size,1);
|
||||||
|
else parent::resize(1,new_size);
|
||||||
|
}
|
||||||
|
|
||||||
void conservativeResize(int new_rows, int new_cols) requires(Rows == -1 && Cols == -1)
|
void conservativeResize(int new_rows, int new_cols) requires(Rows == -1 && Cols == -1)
|
||||||
{
|
{
|
||||||
parent::conservativeResize(new_rows, new_cols);
|
parent::conservativeResize(new_rows, new_cols);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void conservativeResize(int new_size) requires(IsVectorAtCompileTime && (Rows == -1 || Cols == -1))
|
||||||
|
{
|
||||||
|
if constexpr(Rows == -1) parent::conservativeResize(new_size,1);
|
||||||
|
else parent::conservativeResize(1,new_size);
|
||||||
|
}
|
||||||
|
|
||||||
matrix normalized() const requires(IsVectorAtCompileTime)
|
matrix normalized() const requires(IsVectorAtCompileTime)
|
||||||
{
|
{
|
||||||
return matrix(base().normalized());
|
return matrix(base().normalized());
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ namespace rotgen
|
||||||
|
|
||||||
matrix() requires(has_static_storage) {}
|
matrix() requires(has_static_storage) {}
|
||||||
matrix() requires(!has_static_storage) : parent(Rows > 0 ? Rows : 0, Cols > 0 ? Cols : 0){}
|
matrix() requires(!has_static_storage) : parent(Rows > 0 ? Rows : 0, Cols > 0 ? Cols : 0){}
|
||||||
matrix(Index r, Index c) requires(!has_static_storage) : parent(r, c) {}
|
matrix(Index r, Index c) : parent(r, c) {}
|
||||||
|
|
||||||
matrix(const matrix& other) = default;
|
matrix(const matrix& other) = default;
|
||||||
matrix(matrix&& other) = default;
|
matrix(matrix&& other) = default;
|
||||||
|
|
@ -66,7 +66,7 @@ namespace rotgen
|
||||||
{}
|
{}
|
||||||
|
|
||||||
matrix(Index n) requires(IsVectorAtCompileTime && (Rows != 1 || Cols != 1))
|
matrix(Index n) requires(IsVectorAtCompileTime && (Rows != 1 || Cols != 1))
|
||||||
: matrix(Rows != -1 ? 1 : n, Cols != -1 ? 1 : n)
|
: parent(n)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
matrix(Scalar v) requires(Rows == 1 && Cols == 1) : parent
|
matrix(Scalar v) requires(Rows == 1 && Cols == 1) : parent
|
||||||
|
|
@ -210,11 +210,21 @@ namespace rotgen
|
||||||
else return base().cwiseSqrt();
|
else return base().cwiseSqrt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resize(int new_size) requires(IsVectorAtCompileTime && (Rows == -1 || Cols == -1))
|
||||||
|
{
|
||||||
|
parent::resize(new_size);
|
||||||
|
}
|
||||||
|
|
||||||
void resize(int new_rows, int new_cols) requires(Rows == -1 && Cols == -1)
|
void resize(int new_rows, int new_cols) requires(Rows == -1 && Cols == -1)
|
||||||
{
|
{
|
||||||
parent::resize(new_rows, new_cols);
|
parent::resize(new_rows, new_cols);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void conservativeResize(int new_size) requires(IsVectorAtCompileTime && (Rows == -1 || Cols == -1))
|
||||||
|
{
|
||||||
|
parent::conservativeResize(new_size);
|
||||||
|
}
|
||||||
|
|
||||||
void conservativeResize(int new_rows, int new_cols) requires(Rows == -1 && Cols == -1)
|
void conservativeResize(int new_rows, int new_cols) requires(Rows == -1 && Cols == -1)
|
||||||
{
|
{
|
||||||
parent::conservativeResize(new_rows, new_cols);
|
parent::conservativeResize(new_rows, new_cols);
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,12 @@ namespace rotgen
|
||||||
std::size_t cols(concepts::entity auto const& arg) { return arg.cols(); }
|
std::size_t cols(concepts::entity auto const& arg) { return arg.cols(); }
|
||||||
std::size_t size(concepts::entity auto const& arg) { return arg.size(); }
|
std::size_t size(concepts::entity auto const& arg) { return arg.size(); }
|
||||||
|
|
||||||
|
template<concepts::entity E>
|
||||||
|
void resize(E& arg, int sz) requires requires{arg.resize(sz);}
|
||||||
|
{
|
||||||
|
arg.resize(sz);
|
||||||
|
}
|
||||||
|
|
||||||
template<concepts::entity E>
|
template<concepts::entity E>
|
||||||
void resize(E& arg, int new_rows, int new_cols)
|
void resize(E& arg, int new_rows, int new_cols)
|
||||||
requires(E::RowsAtCompileTime == -1 && E::ColsAtCompileTime == -1)
|
requires(E::RowsAtCompileTime == -1 && E::ColsAtCompileTime == -1)
|
||||||
|
|
@ -20,6 +26,12 @@ namespace rotgen
|
||||||
arg.resize(new_rows, new_cols);
|
arg.resize(new_rows, new_cols);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<concepts::entity E>
|
||||||
|
void conservativeResize(E& arg, int sz) requires requires{arg.conservativeResize(sz);}
|
||||||
|
{
|
||||||
|
arg.conservativeResize(sz);
|
||||||
|
}
|
||||||
|
|
||||||
template<concepts::entity E>
|
template<concepts::entity E>
|
||||||
void conservativeResize(E& arg, int new_rows, int new_cols)
|
void conservativeResize(E& arg, int new_rows, int new_cols)
|
||||||
requires(E::RowsAtCompileTime == -1 && E::ColsAtCompileTime == -1)
|
requires(E::RowsAtCompileTime == -1 && E::ColsAtCompileTime == -1)
|
||||||
|
|
|
||||||
|
|
@ -11,16 +11,16 @@
|
||||||
TTS_CASE_TPL("System solver using QR", rotgen::tests::types)
|
TTS_CASE_TPL("System solver using QR", rotgen::tests::types)
|
||||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||||
{
|
{
|
||||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>
|
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic>
|
||||||
a { { 2.3, -1, 0.1}
|
a { { 2.3, -1, 0.1}
|
||||||
, {-1.6, 2.6, -1}
|
, {-1.6, 2.6, -1}
|
||||||
, { 0.3, -1, 2}
|
, { 0.3, -1, 2}
|
||||||
};
|
};
|
||||||
|
|
||||||
rotgen::matrix<T,rotgen::Dynamic,1,O::value> b(3,1);
|
rotgen::matrix<T,rotgen::Dynamic,1> b(3,1);
|
||||||
b(0) = b(2) = 1; b(1) = 0;
|
b(0) = b(2) = 1; b(1) = 0;
|
||||||
|
|
||||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> r(3,1), error;
|
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic> r(3,1), error;
|
||||||
|
|
||||||
auto x = rotgen::extract(r,0,0,3,1);
|
auto x = rotgen::extract(r,0,0,3,1);
|
||||||
rotgen::solver::qr(x, a, b);
|
rotgen::solver::qr(x, a, b);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue