38 #if !EIGEN_VERSION_AT_LEAST(3, 3, 0)
44 template <
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;
66 template <
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;
96 struct functor_has_linear_access<
dart::math::detail::
97 UniformScalarFromMatrixFunctor<T>>
105 template <
typename T>
106 struct functor_has_linear_access<
dart::math::detail::
107 UniformScalarFromVectorFunctor<T>>
126 template <
template <
typename...>
class C,
typename... Ts>
127 std::true_type is_base_of_template_impl(
const C<Ts...>*);
129 template <
template <
typename...>
class C>
130 std::false_type is_base_of_template_impl(...);
132 template <
template <
typename...>
class C,
typename T>
133 using is_base_of_template
134 = decltype(is_base_of_template_impl<C>(std::declval<T*>()));
136 template <
typename T>
137 using is_base_of_matrix = is_base_of_template<Eigen::MatrixBase, T>;
143 template <
typename T,
typename Enable =
void>
144 struct is_compatible_to_uniform_int_distribution : std::false_type
151 template <
typename T>
152 struct 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
171 template <
typename S,
typename Enable =
void>
172 struct UniformScalarImpl
179 template <
typename S>
180 struct 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);
195 template <
typename S>
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);
212 template <
typename Derived,
typename Enable =
void>
213 struct UniformMatrixImpl
220 template <
typename Derived>
221 struct 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));
248 template <
typename Derived>
249 struct 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));
273 template <
typename Derived>
274 struct 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));
298 template <
typename Derived>
299 struct 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));
322 template <
typename T,
typename Enable =
void>
329 template <
typename T>
330 struct UniformImpl<T,
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);
340 template <
typename T>
341 struct UniformImpl<T,
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);
351 template <
typename S,
typename Enable =
void>
352 struct NormalScalarImpl
359 template <
typename S>
360 struct 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);
373 template <
typename S>
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));
391 template <
typename T,
typename Enable =
void>
398 template <
typename T>
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);
411 template <
typename S>
414 return UniformImpl<S>::run(min, max);
418 template <
typename FixedSizeT>
420 typename FixedSizeT::Scalar min,
typename FixedSizeT::Scalar max)
422 return uniform<FixedSizeT>(
423 FixedSizeT::Constant(min), FixedSizeT::Constant(max));
427 template <
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));
439 template <
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));
452 template <
typename S>
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
double round(double _x)
Definition: Helpers.hpp:134
Definition: BulletCollisionDetector.cpp:63
Definition: SharedLibraryManager.hpp:43