Coverage Report

Created: 2025-12-08 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/math/randomnumbers/burley2020sobolrsg.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2023 Peter Caspers
5
6
 This file is part of QuantLib, a free-software/open-source library
7
 for financial quantitative analysts and developers - http://quantlib.org/
8
9
 QuantLib is free software: you can redistribute it and/or modify it
10
 under the terms of the QuantLib license.  You should have received a
11
 copy of the license along with this program; if not, please email
12
 <quantlib-dev@lists.sf.net>. The license is also available online at
13
 <https://www.quantlib.org/license.shtml>.
14
15
 This program is distributed in the hope that it will be useful, but WITHOUT
16
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
 FOR A PARTICULAR PURPOSE.  See the license for more details.
18
*/
19
20
/*! \file burley2020sobolrsg.hpp
21
    \brief scrambled Sobol sequence following Burley, 2020
22
*/
23
24
#ifndef quantlib_burley2020_scrambled_sobolrsg_hpp
25
#define quantlib_burley2020_scrambled_sobolrsg_hpp
26
27
#include <ql/math/randomnumbers/sobolrsg.hpp>
28
#include <ql/shared_ptr.hpp>
29
30
namespace QuantLib {
31
32
    //! Scrambled sobol sequence according to Burley, 2020
33
    /*! Reference: Brent Burley: Practical Hash-based Owen Scrambling,
34
        Journal of Computer Graphics Techniques, Vol. 9, No. 4, 2020 */
35
    class Burley2020SobolRsg {
36
      public:
37
        typedef Sample<std::vector<Real>> sample_type;
38
        explicit Burley2020SobolRsg(
39
            Size dimensionality,
40
            unsigned long seed = 42,
41
            SobolRsg::DirectionIntegers directionIntegers = SobolRsg::Jaeckel,
42
            unsigned long scrambleSeed = 43);
43
        const std::vector<std::uint32_t>& skipTo(std::uint32_t n) const;
44
        const std::vector<std::uint32_t>& nextInt32Sequence() const;
45
        const SobolRsg::sample_type& nextSequence() const;
46
0
        const sample_type& lastSequence() const { return sequence_; }
47
0
        Size dimension() const { return dimensionality_; }
48
49
      private:
50
        void reset() const;
51
        Size dimensionality_;
52
        unsigned long seed_;
53
        SobolRsg::DirectionIntegers directionIntegers_;
54
        mutable ext::shared_ptr<SobolRsg> sobolRsg_;
55
        mutable std::vector<std::uint32_t> integerSequence_;
56
        mutable sample_type sequence_;
57
        mutable std::uint32_t nextSequenceCounter_;
58
        mutable std::vector<std::uint32_t> group4Seeds_;
59
    };
60
61
}
62
63
64
#endif