1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
// @(#)root/mathcore:$Id$
// Authors: L. Moneta 8/2015
/**********************************************************************
* *
* Copyright (c) 2015 , ROOT MathLib Team *
* *
* *
**********************************************************************/
// implementation file of MixMax engine
//
//
// Created by: Lorenzo Moneta : Tue 4 Aug 2015
//
//
#ifndef ROOT_Math_MixMaxEngine_icc
#define ROOT_Math_MixMaxEngine_icc
#ifndef ROOT_Math_MixMaxEngine
#error "Do not use MixMaxEngine.icc directly. #include \"MixMaxEngine.h\" instead."
#endif // ROOT_Math_MixMaxEngine
//#include "Math/mixmax/mixmax.h"
#include <cassert>
#include "Math/Util.h"
namespace ROOT {
namespace Math {
template<int N, int S>
MixMaxEngine<N,S>::MixMaxEngine(uint64_t seed) {
// fRng = new mixmax::mixmax_engine<N>();
// fRng->seed(seed);
fRng = new MixMaxEngineImpl<N>(seed);
}
template<int N, int S>
MixMaxEngine<N,S>::~MixMaxEngine() {
if (fRng) delete fRng;
}
// void template<int N, int S>
//MixMaxEngine<N,S>::SeedUniqueStream(unsigned int clusterID, unsigned int machineID, unsigned int runID, unsigned int streamID) {
// seed_uniquestream(fRngState, clusterID, machineID, runID, streamID);
// }
template<int N, int S>
void MixMaxEngine<N,S>::SetSeed(uint64_t seed) {
//fRng->seed(seed);
fRng->SetSeed(seed);
}
// void template<int N, int S>
// MixMaxEngine<N,S>::SetSeed64(uint64_t seed) {
// seed_spbox(fRngState, seed);
// iterate(fRngState);
// }
// unsigned int template<int N, int S>
// MixMaxEngine<N,S>::GetSeed() const {
// return get_next(fRngState);
// }
// generate one random number in interval ]0,1]
// apply skipping when needed
template<int SkipNumber>
struct SkipFunction {
template<class Engine>
static void Apply (Engine * rng, int counter, int n) {
// apply skipping
if (counter < n) return;
for (int iskip = 0; iskip < SkipNumber; ++iskip)
rng->Iterate();
}
};
// specialization for SkipNumber = 0
template<>
struct SkipFunction<0> {
template<class Engine>
static void Apply (Engine *, int , int ) {
// no operation
}
};
template<int N, int S>
double MixMaxEngine<N,S>::Rndm_impl() {
int counter = fRng->Counter();
SkipFunction<S>::Apply(fRng, counter, N);
//reset counter to original value
// otherwise we would skip -1 time
fRng->SetCounter(counter);
return fRng->Rndm();
}
// generate one integer number
template<int N, int S>
uint64_t MixMaxEngine<N,S>::IntRndm() {
int counter = fRng->Counter();
SkipFunction<S>::Apply(fRng, counter,N);
fRng->SetCounter(counter);
return fRng->IntRndm();
}
template<int N, int S>
uint64_t MixMaxEngine<N,S>::MaxInt() {
//return mixmax::mixmax_engine<N>::max();
return 2305843009213693951ULL;
}
template<int N, int S>
uint64_t MixMaxEngine<N,S>::MinInt() {
//return mixmax::mixmax_engine<N>::min();
return 0;
}
template<int N, int S>
void MixMaxEngine<N,S>::RndmArray(int n, double *array){
// Return an array of n random numbers uniformly distributed in ]0,1]
for (int i = 0; i < n; ++i)
array[i] = Rndm_impl();
}
template<int N, int S>
void MixMaxEngine<N,S>::SetState(const std::vector<StateInt_t> & state) {
assert(state.size() >= N);
// for (int i = 0; i < N; ++i)
// fRng->S.V[i] = state[i];
// //set counter to fore iteration afterwards
// fRng->S.counter = N;
fRng->SetState(state);
fRng->SetCounter(N);
}
template<int N, int S>
void MixMaxEngine<N,S>::GetState(std::vector<StateInt_t> & state) const {
state.resize(N);
fRng->GetState(state);
}
template<int N, int S>
int MixMaxEngine<N,S>::Size() {
return MixMaxEngineImpl<N>::Size();
}
template<int N, int S>
int MixMaxEngine<N,S>::Counter() const {
return fRng->Counter();
}
template<int N, int S>
std::string MixMaxEngine<N,S>::Name() {
std::string name = "MixMax";
name += Util::ToString(N);
if (S > 0) name += std::string("_") + Util::ToString(S);
return name;
}
} // namespace Math
} // namespace ROOT
#endif
|