Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | Friends | List of all members
Filter Struct Reference

#include <qle/math/randomvariable.hpp>

+ Collaboration diagram for Filter:

Public Member Functions

 ~Filter ()
 
 Filter ()
 
 Filter (const Filter &r)
 
 Filter (Filter &&r)
 
Filteroperator= (const Filter &r)
 
Filteroperator= (Filter &&r)
 
 Filter (const Size n, const bool value=false)
 
void clear ()
 
void set (const Size i, const bool v)
 
void setAll (const bool v)
 
void resetSize (const Size n)
 
bool deterministic () const
 
void updateDeterministic ()
 
bool initialised () const
 
Size size () const
 
bool operator[] (const Size i) const
 
bool at (const Size i) const
 
void expand ()
 
booldata ()
 

Private Attributes

Size n_
 
bool constantData_
 
booldata_
 
bool deterministic_
 

Friends

Filter operator&& (Filter, const Filter &)
 
Filter operator|| (Filter, const Filter &)
 
Filter equal (Filter, const Filter &)
 
Filter operator! (Filter)
 
bool operator== (const Filter &, const Filter &)
 

Detailed Description

Definition at line 66 of file randomvariable.hpp.

Constructor & Destructor Documentation

◆ ~Filter()

~Filter ( )

Definition at line 92 of file randomvariable.cpp.

92{ clear(); }
+ Here is the call graph for this function:

◆ Filter() [1/4]

Filter ( )

Definition at line 94 of file randomvariable.cpp.

◆ Filter() [2/4]

Filter ( const Filter r)

Definition at line 96 of file randomvariable.cpp.

96 {
97 n_ = r.n_;
98 constantData_ = r.constantData_;
99 if (r.data_) {
100 resumeDataStats();
101 data_ = new bool[n_];
102 // std::memcpy(data_, r.data_, n_ * sizeof(bool));
103 std::copy(r.data_, r.data_ + n_, data_);
104 stopDataStats(n_);
105 } else {
106 data_ = nullptr;
107 }
108 deterministic_ = r.deterministic_;
109}

◆ Filter() [3/4]

Filter ( Filter &&  r)

Definition at line 111 of file randomvariable.cpp.

111 {
112 n_ = r.n_;
113 constantData_ = r.constantData_;
114 data_ = r.data_;
115 r.data_ = nullptr;
116 deterministic_ = r.deterministic_;
117}

◆ Filter() [4/4]

Filter ( const Size  n,
const bool  value = false 
)
explicit

Definition at line 162 of file randomvariable.cpp.

162: n_(n), constantData_(value), data_(nullptr), deterministic_(n != 0) {}

Member Function Documentation

◆ operator=() [1/2]

Filter & operator= ( const Filter r)

Definition at line 119 of file randomvariable.cpp.

119 {
120 if (r.deterministic_) {
121 deterministic_ = true;
122 if (data_) {
123 delete[] data_;
124 data_ = nullptr;
125 }
126 } else {
127 deterministic_ = false;
128 if (r.n_ != 0) {
129 resumeDataStats();
130 if (n_ != r.n_) {
131 if (data_)
132 delete[] data_;
133 data_ = new bool[r.n_];
134 }
135 // std::memcpy(data_, r.data_, r.n_ * sizeof(bool));
136 std::copy(r.data_, r.data_ + r.n_, data_);
137 stopDataStats(r.n_);
138 } else {
139 if (data_) {
140 delete[] data_;
141 data_ = nullptr;
142 }
143 }
144 }
145 n_ = r.n_;
146 constantData_ = r.constantData_;
147 return *this;
148}

◆ operator=() [2/2]

Filter & operator= ( Filter &&  r)

Definition at line 150 of file randomvariable.cpp.

150 {
151 n_ = r.n_;
152 constantData_ = r.constantData_;
153 if (data_) {
154 delete[] data_;
155 }
156 data_ = r.data_;
157 r.data_ = nullptr;
158 deterministic_ = r.deterministic_;
159 return *this;
160}

