File: MixMaxEngineImpl.h

package info (click to toggle)
bornagain 23.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,956 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 356; ruby: 173; xml: 130; makefile: 45; ansic: 24
file content (138 lines) | stat: -rw-r--r-- 3,026 bytes parent folder | download | duplicates (5)
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


#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

#ifndef ROOT_Math_MixMaxEngineImpl
#define ROOT_Math_MixMaxEngineImpl


#if (ROOT_MM_N==17)
namespace mixmax_17 {
#elif (ROOT_MM_N==240)
namespace mixmax_240 {
#elif (ROOT_MM_N==256)
namespace mixmax_256 {
#else
namespace { 
#endif

#ifdef WIN32
#define __thread __declspec(thread)
#endif

#include "mixmax.icc"

#undef N
}

#include "Math/MixMaxEngine.h"

#include <iostream>

#if (ROOT_MM_N==17)
using namespace mixmax_17;
#elif (ROOT_MM_N==240)
using namespace mixmax_240;
#elif (ROOT_MM_N==256)
using namespace mixmax_256;
#endif


namespace ROOT {
   namespace Math {



         // dummy implementation
   template<int N>
   class MixMaxEngineImpl {
   public: 
      MixMaxEngineImpl(uint64_t) {
         std::cerr << "MixMaxEngineImpl - These template parameters are not supported for MixMaxEngine" << std::endl;
      }
      ~MixMaxEngineImpl() {}
      void SetSeed(uint64_t) { }
      double Rndm() { return -1; }
      double IntRndm() { return 0; }
      void SetState(const std::vector<uint64_t> &) { }
      void GetState(std::vector<uint64_t> &) { }
      int Counter() { return -1; }
      void SetCounter(int) {}
      void Iterate() {} 
   };


template<> 
class MixMaxEngineImpl<ROOT_MM_N> {
   rng_state_t * fRngState;
public:

   typedef MixMaxEngine<ROOT_MM_N,0>::StateInt_t StateInt_t; 
   typedef MixMaxEngine<ROOT_MM_N,0>::Result_t Result_t;
   
   MixMaxEngineImpl(uint64_t seed) {
      fRngState = rng_alloc();
      SetSeed(seed); 
   }
   ~MixMaxEngineImpl() {
      rng_free(fRngState);
   }
   void SetSeedFast(Result_t seed) {
      seed_spbox(fRngState, seed);
   }
   void SetSeed(Result_t seed) {
      //seed_spbox(fRngState, seed);
      seed_uniquestream(fRngState, 0, 0, (uint32_t)(seed>>32), (uint32_t)seed );
   }
   double Rndm() {
       return get_next_float(fRngState);
   }
   // generate one integer number 
   Result_t IntRndm() {
      return get_next(fRngState);
   }
   void SetState(const std::vector<StateInt_t> & state) {
      if (fRngState) rng_free(fRngState);
      fRngState = rng_copy(const_cast<StateInt_t*>(state.data()) );
   }
   void GetState(std::vector<StateInt_t> & state) const {
      int n =  rng_get_N(); 
      state.resize(n);
      for (int i = 0; i < n; ++i)
         state[i] = fRngState->V[i];
   }
   void Iterate() {
      iterate(fRngState); 
   }
   int Counter() const {
      return fRngState->counter; 
   }
   void SetCounter(int val) {
      fRngState->counter = val; 
   }
   static int Size()  {
      return rng_get_N(); 
   }

   // to silent some warning
   void RndmArray(int n, double * array) {
      fill_array(fRngState, n, array); 
   }
   void ReadState(const char filename[] ) {
      read_state(fRngState, filename);
   }
   // branch generator given a vector of seed (at least 4 32 bit values)
   void Branch(uint32_t * seedvec) {
      branch_inplace(fRngState, seedvec); 
   }
     
   
};

      
   } // end namesapce Math
} // end namespace ROOT

#endif