12 #ifndef _OCRA_UTILS_UNCOMPRESS_H_ 13 #define _OCRA_UTILS_UNCOMPRESS_H_ 19 #include <Eigen/Eigen> 26 template <
class T,
class U>
34 template <
class V,
class W>
35 static const Eigen::CwiseBinaryOp<Eigen::internal::scalar_min_op<typename Eigen::internal::traits<V>::Scalar>,
const Eigen::ArrayWrapper<V>,
const Eigen::ArrayWrapper<W> >
36 run(
const V& a,
const W& b) {
return a.array().min(b.array()); }
38 template <
class V,
class W>
39 static const Eigen::CwiseBinaryOp<Eigen::internal::scalar_min_op<typename Eigen::internal::traits<V>::Scalar>,
const Eigen::ArrayWrapper<V>,
const Eigen::CwiseUnaryOp<Eigen::internal::scalar_multiple_op<typename Eigen::internal::traits<T>::Scalar>,
const Eigen::ArrayWrapper<W> > >
40 run(
const V& a,
double alpha,
const W& b) {
return a.array().min(alpha*b.array()); }
46 static const double&
run(
const double& a,
const double& b) {
return std::min(a, b); }
47 static const double&
run(
const double& a,
double alpha,
const double& b) {
return std::min(a, alpha*b); }
51 template <
class T,
class U>
58 template <
class V,
class W>
59 static const Eigen::CwiseBinaryOp<Eigen::internal::scalar_max_op<typename Eigen::internal::traits<V>::Scalar>,
const Eigen::ArrayWrapper<V>,
const Eigen::ArrayWrapper<W> >
60 run(
const V& a,
const W& b) {
return a.array().max(b.array()); }
61 template <
class V,
class W>
62 static const Eigen::CwiseBinaryOp<Eigen::internal::scalar_max_op<typename Eigen::internal::traits<V>::Scalar>,
const Eigen::ArrayWrapper<V>,
const Eigen::CwiseUnaryOp<Eigen::internal::scalar_multiple_op<typename Eigen::internal::traits<V>::Scalar>,
const Eigen::ArrayWrapper<W> > >
63 run(
const V& a,
double alpha,
const W& b) {
return a.array().max(alpha*b.array()); }
69 static const double&
run(
const double& a,
const double& b) {
return std::max(a, b); }
70 static const double&
run(
const double& a,
double alpha,
const double& b) {
return std::max(a, alpha*b); }
74 template<
class T,
class U>
77 static void run(T& out,
const U& in) { out = in; }
78 static void run(T& out,
double alpha,
const U& in) { out = alpha*in; }
81 template<
class T,
class U>
84 static void run(T& out,
const U& in) { out += in; }
85 static void run(T& out,
double alpha,
const U& in) { out += alpha*in; }
88 template<
class T,
class U>
91 static void run(T& out,
const U& in) { out = out.array().min(in.array()); }
92 static void run(T& out,
double alpha,
const U& in) { out = out.array().min(alpha*in.array()); }
95 template<
class T,
class U>
98 static void run(T& out,
const U& in) { out = out.array().max(in.array()); }
99 static void run(T& out,
double alpha,
const U& in) { out = out.array().max(alpha*in.array()); }
104 template<
template <
class T,
class U>
class Functor,
bool ApplyMappingToOut =
true>
107 template<
typename ArgType>
108 static ArgType
selector(ArgType i, ArgType j) {
return ApplyMappingToOut?i:j; }
110 template<
class Derived1,
class Derived2>
111 static void uncompressByCol(
const MatrixBase<Derived1>& in, MatrixBase<Derived2>& out,
112 const std::vector<int>& mapping,
double scale)
114 typedef typename MatrixBase<Derived1>::ConstColXpr col1_t;
115 typedef typename MatrixBase<Derived2>::ColXpr col2_t;
117 const int N =
static_cast<int>( selector(in.cols(), out.cols()) );
122 for (
int i=0; i<N; ++i) {
123 col2_t c2 = out.col(selector(mapping[i],i));
124 Functor<col2_t, col1_t>::run(c2,
125 in.col(selector(i, mapping[i])));
130 for (
int i=0; i<N; ++i) {
131 col2_t c2 = out.col(selector(mapping[i],i));
132 Functor<col2_t, col1_t>::run(c2,
134 in.col(selector(i, mapping[i])));
139 template<
class Derived1,
class Derived2>
140 static void uncompressByRow(
const MatrixBase<Derived1>& in, MatrixBase<Derived2>& out,
141 const std::vector<int>& mapping,
double scale)
143 typedef typename MatrixBase<Derived1>::ConstRowXpr row1_t;
144 typedef typename MatrixBase<Derived2>::RowXpr row2_t;
146 const int N =
static_cast<int>( selector(in.rows(), out.rows()) );
151 for (
int i=0; i<N; ++i) {
152 row2_t r2 = out.row(selector(mapping[i],i));
153 Functor<row2_t, row1_t>::run(r2,
154 in.row(selector(i, mapping[i])));
159 for (
int i=0; i<N; ++i) {
160 row2_t r2 = out.row(selector(mapping[i],i));
161 Functor<row2_t, row1_t>::run(r2, scale,
162 in.row(selector(i, mapping[i])));
167 template<
class Derived1,
class Derived2>
168 static void uncompress2d(
const MatrixBase<Derived1>& in, MatrixBase<Derived2>& out,
169 const std::vector<int>& mappingRow,
const std::vector<int>& mappingCol,
double scale)
171 typedef typename Eigen::internal::traits<Derived1>::Scalar scalar1_t;
172 typedef typename Eigen::internal::traits<Derived2>::Scalar scalar2_t;
174 const int Nc =
static_cast<int>( selector(in.cols(), out.cols()) );
175 const int Nr =
static_cast<int>( selector(in.rows(), out.rows()) );
180 for (
int i=0; i<Nc; ++i)
182 int n = mappingCol[i];
183 for (
int j=0; j<Nr; ++j) {
184 scalar2_t& s2 = out(selector(mappingRow[j], j), selector(n, i));
185 Functor<scalar2_t, scalar1_t>::run(s2,
186 in(selector(j, mappingRow[j]), selector(i, n)));
192 for (
int i=0; i<Nc; ++i)
194 int n = mappingCol[i];
195 for (
int j=0; j<Nr; ++j) {
196 scalar2_t& s2 = out(selector(mappingRow[j], j), selector(n, i));
197 Functor<scalar2_t, scalar1_t>::run(s2, scale,
198 in(selector(j, mappingRow[j]), selector(i, n)));
208 #endif //_OCRA_UTILS_UNCOMPRESS_H_ static const Eigen::CwiseBinaryOp< Eigen::internal::scalar_min_op< typename Eigen::internal::traits< V >::Scalar >, const Eigen::ArrayWrapper< V >, const Eigen::CwiseUnaryOp< Eigen::internal::scalar_multiple_op< typename Eigen::internal::traits< T >::Scalar >, const Eigen::ArrayWrapper< W > > > run(const V &a, double alpha, const W &b)
static const Eigen::CwiseBinaryOp< Eigen::internal::scalar_max_op< typename Eigen::internal::traits< V >::Scalar >, const Eigen::ArrayWrapper< V >, const Eigen::ArrayWrapper< W > > run(const V &a, const W &b)
static const double & run(const double &a, const double &b)
static void run(T &out, const U &in)
static void run(T &out, double alpha, const U &in)
static void run(T &out, double alpha, const U &in)
static void run(T &out, const U &in)
static void uncompress2d(const MatrixBase< Derived1 > &in, MatrixBase< Derived2 > &out, const std::vector< int > &mappingRow, const std::vector< int > &mappingCol, double scale)
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
static const double & run(const double &a, const double &b)
static void uncompressByRow(const MatrixBase< Derived1 > &in, MatrixBase< Derived2 > &out, const std::vector< int > &mapping, double scale)
static void run(T &out, double alpha, const U &in)
static const double & run(const double &a, double alpha, const double &b)
static void run(T &out, const U &in)
static ArgType selector(ArgType i, ArgType j)
static const Eigen::CwiseBinaryOp< Eigen::internal::scalar_min_op< typename Eigen::internal::traits< V >::Scalar >, const Eigen::ArrayWrapper< V >, const Eigen::ArrayWrapper< W > > run(const V &a, const W &b)
static const Eigen::CwiseBinaryOp< Eigen::internal::scalar_max_op< typename Eigen::internal::traits< V >::Scalar >, const Eigen::ArrayWrapper< V >, const Eigen::CwiseUnaryOp< Eigen::internal::scalar_multiple_op< typename Eigen::internal::traits< V >::Scalar >, const Eigen::ArrayWrapper< W > > > run(const V &a, double alpha, const W &b)
static const double & run(const double &a, double alpha, const double &b)
#define ocra_assert(ocra_expression)
static void uncompressByCol(const MatrixBase< Derived1 > &in, MatrixBase< Derived2 > &out, const std::vector< int > &mapping, double scale)
static void run(T &out, const U &in)
static void run(T &out, double alpha, const U &in)