◆ clear()

void clear ( )

Definition at line 164 of file randomvariable.cpp.

164 {
165 n_ = 0;
166 constantData_ = false;
167 if (data_) {
168 delete[] data_;
169 data_ = nullptr;
170 }
171 deterministic_ = false;
172}
+ Here is the caller graph for this function:

◆ set()

void set ( const Size  i,
const bool  v 
)

Definition at line 114 of file randomvariable.hpp.

114 {
115 QL_REQUIRE(i < n_, "Filter::set(" << i << "): out of bounds, size is " << n_);
116 if (deterministic_) {
117 if (v != constantData_)
118 expand();
119 else
120 return;
121 }
122 data_[i] = v;
123}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAll()

void setAll ( const bool  v)

Definition at line 188 of file randomvariable.cpp.

188 {
189 QL_REQUIRE(n_ > 0, "Filter::setAll(): dimension is zero");
190 if (data_) {
191 delete[] data_;
192 data_ = nullptr;
193 }
194 constantData_ = v;
195 deterministic_ = true;
196}
+ Here is the caller graph for this function:

◆ resetSize()

void resetSize ( const Size  n)

Definition at line 198 of file randomvariable.cpp.

198 {
199 QL_REQUIRE(deterministic_, "Filter::resetSize(): only possible for deterministic variables.");
200 n_ = n;
201}

◆ deterministic()

bool deterministic ( ) const

Definition at line 84 of file randomvariable.hpp.

84{ return deterministic_; }
+ Here is the caller graph for this function:

◆ updateDeterministic()

void updateDeterministic ( )

Definition at line 174 of file randomvariable.cpp.

174 {
175 if (deterministic_ || !initialised())
176 return;
177 resumeCalcStats();
178 for (Size i = 0; i < n_; ++i) {
179 if (data_[i] != constantData_) {
180 stopCalcStats(i);
181 return;
182 }
183 }
185 stopCalcStats(n_);
186}
void setAll(const bool v)
bool initialised() const
+ Here is the call graph for this function:

◆ initialised()

bool initialised ( ) const

Definition at line 87 of file randomvariable.hpp.

87{ return n_ != 0; }
+ Here is the caller graph for this function:

◆ size()

Size size ( ) const

Definition at line 88 of file randomvariable.hpp.

88{ return n_; }
+ Here is the caller graph for this function:

◆ operator[]()

bool operator[] ( const Size  i) const

Definition at line 125 of file randomvariable.hpp.

125 {
126 if (deterministic_)
127 return constantData_;
128 else
129 return data_[i];
130}
+ Here is the caller graph for this function:

◆ at()

bool at ( const Size  i) const

Definition at line 132 of file randomvariable.hpp.

132 {
133 QL_REQUIRE(n_ > 0, "Filter::at(" << i << "): dimension is zero");
134 if (deterministic_)
135 return constantData_;
136 QL_REQUIRE(i < n_, "Filter::at(" << i << "): out of bounds, size is " << n_);
137 return operator[](i);
138}
bool operator[](const Size i) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ expand()

void expand ( )

Definition at line 203 of file randomvariable.cpp.

203 {
204 if (!deterministic_)
205 return;
206 deterministic_ = false;
207 resumeDataStats();
208 data_ = new bool[n_];
209 std::fill(data_, data_ + n_, constantData_);
210 stopDataStats(n_);
211}
+ Here is the caller graph for this function:

◆ data()

bool * data ( )

Definition at line 140 of file randomvariable.hpp.

140{ return data_; }

Friends And Related Function Documentation

◆ operator&&

Filter operator&& ( Filter  ,
const Filter  
)
friend

Definition at line 232 of file randomvariable.cpp.

