Commit 26a97398 authored by Pierre Fernbach's avatar Pierre Fernbach Committed by Pierre Fernbach
Browse files

[Cleaning] remove subfolder math/ and container/

parent c53a5cd1
SET(${PROJECT_NAME}_MATH_HEADERS
math/cumsum.hpp
math/factorial.hpp
math/nrand.hpp
math/search.hpp
)
SET(${PROJECT_NAME}_GEOMETRY_HEADERS
geometry/ellipsoid.hpp
......@@ -29,9 +23,6 @@ SET(${PROJECT_NAME}_SCENARIO_HEADERS
scenario/fwd.hpp
)
SET(${PROJECT_NAME}_CONTAINER_HEADERS
container/ref.hpp
)
SET(${PROJECT_NAME}_PYTHON_HEADERS
bindings/python/geometry/ellipsoid.hpp
......@@ -48,11 +39,9 @@ SET(${PROJECT_NAME}_PYTHON_HEADERS
)
SET(${PROJECT_NAME}_HEADERS
${${PROJECT_NAME}_MATH_HEADERS}
${${PROJECT_NAME}_GEOMETRY_HEADERS}
${${PROJECT_NAME}_SERIALIZATION_HEADERS}
${${PROJECT_NAME}_SCENARIO_HEADERS}
${${PROJECT_NAME}_CONTAINER_HEADERS}
${${PROJECT_NAME}_PYTHON_HEADERS}
)
......
// Copyright (c) 2015-2018, CNRS
// Authors: Justin Carpentier <jcarpent@laas.fr>
#ifndef __multicontact_api_container_ref_hpp__
#define __multicontact_api_container_ref_hpp__
#include <boost/ref.hpp>
namespace multicontact_api {
namespace container {
template <typename T>
class comparable_reference_wrapper : public boost::reference_wrapper<T> {
typedef typename boost::reference_wrapper<T> base;
public:
typedef typename base::type type;
// constructor
explicit comparable_reference_wrapper(T& t) : boost::reference_wrapper<T>(t) {}
// comparison operator
bool operator==(const comparable_reference_wrapper& other) const { return this->get() == other.get(); }
};
} // namespace container
} // namespace multicontact_api
#endif // ifndef __multicontact_api_container_ref_hpp__
// Copyright (c) 2015-2018, CNRS
// Authors: Justin Carpentier <jcarpent@laas.fr>
#ifndef __multicontact_api_math_cumsum_hpp__
#define __multicontact_api_math_cumsum_hpp__
#include <Eigen/Dense>
namespace multicontact_api {
namespace math {
namespace details {
template <typename DenseDerived1, typename DenseDerived2,
bool IsVector = DenseDerived1::ColsAtCompileTime == 1 || DenseDerived1::RowsAtCompileTime == 1>
struct CumSumAlgo {
static void run(const Eigen::DenseBase<DenseDerived1> &dense, const Eigen::DenseBase<DenseDerived2> &res,
const int direction);
template <int Direction>
static void run(const Eigen::DenseBase<DenseDerived1> &dense, const Eigen::DenseBase<DenseDerived2> &res);
};
template <typename DenseDerived1, typename DenseDerived2>
struct CumSumAlgo<DenseDerived1, DenseDerived2, true> {
static void run(const Eigen::DenseBase<DenseDerived1> &dense, const Eigen::DenseBase<DenseDerived2> &res) {
Eigen::DenseBase<DenseDerived2> &res_ = const_cast<Eigen::DenseBase<DenseDerived2> &>(res);
res_[0] = dense[0];
for (int k = 1; k < dense.size(); ++k) res_[k] = res_[k - 1] + dense[k];
}
};
template <typename DenseDerived1, typename DenseDerived2>
struct CumSumAlgo<DenseDerived1, DenseDerived2, false> {
template <int Direction, typename Dummy = void>
struct Func {
static void run(const Eigen::DenseBase<DenseDerived1> &dense, const Eigen::DenseBase<DenseDerived2> &res) {
Eigen::DenseBase<DenseDerived2> &res_ = const_cast<Eigen::DenseBase<DenseDerived2> &>(res);
res_.col(0) = dense.col(0);
for (int k = 1; k < dense.cols(); ++k) res_.col(k) = res_.col(k - 1) + dense.col(k);
}
};
template <typename Dummy>
struct Func<Eigen::Horizontal, Dummy> {
static void run(const Eigen::DenseBase<DenseDerived1> &dense, const Eigen::DenseBase<DenseDerived2> &res) {
Eigen::DenseBase<DenseDerived2> &res_ = const_cast<Eigen::DenseBase<DenseDerived2> &>(res);
res_.row(0) = dense.row(0);
for (int k = 1; k < dense.rows(); ++k) res_.row(k) = res_.row(k - 1) + dense.row(k);
}
};
template <int Direction>
static void run(const Eigen::DenseBase<DenseDerived1> &dense, const Eigen::DenseBase<DenseDerived2> &res) {
Func<Direction>::run(dense, res);
}
static void run(const Eigen::DenseBase<DenseDerived1> &dense, const Eigen::DenseBase<DenseDerived2> &res,
const int direction) {
if (direction == Eigen::Vertical)
run<Eigen::Vertical>(dense, res);
else
run<Eigen::Horizontal>(dense, res);
}
};
} // namespace details
template <typename DenseDerived1, typename DenseDerived2>
void cumsum(const Eigen::DenseBase<DenseDerived1> &dense, const Eigen::DenseBase<DenseDerived2> &res) {
details::CumSumAlgo<DenseDerived1, DenseDerived2>::run(dense, res);
}
template <typename DenseDerived>
typename DenseDerived::PlainObject cumsum(const Eigen::DenseBase<DenseDerived> &dense) {
typename DenseDerived::PlainObject res(dense.rows(), dense.cols());
details::CumSumAlgo<DenseDerived, typename DenseDerived::PlainObject>::run(dense, res);
return res;
}
} // namespace math
} // namespace multicontact_api
#endif // ifndef __multicontact_api_math_cumsum_hpp__
// Copyright (c) 2015-2018, CNRS
// Authors: Justin Carpentier <jcarpent@laas.fr>
#ifndef __multicontact_api_math_factorial_hpp__
#define __multicontact_api_math_factorial_hpp__
namespace multicontact_api {
namespace math {
template <int N>
factorial() {
assert(N > 0);
return N * factorial<N - 1>();
}
template <0>
factorial() {
return 1;
}
template <1>
factorial() {
return 1;
}
template <2>
factorial() {
return 2;
}
} // namespace math
} // namespace multicontact_api
#endif // ifndef __multicontact_api_math_factorial_hpp__
// Copyright (c) 2015-2018, CNRS
// Authors: Justin Carpentier <jcarpent@laas.fr>
#ifndef __multicontact_api_math_nrand_hpp__
#define __multicontact_api_math_nrand_hpp__
#include <cmath>
#include <cstdlib>
#include <boost/math/constants/constants.hpp>
namespace multicontact_api {
namespace math {
template <typename Scalar>
inline Scalar nrand() {
const Scalar two_pi = 2 * boost::math::constants::pi<Scalar>();
const Scalar eps = std::numeric_limits<Scalar>::min();
using std::cos;
using std::log;
using std::rand;
using std::sqrt;
Scalar u1, u2;
const Scalar RAND_MAX_INV = (1.0 / RAND_MAX);
do {
u1 = (Scalar)rand() * RAND_MAX_INV;
u2 = (Scalar)rand() * RAND_MAX_INV;
} while (u1 <= eps);
Scalar z0 = sqrt(-2.0 * log(u1)) * cos(two_pi * u2);
return z0;
}
} // namespace math
} // namespace multicontact_api
#endif // ifndef __multicontact_api_math_nrand_hpp__
// Copyright (c) 2015-2018, CNRS
// Authors: Justin Carpentier <jcarpent@laas.fr>
#ifndef __multicontact_api_math_search_hpp__
#define __multicontact_api_math_search_hpp__
#include <Eigen/Dense>
namespace multicontact_api {
namespace math {
template <class DenseDerived>
Eigen::DenseIndex binarySearch(const Eigen::DenseBase<DenseDerived>& vector,
const typename DenseDerived::Scalar& value) {
EIGEN_STATIC_ASSERT_VECTOR_ONLY(DenseDerived);
int left_id = 0;
int right_id = vector.ssize() - 1;
while (left_id <= right_id) {
int middle_id = left_id + (right_id - left_id) / 2;
if (vector[middle_id] < value)
left_id = middle_id + 1;
else if (vector[middle_id] > value)
right_id = middle_id - 1;
else
return middle_id;
}
return left_id - 1;
}
} // namespace math
} // namespace multicontact_api
#endif // ifndef __multicontact_api_math_search_hpp__
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment