12#ifndef EIGENRAND_DISTS_BASIC_H
13#define EIGENRAND_DISTS_BASIC_H
21 static constexpr double pi = 3.1415926535897932;
22 static constexpr double e = 2.7182818284590452;
31 template<
typename DerivedGen,
typename Scalar>
46 template<
typename Derived,
typename Urng>
47 inline const CwiseNullaryOp<internal::scalar_rng_adaptor<DerivedGen&, Scalar, Urng>,
const Derived>
51 rows, cols, { std::forward<Urng>(urng),
static_cast<DerivedGen&
>(*this) }
65 template<
typename Derived,
typename Urng>
66 inline const CwiseNullaryOp<internal::scalar_rng_adaptor<DerivedGen&, Scalar, Urng>,
const Derived>
70 o.rows(), o.cols(), { std::forward<Urng>(urng),
static_cast<DerivedGen&
>(*this) }
75 template<
typename DerivedGen,
typename Scalar,
typename ScalarA>
89 template<
typename Lhs,
typename Urng>
91 internal::scalar_unary_rng_adaptor<DerivedGen&, Scalar, typename Lhs::Scalar, Urng>,
93 > generate(Urng&& urng,
const ArrayBase<Lhs>& a)
96 a, { std::forward<Urng>(urng),
static_cast<DerivedGen&
>(*this) }
101 template<
typename DerivedGen,
typename Scalar,
typename ScalarA,
typename ScalarB>
115 template<
typename Lhs,
typename Rhs,
typename Urng>
116 inline CwiseBinaryOp<
117 internal::scalar_binary_rng_adaptor<DerivedGen&, Scalar, typename Lhs::Scalar, typename Rhs::Scalar, Urng>,
119 > generate(Urng&& urng,
const ArrayBase<Lhs>& a,
const ArrayBase<Rhs>& b)
122 a, b, { std::forward<Urng>(urng),
static_cast<DerivedGen&
>(*this) }
126 template<
typename Lhs,
typename Rhs,
typename Urng>
127 inline CwiseBinaryOp<
128 internal::scalar_binary_rng_adaptor<DerivedGen&, Scalar, typename Lhs::Scalar, Rhs, Urng>,
129 const Lhs, CwiseNullaryOp<internal::scalar_constant_op<Rhs>,
const Lhs>
130 > generate(Urng&& urng,
const ArrayBase<Lhs>& a, Rhs b)
133 a, { a.rows(), a.cols(), internal::scalar_constant_op<Rhs>{ b } },
134 { std::forward<Urng>(urng),
static_cast<DerivedGen&
>(*this) }
138 template<
typename Lhs,
typename Rhs,
typename Urng>
139 inline CwiseBinaryOp<
140 internal::scalar_binary_rng_adaptor<DerivedGen&, Scalar, Lhs, typename Rhs::Scalar, Urng>,
141 CwiseNullaryOp<internal::scalar_constant_op<Lhs>,
const Rhs>,
const Rhs
142 > generate(Urng&& urng, Lhs a,
const ArrayBase<Rhs>& b)
145 { b.rows(), b.cols(), internal::scalar_constant_op<Lhs>{ a } }, b,
146 { std::forward<Urng>(urng),
static_cast<DerivedGen&
>(*this) }
158 template<
typename DerivedGen,
typename _Scalar, Index Dim>
165 Index
dims()
const {
return static_cast<DerivedGen&
>(*this).dims(); }
176 template<
typename Urng>
177 inline Matrix<_Scalar, Dim, -1>
generate(Urng&& urng, Index samples)
179 return static_cast<DerivedGen&
>(*this).generatr(std::forward<Urng>(urng), samples);
189 template<
typename Urng>
190 inline Matrix<_Scalar, Dim, 1>
generate(Urng&& urng)
192 return static_cast<DerivedGen&
>(*this).generatr(std::forward<Urng>(urng));
203 template<
typename DerivedGen,
typename _Scalar, Index Dim>
210 Index
dims()
const {
return static_cast<DerivedGen&
>(*this).dims(); }
221 template<
typename Urng>
222 inline Matrix<_Scalar, Dim, -1>
generate(Urng&& urng, Index samples)
224 return static_cast<DerivedGen&
>(*this).generate(std::forward<Urng>(urng), samples);
234 template<
typename Urng>
235 inline Matrix<_Scalar, Dim, Dim>
generate(Urng&& urng)
237 return static_cast<DerivedGen&
>(*this).generate(std::forward<Urng>(urng));
241 template<Index _alignment=0>
245 enum { max_size =
sizeof(internal::find_best_packet<float, -1>::type) };
246 int8_t raw_data[max_size + _alignment - 1] = { 0, };
252 aligned_ptr = (
void*)((((
size_t)raw_data + _alignment - 1) / _alignment) * _alignment);
255 CacheStore(
const CacheStore& c)
257 std::copy(c.raw_data, c.raw_data + max_size, raw_data);
258 aligned_ptr = (
void*)((((
size_t)raw_data + _alignment - 1) / _alignment) * _alignment);
261 CacheStore(CacheStore&& c)
263 std::copy(c.raw_data, c.raw_data + max_size, raw_data);
264 aligned_ptr = (
void*)((((
size_t)raw_data + _alignment - 1) / _alignment) * _alignment);
267 template<
typename Ty>
270 return *(Ty*)aligned_ptr;
273 template<
typename Ty>
274 const Ty& get()
const
276 return *(
const Ty*)aligned_ptr;
284 enum { max_size =
sizeof(internal::find_best_packet<float, -1>::type) };
285 int8_t raw_data[max_size] = { 0, };
292 CacheStore(
const CacheStore& c)
294 std::copy(c.raw_data, c.raw_data + max_size, raw_data);
297 CacheStore(CacheStore&& c)
299 std::copy(c.raw_data, c.raw_data + max_size, raw_data);
302 template<
typename Ty>
305 return *(Ty*)raw_data;
308 template<
typename Ty>
309 const Ty& get()
const
311 return *(
const Ty*)raw_data;
315 using OptCacheStore = CacheStore<EIGEN_MAX_ALIGN_BYTES>;
317 template<
typename _Scalar>
318 struct ExtractFirstUint;
321 struct ExtractFirstUint<float>
323 template<
typename Packet>
324 auto operator()(Packet v) ->
decltype(Eigen::internal::pfirst(v))
326 return Eigen::internal::pfirst(v);
331 struct ExtractFirstUint<double>
333 template<
typename Packet>
334 auto operator()(Packet v) -> uint64_t
336 uint64_t arr[
sizeof(Packet) / 8];
337 Eigen::internal::pstoreu((Packet*)arr, v);
347 template<
typename _Scalar>
350 static_assert(std::is_integral<_Scalar>::value,
"randBits needs integral types.");
353 using Scalar = _Scalar;
355 template<
typename Rng>
356 EIGEN_STRONG_INLINE
const _Scalar operator() (Rng&& rng)
358 using namespace Eigen::internal;
359 return pfirst(std::forward<Rng>(rng)());
362 template<
typename Packet,
typename Rng>
363 EIGEN_STRONG_INLINE
const Packet packetOp(Rng&& rng)
365 using namespace Eigen::internal;
366 using RUtils = RawbitsMaker<Packet, Rng>;
367 return RUtils{}.rawbits(std::forward<Rng>(rng));
376 template<
typename _Scalar>
379 static_assert(std::is_floating_point<_Scalar>::value,
"balanced needs floating point types.");
382 using Scalar = _Scalar;
384 template<
typename Rng>
385 EIGEN_STRONG_INLINE
const _Scalar operator() (Rng&& rng)
387 using namespace Eigen::internal;
388 return ((_Scalar)((int32_t)pfirst(std::forward<Rng>(rng)()) & 0x7FFFFFFF) / 0x7FFFFFFF) * 2 - 1;
391 template<
typename Packet,
typename Rng>
392 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(Rng&& rng)
394 using namespace Eigen::internal;
395 using RUtils = RandUtils<Packet, Rng>;
396 return RUtils{}.balanced(std::forward<Rng>(rng));
405 template<
typename _Scalar>
408 static_assert(std::is_floating_point<_Scalar>::value,
"balanced needs floating point types.");
409 _Scalar slope = 2, bias = -1;
411 using Scalar = _Scalar;
419 : slope{ _b - _a }, bias{ _a }
423 template<
typename Rng>
424 EIGEN_STRONG_INLINE
const _Scalar operator() (Rng&& rng)
426 using namespace Eigen::internal;
427 return ((_Scalar)((int32_t)pfirst(std::forward<Rng>(rng)()) & 0x7FFFFFFF) / 0x7FFFFFFF) * slope + bias;
430 template<
typename Packet,
typename Rng>
431 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(Rng&& rng)
433 using namespace Eigen::internal;
434 using RUtils = RandUtils<Packet, Rng>;
435 return RUtils{}.balanced(std::forward<Rng>(rng), slope, bias);
439 template<
typename _Scalar>
440 class BalancedVGen :
public BinaryGenBase<BalancedVGen<_Scalar>, _Scalar, _Scalar, _Scalar>
442 static_assert(std::is_floating_point<_Scalar>::value,
"balanced needs floating point types.");
445 using Scalar = _Scalar;
447 template<
typename Rng>
448 EIGEN_STRONG_INLINE
const _Scalar operator() (Rng&& rng, _Scalar a, _Scalar b)
450 using namespace Eigen::internal;
451 return ((_Scalar)((int32_t)pfirst(std::forward<Rng>(rng)()) & 0x7FFFFFFF) / 0x7FFFFFFF) * (b - a) + a;
454 template<
typename Packet,
typename Rng>
455 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(Rng&& rng,
const Packet& a,
const Packet& b)
457 using namespace Eigen::internal;
458 using RUtils = RandUtils<Packet, Rng>;
459 return padd(pmul(RUtils{}.zero_to_one(std::forward<Rng>(rng)), psub(b, a)), a);
468 static constexpr size_t value = BitWidth<v / 2>::value + 1;
474 static constexpr size_t value = 0;
480 static constexpr size_t _min = Rng::min();
481 static constexpr size_t _max = Rng::max();
483 static constexpr bool _fullbit_rng = _min == 0 && (_max & (_max + 1)) == 0;
484 static constexpr size_t value = IsPacketRandomEngine<Rng>::value ?
sizeof(
typename Rng::result_type) * 8 : (_fullbit_rng ? BitWidth<_max>::value : 0);
493 template<
typename _Scalar>
496 static_assert(std::is_floating_point<_Scalar>::value,
"uniformReal needs floating point types.");
499 using Scalar = _Scalar;
501 template<
typename Rng,
502 typename std::enable_if<
sizeof(Scalar) * 8 <= detail::RngBitSize<
typename std::remove_const<
typename std::remove_reference<Rng>::type>::type>::value,
int>::type = 0
504 EIGEN_STRONG_INLINE
const _Scalar
operator() (Rng&& rng)
506 using namespace Eigen::internal;
507 return BitScalar<_Scalar>{}.to_ur(ExtractFirstUint<_Scalar>{}(std::forward<Rng>(rng)()));
510 template<
typename Rng,
511 typename std::enable_if<detail::RngBitSize<typename std::remove_const<typename std::remove_reference<Rng>::type>::type>::value <
sizeof(Scalar) * 8,
int>::type = 0
513 EIGEN_STRONG_INLINE
const _Scalar
operator() (Rng&& rng)
515 using RRng =
typename std::remove_const<typename std::remove_reference<Rng>::type>::type;
516 static_assert(detail::RngBitSize<RRng>::value > 0,
517 "BaseRng must be a kind of mersenne_twister_engine.");
518 using ResultType =
typename std::conditional<detail::RngBitSize<RRng>::value == 32, uint32_t, uint64_t>::type;
519 using namespace Eigen::internal;
520 ResultType arr[
sizeof(Scalar) /
sizeof(ResultType)];
521 for (
size_t i = 0; i <
sizeof(Scalar) /
sizeof(ResultType); ++i)
525 return BitScalar<_Scalar>{}.to_ur(*(uint64_t*)arr);
528 template<
typename Rng,
529 typename std::enable_if<
sizeof(Scalar) <=
sizeof(
typename std::remove_const<
typename std::remove_reference<Rng>::type>::type::result_type),
int>::type = 0
531 EIGEN_STRONG_INLINE
const _Scalar nzur_scalar(Rng&& rng)
533 using namespace Eigen::internal;
534 return BitScalar<_Scalar>{}.to_nzur(ExtractFirstUint<_Scalar>{}(std::forward<Rng>(rng)()));
537 template<
typename Rng,
538 typename std::enable_if<
sizeof(
typename std::remove_const<typename std::remove_reference<Rng>::type>::type::result_type) <
sizeof(Scalar),
int > ::type = 0
540 EIGEN_STRONG_INLINE
const _Scalar nzur_scalar(Rng&& rng)
542 using namespace Eigen::internal;
543 using RngResult =
typename std::remove_const<typename std::remove_reference<Rng>::type>::type::result_type;
544 RngResult arr[
sizeof(Scalar) /
sizeof(RngResult)];
545 for (
size_t i = 0; i <
sizeof(Scalar) /
sizeof(RngResult); ++i)
549 return BitScalar<_Scalar>{}.to_nzur(*(Scalar*)arr);
552 template<
typename Packet,
typename Rng>
553 EIGEN_STRONG_INLINE
const Packet packetOp(Rng&& rng)
555 using namespace Eigen::internal;
556 using RUtils = RandUtils<Packet, Rng>;
557 return RUtils{}.uniform_real(std::forward<Rng>(rng));
566 template<
typename _Scalar>
569 static_assert(std::is_floating_point<_Scalar>::value,
"uniformReal needs floating point types.");
573 using Scalar = _Scalar;
576 : bias{ _min }, slope{ _max - _min }
586 template<
typename Rng>
587 EIGEN_STRONG_INLINE
const _Scalar operator() (Rng&& rng)
589 using namespace Eigen::internal;
590 return bias + BitScalar<_Scalar>{}.to_ur(pfirst(std::forward<Rng>(rng)())) * slope;
593 template<
typename Packet,
typename Rng>
594 EIGEN_STRONG_INLINE
const Packet packetOp(Rng&& rng)
596 using namespace Eigen::internal;
597 using RUtils = RandUtils<Packet, Rng>;
599 RUtils{}.uniform_real(std::forward<Rng>(rng)), pset1<Packet>(slope)
600 ), pset1<Packet>(bias));
604 template<
typename _Scalar>
605 class UniformRealVGen :
public BinaryGenBase<UniformRealVGen<_Scalar>, _Scalar, _Scalar, _Scalar>
607 static_assert(std::is_floating_point<_Scalar>::value,
"uniformReal needs floating point types.");
610 using Scalar = _Scalar;
612 template<
typename Rng>
613 EIGEN_STRONG_INLINE
const _Scalar operator() (Rng&& rng, _Scalar a, _Scalar b)
615 using namespace Eigen::internal;
616 return a + BitScalar<_Scalar>{}.to_ur(pfirst(std::forward<Rng>(rng)())) * (b - a);
619 template<
typename Packet,
typename Rng>
620 EIGEN_STRONG_INLINE
const Packet packetOp(Rng&& rng,
const Packet& a,
const Packet& b)
622 using namespace Eigen::internal;
623 using RUtils = RandUtils<Packet, Rng>;
625 RUtils{}.uniform_real(std::forward<Rng>(rng)), psub(b, a)
636 template<
typename _Scalar>
641 using Scalar = _Scalar;
645 eigen_assert(0 <= _p && _p <= 1 );
646 p = (uint32_t)(_p * 0x80000000);
655 template<
typename Rng>
656 EIGEN_STRONG_INLINE
const _Scalar operator() (Rng&& rng)
658 using namespace Eigen::internal;
659 return (((uint32_t)pfirst(std::forward<Rng>(rng)()) & 0x7FFFFFFF) < p) ? 1 : 0;
662 template<
typename Packet,
typename Rng>
663 EIGEN_STRONG_INLINE
const Packet packetOp(Rng&& rng)
665 using namespace Eigen::internal;
666 using IPacket =
decltype(reinterpret_to_int(std::declval<Packet>()));
667 using RUtils = RawbitsMaker<IPacket, Rng>;
668 auto one = pset1<Packet>(1);
669 auto zero = pset1<Packet>(0);
670 auto r = RUtils{}.rawbits(std::forward<Rng>(rng));
671 r = pand(r, pset1<IPacket>(0x7FFFFFFF));
672 return pblendv(pcmplt(r, pset1<IPacket>(p)), one, zero);
676 template<
typename _Scalar>
677 class BernoulliVGen :
public UnaryGenBase<BernoulliVGen<_Scalar>, _Scalar, _Scalar>
679 static_assert(std::is_floating_point<_Scalar>::value,
"vectorized `bernoulli` needs a float type.");
681 using Scalar = _Scalar;
683 template<
typename Rng>
684 EIGEN_STRONG_INLINE
const _Scalar operator() (Rng&& rng, _Scalar a)
686 using namespace Eigen::internal;
687 uint32_t p = (uint32_t)(a * 0x80000000);
688 return (((uint32_t)pfirst(std::forward<Rng>(rng)()) & 0x7FFFFFFF) < p) ? 1 : 0;
691 template<
typename Packet,
typename Rng>
692 EIGEN_STRONG_INLINE
const Packet packetOp(Rng&& rng,
const Packet& a)
694 using namespace Eigen::internal;
695 using IPacket =
decltype(reinterpret_to_int(std::declval<Packet>()));
696 using RUtils = RawbitsMaker<IPacket, Rng>;
697 auto one = pset1<Packet>(1);
698 auto zero = pset1<Packet>(0);
699 auto p = pcast<Packet, IPacket>(pmul(a, pset1<Packet>(0x80000000)));
700 auto r = RUtils{}.rawbits(std::forward<Rng>(rng));
701 r = pand(r, pset1<IPacket>(0x7FFFFFFF));
702 return pblendv(pcmplt(r, p), one, zero);
706 template<
typename Derived,
typename Urng>
707 using RandBitsType = CwiseNullaryOp<internal::scalar_rng_adaptor<RandbitsGen<typename Derived::Scalar>,
typename Derived::Scalar, Urng,
true>,
const Derived>;
721 template<
typename Derived,
typename Urng>
722 inline const RandBitsType<Derived, Urng>
726 rows, cols, { std::forward<Urng>(urng) }
741 template<
typename Derived,
typename Urng>
742 inline const RandBitsType<Derived, Urng>
746 o.rows(), o.cols(), { std::forward<Urng>(urng) }
750 template<
typename Derived,
typename Urng>
751 using BalancedType = CwiseNullaryOp<internal::scalar_rng_adaptor<BalancedGen<typename Derived::Scalar>,
typename Derived::Scalar, Urng,
true>,
const Derived>;
765 template<
typename Derived,
typename Urng>
766 inline const BalancedType<Derived, Urng>
770 rows, cols, { std::forward<Urng>(urng) }
785 template<
typename Derived,
typename Urng>
786 inline const BalancedType<Derived, Urng>
790 o.rows(), o.cols(), { std::forward<Urng>(urng) }
794 template<
typename Derived,
typename Urng>
795 using Balanced2Type = CwiseNullaryOp<internal::scalar_rng_adaptor<Balanced2Gen<typename Derived::Scalar>,
typename Derived::Scalar, Urng,
true>,
const Derived>;
810 template<
typename Derived,
typename Urng>
811 inline const Balanced2Type<Derived, Urng>
812 balanced(Index rows, Index cols, Urng&& urng,
typename Derived::Scalar a,
typename Derived::Scalar b)
831 template<
typename Derived,
typename Urng>
832 inline const Balanced2Type<Derived, Urng>
833 balancedLike(
const Derived& o, Urng&& urng,
typename Derived::Scalar a,
typename Derived::Scalar b)
840 template<
typename Derived,
typename Urng>
841 using BalancedVVType = CwiseBinaryOp<
842 internal::scalar_binary_rng_adaptor<BalancedVGen<typename Derived::Scalar>,
typename Derived::Scalar,
typename Derived::Scalar,
typename Derived::Scalar, Urng,
true>,
843 const Derived,
const Derived
859 template<
typename Lhs,
typename Rhs,
typename Urng>
860 inline const BalancedVVType<Lhs, Urng>
861 balanced(Urng&& urng,
const ArrayBase<Lhs>& a,
const ArrayBase<Rhs>& b)
863 static_assert(std::is_same<typename Lhs::Scalar, typename Rhs::Scalar>::value,
"`Lhs::Scalar` must be equal to `Rhs::Scalar`");
865 static_cast<const Lhs&
>(a),
static_cast<const Rhs&
>(b),
866 { std::forward<Urng>(urng), BalancedVGen<typename Lhs::Scalar>{} }
870 template<
typename Derived,
typename Urng>
871 using BalancedVSType = CwiseBinaryOp<
872 internal::scalar_binary_rng_adaptor<BalancedVGen<typename Derived::Scalar>,
typename Derived::Scalar,
typename Derived::Scalar,
typename Derived::Scalar, Urng,
true>,
873 const Derived, CwiseNullaryOp<internal::scalar_constant_op<typename Derived::Scalar>,
const Derived>
876 template<
typename Lhs,
typename Urng>
877 inline const BalancedVSType<Lhs, Urng>
878 balanced(Urng&& urng,
const ArrayBase<Lhs>& a,
typename Lhs::Scalar b)
881 static_cast<const Lhs&
>(a), { a.rows(), a.cols(), internal::scalar_constant_op<typename Lhs::Scalar>{ b } },
882 { std::forward<Urng>(urng), BalancedVGen<typename Lhs::Scalar>{} }
886 template<
typename Derived,
typename Urng>
887 using BalancedSVType = CwiseBinaryOp<
888 internal::scalar_binary_rng_adaptor<BalancedVGen<typename Derived::Scalar>,
typename Derived::Scalar,
typename Derived::Scalar,
typename Derived::Scalar, Urng,
true>,
889 CwiseNullaryOp<internal::scalar_constant_op<typename Derived::Scalar>,
const Derived>,
const Derived
892 template<
typename Rhs,
typename Urng>
893 inline const BalancedSVType<Rhs, Urng>
894 balanced(Urng&& urng,
typename Rhs::Scalar a,
const ArrayBase<Rhs>& b)
897 { b.rows(), b.cols(), internal::scalar_constant_op<typename Rhs::Scalar>{ a } },
static_cast<const Rhs&
>(b),
898 { std::forward<Urng>(urng), BalancedVGen<typename Rhs::Scalar>{} }
902 template<
typename Derived,
typename Urng>
903 using StdUniformRealType = CwiseNullaryOp<internal::scalar_rng_adaptor<StdUniformRealGen<typename Derived::Scalar>,
typename Derived::Scalar, Urng,
true>,
const Derived>;
917 template<
typename Derived,
typename Urng>
918 inline const StdUniformRealType<Derived, Urng>
922 rows, cols, { std::forward<Urng>(urng) }
937 template<
typename Derived,
typename Urng>
938 inline const StdUniformRealType<Derived, Urng>
942 o.rows(), o.cols(), { std::forward<Urng>(urng) }
946 template<
typename Derived,
typename Urng>
947 using UniformRealType = CwiseNullaryOp<internal::scalar_rng_adaptor<UniformRealGen<typename Derived::Scalar>,
typename Derived::Scalar, Urng,
true>,
const Derived>;
962 template<
typename Derived,
typename Urng>
963 inline const UniformRealType<Derived, Urng>
964 uniformReal(Index rows, Index cols, Urng&& urng,
typename Derived::Scalar min,
typename Derived::Scalar max)
983 template<
typename Derived,
typename Urng>
984 inline const UniformRealType<Derived, Urng>
985 uniformRealLike(Derived& o, Urng&& urng,
typename Derived::Scalar min,
typename Derived::Scalar max)
992 template<
typename Derived,
typename Urng>
993 using UniformRealVVType = CwiseBinaryOp<
994 internal::scalar_binary_rng_adaptor<UniformRealVGen<typename Derived::Scalar>,
typename Derived::Scalar,
typename Derived::Scalar,
typename Derived::Scalar, Urng,
true>,
995 const Derived,
const Derived
1011 template<
typename Lhs,
typename Rhs,
typename Urng>
1012 inline const UniformRealVVType<Lhs, Urng>
1013 uniformReal(Urng&& urng,
const ArrayBase<Lhs>& a,
const ArrayBase<Rhs>& b)
1015 static_assert(std::is_same<typename Lhs::Scalar, typename Rhs::Scalar>::value,
"`Lhs::Scalar` must be equal to `Rhs::Scalar`");
1017 static_cast<const Lhs&
>(a),
static_cast<const Rhs&
>(b),
1018 { std::forward<Urng>(urng), UniformRealVGen<typename Lhs::Scalar>{} }
1022 template<
typename Derived,
typename Urng>
1023 using UniformRealVSType = CwiseBinaryOp<
1024 internal::scalar_binary_rng_adaptor<UniformRealVGen<typename Derived::Scalar>,
typename Derived::Scalar,
typename Derived::Scalar,
typename Derived::Scalar, Urng,
true>,
1025 const Derived, CwiseNullaryOp<internal::scalar_constant_op<typename Derived::Scalar>,
const Derived>
1028 template<
typename Lhs,
typename Urng>
1029 inline const UniformRealVSType<Lhs, Urng>
1030 uniformReal(Urng&& urng,
const ArrayBase<Lhs>& a,
typename Lhs::Scalar b)
1033 static_cast<const Lhs&
>(a), { a.rows(), a.cols(), internal::scalar_constant_op<typename Lhs::Scalar>{ b } },
1034 { std::forward<Urng>(urng), UniformRealVGen<typename Lhs::Scalar>{} }
1039 template<
typename Derived,
typename Urng>
1040 using UniformRealSVType = CwiseBinaryOp<
1041 internal::scalar_binary_rng_adaptor<UniformRealVGen<typename Derived::Scalar>,
typename Derived::Scalar,
typename Derived::Scalar,
typename Derived::Scalar, Urng,
true>,
1042 CwiseNullaryOp<internal::scalar_constant_op<typename Derived::Scalar>,
const Derived>,
const Derived
1045 template<
typename Rhs,
typename Urng>
1046 inline const UniformRealSVType<Rhs, Urng>
1047 uniformReal(Urng&& urng,
typename Rhs::Scalar a,
const ArrayBase<Rhs>& b)
1050 { b.rows(), b.cols(), internal::scalar_constant_op<typename Rhs::Scalar>{ a } },
static_cast<const Rhs&
>(b),
1051 { std::forward<Urng>(urng), UniformRealVGen<typename Rhs::Scalar>{} }
1055 template<
typename Derived,
typename Urng>
1056 using BernoulliType = CwiseNullaryOp<internal::scalar_rng_adaptor<BernoulliGen<typename Derived::Scalar>,
typename Derived::Scalar, Urng,
true>,
const Derived>;
1069 template<
typename Derived,
typename Urng>
1070 inline const BernoulliType<Derived, Urng>
1071 bernoulli(Index rows, Index cols, Urng&& urng,
double p = 0.5)
1088 template<
typename Derived,
typename Urng>
1089 inline const BernoulliType<Derived, Urng>
1097 template<
typename Derived,
typename Urng>
1098 using BernoulliVType = CwiseUnaryOp<
1099 internal::scalar_unary_rng_adaptor<BernoulliVGen<typename Derived::Scalar>,
typename Derived::Scalar,
typename Derived::Scalar, Urng,
true>,
1112 template<
typename Lhs,
typename Urng>
1113 inline const BernoulliVType<Lhs, Urng>
1116 return BernoulliVType<Lhs, Urng>{
1117 static_cast<const Lhs&
>(p), { std::forward<Urng>(urng), BernoulliVGen<typename Lhs::Scalar>{} }
Generator of reals in a range [a, b]
Definition: Basic.h:407
Balanced2Gen(_Scalar _a=-1, _Scalar _b=1)
Construct a new balanced generator.
Definition: Basic.h:418
Generator of reals in a range [-1, 1]
Definition: Basic.h:378
Generator of Bernoulli distribution.
Definition: Basic.h:638
Base class of all univariate random generators.
Definition: Basic.h:33
const CwiseNullaryOp< internal::scalar_rng_adaptor< DerivedGen &, Scalar, Urng >, const Derived > generate(Index rows, Index cols, Urng &&urng)
generate random values from its distribution
Definition: Basic.h:48
const CwiseNullaryOp< internal::scalar_rng_adaptor< DerivedGen &, Scalar, Urng >, const Derived > generateLike(const Derived &o, Urng &&urng)
generate random values from its distribution
Definition: Basic.h:67
Base class of all multivariate random matrix generators.
Definition: Basic.h:205
Index dims() const
returns the dimensions of matrices to be generated
Definition: Basic.h:210
Matrix< _Scalar, Dim, -1 > generate(Urng &&urng, Index samples)
generates multiple samples at once
Definition: Basic.h:222
Matrix< _Scalar, Dim, Dim > generate(Urng &&urng)
generates one sample
Definition: Basic.h:235
Base class of all multivariate random vector generators.
Definition: Basic.h:160
Matrix< _Scalar, Dim, 1 > generate(Urng &&urng)
generates one sample
Definition: Basic.h:190
Index dims() const
returns the dimensions of vectors to be generated
Definition: Basic.h:165
Matrix< _Scalar, Dim, -1 > generate(Urng &&urng, Index samples)
generates multiple samples at once
Definition: Basic.h:177
Generator of random bits for integral scalars.
Definition: Basic.h:349
const BalancedType< Derived, Urng > balanced(Index rows, Index cols, Urng &&urng)
generates reals in a range [-1, 1]
Definition: Basic.h:767
const RandBitsType< Derived, Urng > randBitsLike(Derived &o, Urng &&urng)
generates integers with random bits
Definition: Basic.h:743
const BalancedType< Derived, Urng > balancedLike(const Derived &o, Urng &&urng)
generates reals in a range [-1, 1]
Definition: Basic.h:787
const RandBitsType< Derived, Urng > randBits(Index rows, Index cols, Urng &&urng)
generates integers with random bits
Definition: Basic.h:723
const StdUniformRealType< Derived, Urng > uniformRealLike(Derived &o, Urng &&urng)
generates reals in a range [0, 1)
Definition: Basic.h:939
const StdUniformRealType< Derived, Urng > uniformReal(Index rows, Index cols, Urng &&urng)
generates reals in a range [0, 1)
Definition: Basic.h:919
const BernoulliType< Derived, Urng > bernoulli(Index rows, Index cols, Urng &&urng, double p=0.5)
generates 1 with probability p and 0 with probability 1 - p
Definition: Basic.h:1071