232 {
233 QL_REQUIRE(!x.initialised() || !y.initialised() || x.size() == y.size(),
234 "RandomVariable: x && y: x size (" << x.size() << ") must be equal to y size (" << y.size() << ")");
235 if (x.deterministic() && !x.constantData_)
236 return Filter(x.size(), false);
237 if (y.deterministic() && !y.constantData_)
238 return Filter(y.size(), false);
239 if (!x.initialised() || !y.initialised())
240 return Filter();
241 if (!y.deterministic_)
242 x.expand();
243 if (x.deterministic_) {
244 x.constantData_ = x.constantData_ && y.constantData_;
245 } else {
246 resumeCalcStats();
247 for (Size i = 0; i < x.size(); ++i) {
248 x.data_[i] = x.data_[i] && y[i];
249 }
250 stopCalcStats(x.size());
251 }
252 return x;
253}

◆ operator||

Filter operator|| ( Filter  ,
const Filter  
)
friend

Definition at line 255 of file randomvariable.cpp.

255 {
256 QL_REQUIRE(!x.initialised() || !y.initialised() || x.size() == y.size(),
257 "RandomVariable: x || y: x size (" << x.size() << ") must be equal to y size (" << y.size() << ")");
258 if (x.deterministic() && x.constantData_)
259 return Filter(x.size(), true);
260 if (y.deterministic() && y.constantData_)
261 return Filter(y.size(), true);
262 if (!x.initialised() || !y.initialised())
263 return Filter();
264 if (!y.deterministic_)
265 x.expand();
266 if (x.deterministic_) {
267 x.constantData_ = x.constantData_ || y.constantData_;
268 } else {
269 resumeCalcStats();
270 for (Size i = 0; i < x.size(); ++i) {
271 x.data_[i] = x.data_[i] || y[i];
272 }
273 stopCalcStats(x.size());
274 }
275 return x;
276}

◆ equal

Filter equal ( Filter  ,
const Filter  
)
friend

Definition at line 278 of file randomvariable.cpp.

278 {
279 if (!x.initialised() || !y.initialised())
280 return Filter();
281 QL_REQUIRE(x.size() == y.size(),
282 "RandomVariable: equal(x,y): x size (" << x.size() << ") must be equal to y size (" << y.size() << ")");
283 if (!y.deterministic_)
284 x.expand();
285 if (x.deterministic_) {
286 x.constantData_ = x.constantData_ == y.constantData_;
287 } else {
288 resumeCalcStats();
289 for (Size i = 0; i < x.size(); ++i) {
290 x.data_[i] = x.data_[i] == y[i];
291 }
292 stopCalcStats(x.size());
293 }
294 return x;
295}

◆ operator!

Filter operator! ( Filter  )
friend

Definition at line 297 of file randomvariable.cpp.

297 {
298 if (x.deterministic_)
299 x.constantData_ = !x.constantData_;
300 else {
301 resumeCalcStats();
302 for (Size i = 0; i < x.size(); ++i) {
303 x.data_[i] = !x.data_[i];
304 }
305 stopCalcStats(x.size());
306 }
307 return x;
308}

◆ operator==

bool operator== ( const Filter ,
const Filter  
)
friend

Definition at line 213 of file randomvariable.cpp.

213 {
214 if (a.size() != b.size())
215 return false;
216 if (a.deterministic_ && b.deterministic_) {
217 return a.constantData_ == b.constantData_;
218 } else {
219 resumeCalcStats();
220 for (Size j = 0; j < a.size(); ++j)
221 if (a[j] != b[j]) {
222 stopCalcStats(j);
223 return false;
224 }
225 stopCalcStats(a.size());
226 }
227 return true;
228}

Member Data Documentation

◆ n_

Size n_
private

Definition at line 106 of file randomvariable.hpp.

◆ constantData_

bool constantData_
private

Definition at line 107 of file randomvariable.hpp.

◆ data_

bool* data_
private

Definition at line 108 of file randomvariable.hpp.

◆ deterministic_

bool deterministic_
private

Definition at line 109 of file randomvariable.hpp.