Core.h
Go to the documentation of this file.
1 
13 #ifndef EIGENRAND_CORE_H
14 #define EIGENRAND_CORE_H
15 
16 #include <EigenRand/RandUtils.h>
17 #include <EigenRand/Dists/Basic.h>
18 #include <EigenRand/Dists/Discrete.h>
19 #include <EigenRand/Dists/NormalExp.h>
20 
21 namespace Eigen
22 {
27  namespace Rand
28  {
29  template<typename Derived, typename Urng>
30  using RandBitsType = CwiseNullaryOp<internal::scalar_randbits_op<typename Derived::Scalar, Urng>, const Derived>;
31 
42  template<typename Derived, typename Urng>
43  inline const RandBitsType<Derived, Urng>
44  randBits(Index rows, Index cols, Urng&& urng)
45  {
46  return {
47  rows, cols, internal::scalar_randbits_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng))
48  };
49  }
50 
60  template<typename Derived, typename Urng>
61  inline const RandBitsType<Derived, Urng>
62  randBitsLike(Derived& o, Urng&& urng)
63  {
64  return {
65  o.rows(), o.cols(), internal::scalar_randbits_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng))
66  };
67  }
68 
69  template<typename Derived, typename Urng>
70  using UniformIntType = CwiseNullaryOp<internal::scalar_uniform_int_op<typename Derived::Scalar, Urng>, const Derived>;
71 
83  template<typename Derived, typename Urng>
84  inline const UniformIntType<Derived, Urng>
85  uniformInt(Index rows, Index cols, Urng&& urng, typename Derived::Scalar min, typename Derived::Scalar max)
86  {
87  return {
88  rows, cols, internal::scalar_uniform_int_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), min, max)
89  };
90  }
91 
102  template<typename Derived, typename Urng>
103  inline const UniformIntType<Derived, Urng>
104  uniformIntLike(Derived& o, Urng&& urng, typename Derived::Scalar min, typename Derived::Scalar max)
105  {
106  return {
107  o.rows(), o.cols(), internal::scalar_uniform_int_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), min, max)
108  };
109  }
110 
111  template<typename Derived, typename Urng>
112  using BalancedType = CwiseNullaryOp<internal::scalar_balanced_op<typename Derived::Scalar, Urng>, const Derived>;
113 
124  template<typename Derived, typename Urng>
125  inline const BalancedType<Derived, Urng>
126  balanced(Index rows, Index cols, Urng&& urng)
127  {
128  return {
129  rows, cols, internal::scalar_balanced_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng))
130  };
131  }
132 
142  template<typename Derived, typename Urng>
143  inline const BalancedType<Derived, Urng>
144  balancedLike(const Derived& o, Urng&& urng)
145  {
146  return {
147  o.rows(), o.cols(), internal::scalar_balanced_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng))
148  };
149  }
150 
151  template<typename Derived, typename Urng>
152  using UniformRealType = CwiseNullaryOp<internal::scalar_uniform_real_op<typename Derived::Scalar, Urng>, const Derived>;
153 
164  template<typename Derived, typename Urng>
165  inline const UniformRealType<Derived, Urng>
166  uniformReal(Index rows, Index cols, Urng&& urng)
167  {
168  return {
169  rows, cols, internal::scalar_uniform_real_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng))
170  };
171  }
172 
182  template<typename Derived, typename Urng>
183  inline const UniformRealType<Derived, Urng>
184  uniformRealLike(Derived& o, Urng&& urng)
185  {
186  return {
187  o.rows(), o.cols(), internal::scalar_uniform_real_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng))
188  };
189  }
190 
191  template<typename Derived, typename Urng>
192  using NormalType = CwiseNullaryOp<internal::scalar_norm_dist_op<typename Derived::Scalar, Urng>, const Derived>;
193 
204  template<typename Derived, typename Urng>
205  inline const NormalType<Derived, Urng>
206  normal(Index rows, Index cols, Urng&& urng)
207  {
208  return {
209  rows, cols, internal::scalar_norm_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng))
210  };
211  }
212 
222  template<typename Derived, typename Urng>
223  inline const NormalType<Derived, Urng>
224  normalLike(Derived& o, Urng&& urng)
225  {
226  return {
227  o.rows(), o.cols(), internal::scalar_norm_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng))
228  };
229  }
230 
231  template<typename Derived, typename Urng>
232  using Normal2Type = CwiseNullaryOp<internal::scalar_norm_dist2_op<typename Derived::Scalar, Urng>, const Derived>;
233 
246  template<typename Derived, typename Urng>
247  inline const Normal2Type<Derived, Urng>
248  normal(Index rows, Index cols, Urng&& urng, typename Derived::Scalar mean, typename Derived::Scalar stdev = 1)
249  {
250  return {
251  rows, cols, internal::scalar_norm_dist2_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), mean, stdev)
252  };
253  }
254 
266  template<typename Derived, typename Urng>
267  inline const Normal2Type<Derived, Urng>
268  normalLike(Derived& o, Urng&& urng, typename Derived::Scalar mean, typename Derived::Scalar stdev = 1)
269  {
270  return {
271  o.rows(), o.cols(), internal::scalar_norm_dist2_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), mean, stdev)
272  };
273  }
274 
275  template<typename Derived, typename Urng>
276  using LognormalType = CwiseNullaryOp<internal::scalar_lognorm_dist_op<typename Derived::Scalar, Urng>, const Derived>;
277 
290  template<typename Derived, typename Urng>
291  inline const LognormalType<Derived, Urng>
292  lognormal(Index rows, Index cols, Urng&& urng, typename Derived::Scalar mean = 0, typename Derived::Scalar stdev = 1)
293  {
294  return {
295  rows, cols, internal::scalar_lognorm_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), mean, stdev)
296  };
297  }
298 
310  template<typename Derived, typename Urng>
311  inline const LognormalType<Derived, Urng>
312  lognormalLike(Derived& o, Urng&& urng, typename Derived::Scalar mean = 0, typename Derived::Scalar stdev = 1)
313  {
314  return {
315  o.rows(), o.cols(), internal::scalar_lognorm_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), mean, stdev)
316  };
317  }
318 
319  template<typename Derived, typename Urng>
320  using ExponentialType = CwiseNullaryOp<internal::scalar_exp_dist_op<typename Derived::Scalar, Urng>, const Derived>;
321 
333  template<typename Derived, typename Urng>
334  inline const ExponentialType<Derived, Urng>
335  exponential(Index rows, Index cols, Urng&& urng, typename Derived::Scalar lambda = 1)
336  {
337  return {
338  rows, cols, internal::scalar_exp_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), lambda)
339  };
340  }
341 
352  template<typename Derived, typename Urng>
353  inline const ExponentialType<Derived, Urng>
354  exponentialLike(Derived& o, Urng&& urng, typename Derived::Scalar lambda = 1)
355  {
356  return {
357  o.rows(), o.cols(), internal::scalar_exp_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), lambda)
358  };
359  }
360 
361  template<typename Derived, typename Urng>
362  using GammaType = CwiseNullaryOp<internal::scalar_gamma_dist_op<typename Derived::Scalar, Urng>, const Derived>;
363 
376  template<typename Derived, typename Urng>
377  inline const GammaType<Derived, Urng>
378  gamma(Index rows, Index cols, Urng&& urng, typename Derived::Scalar alpha = 1, typename Derived::Scalar beta = 1)
379  {
380  return {
381  rows, cols, internal::scalar_gamma_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), alpha, beta)
382  };
383  }
384 
396  template<typename Derived, typename Urng>
397  inline const GammaType<Derived, Urng>
398  gammaLike(Derived& o, Urng&& urng, typename Derived::Scalar alpha = 1, typename Derived::Scalar beta = 1)
399  {
400  return {
401  o.rows(), o.cols(), internal::scalar_gamma_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), alpha, beta)
402  };
403  }
404 
405  template<typename Derived, typename Urng>
406  using WeibullType = CwiseNullaryOp<internal::scalar_weibull_dist_op<typename Derived::Scalar, Urng>, const Derived>;
407 
420  template<typename Derived, typename Urng>
421  inline const WeibullType<Derived, Urng>
422  weibull(Index rows, Index cols, Urng&& urng, typename Derived::Scalar a = 1, typename Derived::Scalar b = 1)
423  {
424  return {
425  rows, cols, internal::scalar_weibull_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), a, b)
426  };
427  }
428 
440  template<typename Derived, typename Urng>
441  inline const WeibullType<Derived, Urng>
442  weibullLike(Derived& o, Urng&& urng, typename Derived::Scalar a = 1, typename Derived::Scalar b = 1)
443  {
444  return {
445  o.rows(), o.cols(), internal::scalar_weibull_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), a, b)
446  };
447  }
448 
449  template<typename Derived, typename Urng>
450  using ExtremeValueType = CwiseNullaryOp<internal::scalar_extreme_value_dist_op<typename Derived::Scalar, Urng>, const Derived>;
451 
465  template<typename Derived, typename Urng>
466  inline const ExtremeValueType<Derived, Urng>
467  extremeValue(Index rows, Index cols, Urng&& urng, typename Derived::Scalar a = 0, typename Derived::Scalar b = 1)
468  {
469  return {
470  rows, cols, internal::scalar_extreme_value_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), a, b)
471  };
472  }
473 
486  template<typename Derived, typename Urng>
487  inline const ExtremeValueType<Derived, Urng>
488  extremeValueLike(Derived& o, Urng&& urng, typename Derived::Scalar a = 0, typename Derived::Scalar b = 1)
489  {
490  return {
491  o.rows(), o.cols(), internal::scalar_extreme_value_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), a, b)
492  };
493  }
494 
495  template<typename Derived, typename Urng>
496  using ChiSquaredType = CwiseNullaryOp<internal::scalar_chi_squared_dist_op<typename Derived::Scalar, Urng>, const Derived>;
497 
509  template<typename Derived, typename Urng>
510  inline const ChiSquaredType<Derived, Urng>
511  chiSquared(Index rows, Index cols, Urng&& urng, typename Derived::Scalar n = 1)
512  {
513  return {
514  rows, cols, internal::scalar_chi_squared_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), n)
515  };
516  }
517 
528  template<typename Derived, typename Urng>
529  inline const ChiSquaredType<Derived, Urng>
530  chiSquaredLike(Derived& o, Urng&& urng, typename Derived::Scalar n = 1)
531  {
532  return {
533  o.rows(), o.cols(), internal::scalar_chi_squared_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), n)
534  };
535  }
536 
537  template<typename Derived, typename Urng>
538  using DiscreteFType = CwiseNullaryOp<internal::scalar_discrete_dist_op<typename Derived::Scalar, Urng, float>, const Derived>;
539 
552  template<typename Derived, typename Urng, typename RealIter>
553  inline const DiscreteFType<Derived, Urng>
554  discreteF(Index rows, Index cols, Urng&& urng, RealIter first, RealIter last)
555  {
556  return {
557  rows, cols, internal::scalar_discrete_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), first, last)
558  };
559  }
560 
572  template<typename Derived, typename Urng, typename RealIter>
573  inline const DiscreteFType<Derived, Urng>
574  discreteFLike(Derived& o, Urng&& urng, RealIter first, RealIter last)
575  {
576  return {
577  o.rows(), o.cols(), internal::scalar_discrete_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), first, last)
578  };
579  }
580 
593  template<typename Derived, typename Urng, typename Real>
594  inline const DiscreteFType<Derived, Urng>
595  discreteF(Index rows, Index cols, Urng&& urng, const std::initializer_list<Real>& il)
596  {
597  return {
598  rows, cols, internal::scalar_discrete_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), il.begin(), il.end())
599  };
600  }
601 
613  template<typename Derived, typename Urng, typename Real>
614  inline const DiscreteFType<Derived, Urng>
615  discreteFLike(Derived& o, Urng&& urng, const std::initializer_list<Real>& il)
616  {
617  return {
618  o.rows(), o.cols(), internal::scalar_discrete_dist_op<typename Derived::Scalar, Urng>(std::forward<Urng>(urng), il.begin(), il.end())
619  };
620  }
621 
622  template<typename Derived, typename Urng>
623  using DiscreteDType = CwiseNullaryOp<internal::scalar_discrete_dist_op<typename Derived::Scalar, Urng, double>, const Derived>;
624 
637  template<typename Derived, typename Urng, typename RealIter>
638  inline const DiscreteDType<Derived, Urng>
639  discreteD(Index rows, Index cols, Urng&& urng, RealIter first, RealIter last)
640  {
641  return {
642  rows, cols, internal::scalar_discrete_dist_op<typename Derived::Scalar, Urng, double>(std::forward<Urng>(urng), first, last)
643  };
644  }
645 
657  template<typename Derived, typename Urng, typename RealIter>
658  inline const DiscreteDType<Derived, Urng>
659  discreteDLike(Derived& o, Urng&& urng, RealIter first, RealIter last)
660  {
661  return {
662  o.rows(), o.cols(), internal::scalar_discrete_dist_op<typename Derived::Scalar, Urng, double>(std::forward<Urng>(urng), first, last)
663  };
664  }
665 
678  template<typename Derived, typename Urng, typename Real>
679  inline const DiscreteDType<Derived, Urng>
680  discreteD(Index rows, Index cols, Urng&& urng, const std::initializer_list<Real>& il)
681  {
682  return {
683  rows, cols, internal::scalar_discrete_dist_op<typename Derived::Scalar, Urng, double>(std::forward<Urng>(urng), il.begin(), il.end())
684  };
685  }
686 
698  template<typename Derived, typename Urng, typename Real>
699  inline const DiscreteDType<Derived, Urng>
700  discreteDLike(Derived& o, Urng&& urng, const std::initializer_list<Real>& il)
701  {
702  return {
703  o.rows(), o.cols(), internal::scalar_discrete_dist_op<typename Derived::Scalar, Urng, double>(std::forward<Urng>(urng), il.begin(), il.end())
704  };
705  }
706 
707  template<typename Derived, typename Urng>
708  using DiscreteType = CwiseNullaryOp<internal::scalar_discrete_dist_op<typename Derived::Scalar, Urng, int32_t>, const Derived>;
709 
722  template<typename Derived, typename Urng, typename RealIter>
723  inline const DiscreteType<Derived, Urng>
724  discrete(Index rows, Index cols, Urng&& urng, RealIter first, RealIter last)
725  {
726  return {
727  rows, cols, internal::scalar_discrete_dist_op<typename Derived::Scalar, Urng, int32_t>(std::forward<Urng>(urng), first, last)
728  };
729  }
730 
742  template<typename Derived, typename Urng, typename RealIter>
743  inline const DiscreteType<Derived, Urng>
744  discreteLike(Derived& o, Urng&& urng, RealIter first, RealIter last)
745  {
746  return {
747  o.rows(), o.cols(), internal::scalar_discrete_dist_op<typename Derived::Scalar, Urng, int32_t>(std::forward<Urng>(urng), first, last)
748  };
749  }
750 
763  template<typename Derived, typename Urng, typename Real>
764  inline const DiscreteType<Derived, Urng>
765  discrete(Index rows, Index cols, Urng&& urng, const std::initializer_list<Real>& il)
766  {
767  return {
768  rows, cols, internal::scalar_discrete_dist_op<typename Derived::Scalar, Urng, int32_t>(std::forward<Urng>(urng), il.begin(), il.end())
769  };
770  }
771 
783  template<typename Derived, typename Urng, typename Real>
784  inline const DiscreteType<Derived, Urng>
785  discreteLike(Derived& o, Urng&& urng, const std::initializer_list<Real>& il)
786  {
787  return {
788  o.rows(), o.cols(), internal::scalar_discrete_dist_op<typename Derived::Scalar, Urng, int32_t>(std::forward<Urng>(urng), il.begin(), il.end())
789  };
790  }
791  }
792 }
793 
794 #endif
Eigen::Rand::balanced
const BalancedType< Derived, Urng > balanced(Index rows, Index cols, Urng &&urng)
generates reals in a range [-1, 1]
Definition: Core.h:126
Eigen::Rand::normalLike
const NormalType< Derived, Urng > normalLike(Derived &o, Urng &&urng)
generates reals on a standard normal distribution (mean = 0, stdev=1)
Definition: Core.h:224
Eigen::Rand::discreteFLike
const DiscreteFType< Derived, Urng > discreteFLike(Derived &o, Urng &&urng, RealIter first, RealIter last)
generates random integers on the interval [0, n), where the probability of each individual integer i ...
Definition: Core.h:574
Eigen::Rand::uniformReal
const UniformRealType< Derived, Urng > uniformReal(Index rows, Index cols, Urng &&urng)
generates reals in a range [0, 1)
Definition: Core.h:166
Eigen::Rand::exponentialLike
const ExponentialType< Derived, Urng > exponentialLike(Derived &o, Urng &&urng, typename Derived::Scalar lambda=1)
generates reals on an exponential distribution with arbitrary scale parameter.
Definition: Core.h:354
Eigen::Rand::exponential
const ExponentialType< Derived, Urng > exponential(Index rows, Index cols, Urng &&urng, typename Derived::Scalar lambda=1)
generates reals on an exponential distribution with arbitrary scale parameter.
Definition: Core.h:335
Eigen::Rand::discreteD
const DiscreteDType< Derived, Urng > discreteD(Index rows, Index cols, Urng &&urng, RealIter first, RealIter last)
generates random integers on the interval [0, n), where the probability of each individual integer i ...
Definition: Core.h:639
Eigen::Rand::normal
const NormalType< Derived, Urng > normal(Index rows, Index cols, Urng &&urng)
generates reals on a standard normal distribution (mean = 0, stdev=1)
Definition: Core.h:206
Eigen::Rand::randBitsLike
const RandBitsType< Derived, Urng > randBitsLike(Derived &o, Urng &&urng)
generates integers with random bits
Definition: Core.h:62
Eigen::Rand::gammaLike
const GammaType< Derived, Urng > gammaLike(Derived &o, Urng &&urng, typename Derived::Scalar alpha=1, typename Derived::Scalar beta=1)
generates reals on a gamma distribution with arbitrary shape and scale parameter.
Definition: Core.h:398
Eigen::Rand::discrete
const DiscreteType< Derived, Urng > discrete(Index rows, Index cols, Urng &&urng, RealIter first, RealIter last)
generates random integers on the interval [0, n), where the probability of each individual integer i ...
Definition: Core.h:724
Eigen::Rand::weibull
const WeibullType< Derived, Urng > weibull(Index rows, Index cols, Urng &&urng, typename Derived::Scalar a=1, typename Derived::Scalar b=1)
generates reals on a Weibull distribution with arbitrary shape and scale parameter.
Definition: Core.h:422
Eigen::Rand::chiSquared
const ChiSquaredType< Derived, Urng > chiSquared(Index rows, Index cols, Urng &&urng, typename Derived::Scalar n=1)
generates reals on the Chi-squared distribution with arbitrary degrees of freedom.
Definition: Core.h:511
Eigen::Rand::lognormal
const LognormalType< Derived, Urng > lognormal(Index rows, Index cols, Urng &&urng, typename Derived::Scalar mean=0, typename Derived::Scalar stdev=1)
generates reals on a lognormal distribution with arbitrary mean and stdev.
Definition: Core.h:292
Eigen::Rand::extremeValue
const ExtremeValueType< Derived, Urng > extremeValue(Index rows, Index cols, Urng &&urng, typename Derived::Scalar a=0, typename Derived::Scalar b=1)
generates reals on an extreme value distribution (a.k.a Gumbel Type I, log-Weibull,...
Definition: Core.h:467
Eigen::Rand::chiSquaredLike
const ChiSquaredType< Derived, Urng > chiSquaredLike(Derived &o, Urng &&urng, typename Derived::Scalar n=1)
generates reals on the Chi-squared distribution with arbitrary degrees of freedom.
Definition: Core.h:530
Eigen::Rand::extremeValueLike
const ExtremeValueType< Derived, Urng > extremeValueLike(Derived &o, Urng &&urng, typename Derived::Scalar a=0, typename Derived::Scalar b=1)
generates reals on an extreme value distribution (a.k.a Gumbel Type I, log-Weibull,...
Definition: Core.h:488
Eigen::Rand::uniformRealLike
const UniformRealType< Derived, Urng > uniformRealLike(Derived &o, Urng &&urng)
generates reals in a range [0, 1)
Definition: Core.h:184
Eigen::Rand::balancedLike
const BalancedType< Derived, Urng > balancedLike(const Derived &o, Urng &&urng)
generates reals in a range [-1, 1]
Definition: Core.h:144
Eigen::Rand::discreteLike
const DiscreteType< Derived, Urng > discreteLike(Derived &o, Urng &&urng, RealIter first, RealIter last)
generates random integers on the interval [0, n), where the probability of each individual integer i ...
Definition: Core.h:744
RandUtils.h
Eigen::Rand::gamma
const GammaType< Derived, Urng > gamma(Index rows, Index cols, Urng &&urng, typename Derived::Scalar alpha=1, typename Derived::Scalar beta=1)
generates reals on a gamma distribution with arbitrary shape and scale parameter.
Definition: Core.h:378
Eigen::Rand::lognormalLike
const LognormalType< Derived, Urng > lognormalLike(Derived &o, Urng &&urng, typename Derived::Scalar mean=0, typename Derived::Scalar stdev=1)
generates reals on a lognormal distribution with arbitrary mean and stdev.
Definition: Core.h:312
Eigen::Rand::weibullLike
const WeibullType< Derived, Urng > weibullLike(Derived &o, Urng &&urng, typename Derived::Scalar a=1, typename Derived::Scalar b=1)
generates reals on a Weibull distribution with arbitrary shape and scale parameter.
Definition: Core.h:442
Eigen::Rand::uniformInt
const UniformIntType< Derived, Urng > uniformInt(Index rows, Index cols, Urng &&urng, typename Derived::Scalar min, typename Derived::Scalar max)
generates integers with a given range [min, max]
Definition: Core.h:85
Eigen::Rand::randBits
const RandBitsType< Derived, Urng > randBits(Index rows, Index cols, Urng &&urng)
generates integers with random bits
Definition: Core.h:44
Eigen::Rand::discreteF
const DiscreteFType< Derived, Urng > discreteF(Index rows, Index cols, Urng &&urng, RealIter first, RealIter last)
generates random integers on the interval [0, n), where the probability of each individual integer i ...
Definition: Core.h:554
Eigen::Rand::uniformIntLike
const UniformIntType< Derived, Urng > uniformIntLike(Derived &o, Urng &&urng, typename Derived::Scalar min, typename Derived::Scalar max)
generates integers with a given range [min, max]
Definition: Core.h:104
Eigen::Rand::discreteDLike
const DiscreteDType< Derived, Urng > discreteDLike(Derived &o, Urng &&urng, RealIter first, RealIter last)
generates random integers on the interval [0, n), where the probability of each individual integer i ...
Definition: Core.h:659