-
Notifications
You must be signed in to change notification settings - Fork 7
/
Storage-SIMPLE-DIGITAL.h
118 lines (98 loc) · 4.49 KB
/
Storage-SIMPLE-DIGITAL.h
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
// This file is part of LatNet Builder.
//
// Copyright (C) 2012-2021 The LatNet Builder author's, supervised by Pierre L'Ecuyer, Universite de Montreal.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef LATBUILDER__STORAGE_SIMPLE_DIGITAL_H
#define LATBUILDER__STORAGE_SIMPLE_DIGITAL_H
#include "latbuilder/Storage.h"
#include "latbuilder/CompressTraits.h"
#include "latbuilder/SizeParam.h"
#include "latbuilder/Types.h"
#include "latbuilder/Util.h"
namespace LatBuilder {
template <Compress COMPRESS>
struct StorageTraits<Storage<LatticeType::DIGITAL, EmbeddingType::UNILEVEL, COMPRESS>> {
typedef uInteger size_type;
typedef typename LatticeTraits<LatticeType::DIGITAL>::GenValue value_type;
typedef CompressTraits<COMPRESS> Compress;
typedef Real MeritValue;
typedef LatBuilder::SizeParam<LatticeType::DIGITAL, EmbeddingType::UNILEVEL> SizeParam;
/**
* Unpermuted permutation.
*/
class Unpermute {
public:
typedef StorageTraits::size_type size_type;
Unpermute(Storage<LatticeType::DIGITAL, EmbeddingType::UNILEVEL, COMPRESS> storage): m_storage(std::move(storage)) {}
size_type operator() (size_type i) const { return Compress::compressIndex(i, m_storage.virtualSize()); }
size_type size() const { return m_storage.virtualSize(); }
private:
Storage<LatticeType::DIGITAL, EmbeddingType::UNILEVEL, COMPRESS> m_storage;
};
/**
* Stride permutation.
*
* For digital nets:
* a Stride with takes as parameter a generating matrix \f$M\f$ is the mapping that maps an index \f$i\f$ as follows:
* - convert the binary representation of \f$i\f$ to its associated Gray code \f$\boldsymbol i'\f$
* - compute \f$M \boldsymbol i'\f$ which is the reversed binary representation of the result integer
*
* Since the integers are first converted to Gray code, the computation of \f$M \boldsymbol i'\f$ can be fastened as explained in
* these <a href="http://web.maths.unsw.edu.au/~fkuo/sobol/joe-kuo-notes.pdf">notes by Joe and Kuo on the generation of Sobol' sequences</a>.
*/
class Stride {
public:
typedef StorageTraits::size_type size_type;
typedef StorageTraits::value_type value_type;
Stride(Storage<LatticeType::DIGITAL, EmbeddingType::UNILEVEL, COMPRESS> storage, value_type stride):
m_storage(std::move(storage)),
m_stride(stride),
m_permutation(m_storage.virtualSize(), 0)
{
std::vector<unsigned long> cols = m_stride.getColsReverse();
for(size_type i=m_graycode.size(); i < m_permutation.size(); i++){
m_graycode.push_back(getmsb(((i >> 1) ^ i)^(((i+1) >> 1) ^ (i+1))));
}
for (size_type i=1; i<m_permutation.size(); ++i){
m_permutation[i] = m_permutation[i-1] ^ cols[m_graycode[i-1]];
}
}
size_type operator() (size_type i) const
{
return Compress::compressIndex(m_permutation[i], m_storage.virtualSize());
}
size_type size() const
{ return m_storage.size(); }
private:
Storage<LatticeType::DIGITAL, EmbeddingType::UNILEVEL, COMPRESS> m_storage;
value_type m_stride;
std::vector<size_type> m_permutation;
static std::vector<size_type> m_graycode;
static unsigned int
getmsb (unsigned long long x)
{
unsigned int r = 0;
if (x < 1) return 0;
while (x >>= 1) r++;
return r;
}
};
};
// template
template <Compress COMPRESS> std::vector<uInteger> StorageTraits<Storage<LatticeType::DIGITAL, EmbeddingType::UNILEVEL, COMPRESS>>::Stride::m_graycode = std::vector<uInteger>();
// StorageTraits< = std::vector<size_type>()
// template<> std::vector<uInteger> StorageTraits<Storage<LatticeType::DIGITAL, EmbeddingType::UNILEVEL, Compress::NONE>>::Stride::m_graycode = std::vector<uInteger>();
// template<> std::vector<uInteger> StorageTraits<Storage<LatticeType::DIGITAL, EmbeddingType::UNILEVEL, Compress::SYMMETRIC>>::Stride::m_graycode = std::vector<uInteger>();
}
#endif