38#if !EIGEN_VERSION_AT_LEAST(3, 3, 0)
44template <
typename Derived>
47 using S =
typename Derived::Scalar;
50 const Eigen::MatrixBase<Derived>& min,
51 const Eigen::MatrixBase<Derived>& max)
59 return Random::uniform<S>(
mMin(i, j),
mMax(i, j));
62 const Eigen::MatrixBase<Derived>&
mMin;
63 const Eigen::MatrixBase<Derived>&
mMax;
66template <
typename Derived>
69 using S =
typename Derived::Scalar;
72 const Eigen::MatrixBase<Derived>& min,
73 const Eigen::MatrixBase<Derived>& max)
81 return Random::uniform<S>(
mMin[i],
mMax[i]);
84 const Eigen::MatrixBase<Derived>&
mMin;
85 const Eigen::MatrixBase<Derived>&
mMax;
96struct functor_has_linear_access<
dart::math::detail::
97 UniformScalarFromMatrixFunctor<T>>
106struct functor_has_linear_access<
dart::math::detail::
107 UniformScalarFromVectorFunctor<T>>
126template <
template <
typename...>
class C,
typename... Ts>
127std::true_type is_base_of_template_impl(
const C<Ts...>*);
129template <
template <
typename...>
class C>
130std::false_type is_base_of_template_impl(...);
132template <
template <
typename...>
class C,
typename T>
133using is_base_of_template
134 =
decltype(is_base_of_template_impl<C>(std::declval<T*>()));
137using is_base_of_matrix = is_base_of_template<Eigen::MatrixBase, T>;
143template <
typename T,
typename Enable =
void>
144struct is_compatible_to_uniform_int_distribution : std::false_type
152struct is_compatible_to_uniform_int_distribution<
153 T, typename
std::enable_if<
154 std::is_same<typename std::remove_cv<T>::type, short>::value
155 || std::is_same<typename std::remove_cv<T>::type, int>::value
156 || std::is_same<typename std::remove_cv<T>::type, long>::value
157 || std::is_same<typename std::remove_cv<T>::type, long long>::value
158 || std::is_same<typename std::remove_cv<T>::type, unsigned short>::value
159 || std::is_same<typename std::remove_cv<T>::type, unsigned int>::value
160 || std::is_same<typename std::remove_cv<T>::type, unsigned long>::value
161 || std::is_same<typename std::remove_cv<T>::type, unsigned long long>::value
171template <
typename S,
typename Enable =
void>
172struct UniformScalarImpl
180struct UniformScalarImpl<S,
182 enable_if<std::is_floating_point<S>::value>
::type>
184 static S run(S min, S max)
188 Random::UniformRealDist<S> d(min, max);
199 enable_if<is_compatible_to_uniform_int_distribution<S>::
202 static S run(S min, S max)
206 Random::UniformIntDist<S> d(min, max);
212template <
typename Derived,
typename Enable =
void>
213struct UniformMatrixImpl
220template <
typename Derived>
221struct UniformMatrixImpl<Derived,
222 typename
std::enable_if<!Derived::IsVectorAtCompileTime
223 && Derived::SizeAtCompileTime
227 static typename Derived::PlainObject run(
228 const Eigen::MatrixBase<Derived>& min,
229 const Eigen::MatrixBase<Derived>& max)
231#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
232 const auto uniformFunc = [&](
int i,
int j) {
233 return Random::uniform<typename Derived::Scalar>(min(i, j), max(i, j));
235 return Derived::PlainObject::NullaryExpr(
236 min.rows(), min.cols(), uniformFunc);
238 return Derived::PlainObject::NullaryExpr(
241 detail::UniformScalarFromMatrixFunctor<Derived>(min, max));
248template <
typename Derived>
249struct UniformMatrixImpl<Derived,
250 typename
std::enable_if<Derived::IsVectorAtCompileTime
251 && Derived::SizeAtCompileTime
255 static typename Derived::PlainObject run(
256 const Eigen::MatrixBase<Derived>& min,
257 const Eigen::MatrixBase<Derived>& max)
259#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
260 const auto uniformFunc = [&](
int i) {
261 return Random::uniform<typename Derived::Scalar>(min[i], max[i]);
263 return Derived::PlainObject::NullaryExpr(min.size(), uniformFunc);
265 return Derived::PlainObject::NullaryExpr(
266 min.size(), detail::UniformScalarFromVectorFunctor<Derived>(min, max));
273template <
typename Derived>
274struct UniformMatrixImpl<Derived,
275 typename
std::enable_if<!Derived::IsVectorAtCompileTime
276 && Derived::SizeAtCompileTime
280 static typename Derived::PlainObject run(
281 const Eigen::MatrixBase<Derived>& min,
282 const Eigen::MatrixBase<Derived>& max)
284#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
285 const auto uniformFunc = [&](
int i,
int j) {
286 return Random::uniform<typename Derived::Scalar>(min(i, j), max(i, j));
288 return Derived::PlainObject::NullaryExpr(uniformFunc);
290 return Derived::PlainObject::NullaryExpr(
291 detail::UniformScalarFromMatrixFunctor<Derived>(min, max));
298template <
typename Derived>
299struct UniformMatrixImpl<Derived,
300 typename
std::enable_if<Derived::IsVectorAtCompileTime
301 && Derived::SizeAtCompileTime
305 static typename Derived::PlainObject run(
306 const Eigen::MatrixBase<Derived>& min,
307 const Eigen::MatrixBase<Derived>& max)
309#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
310 const auto uniformFunc = [&](
int i) {
311 return Random::uniform<typename Derived::Scalar>(min[i], max[i]);
313 return Derived::PlainObject::NullaryExpr(uniformFunc);
315 return Derived::PlainObject::NullaryExpr(
316 detail::UniformScalarFromVectorFunctor<Derived>(min, max));
322template <
typename T,
typename Enable =
void>
331 typename
std::enable_if<std::is_arithmetic<T>::value>
::type>
333 static T run(T min, T max)
335 return UniformScalarImpl<T>::run(min, max);
342 typename
std::enable_if<is_base_of_matrix<T>::value>
::type>
344 static T run(
const Eigen::MatrixBase<T>& min,
const Eigen::MatrixBase<T>& max)
346 return UniformMatrixImpl<T>::run(min, max);
351template <
typename S,
typename Enable =
void>
352struct NormalScalarImpl
360struct NormalScalarImpl<S,
362 enable_if<std::is_floating_point<S>::value>
::type>
364 static S run(S mean, S sigma)
366 Random::NormalRealDist<S> d(mean, sigma);
377 enable_if<is_compatible_to_uniform_int_distribution<S>::
380 static S run(S mean, S sigma)
382 using DefaultFloatType = float;
384 static_cast<DefaultFloatType
>(mean),
385 static_cast<DefaultFloatType
>(sigma));
386 return static_cast<S
>(std::round(realNormal));
391template <
typename T,
typename Enable =
void>
400 typename
std::enable_if<std::is_arithmetic<T>::value>
::type>
402 static T run(T min, T max)
404 return NormalScalarImpl<T>::run(min, max);
414 return UniformImpl<S>::run(min, max);
418template <
typename FixedSizeT>
420 typename FixedSizeT::Scalar min,
typename FixedSizeT::Scalar max)
422 return uniform<FixedSizeT>(
423 FixedSizeT::Constant(min), FixedSizeT::Constant(max));
427template <
typename DynamicSizeVectorT>
430 typename DynamicSizeVectorT::Scalar min,
431 typename DynamicSizeVectorT::Scalar max)
433 return uniform<DynamicSizeVectorT>(
434 DynamicSizeVectorT::Constant(size, min),
435 DynamicSizeVectorT::Constant(size, max));
439template <
typename DynamicSizeMatrixT>
443 typename DynamicSizeMatrixT::Scalar min,
444 typename DynamicSizeMatrixT::Scalar max)
446 return uniform<DynamicSizeMatrixT>(
447 DynamicSizeMatrixT::Constant(rows, cols, min),
448 DynamicSizeMatrixT::Constant(rows, cols, max));
455 return NormalImpl<S>::run(min, max);
std::string type
Definition SdfParser.cpp:82
static S normal(S mean, S sigma)
Returns a random number from a normal distribution.
Definition Random-impl.hpp:453
static GeneratorType & getGenerator()
Returns a mutable reference to the random generator.
Definition Random.cpp:39
static S uniform(S min, S max)
Returns a random number from an uniform distribution.
Definition Random-impl.hpp:412
Definition Random-impl.hpp:92
Definition BulletCollisionDetector.cpp:63
Definition SharedLibraryManager.hpp:43