From 460a74805ac2b6939169705d5d42f35568ec7d5b Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:14:57 +0200 Subject: [PATCH 01/19] Removed workflows for the time being to reduce the amount of builds --- .github/workflows/copyrights.yml | 21 --- .github/workflows/devenv-images.yml | 42 ----- .github/workflows/linux-full-tests.yml | 224 ------------------------- .github/workflows/linux-nondefault.yml | 178 -------------------- .github/workflows/linux.yml | 169 ------------------- .github/workflows/macos-nondefault.yml | 38 ----- .github/workflows/macos.yml | 38 ----- .github/workflows/misspell.yml | 19 --- .github/workflows/msvc-all-configs.yml | 68 -------- .github/workflows/msvc-analysis.yml | 53 ------ .github/workflows/msvc-nondefault.yml | 66 -------- .github/workflows/msvc.yml | 61 ------- .github/workflows/sanitizer.yml | 44 ----- .github/workflows/stale.yml | 22 --- .github/workflows/tidy.yml | 32 ---- 15 files changed, 1075 deletions(-) delete mode 100644 .github/workflows/copyrights.yml delete mode 100644 .github/workflows/devenv-images.yml delete mode 100644 .github/workflows/linux-full-tests.yml delete mode 100644 .github/workflows/linux-nondefault.yml delete mode 100644 .github/workflows/linux.yml delete mode 100644 .github/workflows/macos-nondefault.yml delete mode 100644 .github/workflows/macos.yml delete mode 100644 .github/workflows/misspell.yml delete mode 100644 .github/workflows/msvc-all-configs.yml delete mode 100644 .github/workflows/msvc-analysis.yml delete mode 100644 .github/workflows/msvc-nondefault.yml delete mode 100644 .github/workflows/msvc.yml delete mode 100644 .github/workflows/sanitizer.yml delete mode 100644 .github/workflows/stale.yml delete mode 100644 .github/workflows/tidy.yml diff --git a/.github/workflows/copyrights.yml b/.github/workflows/copyrights.yml deleted file mode 100644 index 776cf32a581..00000000000 --- a/.github/workflows/copyrights.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Update copyright list -on: - push: - branches: - - '**' -jobs: - copyrights: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Check - run: | - ./tools/check_copyrights.sh - - uses: peter-evans/create-pull-request@v6 - with: - token: ${{ secrets.GITHUB_TOKEN }} - branch: update-copyright-list-${{ github.ref_name }} - delete-branch: true - commit-message: 'Update copyright list in license' - title: 'Update copyright list in license' - author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> diff --git a/.github/workflows/devenv-images.yml b/.github/workflows/devenv-images.yml deleted file mode 100644 index d28759a30f9..00000000000 --- a/.github/workflows/devenv-images.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Build quantlib-devenv Docker images -on: - workflow_dispatch: - inputs: - boostVersion: - description: 'Boost version' - required: true -env: - ROLLING: mantic -jobs: - docker-images: - runs-on: ubuntu-latest - strategy: - matrix: - tag: [lunar, mantic, noble] - steps: - - uses: actions/checkout@v4 - - name: Build CI images - working-directory: dockerfiles - run: | - docker build -f ci.Dockerfile \ - --build-arg tag=${{ matrix.tag }} \ - --build-arg boost_version=${{ github.event.inputs.boostVersion }} \ - --build-arg boost_dir=boost_$(echo "${{ github.event.inputs.boostVersion }}" | sed "s/\./_/g") \ - -t ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }} . - docker tag ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }} ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }}-${{ github.event.inputs.boostVersion }} - if test "${{ matrix.tag }}" = "$ROLLING" ; then - docker tag ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }} ghcr.io/lballabio/quantlib-devenv:rolling - fi - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GHCR_PAT }} - - name: Push Docker images - run: | - docker push ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }}-${{ github.event.inputs.boostVersion }} - docker push ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }} - if test "${{ matrix.tag }}" = "$ROLLING" ; then - docker push ghcr.io/lballabio/quantlib-devenv:rolling - fi diff --git a/.github/workflows/linux-full-tests.yml b/.github/workflows/linux-full-tests.yml deleted file mode 100644 index 7561d4a451b..00000000000 --- a/.github/workflows/linux-full-tests.yml +++ /dev/null @@ -1,224 +0,0 @@ -name: Linux build with full test matrix -on: - schedule: - - cron: '0 0 * * 0' - workflow_dispatch: -jobs: - build: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - include: - - name: "gcc 5.4 (Boost 1.66)" - shortname: gcc5 - tag: xenial - cc: gcc - cxx: g++ - - name: "gcc 6.3 (Boost 1.66)" - shortname: gcc6 - tag: zesty - cc: gcc - cxx: g++ - - name: "gcc 7.4 (Boost 1.72)" - shortname: gcc7 - tag: bionic - cc: gcc - cxx: g++ - - name: "gcc 8.3 (Boost 1.72)" - shortname: gcc8 - tag: cosmic - cc: gcc - cxx: g++ - - name: "gcc 9.3 (Boost 1.78)" - shortname: gcc9 - tag: focal - cc: gcc - cxx: g++ - - name: "gcc 10.3 (Boost 1.79)" - shortname: gcc10 - tag: hirsute - cc: gcc - cxx: g++ - - name: "gcc 11.4 (Boost 1.82)" - shortname: gcc11 - tag: jammy - cc: gcc - cxx: g++ - - name: "gcc 12.x" - shortname: gcc12 - tag: lunar - cc: gcc - cxx: g++ - - name: "gcc 13.x" - shortname: gcc13 - tag: mantic - cc: gcc - cxx: g++ - - name: "Clang 6 (Boost 1.72)" - shortname: clang6 - tag: bionic - cc: clang - cxx: clang++ - - name: "Clang 7 (Boost 1.72)" - shortname: clang7 - tag: cosmic - cc: clang - cxx: clang++ - - name: "Clang 8 (Boost 1.72)" - shortname: clang8 - tag: disco - cc: clang - cxx: clang++ - - name: "Clang 9 (Boost 1.74)" - shortname: clang9 - tag: eoan - cc: clang - cxx: clang++ - - name: "Clang 10 (Boost 1.78)" - shortname: clang10 - tag: focal - cc: clang - cxx: clang++ - - name: "Clang 11 (Boost 1.78)" - shortname: clang11 - tag: groovy - cc: clang - cxx: clang++ - - name: "Clang 12 (Boost 1.79)" - shortname: clang12 - tag: hirsute - cc: clang - cxx: clang++ - - name: "Clang 13 (Boost 1.79)" - shortname: clang13 - tag: impish - cc: clang - cxx: clang++ - - name: "Clang 14 (Boost 1.82)" - shortname: clang14 - tag: jammy - cc: clang - cxx: clang++ - - name: "Clang 15" - shortname: clang15 - tag: lunar - cc: clang - cxx: clang++ - - name: "Clang 16" - shortname: clang16 - tag: mantic - cc: clang - cxx: clang++ - - name: "Clang 17 (Boost 1.84)" - shortname: clang17 - tag: clang-17 - cc: clang - cxx: clang++ - - name: "Clang 18" - shortname: clang18 - tag: noble - cc: clang - cxx: clang++ - cxxflags: -Wno-deprecated-declarations - - name: "C++14 mode" - shortname: c++14 - tag: rolling - cc: gcc - cxx: g++ - cxxflags: "-std=c++14" - - name: "C++17 mode" - shortname: c++17 - tag: rolling - cc: gcc - cxx: g++ - cxxflags: "-std=c++17" - - name: "C++20 mode" - shortname: c++20 - tag: rolling - cc: gcc - cxx: g++ - cxxflags: "-std=c++20" - - name: "Unity build enabled" - shortname: unity - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-unity-build - - name: "Intraday calculations enabled" - shortname: intraday - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-intraday - - name: "Throwing in cycles enabled" - shortname: cycles - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-throwing-in-cycles --disable-faster-lazy-objects - - name: "Indexed coupons enabled" - shortname: indexed - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-indexed-coupons - - name: "Standard Library classes enabled/disabled" - shortname: stdclasses - tag: rolling - cc: gcc - cxx: g++ - configureflags: --disable-std-function --disable-std-tuple --enable-std-pointers --enable-std-any --enable-std-optional - - name: "Thread-safe observer enabled" - shortname: threadsafe - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-thread-safe-observer-pattern - - name: "Sessions enabled" - shortname: sessions - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-sessions - - name: "OpenMP enabled" - shortname: openmp - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-openmp - - name: "Parallel unit-test runner" - shortname: paralleltests - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-parallel-unit-test-runner - - name: "Null as function template" - shortname: nullfunctions - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-null-as-functions - container: ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }} - steps: - - uses: actions/checkout@v3 - - name: Compiler version - run: | - ${{ matrix.cc }} --version - - name: Build - run: | - ./autogen.sh - ./configure --disable-static ${{ matrix.configureflags }} CC="${{ matrix.cc }}" CXX="${{ matrix.cxx }}" CXXFLAGS="-O2 -g0 -Wall -Wno-unknown-pragmas -Werror ${{ matrix.cxxflags }}" - make -j 4 - - name: Run tests - run: | - ./test-suite/quantlib-test-suite --log_level=message - - name: Run examples - run: | - make check-examples - - name: Check global header - run: | - echo "#include " > test1.cpp && echo "int main() { return 0; }" >> test1.cpp - echo "#include " > test2.cpp - make install - ${{ matrix.cxx }} -O2 -g0 -Wall -Wno-unknown-pragmas -Werror ${{ matrix.cxxflags }} `quantlib-config --cflags` test1.cpp test2.cpp `quantlib-config --libs` diff --git a/.github/workflows/linux-nondefault.yml b/.github/workflows/linux-nondefault.yml deleted file mode 100644 index f55c60aabd6..00000000000 --- a/.github/workflows/linux-nondefault.yml +++ /dev/null @@ -1,178 +0,0 @@ -name: Linux build with non-default configuration -on: - schedule: - - cron: '0 0 * * 0' - workflow_dispatch: -jobs: - build: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - include: - - name: "gcc 5.4 (Boost 1.66)" - shortname: gcc5 - tag: xenial - cc: gcc - cxx: g++ - - name: "gcc 6.3 (Boost 1.66)" - shortname: gcc6 - tag: zesty - cc: gcc - cxx: g++ - - name: "gcc 7.4 (Boost 1.72)" - shortname: gcc7 - tag: bionic - cc: gcc - cxx: g++ - - name: "gcc 8.3 (Boost 1.72)" - shortname: gcc8 - tag: cosmic - cc: gcc - cxx: g++ - - name: "gcc 9.3 (Boost 1.78)" - shortname: gcc9 - tag: focal - cc: gcc - cxx: g++ - - name: "gcc 10.3 (Boost 1.79)" - shortname: gcc10 - tag: hirsute - cc: gcc - cxx: g++ - - name: "gcc 11.4 (Boost 1.82)" - shortname: gcc11 - tag: jammy - cc: gcc - cxx: g++ - - name: "gcc 12.x" - shortname: gcc12 - tag: lunar - cc: gcc - cxx: g++ - - name: "gcc 13.x" - shortname: gcc13 - tag: mantic - cc: gcc - cxx: g++ - - name: "Clang 6 (Boost 1.72)" - shortname: clang6 - tag: bionic - cc: clang - cxx: clang++ - - name: "Clang 7 (Boost 1.72)" - shortname: clang7 - tag: cosmic - cc: clang - cxx: clang++ - - name: "Clang 8 (Boost 1.72)" - shortname: clang8 - tag: disco - cc: clang - cxx: clang++ - - name: "Clang 9 (Boost 1.74)" - shortname: clang9 - tag: eoan - cc: clang - cxx: clang++ - - name: "Clang 10 (Boost 1.78)" - shortname: clang10 - tag: focal - cc: clang - cxx: clang++ - - name: "Clang 11 (Boost 1.78)" - shortname: clang11 - tag: groovy - cc: clang - cxx: clang++ - - name: "Clang 12 (Boost 1.79)" - shortname: clang12 - tag: hirsute - cc: clang - cxx: clang++ - - name: "Clang 13 (Boost 1.79)" - shortname: clang13 - tag: impish - cc: clang - cxx: clang++ - - name: "Clang 14 (Boost 1.82)" - shortname: clang14 - tag: jammy - cc: clang - cxx: clang++ - - name: "Clang 15" - shortname: clang15 - tag: lunar - cc: clang - cxx: clang++ - - name: "Clang 16" - shortname: clang16 - tag: mantic - cc: clang - cxx: clang++ - - name: "Clang 18" - shortname: clang18 - tag: noble - cc: clang - cxx: clang++ - cxxflags: -Wno-deprecated-declarations - - name: "C++14 mode" - shortname: c++14 - tag: rolling - cc: gcc - cxx: g++ - cxxflags: "-std=c++14" - - name: "C++17 mode" - shortname: c++17 - tag: rolling - cc: gcc - cxx: g++ - cxxflags: "-std=c++17" - - name: "C++20 mode" - shortname: c++20 - tag: rolling - cc: gcc - cxx: g++ - cxxflags: "-std=c++20" - - name: "Unity build enabled" - shortname: unity - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-unity-build - - name: "Standard Library classes enabled/disabled" - shortname: stdclasses - tag: rolling - cc: gcc - cxx: g++ - cxxflags: "-std=c++17" - configureflags: --disable-std-function --disable-std-tuple --enable-std-pointers --enable-std-any --enable-std-optional - - name: "OpenMP enabled" - shortname: openmp - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-openmp - container: ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }} - steps: - - uses: actions/checkout@v3 - - name: Compiler version - run: | - ${{ matrix.cc }} --version - - name: Build - run: | - ./autogen.sh - ./configure --disable-static --enable-error-lines --enable-error-functions --enable-tracing --enable-indexed-coupons --enable-extra-safety-checks --enable-sessions --enable-thread-safe-observer-pattern --enable-intraday --disable-faster-lazy-objects --enable-throwing-in-cycles --enable-null-as-functions ${{ matrix.configureflags }} CC="${{ matrix.cc }}" CXX="${{ matrix.cxx }}" CXXFLAGS="-O2 -g0 -Wall -Wno-unknown-pragmas -Wno-array-bounds -Werror ${{ matrix.cxxflags }}" - make -j 4 - - name: Run tests - run: | - ./test-suite/quantlib-test-suite --log_level=message - - name: Run examples - run: | - make check-examples - - name: Check global header - run: | - echo "#include " > test1.cpp && echo "int main() { return 0; }" >> test1.cpp - echo "#include " > test2.cpp - make install - ${{ matrix.cxx }} -O2 -g0 -Wall -Wno-unknown-pragmas -Werror ${{ matrix.cxxflags }} `quantlib-config --cflags` test1.cpp test2.cpp `quantlib-config --libs` diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml deleted file mode 100644 index 1dd8d41ba34..00000000000 --- a/.github/workflows/linux.yml +++ /dev/null @@ -1,169 +0,0 @@ -name: Linux build -on: [push, pull_request] -jobs: - build: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - include: - - name: "gcc 9.3 (Boost 1.78)" - shortname: gcc9 - tag: focal - cc: gcc - cxx: g++ - - name: "gcc 11.4 (Boost 1.82)" - shortname: gcc11 - tag: jammy - cc: gcc - cxx: g++ - - name: "gcc 13.x" - shortname: gcc13 - tag: mantic - cc: gcc - cxx: g++ - tests: true - - name: "Clang 10 (Boost 1.78)" - shortname: clang10 - tag: focal - cc: clang - cxx: clang++ - - name: "Clang 14 (Boost 1.82)" - shortname: clang14 - tag: jammy - cc: clang - cxx: clang++ - - name: "Clang 16" - shortname: clang16 - tag: mantic - cc: clang - cxx: clang++ - tests: true - - name: "Clang 18" - shortname: clang18 - tag: noble - cc: clang - cxx: clang++ - cxxflags: -Wno-deprecated-declarations - tests: true - - name: "C++14 mode" - shortname: c++14 - tag: rolling - cc: gcc - cxx: g++ - cxxflags: "-std=c++14" - - name: "C++17 mode" - shortname: c++17 - tag: rolling - cc: gcc - cxx: g++ - cxxflags: "-std=c++17" - - name: "C++20 mode" - shortname: c++20 - tag: rolling - cc: gcc - cxx: g++ - cxxflags: "-std=c++20" - - name: "Unity build enabled" - shortname: unity - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-unity-build - - name: "Intraday calculations enabled" - shortname: intraday - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-intraday - tests: true - - name: "Throwing in cycles enabled" - shortname: cycles - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-throwing-in-cycles --disable-faster-lazy-objects - tests: true - - name: "Indexed coupons enabled" - shortname: indexed - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-indexed-coupons - tests: true - - name: "Standard Library classes enabled/disabled" - shortname: stdclasses - tag: rolling - cc: gcc - cxx: g++ - configureflags: --disable-std-function --disable-std-tuple --enable-std-pointers --enable-std-any --enable-std-optional - tests: true - - name: "Thread-safe observer enabled" - shortname: threadsafe - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-thread-safe-observer-pattern - tests: true - - name: "Sessions enabled" - shortname: sessions - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-sessions - tests: true - - name: "OpenMP enabled" - shortname: openmp - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-openmp - tests: true - - name: "Parallel unit-test runner" - shortname: paralleltests - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-parallel-unit-test-runner - tests: true - - name: "Null as function template" - shortname: nullfunctions - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-null-as-functions - tests: true - container: ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }} - steps: - - uses: actions/checkout@v4 - - name: Cache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: linux-ci-build-${{ matrix.shortname }}-${{ github.ref }} - restore-keys: | - linux-ci-build-${{ matrix.shortname }}-${{ github.ref }} - linux-ci-build-${{ matrix.shortname }}-refs/heads/master - linux-ci-build-${{ matrix.shortname }}- - - name: Compiler version - run: | - ${{ matrix.cc }} --version - - name: Build - run: | - ./autogen.sh - ./configure --disable-static ${{ matrix.configureflags }} CC="ccache ${{ matrix.cc }}" CXX="ccache ${{ matrix.cxx }}" CXXFLAGS="-O2 -g0 -Wall -Wno-unknown-pragmas -Werror ${{ matrix.cxxflags }}" - make -j 4 - - name: Run tests - if: ${{ matrix.tests }} - run: | - ./test-suite/quantlib-test-suite --log_level=message - - name: Run examples - if: ${{ matrix.tests }} - run: | - make check-examples - - name: Check global header - if: ${{ matrix.tests }} - run: | - echo "#include " > test1.cpp && echo "int main() { return 0; }" >> test1.cpp - echo "#include " > test2.cpp - make install - ${{ matrix.cxx }} -O2 -g0 -Wall -Wno-unknown-pragmas -Werror ${{ matrix.cxxflags }} `quantlib-config --cflags` test1.cpp test2.cpp `quantlib-config --libs` diff --git a/.github/workflows/macos-nondefault.yml b/.github/workflows/macos-nondefault.yml deleted file mode 100644 index b49093a499c..00000000000 --- a/.github/workflows/macos-nondefault.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Mac OS build with non-default configuration -on: - schedule: - - cron: '0 0 * * 0' - workflow_dispatch: -jobs: - build: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [macos-12, macos-13, macos-14] - classes: [boost, std] - include: - - classes: std - cxxflags: "-std=c++17" - configureflags: --disable-std-function --disable-std-tuple --enable-std-pointers --enable-std-optional --enable-std-any - steps: - - uses: actions/checkout@v4 - - name: Setup - env: - HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1 - run: | - brew install automake autoconf libtool boost - - name: Compiler version - run: | - clang --version - - name: Build - run: | - ./autogen.sh - ./configure --disable-shared --with-boost-include=`brew --prefix`/include --enable-error-lines --enable-error-functions --enable-tracing --enable-indexed-coupons --enable-extra-safety-checks --enable-sessions --enable-thread-safe-observer-pattern --enable-intraday --disable-faster-lazy-objects --enable-throwing-in-cycles --enable-null-as-functions ${{ matrix.configureflags }} CC="clang" CXX="clang++" CXXFLAGS="-O2 -g0 -Wall -Werror ${{ matrix.cxxflags }}" - make -j 3 - - name: Run tests - run: | - ./test-suite/quantlib-test-suite --log_level=message - - name: Run examples - run: | - make -C Examples check-examples diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml deleted file mode 100644 index fa61ac1d010..00000000000 --- a/.github/workflows/macos.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Mac OS build -on: [push, pull_request] -jobs: - build: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [macos-12, macos-13, macos-14] - steps: - - uses: actions/checkout@v4 - - name: Setup - env: - HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1 - run: | - brew install automake autoconf libtool boost ccache - - name: Cache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: macos-ci-build-${{ matrix.os }}-${{ github.ref }} - restore-keys: | - macos-ci-build-${{ matrix.os }}-${{ github.ref }} - macos-ci-build-${{ matrix.os }}-refs/heads/master - macos-ci-build-${{ matrix.os }}- - - name: Compiler version - run: | - clang --version - - name: Build - run: | - ./autogen.sh - ./configure --disable-shared --with-boost-include=`brew --prefix`/include ${{ matrix.configureflags }} CC="ccache clang" CXX="ccache clang++" CXXFLAGS="-O2 -g0 -Wall -Werror ${{ matrix.cxxflags }}" - make -j 3 - - name: Run tests - run: | - ./test-suite/quantlib-test-suite --log_level=message - - name: Run examples - run: | - make -C Examples check-examples diff --git a/.github/workflows/misspell.yml b/.github/workflows/misspell.yml deleted file mode 100644 index 75cee119178..00000000000 --- a/.github/workflows/misspell.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Misspell fixer -on: - push: - branches: - - '**' -jobs: - check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: sobolevn/misspell-fixer-action@master - - uses: peter-evans/create-pull-request@v6 - with: - token: ${{ secrets.GITHUB_TOKEN }} - branch: misspell-fixes-${{ github.ref_name }} - delete-branch: true - commit-message: 'Fixes by misspell-fixer' - title: 'Typos fixed by misspell-fixer' - author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> diff --git a/.github/workflows/msvc-all-configs.yml b/.github/workflows/msvc-all-configs.yml deleted file mode 100644 index 9de0a6d0890..00000000000 --- a/.github/workflows/msvc-all-configs.yml +++ /dev/null @@ -1,68 +0,0 @@ -name: Windows build with all configurations -on: - schedule: - - cron: '0 0 * * 0' - workflow_dispatch: -jobs: - msbuild: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - vsversion: [2019, 2022] - platform: [x64, Win32] - configuration: ['Release', 'Debug', 'Release (static runtime)', 'Debug (static runtime)'] - unity: [unity, singles] - include: - - vsversion: 2019 - os: windows-2019 - toolset: "14.2" - boost_version: 77 - - vsversion: 2022 - os: windows-2022 - toolset: "14.3" - boost_version: 85 - steps: - - uses: actions/checkout@v4 - - name: Setup MSVC++ environment - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: x64 - toolset: ${{ matrix.toolset }} - vsversion: ${{ matrix.vsversion }} - - name: Setup Boost - run: | - $Url = "https://boostorg.jfrog.io/artifactory/main/release/1.${{ matrix.boost_version }}.0/source/boost_1_${{ matrix.boost_version }}_0.zip" - (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\boost.zip") - Expand-Archive -Path "$RUNNER_TEMP\boost.zip" -DestinationPath C:\local - Rename-Item -Path "C:\local\boost_1_${{ matrix.boost_version }}_0" -NewName "boost" - - name: Setup local properties - shell: cmd - run: | - COPY .ci\VS${{ matrix.vsversion }}.props .\Build.props - - name: Setup unity build - if: ${{ matrix.unity == 'unity' }} - shell: cmd - run: | - COPY .ci\Unity.props .\Directory.Build.props - - name: Setup MSVC++ environment - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: x64 - toolset: ${{ matrix.toolset }} - vsversion: ${{ matrix.vsversion }} - - name: Build - run: | - msbuild ./QuantLib.sln /verbosity:normal /property:Configuration="${{ matrix.configuration }}" /property:Platform=${{ matrix.platform }} - - name: Test - if: ${{ contains(matrix.configuration, 'Release') }} - run: | - .\test-suite\bin\QuantLib-test-suite*.exe --log_level=message - - name: Run examples - if: ${{ contains(matrix.configuration, 'Release') }} - run: | - foreach ($file in Get-ChildItem -Path .\Examples\*.exe -Recurse) - { - & $file.FullName - if (!$?) { Exit $LASTEXITCODE } - } diff --git a/.github/workflows/msvc-analysis.yml b/.github/workflows/msvc-analysis.yml deleted file mode 100644 index 5566e770051..00000000000 --- a/.github/workflows/msvc-analysis.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Microsoft C++ Code Analysis - -on: - schedule: - - cron: '0 0 * * 0' - workflow_dispatch: - -env: - # Path to the CMake build directory. - build: '${{ github.workspace }}/build' - -jobs: - analyze: - name: Analyze - runs-on: windows-2022 - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup - run: | - $Url = "https://boostorg.jfrog.io/artifactory/main/release/1.85.0/binaries/boost_1_85_0-msvc-14.3-64.exe" - (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\boost.exe") - Start-Process -Wait -FilePath "$RUNNER_TEMP\boost.exe" "/SILENT","/SP-","/SUPPRESSMSGBOXES","/DIR=C:\local\boost" - - - name: Configure CMake - env: - BOOST_ROOT: C:\local\boost - run: cmake -B ${{ env.build }} -DQL_USE_STD_CLASSES=ON - - - name: Run MSVC Code Analysis - uses: microsoft/msvc-code-analysis-action@v0.1.1 - # Provide a unique ID to access the sarif output path - id: run-analysis - env: - CAExcludePath: C:\local\boost - with: - cmakeBuildDirectory: ${{ env.build }} - buildConfiguration: Release - ruleset: '${{ github.workspace }}/.msvc-analysis.ruleset' - - - name: Upload SARIF to GitHub - uses: github/codeql-action/upload-sarif@v3 - with: - sarif_file: ${{ steps.run-analysis.outputs.sarif }} - - - name: Upload SARIF as an Artifact - uses: actions/upload-artifact@v4 - with: - name: sarif-file - path: ${{ steps.run-analysis.outputs.sarif }} - diff --git a/.github/workflows/msvc-nondefault.yml b/.github/workflows/msvc-nondefault.yml deleted file mode 100644 index aa7af9d1c8d..00000000000 --- a/.github/workflows/msvc-nondefault.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: Windows build with non-default configuration -on: - schedule: - - cron: '0 0 * * 0' - workflow_dispatch: -jobs: - msbuild: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - vsversion: [2019, 2022] - platform: [x64, Win32] - unity: [unity, singles] - include: - - vsversion: 2019 - os: windows-2019 - toolset: "14.2" - boost_version: 77 - - vsversion: 2022 - os: windows-2022 - toolset: "14.3" - boost_version: 85 - steps: - - uses: actions/checkout@v4 - - name: Setup MSVC++ environment - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: x64 - toolset: ${{ matrix.toolset }} - vsversion: ${{ matrix.vsversion }} - - name: Setup Boost - run: | - $Url = "https://boostorg.jfrog.io/artifactory/main/release/1.${{ matrix.boost_version }}.0/source/boost_1_${{ matrix.boost_version }}_0.zip" - (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\boost.zip") - Expand-Archive -Path "$RUNNER_TEMP\boost.zip" -DestinationPath C:\local - Rename-Item -Path "C:\local\boost_1_${{ matrix.boost_version }}_0" -NewName "boost" - - name: Setup local properties - shell: cmd - run: | - COPY .ci\VS${{ matrix.vsversion }}.alt.props .\Build.props - COPY .ci\userconfig${{ matrix.vsversion }}.alt.hpp .\ql\userconfig.hpp - - name: Setup unity build - if: ${{ matrix.unity == 'unity' }} - shell: cmd - run: | - COPY .ci\Unity.props .\Directory.Build.props - - name: Setup MSVC++ environment - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: x64 - toolset: ${{ matrix.toolset }} - vsversion: ${{ matrix.vsversion }} - - name: Build - run: | - msbuild ./QuantLib.sln /verbosity:normal /property:Configuration=Release /property:Platform=${{ matrix.platform }} - - name: Test - run: | - .\test-suite\bin\QuantLib-test-suite*.exe --log_level=message - - name: Run examples - run: | - foreach ($file in Get-ChildItem -Path .\Examples\*.exe -Recurse) - { - & $file.FullName - if (!$?) { Exit $LASTEXITCODE } - } diff --git a/.github/workflows/msvc.yml b/.github/workflows/msvc.yml deleted file mode 100644 index 8a2fd4f5772..00000000000 --- a/.github/workflows/msvc.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: Windows build -on: [push, pull_request] -jobs: - msbuild: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - vsversion: [2019, 2022] - unity: [unity, singles] - include: - - vsversion: 2019 - os: windows-2019 - toolset: "14.2" - boost_version: 77 - - vsversion: 2022 - os: windows-2022 - toolset: "14.3" - boost_version: 85 - steps: - - uses: actions/checkout@v4 - - name: Setup MSVC++ environment - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: x64 - toolset: ${{ matrix.toolset }} - vsversion: ${{ matrix.vsversion }} - - name: Setup Boost - run: | - $Url = "https://boostorg.jfrog.io/artifactory/main/release/1.${{ matrix.boost_version }}.0/source/boost_1_${{ matrix.boost_version }}_0.zip" - (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\boost.zip") - Expand-Archive -Path "$RUNNER_TEMP\boost.zip" -DestinationPath C:\local - Rename-Item -Path "C:\local\boost_1_${{ matrix.boost_version }}_0" -NewName "boost" - - name: Setup local properties - shell: cmd - run: | - COPY .ci\VS${{ matrix.vsversion }}.props .\Build.props - - name: Setup unity build - if: ${{ matrix.unity == 'unity' }} - shell: cmd - run: | - COPY .ci\Unity.props .\Directory.Build.props - - name: Setup MSVC++ environment - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: x64 - toolset: ${{ matrix.toolset }} - vsversion: ${{ matrix.vsversion }} - - name: Build - run: | - msbuild ./QuantLib.sln /verbosity:normal /property:Configuration=Release /property:Platform=x64 - - name: Test - run: | - .\test-suite\bin\QuantLib-test-suite*.exe --log_level=message - - name: Run examples - run: | - foreach ($file in Get-ChildItem -Path .\Examples\*.exe -Recurse) - { - & $file.FullName - if (!$?) { Exit $LASTEXITCODE } - } diff --git a/.github/workflows/sanitizer.yml b/.github/workflows/sanitizer.yml deleted file mode 100644 index c521a675ce3..00000000000 --- a/.github/workflows/sanitizer.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Linux build with address sanitizer enabled -on: - schedule: - - cron: '0 0 * * 0' - workflow_dispatch: -jobs: - sanitize-address-undefined: - runs-on: ubuntu-latest - container: ghcr.io/lballabio/quantlib-devenv:rolling - steps: - - uses: actions/checkout@v4 - - name: Compiler version - run: | - gcc --version - - name: Build - run: | - ./autogen.sh - ./configure --disable-static CC="gcc" CXX="g++" CXXFLAGS="-O2 -g0 -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer -Wall -Wno-unknown-pragmas -Werror" - make -j 4 - - name: Run tests - run: | - LSAN_OPTIONS=suppressions=.lsan.txt ./test-suite/quantlib-test-suite --log_level=message - - name: Run examples - run: | - make check-examples - sanitize-thread: - runs-on: ubuntu-latest - container: ghcr.io/lballabio/quantlib-devenv:rolling - steps: - - uses: actions/checkout@v4 - - name: Compiler version - run: | - gcc --version - - name: Build - run: | - ./autogen.sh - ./configure --disable-static --enable-sessions --enable-thread-safe-observer-pattern CC="gcc" CXX="g++" CXXFLAGS="-O2 -g0 -fsanitize=thread -fno-sanitize-recover=all -Wall -Wno-unknown-pragmas -Werror" - make -j 4 - - name: Run tests - run: | - ./test-suite/quantlib-test-suite --log_level=message - - name: Run examples - run: | - make check-examples diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml deleted file mode 100644 index 14d8c62f78e..00000000000 --- a/.github/workflows/stale.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Close stale issues and PR -on: - schedule: - - cron: '30 1 * * *' -jobs: - staleness-check: - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v9 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'This issue was automatically marked as stale because it has been open 60 days with no activity. Remove stale label or comment, or this will be closed in two weeks.' - close-issue-message: 'This issue was automatically closed because it has been stalled for two weeks with no further activity.' - stale-pr-message: 'This PR was automatically marked as stale because it has been open 60 days with no activity. Remove stale label or comment, or this will be closed in two weeks.' - close-pr-message: 'This PR was automatically closed because it has been stalled for two weeks with no further activity.' - days-before-stale: 60 - days-before-close: 14 - stale-issue-label: 'stale' - stale-pr-label: 'stale' - exempt-issue-labels: 'help wanted,in progress' - exempt-pr-labels: 'help wanted,in progress' - exempt-all-milestones: true diff --git a/.github/workflows/tidy.yml b/.github/workflows/tidy.yml deleted file mode 100644 index d14c3a246cd..00000000000 --- a/.github/workflows/tidy.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Apply clang-tidy fixes -on: - schedule: - - cron: '0 0 * * 0' - workflow_dispatch: -jobs: - check: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4 - - name: Setup - run: | - sudo apt-get update - sudo apt-get install -y clang-tidy-15 libboost-dev - - name: Check - run: | - cmake --preset linux-ci-build-with-clang-tidy - cd build/linux-ci-build-with-clang-tidy - cmake --build . -j1 - - uses: peter-evans/create-pull-request@v6 - with: - token: ${{ secrets.GITHUB_TOKEN }} - branch: clang-tidy-fixes-${{ github.ref_name }} - delete-branch: true - commit-message: 'Automated fixes by clang-tidy' - title: 'Automated fixes by clang-tidy' - author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> - body: | - This is an automated PR generated by the [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action. - - Please review the changes before merging. - From 4adf4308f215bf9881465a9ba625ec5404dddcda Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:39:52 +0200 Subject: [PATCH 02/19] Adding skeleton for ZigguratGaussianRng --- ql/CMakeLists.txt | 2 + ql/math/randomnumbers/zigguratgaussianrng.cpp | 22 ++++++ ql/math/randomnumbers/zigguratgaussianrng.hpp | 76 +++++++++++++++++++ test-suite/CMakeLists.txt | 1 + test-suite/zigguratgaussian.cpp | 64 ++++++++++++++++ 5 files changed, 165 insertions(+) create mode 100644 ql/math/randomnumbers/zigguratgaussianrng.cpp create mode 100644 ql/math/randomnumbers/zigguratgaussianrng.hpp create mode 100644 test-suite/zigguratgaussian.cpp diff --git a/ql/CMakeLists.txt b/ql/CMakeLists.txt index 0de4fde7bca..de4902d24dc 100644 --- a/ql/CMakeLists.txt +++ b/ql/CMakeLists.txt @@ -427,6 +427,7 @@ set(QL_SOURCES math/randomnumbers/sobolrsg.cpp math/randomnumbers/stochasticcollocationinvcdf.cpp math/randomnumbers/xoshiro256starstaruniformrng.cpp + math/randomnumbers/zigguratgaussianrng.cpp math/richardsonextrapolation.cpp math/rounding.cpp math/sampledcurve.cpp @@ -1537,6 +1538,7 @@ set(QL_HEADERS math/randomnumbers/sobolrsg.hpp math/randomnumbers/stochasticcollocationinvcdf.hpp math/randomnumbers/xoshiro256starstaruniformrng.hpp + math/randomnumbers/zigguratgaussianrng.hpp math/richardsonextrapolation.hpp math/rounding.hpp math/sampledcurve.hpp diff --git a/ql/math/randomnumbers/zigguratgaussianrng.cpp b/ql/math/randomnumbers/zigguratgaussianrng.cpp new file mode 100644 index 00000000000..7be1a1740a5 --- /dev/null +++ b/ql/math/randomnumbers/zigguratgaussianrng.cpp @@ -0,0 +1,22 @@ +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* + Copyright (C) 2024 Ralf Konrad Eckel + + This file is part of QuantLib, a free-software/open-source library + for financial quantitative analysts and developers - http://quantlib.org/ + + QuantLib is free software: you can redistribute it and/or modify it + under the terms of the QuantLib license. You should have received a + copy of the license along with this program; if not, please email + . The license is also available online at + . + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the license for more details. +*/ + +#include + +namespace QuantLib {} diff --git a/ql/math/randomnumbers/zigguratgaussianrng.hpp b/ql/math/randomnumbers/zigguratgaussianrng.hpp new file mode 100644 index 00000000000..18a2ad35077 --- /dev/null +++ b/ql/math/randomnumbers/zigguratgaussianrng.hpp @@ -0,0 +1,76 @@ +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* + Copyright (C) 2024 Ralf Konrad Eckel + + This file is part of QuantLib, a free-software/open-source library + for financial quantitative analysts and developers - http://quantlib.org/ + + QuantLib is free software: you can redistribute it and/or modify it + under the terms of the QuantLib license. You should have received a + copy of the license along with this program; if not, please email + . The license is also available online at + . + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the license for more details. +*/ + +/*! \file zigguratgaussianrng.hpp + \brief Ziggurat Gaussian random-number generator +*/ + +#ifndef quantlib_ziggurat_gaussian_rng_h +#define quantlib_ziggurat_gaussian_rng_h + +#include + +namespace QuantLib { + + //! Gaussian random number generator + /*! It uses the Ziggurat transformation to return a + normal distributed Gaussian deviate with average 0.0 and + standard deviation of 1.0, from a random integer + in the [0,0xffffffffffffffffULL]-interval like. + + For a more detailed description see the article + "An Improved Ziggurat Method to Generate Normal Random Samples" + by Jurgen A. Doornik + (https://www.doornik.com/research/ziggurat.pdf). + + The code here is inspired by the rust implementation in + https://github.com/rust-random/rand/blob/d42daabf65a3ceaf58c2eefc7eb477c4d5a9b4ba/rand_distr/src/normal.rs + and + https://github.com/rust-random/rand/blob/d42daabf65a3ceaf58c2eefc7eb477c4d5a9b4ba/rand_distr/src/utils.rs. + + Class RNG must implement the following interface: + \code + std::uint64_t nextInt64() const; + \endcode + Currently, Xoshiro256StarStarUniformRng is the only RNG supporting this. + */ + template + class ZigguratGaussianRng { + public: + typedef Sample sample_type; + + explicit ZigguratGaussianRng(const RNG& uint64Generator) + : uint64Generator_(uint64Generator) {} + + //! returns a sample from a Gaussian distribution + sample_type next() const { return {nextReal(), 1.0}; } + + //! return a random number from a Gaussian distribution + Real nextReal() const; + + private: + RNG uint64Generator_; + }; + template + inline Real ZigguratGaussianRng::nextReal() const { + return 0.0; + } +} + +#endif diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 0319b497b9f..d6371332678 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -172,6 +172,7 @@ set(QL_TEST_SOURCES xoshiro256starstar.cpp zabr.cpp zerocouponswap.cpp + zigguratgaussian.cpp ) set(QL_TEST_HEADERS diff --git a/test-suite/zigguratgaussian.cpp b/test-suite/zigguratgaussian.cpp new file mode 100644 index 00000000000..31dc3161b0b --- /dev/null +++ b/test-suite/zigguratgaussian.cpp @@ -0,0 +1,64 @@ +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* + Copyright (C) 2024 Ralf Konrad Eckel + + This file is part of QuantLib, a free-software/open-source library + for financial quantitative analysts and developers - http://quantlib.org/ + + QuantLib is free software: you can redistribute it and/or modify it + under the terms of the QuantLib license. You should have received a + copy of the license along with this program; if not, please email + . The license is also available online at + . + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the license for more details. +*/ + +#include "toplevelfixture.hpp" +#include "utilities.hpp" +#include +#include +#include + +using namespace QuantLib; + +BOOST_FIXTURE_TEST_SUITE(QuantLibTests, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(ZigguratGaussianTests) + +BOOST_AUTO_TEST_CASE(testMeanAndStdDevOfNextReal) { + BOOST_TEST_MESSAGE("Testing ZigguratGaussianRng::nextReal() for " + "mean=0.0 and stddev=1.0..."); + + auto uniformRandom = Xoshiro256StarStarUniformRng(1); + auto random = ZigguratGaussianRng(uniformRandom); + + const auto iterations = 10'000'000; + auto randoms = std::vector(); + randoms.reserve(iterations); + for (auto j = 0; j < iterations; ++j) { + auto next = random.nextReal(); + randoms.push_back(next); + } + Real mean = std::accumulate(randoms.begin(), randoms.end(), Real(0.0)) / randoms.size(); + Real meanError = std::fabs(0.0 - mean); + if (meanError > 0.005) { + BOOST_ERROR("Mean " << mean << " for seed 1 is not close to 0."); + } + std::vector diff(randoms.size()); + std::transform(randoms.begin(), randoms.end(), diff.begin(), + [mean](Real x) -> Real { return x - mean; }); + Real stdDev = + std::inner_product(diff.begin(), diff.end(), diff.begin(), Real(0.0)) / randoms.size(); + Real stdDevError = std::fabs(1.0 - stdDev); + if (stdDevError > 0.00005) { + BOOST_ERROR("Standard deviation " << stdDev << " for seed 1 is not close to 1."); + } +} + +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() From 6796fda9ad728381d4e17037aac080461ff5e1e0 Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Tue, 23 Apr 2024 22:01:57 +0200 Subject: [PATCH 03/19] Working on the implementation --- ql/math/randomnumbers/zigguratgaussianrng.cpp | 307 +++++++++++++++++- ql/math/randomnumbers/zigguratgaussianrng.hpp | 36 +- 2 files changed, 340 insertions(+), 3 deletions(-) diff --git a/ql/math/randomnumbers/zigguratgaussianrng.cpp b/ql/math/randomnumbers/zigguratgaussianrng.cpp index 7be1a1740a5..d87550ecb99 100644 --- a/ql/math/randomnumbers/zigguratgaussianrng.cpp +++ b/ql/math/randomnumbers/zigguratgaussianrng.cpp @@ -19,4 +19,309 @@ #include -namespace QuantLib {} +namespace QuantLib { + Real ZigguratGaussianRngUtils::pdf(Real x) const { + return std::exp(-x * x / 2.0); + } + + Real + ZigguratGaussianRngUtils::zeroCase(Real u, + const std::function& uniformNextReal) const { + // compute a random number in the tail by hand + Real x, y; + do { + x = std::log(uniformNextReal()) / normR(); + y = std::log(uniformNextReal()); + } while (-2.0 * y < x * x); + + return (u < 0.0) ? x - normR() : normR() - x; + } + + Real ZigguratGaussianRngUtils::normR() const { + return 3.654152885361008796; + } + + Real ZigguratGaussianRngUtils::normX(int i) const { + static const ZigguratGaussianRngUtils::ZigguratTable normX = { + 3.910757959537090045, 3.654152885361008796, 3.449278298560964462, 3.320244733839166074, + 3.224575052047029100, 3.147889289517149969, 3.083526132001233044, 3.027837791768635434, + 2.978603279880844834, 2.934366867207854224, 2.894121053612348060, 2.857138730872132548, + 2.822877396825325125, 2.790921174000785765, 2.760944005278822555, 2.732685359042827056, + 2.705933656121858100, 2.680514643284522158, 2.656283037575502437, 2.633116393630324570, + 2.610910518487548515, 2.589575986706995181, 2.569035452680536569, 2.549221550323460761, + 2.530075232158516929, 2.511544441625342294, 2.493583041269680667, 2.476149939669143318, + 2.459208374333311298, 2.442725318198956774, 2.426670984935725972, 2.411018413899685520, + 2.395743119780480601, 2.380822795170626005, 2.366237056715818632, 2.351967227377659952, + 2.337996148795031370, 2.324308018869623016, 2.310888250599850036, 2.297723348901329565, + 2.284800802722946056, 2.272108990226823888, 2.259637095172217780, 2.247375032945807760, + 2.235313384928327984, 2.223443340090905718, 2.211756642882544366, 2.200245546609647995, + 2.188902771624720689, 2.177721467738641614, 2.166695180352645966, 2.155817819875063268, + 2.145083634046203613, 2.134487182844320152, 2.124023315687815661, 2.113687150684933957, + 2.103474055713146829, 2.093379631137050279, 2.083399693996551783, 2.073530263516978778, + 2.063767547809956415, 2.054107931648864849, 2.044547965215732788, 2.035084353727808715, + 2.025713947862032960, 2.016433734904371722, 2.007240830558684852, 1.998132471356564244, + 1.989106007615571325, 1.980158896898598364, 1.971288697931769640, 1.962493064942461896, + 1.953769742382734043, 1.945116560006753925, 1.936531428273758904, 1.928012334050718257, + 1.919557336591228847, 1.911164563769282232, 1.902832208548446369, 1.894558525668710081, + 1.886341828534776388, 1.878180486290977669, 1.870072921069236838, 1.862017605397632281, + 1.854013059758148119, 1.846057850283119750, 1.838150586580728607, 1.830289919680666566, + 1.822474540091783224, 1.814703175964167636, 1.806974591348693426, 1.799287584547580199, + 1.791640986550010028, 1.784033659547276329, 1.776464495522344977, 1.768932414909077933, + 1.761436365316706665, 1.753975320315455111, 1.746548278279492994, 1.739154261283669012, + 1.731792314050707216, 1.724461502945775715, 1.717160915015540690, 1.709889657069006086, + 1.702646854797613907, 1.695431651932238548, 1.688243209434858727, 1.681080704722823338, + 1.673943330923760353, 1.666830296159286684, 1.659740822855789499, 1.652674147080648526, + 1.645629517902360339, 1.638606196773111146, 1.631603456932422036, 1.624620582830568427, + 1.617656869570534228, 1.610711622367333673, 1.603784156023583041, 1.596873794420261339, + 1.589979870021648534, 1.583101723393471438, 1.576238702733332886, 1.569390163412534456, + 1.562555467528439657, 1.555733983466554893, 1.548925085471535512, 1.542128153226347553, + 1.535342571438843118, 1.528567729435024614, 1.521803020758293101, 1.515047842773992404, + 1.508301596278571965, 1.501563685112706548, 1.494833515777718391, 1.488110497054654369, + 1.481394039625375747, 1.474683555695025516, 1.467978458615230908, 1.461278162507407830, + 1.454582081885523293, 1.447889631277669675, 1.441200224845798017, 1.434513276002946425, + 1.427828197027290358, 1.421144398672323117, 1.414461289772464658, 1.407778276843371534, + 1.401094763676202559, 1.394410150925071257, 1.387723835686884621, 1.381035211072741964, + 1.374343665770030531, 1.367648583594317957, 1.360949343030101844, 1.354245316759430606, + 1.347535871177359290, 1.340820365893152122, 1.334098153216083604, 1.327368577624624679, + 1.320630975217730096, 1.313884673146868964, 1.307128989027353860, 1.300363230327433728, + 1.293586693733517645, 1.286798664489786415, 1.279998415710333237, 1.273185207661843732, + 1.266358287014688333, 1.259516886060144225, 1.252660221891297887, 1.245787495544997903, + 1.238897891102027415, 1.231990574742445110, 1.225064693752808020, 1.218119375481726552, + 1.211153726239911244, 1.204166830140560140, 1.197157747875585931, 1.190125515422801650, + 1.183069142678760732, 1.175987612011489825, 1.168879876726833800, 1.161744859441574240, + 1.154581450355851802, 1.147388505416733873, 1.140164844363995789, 1.132909248648336975, + 1.125620459211294389, 1.118297174115062909, 1.110938046009249502, 1.103541679420268151, + 1.096106627847603487, 1.088631390649514197, 1.081114409698889389, 1.073554065787871714, + 1.065948674757506653, 1.058296483326006454, 1.050595664586207123, 1.042844313139370538, + 1.035040439828605274, 1.027181966030751292, 1.019266717460529215, 1.011292417434978441, + 1.003256679539591412, 0.995156999629943084, 0.986990747093846266, 0.978755155288937750, + 0.970447311058864615, 0.962064143217605250, 0.953602409875572654, 0.945058684462571130, + 0.936429340280896860, 0.927710533396234771, 0.918898183643734989, 0.909987953490768997, + 0.900975224455174528, 0.891855070726792376, 0.882622229578910122, 0.873271068082494550, + 0.863795545546826915, 0.854189171001560554, 0.844444954902423661, 0.834555354079518752, + 0.824512208745288633, 0.814306670128064347, 0.803929116982664893, 0.793369058833152785, + 0.782615023299588763, 0.771654424216739354, 0.760473406422083165, 0.749056662009581653, + 0.737387211425838629, 0.725446140901303549, 0.713212285182022732, 0.700661841097584448, + 0.687767892786257717, 0.674499822827436479, 0.660822574234205984, 0.646695714884388928, + 0.632072236375024632, 0.616896989996235545, 0.601104617743940417, 0.584616766093722262, + 0.567338257040473026, 0.549151702313026790, 0.529909720646495108, 0.509423329585933393, + 0.487443966121754335, 0.463634336771763245, 0.437518402186662658, 0.408389134588000746, + 0.375121332850465727, 0.335737519180459465, 0.286174591747260509, 0.215241895913273806, + 0.000000000000000000}; + return normX[i]; + } + + Real ZigguratGaussianRngUtils::normF(int i) const { + static const ZigguratGaussianRngUtils::ZigguratTable normF = { + 0.000477467764586655, 0.001260285930498598, 0.002609072746106363, 0.004037972593371872, + 0.005522403299264754, 0.007050875471392110, 0.008616582769422917, 0.010214971439731100, + 0.011842757857943104, 0.013497450601780807, 0.015177088307982072, 0.016880083152595839, + 0.018605121275783350, 0.020351096230109354, 0.022117062707379922, 0.023902203305873237, + 0.025705804008632656, 0.027527235669693315, 0.029365939758230111, 0.031221417192023690, + 0.033093219458688698, 0.034980941461833073, 0.036884215688691151, 0.038802707404656918, + 0.040736110656078753, 0.042684144916619378, 0.044646552251446536, 0.046623094902089664, + 0.048613553216035145, 0.050617723861121788, 0.052635418276973649, 0.054666461325077916, + 0.056710690106399467, 0.058767952921137984, 0.060838108349751806, 0.062921024437977854, + 0.065016577971470438, 0.067124653828023989, 0.069245144397250269, 0.071377949059141965, + 0.073522973714240991, 0.075680130359194964, 0.077849336702372207, 0.080030515814947509, + 0.082223595813495684, 0.084428509570654661, 0.086645194450867782, 0.088873592068594229, + 0.091113648066700734, 0.093365311913026619, 0.095628536713353335, 0.097903279039215627, + 0.100189498769172020, 0.102487158942306270, 0.104796225622867056, 0.107116667775072880, + 0.109448457147210021, 0.111791568164245583, 0.114145977828255210, 0.116511665626037014, + 0.118888613443345698, 0.121276805485235437, 0.123676228202051403, 0.126086870220650349, + 0.128508722280473636, 0.130941777174128166, 0.133386029692162844, 0.135841476571757352, + 0.138308116449064322, 0.140785949814968309, 0.143274978974047118, 0.145775208006537926, + 0.148286642733128721, 0.150809290682410169, 0.153343161060837674, 0.155888264725064563, + 0.158444614156520225, 0.161012223438117663, 0.163591108232982951, 0.166181285765110071, + 0.168782774801850333, 0.171395595638155623, 0.174019770082499359, 0.176655321444406654, + 0.179302274523530397, 0.181960655600216487, 0.184630492427504539, 0.187311814224516926, + 0.190004651671193070, 0.192709036904328807, 0.195425003514885592, 0.198152586546538112, + 0.200891822495431333, 0.203642749311121501, 0.206405406398679298, 0.209179834621935651, + 0.211966076307852941, 0.214764175252008499, 0.217574176725178370, 0.220396127481011589, + 0.223230075764789593, 0.226076071323264877, 0.228934165415577484, 0.231804410825248525, + 0.234686861873252689, 0.237581574432173676, 0.240488605941449107, 0.243408015423711988, + 0.246339863502238771, 0.249284212419516704, 0.252241126056943765, 0.255210669955677150, + 0.258192911338648023, 0.261187919133763713, 0.264195763998317568, 0.267216518344631837, + 0.270250256366959984, 0.273297054069675804, 0.276356989296781264, 0.279430141762765316, + 0.282516593084849388, 0.285616426816658109, 0.288729728483353931, 0.291856585618280984, + 0.294997087801162572, 0.298151326697901342, 0.301319396102034120, 0.304501391977896274, + 0.307697412505553769, 0.310907558127563710, 0.314131931597630143, 0.317370638031222396, + 0.320623784958230129, 0.323891482377732021, 0.327173842814958593, 0.330470981380537099, + 0.333783015832108509, 0.337110066638412809, 0.340452257045945450, 0.343809713148291340, + 0.347182563958251478, 0.350570941482881204, 0.353974980801569250, 0.357394820147290515, + 0.360830600991175754, 0.364282468130549597, 0.367750569780596226, 0.371235057669821344, + 0.374736087139491414, 0.378253817247238111, 0.381788410875031348, 0.385340034841733958, + 0.388908860020464597, 0.392495061461010764, 0.396098818517547080, 0.399720314981931668, + 0.403359739222868885, 0.407017284331247953, 0.410693148271983222, 0.414387534042706784, + 0.418100649839684591, 0.421832709231353298, 0.425583931339900579, 0.429354541031341519, + 0.433144769114574058, 0.436954852549929273, 0.440785034667769915, 0.444635565397727750, + 0.448506701509214067, 0.452398706863882505, 0.456311852680773566, 0.460246417814923481, + 0.464202689050278838, 0.468180961407822172, 0.472181538469883255, 0.476204732721683788, + 0.480250865911249714, 0.484320269428911598, 0.488413284707712059, 0.492530263646148658, + 0.496671569054796314, 0.500837575128482149, 0.505028667945828791, 0.509245245998136142, + 0.513487720749743026, 0.517756517232200619, 0.522052074674794864, 0.526374847174186700, + 0.530725304406193921, 0.535103932383019565, 0.539511234259544614, 0.543947731192649941, + 0.548413963257921133, 0.552910490428519918, 0.557437893621486324, 0.561996775817277916, + 0.566587763258951771, 0.571211506738074970, 0.575868682975210544, 0.580559996103683473, + 0.585286179266300333, 0.590047996335791969, 0.594846243770991268, 0.599681752622167719, + 0.604555390700549533, 0.609468064928895381, 0.614420723892076803, 0.619414360609039205, + 0.624450015550274240, 0.629528779928128279, 0.634651799290960050, 0.639820277456438991, + 0.645035480824251883, 0.650298743114294586, 0.655611470583224665, 0.660975147780241357, + 0.666391343912380640, 0.671861719900766374, 0.677388036222513090, 0.682972161648791376, + 0.688616083008527058, 0.694321916130032579, 0.700091918140490099, 0.705928501336797409, + 0.711834248882358467, 0.717811932634901395, 0.723864533472881599, 0.729995264565802437, + 0.736207598131266683, 0.742505296344636245, 0.748892447223726720, 0.755373506511754500, + 0.761953346841546475, 0.768637315803334831, 0.775431304986138326, 0.782341832659861902, + 0.789376143571198563, 0.796542330428254619, 0.803849483176389490, 0.811307874318219935, + 0.818929191609414797, 0.826726833952094231, 0.834716292992930375, 0.842915653118441077, + 0.851346258465123684, 0.860033621203008636, 0.869008688043793165, 0.878309655816146839, + 0.887984660763399880, 0.898095921906304051, 0.908726440060562912, 0.919991505048360247, + 0.932060075968990209, 0.945198953453078028, 0.959879091812415930, 0.977101701282731328, + 1.000000000000000000}; + return normF[i]; + } + + Real ZigguratGaussianRngUtils::expR() const { + return 7.697117470131050077; + } + + Real ZigguratGaussianRngUtils::expX(int i) const { + static const ZigguratGaussianRngUtils::ZigguratTable expX = { + 8.697117470131052741, 7.697117470131050077, 6.941033629377212577, 6.478378493832569696, + 6.144164665772472667, 5.882144315795399869, 5.666410167454033697, 5.482890627526062488, + 5.323090505754398016, 5.181487281301500047, 5.054288489981304089, 4.938777085901250530, + 4.832939741025112035, 4.735242996601741083, 4.644491885420085175, 4.559737061707351380, + 4.480211746528421912, 4.405287693473573185, 4.334443680317273007, 4.267242480277365857, + 4.203313713735184365, 4.142340865664051464, 4.084051310408297830, 4.028208544647936762, + 3.974606066673788796, 3.923062500135489739, 3.873417670399509127, 3.825529418522336744, + 3.779270992411667862, 3.734528894039797375, 3.691201090237418825, 3.649195515760853770, + 3.608428813128909507, 3.568825265648337020, 3.530315889129343354, 3.492837654774059608, + 3.456332821132760191, 3.420748357251119920, 3.386035442460300970, 3.352149030900109405, + 3.319047470970748037, 3.286692171599068679, 3.255047308570449882, 3.224079565286264160, + 3.193757903212240290, 3.164053358025972873, 3.134938858084440394, 3.106389062339824481, + 3.078380215254090224, 3.050890016615455114, 3.023897504455676621, 2.997382949516130601, + 2.971327759921089662, 2.945714394895045718, 2.920526286512740821, 2.895747768600141825, + 2.871364012015536371, 2.847360965635188812, 2.823725302450035279, 2.800444370250737780, + 2.777506146439756574, 2.754899196562344610, 2.732612636194700073, 2.710636095867928752, + 2.688959688741803689, 2.667573980773266573, 2.646469963151809157, 2.625639026797788489, + 2.605072938740835564, 2.584763820214140750, 2.564704126316905253, 2.544886627111869970, + 2.525304390037828028, 2.505950763528594027, 2.486819361740209455, 2.467904050297364815, + 2.449198932978249754, 2.430698339264419694, 2.412396812688870629, 2.394289099921457886, + 2.376370140536140596, 2.358635057409337321, 2.341079147703034380, 2.323697874390196372, + 2.306486858283579799, 2.289441870532269441, 2.272558825553154804, 2.255833774367219213, + 2.239262898312909034, 2.222842503111036816, 2.206569013257663858, 2.190438966723220027, + 2.174449009937774679, 2.158595893043885994, 2.142876465399842001, 2.127287671317368289, + 2.111826546019042183, 2.096490211801715020, 2.081275874393225145, 2.066180819490575526, + 2.051202409468584786, 2.036338080248769611, 2.021585338318926173, 2.006941757894518563, + 1.992404978213576650, 1.977972700957360441, 1.963642687789548313, 1.949412758007184943, + 1.935280786297051359, 1.921244700591528076, 1.907302480018387536, 1.893452152939308242, + 1.879691795072211180, 1.866019527692827973, 1.852433515911175554, 1.838931967018879954, + 1.825513128903519799, 1.812175288526390649, 1.798916770460290859, 1.785735935484126014, + 1.772631179231305643, 1.759600930889074766, 1.746643651946074405, 1.733757834985571566, + 1.720942002521935299, 1.708194705878057773, 1.695514524101537912, 1.682900062917553896, + 1.670349953716452118, 1.657862852574172763, 1.645437439303723659, 1.633072416535991334, + 1.620766508828257901, 1.608518461798858379, 1.596327041286483395, 1.584191032532688892, + 1.572109239386229707, 1.560080483527888084, 1.548103603714513499, 1.536177455041032092, + 1.524300908219226258, 1.512472848872117082, 1.500692176842816750, 1.488957805516746058, + 1.477268661156133867, 1.465623682245745352, 1.454021818848793446, 1.442462031972012504, + 1.430943292938879674, 1.419464582769983219, 1.408024891569535697, 1.396623217917042137, + 1.385258568263121992, 1.373929956328490576, 1.362636402505086775, 1.351376933258335189, + 1.340150580529504643, 1.328956381137116560, 1.317793376176324749, 1.306660610415174117, + 1.295557131686601027, 1.284481990275012642, 1.273434238296241139, 1.262412929069615330, + 1.251417116480852521, 1.240445854334406572, 1.229498195693849105, 1.218573192208790124, + 1.207669893426761121, 1.196787346088403092, 1.185924593404202199, 1.175080674310911677, + 1.164254622705678921, 1.153445466655774743, 1.142652227581672841, 1.131873919411078511, + 1.121109547701330200, 1.110358108727411031, 1.099618588532597308, 1.088889961938546813, + 1.078171191511372307, 1.067461226479967662, 1.056759001602551429, 1.046063435977044209, + 1.035373431790528542, 1.024687873002617211, 1.014005623957096480, 1.003325527915696735, + 0.992646405507275897, 0.981967053085062602, 0.971286240983903260, 0.960602711668666509, + 0.949915177764075969, 0.939222319955262286, 0.928522784747210395, 0.917815182070044311, + 0.907098082715690257, 0.896370015589889935, 0.885629464761751528, 0.874874866291025066, + 0.864104604811004484, 0.853317009842373353, 0.842510351810368485, 0.831682837734273206, + 0.820832606554411814, 0.809957724057418282, 0.799056177355487174, 0.788125868869492430, + 0.777164609759129710, 0.766170112735434672, 0.755139984181982249, 0.744071715500508102, + 0.732962673584365398, 0.721810090308756203, 0.710611050909655040, 0.699362481103231959, + 0.688061132773747808, 0.676703568029522584, 0.665286141392677943, 0.653804979847664947, + 0.642255960424536365, 0.630634684933490286, 0.618936451394876075, 0.607156221620300030, + 0.595288584291502887, 0.583327712748769489, 0.571267316532588332, 0.559100585511540626, + 0.546820125163310577, 0.534417881237165604, 0.521885051592135052, 0.509211982443654398, + 0.496388045518671162, 0.483401491653461857, 0.470239275082169006, 0.456886840931420235, + 0.443327866073552401, 0.429543940225410703, 0.415514169600356364, 0.401214678896277765, + 0.386617977941119573, 0.371692145329917234, 0.356399760258393816, 0.340696481064849122, + 0.324529117016909452, 0.307832954674932158, 0.290527955491230394, 0.272513185478464703, + 0.253658363385912022, 0.233790483059674731, 0.212671510630966620, 0.189958689622431842, + 0.165127622564187282, 0.137304980940012589, 0.104838507565818778, 0.063852163815001570, + 0.000000000000000000}; + return expX[i]; + } + + Real ZigguratGaussianRngUtils::expF(int i) const { + static const ZigguratGaussianRngUtils::ZigguratTable expF = { + 0.000167066692307963, 0.000454134353841497, 0.000967269282327174, 0.001536299780301573, + 0.002145967743718907, 0.002788798793574076, 0.003460264777836904, 0.004157295120833797, + 0.004877655983542396, 0.005619642207205489, 0.006381905937319183, 0.007163353183634991, + 0.007963077438017043, 0.008780314985808977, 0.009614413642502212, 0.010464810181029981, + 0.011331013597834600, 0.012212592426255378, 0.013109164931254991, 0.014020391403181943, + 0.014945968011691148, 0.015885621839973156, 0.016839106826039941, 0.017806200410911355, + 0.018786700744696024, 0.019780424338009740, 0.020787204072578114, 0.021806887504283581, + 0.022839335406385240, 0.023884420511558174, 0.024942026419731787, 0.026012046645134221, + 0.027094383780955803, 0.028188948763978646, 0.029295660224637411, 0.030414443910466622, + 0.031545232172893622, 0.032687963508959555, 0.033842582150874358, 0.035009037697397431, + 0.036187284781931443, 0.037377282772959382, 0.038578995503074871, 0.039792391023374139, + 0.041017441380414840, 0.042254122413316254, 0.043502413568888197, 0.044762297732943289, + 0.046033761076175184, 0.047316792913181561, 0.048611385573379504, 0.049917534282706379, + 0.051235237055126281, 0.052564494593071685, 0.053905310196046080, 0.055257689676697030, + 0.056621641283742870, 0.057997175631200659, 0.059384305633420280, 0.060783046445479660, + 0.062193415408541036, 0.063615431999807376, 0.065049117786753805, 0.066494496385339816, + 0.067951593421936643, 0.069420436498728783, 0.070901055162371843, 0.072393480875708752, + 0.073897746992364746, 0.075413888734058410, 0.076941943170480517, 0.078481949201606435, + 0.080033947542319905, 0.081597980709237419, 0.083174093009632397, 0.084762330532368146, + 0.086362741140756927, 0.087975374467270231, 0.089600281910032886, 0.091237516631040197, + 0.092887133556043569, 0.094549189376055873, 0.096223742550432825, 0.097910853311492213, + 0.099610583670637132, 0.101322997425953631, 0.103048160171257702, 0.104786139306570145, + 0.106537004050001632, 0.108300825451033755, 0.110077676405185357, 0.111867631670056283, + 0.113670767882744286, 0.115487163578633506, 0.117316899211555525, 0.119160057175327641, + 0.121016721826674792, 0.122886979509545108, 0.124770918580830933, 0.126668629437510671, + 0.128580204545228199, 0.130505738468330773, 0.132445327901387494, 0.134399071702213602, + 0.136367070926428829, 0.138349428863580176, 0.140346251074862399, 0.142357645432472146, + 0.144383722160634720, 0.146424593878344889, 0.148480375643866735, 0.150551185001039839, + 0.152637142027442801, 0.154738369384468027, 0.156854992369365148, 0.158987138969314129, + 0.161134939917591952, 0.163298528751901734, 0.165478041874935922, 0.167673618617250081, + 0.169885401302527550, 0.172113535315319977, 0.174358169171353411, 0.176619454590494829, + 0.178897546572478278, 0.181192603475496261, 0.183504787097767436, 0.185834262762197083, + 0.188181199404254262, 0.190545769663195363, 0.192928149976771296, 0.195328520679563189, + 0.197747066105098818, 0.200183974691911210, 0.202639439093708962, 0.205113656293837654, + 0.207606827724221982, 0.210119159388988230, 0.212650861992978224, 0.215202151075378628, + 0.217773247148700472, 0.220364375843359439, 0.222975768058120111, 0.225607660116683956, + 0.228260293930716618, 0.230933917169627356, 0.233628783437433291, 0.236345152457059560, + 0.239083290262449094, 0.241843469398877131, 0.244625969131892024, 0.247431075665327543, + 0.250259082368862240, 0.253110290015629402, 0.255985007030415324, 0.258883549749016173, + 0.261806242689362922, 0.264753418835062149, 0.267725419932044739, 0.270722596799059967, + 0.273745309652802915, 0.276793928448517301, 0.279868833236972869, 0.282970414538780746, + 0.286099073737076826, 0.289255223489677693, 0.292439288161892630, 0.295651704281261252, + 0.298892921015581847, 0.302163400675693528, 0.305463619244590256, 0.308794066934560185, + 0.312155248774179606, 0.315547685227128949, 0.318971912844957239, 0.322428484956089223, + 0.325917972393556354, 0.329440964264136438, 0.332998068761809096, 0.336589914028677717, + 0.340217149066780189, 0.343880444704502575, 0.347580494621637148, 0.351318016437483449, + 0.355093752866787626, 0.358908472948750001, 0.362762973354817997, 0.366658079781514379, + 0.370594648435146223, 0.374573567615902381, 0.378595759409581067, 0.382662181496010056, + 0.386773829084137932, 0.390931736984797384, 0.395136981833290435, 0.399390684475231350, + 0.403694012530530555, 0.408048183152032673, 0.412454465997161457, 0.416914186433003209, + 0.421428728997616908, 0.425999541143034677, 0.430628137288459167, 0.435316103215636907, + 0.440065100842354173, 0.444876873414548846, 0.449753251162755330, 0.454696157474615836, + 0.459707615642138023, 0.464789756250426511, 0.469944825283960310, 0.475175193037377708, + 0.480483363930454543, 0.485871987341885248, 0.491343869594032867, 0.496901987241549881, + 0.502549501841348056, 0.508289776410643213, 0.514126393814748894, 0.520063177368233931, + 0.526104213983620062, 0.532253880263043655, 0.538516872002862246, 0.544898237672440056, + 0.551403416540641733, 0.558038282262587892, 0.564809192912400615, 0.571723048664826150, + 0.578787358602845359, 0.586010318477268366, 0.593400901691733762, 0.600968966365232560, + 0.608725382079622346, 0.616682180915207878, 0.624852738703666200, 0.633251994214366398, + 0.641896716427266423, 0.650805833414571433, 0.660000841079000145, 0.669506316731925177, + 0.679350572264765806, 0.689566496117078431, 0.700192655082788606, 0.711274760805076456, + 0.722867659593572465, 0.735038092431424039, 0.747868621985195658, 0.761463388849896838, + 0.775956852040116218, 0.791527636972496285, 0.808421651523009044, 0.826993296643051101, + 0.847785500623990496, 0.871704332381204705, 0.900469929925747703, 0.938143680862176477, + 1.000000000000000000}; + return expF[i]; + } +} diff --git a/ql/math/randomnumbers/zigguratgaussianrng.hpp b/ql/math/randomnumbers/zigguratgaussianrng.hpp index 18a2ad35077..2cc57bc013a 100644 --- a/ql/math/randomnumbers/zigguratgaussianrng.hpp +++ b/ql/math/randomnumbers/zigguratgaussianrng.hpp @@ -25,6 +25,8 @@ #define quantlib_ziggurat_gaussian_rng_h #include +#include +#include namespace QuantLib { @@ -46,10 +48,13 @@ namespace QuantLib { Class RNG must implement the following interface: \code + Real nextReal() const; std::uint64_t nextInt64() const; \endcode Currently, Xoshiro256StarStarUniformRng is the only RNG supporting this. */ + class ZigguratGaussianRngUtils; + template class ZigguratGaussianRng { public: @@ -62,15 +67,42 @@ namespace QuantLib { sample_type next() const { return {nextReal(), 1.0}; } //! return a random number from a Gaussian distribution - Real nextReal() const; + [[noreturn]] Real nextReal() const; private: RNG uint64Generator_; + ZigguratGaussianRngUtils utils_; }; + template inline Real ZigguratGaussianRng::nextReal() const { - return 0.0; + while (true) { + std::uint64_t randomU64 = uint64Generator_.nextInt64(); + auto i = randomU64; + return 0.0; + } } + + class ZigguratGaussianRngUtils { + template + friend class ZigguratGaussianRng; + + typedef Real ZigguratTable[257]; + + private: + Real pdf(Real x) const; + + //! compute a random number in the tail by hand + Real zeroCase(Real u, const std::function& uniformNextReal) const; + + Real normR() const; + Real normX(int i) const; + Real normF(int i) const; + + Real expR() const; + Real expX(int i) const; + Real expF(int i) const; + }; } #endif From 12a8c3fb42b7d549fc8a4d63332856a9f781938a Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Tue, 23 Apr 2024 22:04:16 +0200 Subject: [PATCH 04/19] Removed more workflow jobs to reduce workload --- .github/workflows/cmake.yml | 98 ------------------------- .github/workflows/codeql-analysis.yml | 52 ------------- .github/workflows/coveralls.yml | 41 ----------- .github/workflows/doxygen.yml | 28 ------- .github/workflows/filelists.yml | 19 ----- .github/workflows/generated-headers.yml | 32 -------- .github/workflows/headers.yml | 25 ------- .github/workflows/test-times.yml | 42 ----------- 8 files changed, 337 deletions(-) delete mode 100644 .github/workflows/codeql-analysis.yml delete mode 100644 .github/workflows/coveralls.yml delete mode 100644 .github/workflows/doxygen.yml delete mode 100644 .github/workflows/filelists.yml delete mode 100644 .github/workflows/generated-headers.yml delete mode 100644 .github/workflows/headers.yml delete mode 100644 .github/workflows/test-times.yml diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index dafe942b20b..440290c5346 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -29,32 +29,6 @@ jobs: - name: Test run: | quantlib-test-suite --log_level=message - cmake-linux-with-options: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Setup - run: | - sudo rm /etc/apt/sources.list.d/microsoft-prod.list - sudo apt update - sudo apt install -y libboost-all-dev ccache ninja-build - - name: Cache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: cmake-linux-ci-opts-${{ github.ref }} - restore-keys: | - cmake-linux-ci-opts-${{ github.ref }} - cmake-linux-ci-opts-refs/heads/master - cmake-linux-ci-opts- - - name: Compile - run: | - cmake --preset linux-ci-build-with-nonstandard-options -L - cd build/linux-ci-build-with-nonstandard-options - cmake --build . --verbose - sudo cmake --build . --target install - - name: Test - run: | - quantlib-test-suite --log_level=message cmake-win: runs-on: windows-2022 steps: @@ -92,78 +66,6 @@ jobs: - name: Test run: | & "C:\Program Files (x86)\QuantLib\bin\quantlib-test-suite" --log_level=message - cmake-win-dynamic-runtime: - runs-on: windows-2022 - steps: - - uses: actions/checkout@v4 - - name: Cache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: cmake-windows-ci-dyn-build-${{ github.ref }} - restore-keys: | - cmake-windows-ci-dyn-build-${{ github.ref }} - cmake-windows-ci-dyn-build-refs/heads/master - cmake-windows-ci-dyn-build- - variant: sccache - - name: Setup - run: | - $Url = "https://boostorg.jfrog.io/artifactory/main/release/1.85.0/binaries/boost_1_85_0-msvc-14.3-64.exe" - (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\boost.exe") - Start-Process -Wait -FilePath "$RUNNER_TEMP\boost.exe" "/SILENT","/SP-","/SUPPRESSMSGBOXES","/DIR=C:\local\boost" - $Url = "https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-win.zip" - (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\ninja-win.zip") - Expand-Archive -Path "$RUNNER_TEMP\ninja-win.zip" -DestinationPath C:\local\ninja - Add-Content $env:GITHUB_PATH "C:\local\ninja" - - name: Compile - env: - BOOST_ROOT: C:\local\boost - shell: cmd - run: | - mkdir build - cd build - call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Vc\Auxiliary\Build\vcvarsall.bat" amd64 -vcvars_ver=14.3 || exit 1 - cmake .. -GNinja -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL -DCMAKE_BUILD_TYPE=Release -DQL_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -L - cmake --build . --verbose - cmake --install . - dir ql\*.lib - - name: Test - run: | - & "C:\Program Files (x86)\QuantLib\bin\quantlib-test-suite" --log_level=message - cmake-win-with-options: - runs-on: windows-2022 - steps: - - uses: actions/checkout@v4 - - name: Cache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: cmake-windows-ci-opts-${{ github.ref }} - restore-keys: | - cmake-windows-ci-opts-${{ github.ref }} - cmake-windows-ci-opts-refs/heads/master - cmake-windows-ci-opts- - variant: sccache - - name: Setup - run: | - $Url = "https://boostorg.jfrog.io/artifactory/main/release/1.85.0/binaries/boost_1_85_0-msvc-14.3-64.exe" - (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\boost.exe") - Start-Process -Wait -FilePath "$RUNNER_TEMP\boost.exe" "/SILENT","/SP-","/SUPPRESSMSGBOXES","/DIR=C:\local\boost" - $Url = "https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-win.zip" - (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\ninja-win.zip") - Expand-Archive -Path "$RUNNER_TEMP\ninja-win.zip" -DestinationPath C:\local\ninja - Add-Content $env:GITHUB_PATH "C:\local\ninja" - - name: Compile - env: - BOOST_ROOT: C:\local\boost - shell: cmd - run: | - call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Vc\Auxiliary\Build\vcvarsall.bat" amd64 -vcvars_ver=14.3 || exit 1 - cmake --preset windows-ci-build-with-nonstandard-options -L - cd build/windows-ci-build-with-nonstandard-options - cmake --build . --verbose - cmake --build . --target install - - name: Test - run: | - & "C:\Program Files (x86)\QuantLib\bin\quantlib-test-suite" --log_level=message cmake-macos: runs-on: macos-latest steps: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index f8abad984b5..00000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,52 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -name: "CodeQL" - -on: - schedule: - - cron: '0 0 * * 0' - workflow_dispatch: - -jobs: - analyze: - name: CodeQL analysis - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: cpp - - # Set up build environment - - name: Setup - run: | - sudo rm /etc/apt/sources.list.d/microsoft-prod.list - sudo apt update - sudo apt install -y libboost-dev - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v3 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/coveralls.yml b/.github/workflows/coveralls.yml deleted file mode 100644 index 0775a908323..00000000000 --- a/.github/workflows/coveralls.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Coverage report -on: - push: - branches: - - master - pull_request: -jobs: - coverage: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Setup - run: | - sudo rm /etc/apt/sources.list.d/microsoft-prod.list - sudo apt update - sudo apt install -y lcov libboost-dev - - name: Compile - run: | - ./autogen.sh - ./configure --disable-shared CXXFLAGS='-O1 -fprofile-arcs -ftest-coverage' LDFLAGS='-lgcov' - make -j 4 - - name: Capture baseline - run: | - mkdir -p coverage tmp - lcov --no-external --capture --initial --directory . --output-file ./tmp/lcov_base.info - - name: Run tests - run: | - ./test-suite/quantlib-test-suite --log_level=message - - name: Run examples - run: | - make -C Examples check-examples - - name: Capture coverage - run: | - lcov --no-external --capture --directory . --output-file ./tmp/lcov_run.info - lcov --add-tracefile ./tmp/lcov_base.info --add-tracefile ./tmp/lcov_run.info --output-file ./tmp/lcov_total.info - lcov --remove ./tmp/lcov_total.info "$PWD/Examples/*" "$PWD/test-suite/*" --output-file ./coverage/lcov.info - - name: Upload coverage to Coveralls - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ./coverage/lcov.info diff --git a/.github/workflows/doxygen.yml b/.github/workflows/doxygen.yml deleted file mode 100644 index 84a98c08c66..00000000000 --- a/.github/workflows/doxygen.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Check doc generation -on: [push, pull_request] -jobs: - docs: - runs-on: macos-latest - steps: - - uses: actions/checkout@v4 - - name: Setup - env: - HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1 - run: | - brew install automake autoconf libtool boost doxygen graphviz - ./autogen.sh - ./configure --with-boost-include=$(brew --prefix)/include - - name: Doxygen version - run: | - doxygen --version - - name: Check - run: | - make docs - - header-docs: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Check - run: | - ./tools/check_all_header_docs.sh diff --git a/.github/workflows/filelists.yml b/.github/workflows/filelists.yml deleted file mode 100644 index 501ef2b0f77..00000000000 --- a/.github/workflows/filelists.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Check CMake file list and VC++ projects -on: [push, pull_request] -jobs: - filelists: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Setup - run: | - sudo rm /etc/apt/sources.list.d/microsoft-prod.list - sudo apt update - sudo apt install -y libboost-dev - - name: Configure - run: | - ./autogen.sh - ./configure - - name: Check - run: | - ./tools/check_filelists.sh diff --git a/.github/workflows/generated-headers.yml b/.github/workflows/generated-headers.yml deleted file mode 100644 index b79cf9e5b6d..00000000000 --- a/.github/workflows/generated-headers.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Update generated headers -on: - push: - branches: - - '**' -jobs: - filelists: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Setup - run: | - sudo rm /etc/apt/sources.list.d/microsoft-prod.list - sudo apt update - sudo apt install -y libboost-dev - - name: Configure - run: | - ./autogen.sh - ./configure - - name: Update headers - run: | - find ql -name *.am | xargs touch - make dist - rm QuantLib-*.tar.gz - - uses: peter-evans/create-pull-request@v6 - with: - token: ${{ secrets.GITHUB_TOKEN }} - branch: update-generated-headers-${{ github.ref_name }} - delete-branch: true - commit-message: 'Update generated headers' - title: 'Update generated headers' - author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> diff --git a/.github/workflows/headers.yml b/.github/workflows/headers.yml deleted file mode 100644 index a6eb0a7ad35..00000000000 --- a/.github/workflows/headers.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Compile single headers -on: [push, pull_request] -jobs: - headers: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Setup - run: | - sudo rm /etc/apt/sources.list.d/microsoft-prod.list - sudo apt update - sudo apt install -y libboost-dev ccache - - name: Cache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: single-headers-${{ github.ref }} - restore-keys: | - single-headers-${{ github.ref }} - single-headers-refs/heads/master - single-headers- - - name: Check - env: - CXX: ccache g++ - run: | - ./tools/check_all_headers.sh diff --git a/.github/workflows/test-times.yml b/.github/workflows/test-times.yml deleted file mode 100644 index defad441651..00000000000 --- a/.github/workflows/test-times.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Check test times -on: [push, pull_request] -jobs: - check-test-times: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Cache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: linux-ci-test-times-${{ github.ref }} - restore-keys: | - linux-ci-test-times-${{ github.ref }} - linux-ci-test-times-refs/heads/master - linux-ci-test-times- - - name: Setup - run: | - sudo rm /etc/apt/sources.list.d/microsoft-prod.list - sudo apt update - sudo apt install -y libboost-dev autoconf automake libtool ccache - - name: Build - run: | - ./autogen.sh - ./configure --disable-static CC="ccache gcc" CXX="ccache g++" CXXFLAGS="-O2 -g0" - make -j 4 - - name: Run faster tests - run: | - ./test-suite/quantlib-test-suite --logger=JUNIT,warning,faster.xml:HRF,message -- --faster - - name: Run fast tests - run: | - ./test-suite/quantlib-test-suite --logger=JUNIT,warning,fast.xml:HRF,message -- --fast - - name: Run all tests - run: | - ./test-suite/quantlib-test-suite --logger=JUNIT,warning,all.xml:HRF,message - - name: Save test times - uses: actions/upload-artifact@v4 - with: - name: test-reports - path: ./*.xml - - name: Check test times - run: | - python ./tools/check_test_times.py From 17793a1f3b2d0009d91c0e36ccf84562c0f4fdc5 Mon Sep 17 00:00:00 2001 From: ralfeckel Date: Thu, 25 Apr 2024 11:42:40 +0200 Subject: [PATCH 05/19] Removed ZigguratGaussianRngUtils and moved its functionality to ZigguratGaussianRng --- ql/math/randomnumbers/zigguratgaussianrng.cpp | 304 --------------- ql/math/randomnumbers/zigguratgaussianrng.hpp | 353 +++++++++++++++++- test-suite/zigguratgaussian.cpp | 11 +- 3 files changed, 345 insertions(+), 323 deletions(-) diff --git a/ql/math/randomnumbers/zigguratgaussianrng.cpp b/ql/math/randomnumbers/zigguratgaussianrng.cpp index d87550ecb99..5d8b505a766 100644 --- a/ql/math/randomnumbers/zigguratgaussianrng.cpp +++ b/ql/math/randomnumbers/zigguratgaussianrng.cpp @@ -20,308 +20,4 @@ #include namespace QuantLib { - Real ZigguratGaussianRngUtils::pdf(Real x) const { - return std::exp(-x * x / 2.0); - } - - Real - ZigguratGaussianRngUtils::zeroCase(Real u, - const std::function& uniformNextReal) const { - // compute a random number in the tail by hand - Real x, y; - do { - x = std::log(uniformNextReal()) / normR(); - y = std::log(uniformNextReal()); - } while (-2.0 * y < x * x); - - return (u < 0.0) ? x - normR() : normR() - x; - } - - Real ZigguratGaussianRngUtils::normR() const { - return 3.654152885361008796; - } - - Real ZigguratGaussianRngUtils::normX(int i) const { - static const ZigguratGaussianRngUtils::ZigguratTable normX = { - 3.910757959537090045, 3.654152885361008796, 3.449278298560964462, 3.320244733839166074, - 3.224575052047029100, 3.147889289517149969, 3.083526132001233044, 3.027837791768635434, - 2.978603279880844834, 2.934366867207854224, 2.894121053612348060, 2.857138730872132548, - 2.822877396825325125, 2.790921174000785765, 2.760944005278822555, 2.732685359042827056, - 2.705933656121858100, 2.680514643284522158, 2.656283037575502437, 2.633116393630324570, - 2.610910518487548515, 2.589575986706995181, 2.569035452680536569, 2.549221550323460761, - 2.530075232158516929, 2.511544441625342294, 2.493583041269680667, 2.476149939669143318, - 2.459208374333311298, 2.442725318198956774, 2.426670984935725972, 2.411018413899685520, - 2.395743119780480601, 2.380822795170626005, 2.366237056715818632, 2.351967227377659952, - 2.337996148795031370, 2.324308018869623016, 2.310888250599850036, 2.297723348901329565, - 2.284800802722946056, 2.272108990226823888, 2.259637095172217780, 2.247375032945807760, - 2.235313384928327984, 2.223443340090905718, 2.211756642882544366, 2.200245546609647995, - 2.188902771624720689, 2.177721467738641614, 2.166695180352645966, 2.155817819875063268, - 2.145083634046203613, 2.134487182844320152, 2.124023315687815661, 2.113687150684933957, - 2.103474055713146829, 2.093379631137050279, 2.083399693996551783, 2.073530263516978778, - 2.063767547809956415, 2.054107931648864849, 2.044547965215732788, 2.035084353727808715, - 2.025713947862032960, 2.016433734904371722, 2.007240830558684852, 1.998132471356564244, - 1.989106007615571325, 1.980158896898598364, 1.971288697931769640, 1.962493064942461896, - 1.953769742382734043, 1.945116560006753925, 1.936531428273758904, 1.928012334050718257, - 1.919557336591228847, 1.911164563769282232, 1.902832208548446369, 1.894558525668710081, - 1.886341828534776388, 1.878180486290977669, 1.870072921069236838, 1.862017605397632281, - 1.854013059758148119, 1.846057850283119750, 1.838150586580728607, 1.830289919680666566, - 1.822474540091783224, 1.814703175964167636, 1.806974591348693426, 1.799287584547580199, - 1.791640986550010028, 1.784033659547276329, 1.776464495522344977, 1.768932414909077933, - 1.761436365316706665, 1.753975320315455111, 1.746548278279492994, 1.739154261283669012, - 1.731792314050707216, 1.724461502945775715, 1.717160915015540690, 1.709889657069006086, - 1.702646854797613907, 1.695431651932238548, 1.688243209434858727, 1.681080704722823338, - 1.673943330923760353, 1.666830296159286684, 1.659740822855789499, 1.652674147080648526, - 1.645629517902360339, 1.638606196773111146, 1.631603456932422036, 1.624620582830568427, - 1.617656869570534228, 1.610711622367333673, 1.603784156023583041, 1.596873794420261339, - 1.589979870021648534, 1.583101723393471438, 1.576238702733332886, 1.569390163412534456, - 1.562555467528439657, 1.555733983466554893, 1.548925085471535512, 1.542128153226347553, - 1.535342571438843118, 1.528567729435024614, 1.521803020758293101, 1.515047842773992404, - 1.508301596278571965, 1.501563685112706548, 1.494833515777718391, 1.488110497054654369, - 1.481394039625375747, 1.474683555695025516, 1.467978458615230908, 1.461278162507407830, - 1.454582081885523293, 1.447889631277669675, 1.441200224845798017, 1.434513276002946425, - 1.427828197027290358, 1.421144398672323117, 1.414461289772464658, 1.407778276843371534, - 1.401094763676202559, 1.394410150925071257, 1.387723835686884621, 1.381035211072741964, - 1.374343665770030531, 1.367648583594317957, 1.360949343030101844, 1.354245316759430606, - 1.347535871177359290, 1.340820365893152122, 1.334098153216083604, 1.327368577624624679, - 1.320630975217730096, 1.313884673146868964, 1.307128989027353860, 1.300363230327433728, - 1.293586693733517645, 1.286798664489786415, 1.279998415710333237, 1.273185207661843732, - 1.266358287014688333, 1.259516886060144225, 1.252660221891297887, 1.245787495544997903, - 1.238897891102027415, 1.231990574742445110, 1.225064693752808020, 1.218119375481726552, - 1.211153726239911244, 1.204166830140560140, 1.197157747875585931, 1.190125515422801650, - 1.183069142678760732, 1.175987612011489825, 1.168879876726833800, 1.161744859441574240, - 1.154581450355851802, 1.147388505416733873, 1.140164844363995789, 1.132909248648336975, - 1.125620459211294389, 1.118297174115062909, 1.110938046009249502, 1.103541679420268151, - 1.096106627847603487, 1.088631390649514197, 1.081114409698889389, 1.073554065787871714, - 1.065948674757506653, 1.058296483326006454, 1.050595664586207123, 1.042844313139370538, - 1.035040439828605274, 1.027181966030751292, 1.019266717460529215, 1.011292417434978441, - 1.003256679539591412, 0.995156999629943084, 0.986990747093846266, 0.978755155288937750, - 0.970447311058864615, 0.962064143217605250, 0.953602409875572654, 0.945058684462571130, - 0.936429340280896860, 0.927710533396234771, 0.918898183643734989, 0.909987953490768997, - 0.900975224455174528, 0.891855070726792376, 0.882622229578910122, 0.873271068082494550, - 0.863795545546826915, 0.854189171001560554, 0.844444954902423661, 0.834555354079518752, - 0.824512208745288633, 0.814306670128064347, 0.803929116982664893, 0.793369058833152785, - 0.782615023299588763, 0.771654424216739354, 0.760473406422083165, 0.749056662009581653, - 0.737387211425838629, 0.725446140901303549, 0.713212285182022732, 0.700661841097584448, - 0.687767892786257717, 0.674499822827436479, 0.660822574234205984, 0.646695714884388928, - 0.632072236375024632, 0.616896989996235545, 0.601104617743940417, 0.584616766093722262, - 0.567338257040473026, 0.549151702313026790, 0.529909720646495108, 0.509423329585933393, - 0.487443966121754335, 0.463634336771763245, 0.437518402186662658, 0.408389134588000746, - 0.375121332850465727, 0.335737519180459465, 0.286174591747260509, 0.215241895913273806, - 0.000000000000000000}; - return normX[i]; - } - - Real ZigguratGaussianRngUtils::normF(int i) const { - static const ZigguratGaussianRngUtils::ZigguratTable normF = { - 0.000477467764586655, 0.001260285930498598, 0.002609072746106363, 0.004037972593371872, - 0.005522403299264754, 0.007050875471392110, 0.008616582769422917, 0.010214971439731100, - 0.011842757857943104, 0.013497450601780807, 0.015177088307982072, 0.016880083152595839, - 0.018605121275783350, 0.020351096230109354, 0.022117062707379922, 0.023902203305873237, - 0.025705804008632656, 0.027527235669693315, 0.029365939758230111, 0.031221417192023690, - 0.033093219458688698, 0.034980941461833073, 0.036884215688691151, 0.038802707404656918, - 0.040736110656078753, 0.042684144916619378, 0.044646552251446536, 0.046623094902089664, - 0.048613553216035145, 0.050617723861121788, 0.052635418276973649, 0.054666461325077916, - 0.056710690106399467, 0.058767952921137984, 0.060838108349751806, 0.062921024437977854, - 0.065016577971470438, 0.067124653828023989, 0.069245144397250269, 0.071377949059141965, - 0.073522973714240991, 0.075680130359194964, 0.077849336702372207, 0.080030515814947509, - 0.082223595813495684, 0.084428509570654661, 0.086645194450867782, 0.088873592068594229, - 0.091113648066700734, 0.093365311913026619, 0.095628536713353335, 0.097903279039215627, - 0.100189498769172020, 0.102487158942306270, 0.104796225622867056, 0.107116667775072880, - 0.109448457147210021, 0.111791568164245583, 0.114145977828255210, 0.116511665626037014, - 0.118888613443345698, 0.121276805485235437, 0.123676228202051403, 0.126086870220650349, - 0.128508722280473636, 0.130941777174128166, 0.133386029692162844, 0.135841476571757352, - 0.138308116449064322, 0.140785949814968309, 0.143274978974047118, 0.145775208006537926, - 0.148286642733128721, 0.150809290682410169, 0.153343161060837674, 0.155888264725064563, - 0.158444614156520225, 0.161012223438117663, 0.163591108232982951, 0.166181285765110071, - 0.168782774801850333, 0.171395595638155623, 0.174019770082499359, 0.176655321444406654, - 0.179302274523530397, 0.181960655600216487, 0.184630492427504539, 0.187311814224516926, - 0.190004651671193070, 0.192709036904328807, 0.195425003514885592, 0.198152586546538112, - 0.200891822495431333, 0.203642749311121501, 0.206405406398679298, 0.209179834621935651, - 0.211966076307852941, 0.214764175252008499, 0.217574176725178370, 0.220396127481011589, - 0.223230075764789593, 0.226076071323264877, 0.228934165415577484, 0.231804410825248525, - 0.234686861873252689, 0.237581574432173676, 0.240488605941449107, 0.243408015423711988, - 0.246339863502238771, 0.249284212419516704, 0.252241126056943765, 0.255210669955677150, - 0.258192911338648023, 0.261187919133763713, 0.264195763998317568, 0.267216518344631837, - 0.270250256366959984, 0.273297054069675804, 0.276356989296781264, 0.279430141762765316, - 0.282516593084849388, 0.285616426816658109, 0.288729728483353931, 0.291856585618280984, - 0.294997087801162572, 0.298151326697901342, 0.301319396102034120, 0.304501391977896274, - 0.307697412505553769, 0.310907558127563710, 0.314131931597630143, 0.317370638031222396, - 0.320623784958230129, 0.323891482377732021, 0.327173842814958593, 0.330470981380537099, - 0.333783015832108509, 0.337110066638412809, 0.340452257045945450, 0.343809713148291340, - 0.347182563958251478, 0.350570941482881204, 0.353974980801569250, 0.357394820147290515, - 0.360830600991175754, 0.364282468130549597, 0.367750569780596226, 0.371235057669821344, - 0.374736087139491414, 0.378253817247238111, 0.381788410875031348, 0.385340034841733958, - 0.388908860020464597, 0.392495061461010764, 0.396098818517547080, 0.399720314981931668, - 0.403359739222868885, 0.407017284331247953, 0.410693148271983222, 0.414387534042706784, - 0.418100649839684591, 0.421832709231353298, 0.425583931339900579, 0.429354541031341519, - 0.433144769114574058, 0.436954852549929273, 0.440785034667769915, 0.444635565397727750, - 0.448506701509214067, 0.452398706863882505, 0.456311852680773566, 0.460246417814923481, - 0.464202689050278838, 0.468180961407822172, 0.472181538469883255, 0.476204732721683788, - 0.480250865911249714, 0.484320269428911598, 0.488413284707712059, 0.492530263646148658, - 0.496671569054796314, 0.500837575128482149, 0.505028667945828791, 0.509245245998136142, - 0.513487720749743026, 0.517756517232200619, 0.522052074674794864, 0.526374847174186700, - 0.530725304406193921, 0.535103932383019565, 0.539511234259544614, 0.543947731192649941, - 0.548413963257921133, 0.552910490428519918, 0.557437893621486324, 0.561996775817277916, - 0.566587763258951771, 0.571211506738074970, 0.575868682975210544, 0.580559996103683473, - 0.585286179266300333, 0.590047996335791969, 0.594846243770991268, 0.599681752622167719, - 0.604555390700549533, 0.609468064928895381, 0.614420723892076803, 0.619414360609039205, - 0.624450015550274240, 0.629528779928128279, 0.634651799290960050, 0.639820277456438991, - 0.645035480824251883, 0.650298743114294586, 0.655611470583224665, 0.660975147780241357, - 0.666391343912380640, 0.671861719900766374, 0.677388036222513090, 0.682972161648791376, - 0.688616083008527058, 0.694321916130032579, 0.700091918140490099, 0.705928501336797409, - 0.711834248882358467, 0.717811932634901395, 0.723864533472881599, 0.729995264565802437, - 0.736207598131266683, 0.742505296344636245, 0.748892447223726720, 0.755373506511754500, - 0.761953346841546475, 0.768637315803334831, 0.775431304986138326, 0.782341832659861902, - 0.789376143571198563, 0.796542330428254619, 0.803849483176389490, 0.811307874318219935, - 0.818929191609414797, 0.826726833952094231, 0.834716292992930375, 0.842915653118441077, - 0.851346258465123684, 0.860033621203008636, 0.869008688043793165, 0.878309655816146839, - 0.887984660763399880, 0.898095921906304051, 0.908726440060562912, 0.919991505048360247, - 0.932060075968990209, 0.945198953453078028, 0.959879091812415930, 0.977101701282731328, - 1.000000000000000000}; - return normF[i]; - } - - Real ZigguratGaussianRngUtils::expR() const { - return 7.697117470131050077; - } - - Real ZigguratGaussianRngUtils::expX(int i) const { - static const ZigguratGaussianRngUtils::ZigguratTable expX = { - 8.697117470131052741, 7.697117470131050077, 6.941033629377212577, 6.478378493832569696, - 6.144164665772472667, 5.882144315795399869, 5.666410167454033697, 5.482890627526062488, - 5.323090505754398016, 5.181487281301500047, 5.054288489981304089, 4.938777085901250530, - 4.832939741025112035, 4.735242996601741083, 4.644491885420085175, 4.559737061707351380, - 4.480211746528421912, 4.405287693473573185, 4.334443680317273007, 4.267242480277365857, - 4.203313713735184365, 4.142340865664051464, 4.084051310408297830, 4.028208544647936762, - 3.974606066673788796, 3.923062500135489739, 3.873417670399509127, 3.825529418522336744, - 3.779270992411667862, 3.734528894039797375, 3.691201090237418825, 3.649195515760853770, - 3.608428813128909507, 3.568825265648337020, 3.530315889129343354, 3.492837654774059608, - 3.456332821132760191, 3.420748357251119920, 3.386035442460300970, 3.352149030900109405, - 3.319047470970748037, 3.286692171599068679, 3.255047308570449882, 3.224079565286264160, - 3.193757903212240290, 3.164053358025972873, 3.134938858084440394, 3.106389062339824481, - 3.078380215254090224, 3.050890016615455114, 3.023897504455676621, 2.997382949516130601, - 2.971327759921089662, 2.945714394895045718, 2.920526286512740821, 2.895747768600141825, - 2.871364012015536371, 2.847360965635188812, 2.823725302450035279, 2.800444370250737780, - 2.777506146439756574, 2.754899196562344610, 2.732612636194700073, 2.710636095867928752, - 2.688959688741803689, 2.667573980773266573, 2.646469963151809157, 2.625639026797788489, - 2.605072938740835564, 2.584763820214140750, 2.564704126316905253, 2.544886627111869970, - 2.525304390037828028, 2.505950763528594027, 2.486819361740209455, 2.467904050297364815, - 2.449198932978249754, 2.430698339264419694, 2.412396812688870629, 2.394289099921457886, - 2.376370140536140596, 2.358635057409337321, 2.341079147703034380, 2.323697874390196372, - 2.306486858283579799, 2.289441870532269441, 2.272558825553154804, 2.255833774367219213, - 2.239262898312909034, 2.222842503111036816, 2.206569013257663858, 2.190438966723220027, - 2.174449009937774679, 2.158595893043885994, 2.142876465399842001, 2.127287671317368289, - 2.111826546019042183, 2.096490211801715020, 2.081275874393225145, 2.066180819490575526, - 2.051202409468584786, 2.036338080248769611, 2.021585338318926173, 2.006941757894518563, - 1.992404978213576650, 1.977972700957360441, 1.963642687789548313, 1.949412758007184943, - 1.935280786297051359, 1.921244700591528076, 1.907302480018387536, 1.893452152939308242, - 1.879691795072211180, 1.866019527692827973, 1.852433515911175554, 1.838931967018879954, - 1.825513128903519799, 1.812175288526390649, 1.798916770460290859, 1.785735935484126014, - 1.772631179231305643, 1.759600930889074766, 1.746643651946074405, 1.733757834985571566, - 1.720942002521935299, 1.708194705878057773, 1.695514524101537912, 1.682900062917553896, - 1.670349953716452118, 1.657862852574172763, 1.645437439303723659, 1.633072416535991334, - 1.620766508828257901, 1.608518461798858379, 1.596327041286483395, 1.584191032532688892, - 1.572109239386229707, 1.560080483527888084, 1.548103603714513499, 1.536177455041032092, - 1.524300908219226258, 1.512472848872117082, 1.500692176842816750, 1.488957805516746058, - 1.477268661156133867, 1.465623682245745352, 1.454021818848793446, 1.442462031972012504, - 1.430943292938879674, 1.419464582769983219, 1.408024891569535697, 1.396623217917042137, - 1.385258568263121992, 1.373929956328490576, 1.362636402505086775, 1.351376933258335189, - 1.340150580529504643, 1.328956381137116560, 1.317793376176324749, 1.306660610415174117, - 1.295557131686601027, 1.284481990275012642, 1.273434238296241139, 1.262412929069615330, - 1.251417116480852521, 1.240445854334406572, 1.229498195693849105, 1.218573192208790124, - 1.207669893426761121, 1.196787346088403092, 1.185924593404202199, 1.175080674310911677, - 1.164254622705678921, 1.153445466655774743, 1.142652227581672841, 1.131873919411078511, - 1.121109547701330200, 1.110358108727411031, 1.099618588532597308, 1.088889961938546813, - 1.078171191511372307, 1.067461226479967662, 1.056759001602551429, 1.046063435977044209, - 1.035373431790528542, 1.024687873002617211, 1.014005623957096480, 1.003325527915696735, - 0.992646405507275897, 0.981967053085062602, 0.971286240983903260, 0.960602711668666509, - 0.949915177764075969, 0.939222319955262286, 0.928522784747210395, 0.917815182070044311, - 0.907098082715690257, 0.896370015589889935, 0.885629464761751528, 0.874874866291025066, - 0.864104604811004484, 0.853317009842373353, 0.842510351810368485, 0.831682837734273206, - 0.820832606554411814, 0.809957724057418282, 0.799056177355487174, 0.788125868869492430, - 0.777164609759129710, 0.766170112735434672, 0.755139984181982249, 0.744071715500508102, - 0.732962673584365398, 0.721810090308756203, 0.710611050909655040, 0.699362481103231959, - 0.688061132773747808, 0.676703568029522584, 0.665286141392677943, 0.653804979847664947, - 0.642255960424536365, 0.630634684933490286, 0.618936451394876075, 0.607156221620300030, - 0.595288584291502887, 0.583327712748769489, 0.571267316532588332, 0.559100585511540626, - 0.546820125163310577, 0.534417881237165604, 0.521885051592135052, 0.509211982443654398, - 0.496388045518671162, 0.483401491653461857, 0.470239275082169006, 0.456886840931420235, - 0.443327866073552401, 0.429543940225410703, 0.415514169600356364, 0.401214678896277765, - 0.386617977941119573, 0.371692145329917234, 0.356399760258393816, 0.340696481064849122, - 0.324529117016909452, 0.307832954674932158, 0.290527955491230394, 0.272513185478464703, - 0.253658363385912022, 0.233790483059674731, 0.212671510630966620, 0.189958689622431842, - 0.165127622564187282, 0.137304980940012589, 0.104838507565818778, 0.063852163815001570, - 0.000000000000000000}; - return expX[i]; - } - - Real ZigguratGaussianRngUtils::expF(int i) const { - static const ZigguratGaussianRngUtils::ZigguratTable expF = { - 0.000167066692307963, 0.000454134353841497, 0.000967269282327174, 0.001536299780301573, - 0.002145967743718907, 0.002788798793574076, 0.003460264777836904, 0.004157295120833797, - 0.004877655983542396, 0.005619642207205489, 0.006381905937319183, 0.007163353183634991, - 0.007963077438017043, 0.008780314985808977, 0.009614413642502212, 0.010464810181029981, - 0.011331013597834600, 0.012212592426255378, 0.013109164931254991, 0.014020391403181943, - 0.014945968011691148, 0.015885621839973156, 0.016839106826039941, 0.017806200410911355, - 0.018786700744696024, 0.019780424338009740, 0.020787204072578114, 0.021806887504283581, - 0.022839335406385240, 0.023884420511558174, 0.024942026419731787, 0.026012046645134221, - 0.027094383780955803, 0.028188948763978646, 0.029295660224637411, 0.030414443910466622, - 0.031545232172893622, 0.032687963508959555, 0.033842582150874358, 0.035009037697397431, - 0.036187284781931443, 0.037377282772959382, 0.038578995503074871, 0.039792391023374139, - 0.041017441380414840, 0.042254122413316254, 0.043502413568888197, 0.044762297732943289, - 0.046033761076175184, 0.047316792913181561, 0.048611385573379504, 0.049917534282706379, - 0.051235237055126281, 0.052564494593071685, 0.053905310196046080, 0.055257689676697030, - 0.056621641283742870, 0.057997175631200659, 0.059384305633420280, 0.060783046445479660, - 0.062193415408541036, 0.063615431999807376, 0.065049117786753805, 0.066494496385339816, - 0.067951593421936643, 0.069420436498728783, 0.070901055162371843, 0.072393480875708752, - 0.073897746992364746, 0.075413888734058410, 0.076941943170480517, 0.078481949201606435, - 0.080033947542319905, 0.081597980709237419, 0.083174093009632397, 0.084762330532368146, - 0.086362741140756927, 0.087975374467270231, 0.089600281910032886, 0.091237516631040197, - 0.092887133556043569, 0.094549189376055873, 0.096223742550432825, 0.097910853311492213, - 0.099610583670637132, 0.101322997425953631, 0.103048160171257702, 0.104786139306570145, - 0.106537004050001632, 0.108300825451033755, 0.110077676405185357, 0.111867631670056283, - 0.113670767882744286, 0.115487163578633506, 0.117316899211555525, 0.119160057175327641, - 0.121016721826674792, 0.122886979509545108, 0.124770918580830933, 0.126668629437510671, - 0.128580204545228199, 0.130505738468330773, 0.132445327901387494, 0.134399071702213602, - 0.136367070926428829, 0.138349428863580176, 0.140346251074862399, 0.142357645432472146, - 0.144383722160634720, 0.146424593878344889, 0.148480375643866735, 0.150551185001039839, - 0.152637142027442801, 0.154738369384468027, 0.156854992369365148, 0.158987138969314129, - 0.161134939917591952, 0.163298528751901734, 0.165478041874935922, 0.167673618617250081, - 0.169885401302527550, 0.172113535315319977, 0.174358169171353411, 0.176619454590494829, - 0.178897546572478278, 0.181192603475496261, 0.183504787097767436, 0.185834262762197083, - 0.188181199404254262, 0.190545769663195363, 0.192928149976771296, 0.195328520679563189, - 0.197747066105098818, 0.200183974691911210, 0.202639439093708962, 0.205113656293837654, - 0.207606827724221982, 0.210119159388988230, 0.212650861992978224, 0.215202151075378628, - 0.217773247148700472, 0.220364375843359439, 0.222975768058120111, 0.225607660116683956, - 0.228260293930716618, 0.230933917169627356, 0.233628783437433291, 0.236345152457059560, - 0.239083290262449094, 0.241843469398877131, 0.244625969131892024, 0.247431075665327543, - 0.250259082368862240, 0.253110290015629402, 0.255985007030415324, 0.258883549749016173, - 0.261806242689362922, 0.264753418835062149, 0.267725419932044739, 0.270722596799059967, - 0.273745309652802915, 0.276793928448517301, 0.279868833236972869, 0.282970414538780746, - 0.286099073737076826, 0.289255223489677693, 0.292439288161892630, 0.295651704281261252, - 0.298892921015581847, 0.302163400675693528, 0.305463619244590256, 0.308794066934560185, - 0.312155248774179606, 0.315547685227128949, 0.318971912844957239, 0.322428484956089223, - 0.325917972393556354, 0.329440964264136438, 0.332998068761809096, 0.336589914028677717, - 0.340217149066780189, 0.343880444704502575, 0.347580494621637148, 0.351318016437483449, - 0.355093752866787626, 0.358908472948750001, 0.362762973354817997, 0.366658079781514379, - 0.370594648435146223, 0.374573567615902381, 0.378595759409581067, 0.382662181496010056, - 0.386773829084137932, 0.390931736984797384, 0.395136981833290435, 0.399390684475231350, - 0.403694012530530555, 0.408048183152032673, 0.412454465997161457, 0.416914186433003209, - 0.421428728997616908, 0.425999541143034677, 0.430628137288459167, 0.435316103215636907, - 0.440065100842354173, 0.444876873414548846, 0.449753251162755330, 0.454696157474615836, - 0.459707615642138023, 0.464789756250426511, 0.469944825283960310, 0.475175193037377708, - 0.480483363930454543, 0.485871987341885248, 0.491343869594032867, 0.496901987241549881, - 0.502549501841348056, 0.508289776410643213, 0.514126393814748894, 0.520063177368233931, - 0.526104213983620062, 0.532253880263043655, 0.538516872002862246, 0.544898237672440056, - 0.551403416540641733, 0.558038282262587892, 0.564809192912400615, 0.571723048664826150, - 0.578787358602845359, 0.586010318477268366, 0.593400901691733762, 0.600968966365232560, - 0.608725382079622346, 0.616682180915207878, 0.624852738703666200, 0.633251994214366398, - 0.641896716427266423, 0.650805833414571433, 0.660000841079000145, 0.669506316731925177, - 0.679350572264765806, 0.689566496117078431, 0.700192655082788606, 0.711274760805076456, - 0.722867659593572465, 0.735038092431424039, 0.747868621985195658, 0.761463388849896838, - 0.775956852040116218, 0.791527636972496285, 0.808421651523009044, 0.826993296643051101, - 0.847785500623990496, 0.871704332381204705, 0.900469929925747703, 0.938143680862176477, - 1.000000000000000000}; - return expF[i]; - } } diff --git a/ql/math/randomnumbers/zigguratgaussianrng.hpp b/ql/math/randomnumbers/zigguratgaussianrng.hpp index 2cc57bc013a..3e0e37c5f12 100644 --- a/ql/math/randomnumbers/zigguratgaussianrng.hpp +++ b/ql/math/randomnumbers/zigguratgaussianrng.hpp @@ -26,6 +26,7 @@ #include #include +#include #include namespace QuantLib { @@ -60,6 +61,7 @@ namespace QuantLib { public: typedef Sample sample_type; + explicit ZigguratGaussianRng(const RNG& uint64Generator) : uint64Generator_(uint64Generator) {} @@ -67,42 +69,357 @@ namespace QuantLib { sample_type next() const { return {nextReal(), 1.0}; } //! return a random number from a Gaussian distribution - [[noreturn]] Real nextReal() const; + Real nextReal() const; private: + class Utils; + RNG uint64Generator_; - ZigguratGaussianRngUtils utils_; + std::unique_ptr utils_ = std::make_unique(); + + class Utils { + public: + typedef Real ZigguratTable[257]; + + Real pdf(Real x) const; + + //! compute a random number in the tail by hand + Real zeroCase(Real u, const std::function& uniformNextReal) const; + + Real normR() const; + Real normX(int i) const; + Real normF(int i) const; + + Real expR() const; + Real expX(int i) const; + Real expF(int i) const; + }; }; template inline Real ZigguratGaussianRng::nextReal() const { while (true) { std::uint64_t randomU64 = uint64Generator_.nextInt64(); - auto i = randomU64; + int i = (int)(randomU64 & 0xff); + // auto zeroCase = + // utils_->zeroCase(0.5, [&rng = uint64Generator_]() { return + // rng.nextReal(); }); return 0.0; } } - class ZigguratGaussianRngUtils { - template - friend class ZigguratGaussianRng; + template + inline Real ZigguratGaussianRng::Utils::pdf(Real x) const { + return std::exp(-x * x / 2.0); + } - typedef Real ZigguratTable[257]; + template + inline Real ZigguratGaussianRng::Utils::zeroCase( + Real u, const std::function& uniformNextReal) const { + // compute a random number in the tail by hand + Real x, y; + do { + x = std::log(uniformNextReal()) / normR(); + y = std::log(uniformNextReal()); + } while (-2.0 * y < x * x); - private: - Real pdf(Real x) const; + return (u < 0.0) ? x - normR() : normR() - x; + } - //! compute a random number in the tail by hand - Real zeroCase(Real u, const std::function& uniformNextReal) const; + template + inline Real ZigguratGaussianRng::Utils::normR() const { + return 3.654152885361008796; + } - Real normR() const; - Real normX(int i) const; - Real normF(int i) const; + template + Real ZigguratGaussianRng::Utils::normX(int i) const { + static const Utils::ZigguratTable normX = { + 3.910757959537090045, 3.654152885361008796, 3.449278298560964462, 3.320244733839166074, + 3.224575052047029100, 3.147889289517149969, 3.083526132001233044, 3.027837791768635434, + 2.978603279880844834, 2.934366867207854224, 2.894121053612348060, 2.857138730872132548, + 2.822877396825325125, 2.790921174000785765, 2.760944005278822555, 2.732685359042827056, + 2.705933656121858100, 2.680514643284522158, 2.656283037575502437, 2.633116393630324570, + 2.610910518487548515, 2.589575986706995181, 2.569035452680536569, 2.549221550323460761, + 2.530075232158516929, 2.511544441625342294, 2.493583041269680667, 2.476149939669143318, + 2.459208374333311298, 2.442725318198956774, 2.426670984935725972, 2.411018413899685520, + 2.395743119780480601, 2.380822795170626005, 2.366237056715818632, 2.351967227377659952, + 2.337996148795031370, 2.324308018869623016, 2.310888250599850036, 2.297723348901329565, + 2.284800802722946056, 2.272108990226823888, 2.259637095172217780, 2.247375032945807760, + 2.235313384928327984, 2.223443340090905718, 2.211756642882544366, 2.200245546609647995, + 2.188902771624720689, 2.177721467738641614, 2.166695180352645966, 2.155817819875063268, + 2.145083634046203613, 2.134487182844320152, 2.124023315687815661, 2.113687150684933957, + 2.103474055713146829, 2.093379631137050279, 2.083399693996551783, 2.073530263516978778, + 2.063767547809956415, 2.054107931648864849, 2.044547965215732788, 2.035084353727808715, + 2.025713947862032960, 2.016433734904371722, 2.007240830558684852, 1.998132471356564244, + 1.989106007615571325, 1.980158896898598364, 1.971288697931769640, 1.962493064942461896, + 1.953769742382734043, 1.945116560006753925, 1.936531428273758904, 1.928012334050718257, + 1.919557336591228847, 1.911164563769282232, 1.902832208548446369, 1.894558525668710081, + 1.886341828534776388, 1.878180486290977669, 1.870072921069236838, 1.862017605397632281, + 1.854013059758148119, 1.846057850283119750, 1.838150586580728607, 1.830289919680666566, + 1.822474540091783224, 1.814703175964167636, 1.806974591348693426, 1.799287584547580199, + 1.791640986550010028, 1.784033659547276329, 1.776464495522344977, 1.768932414909077933, + 1.761436365316706665, 1.753975320315455111, 1.746548278279492994, 1.739154261283669012, + 1.731792314050707216, 1.724461502945775715, 1.717160915015540690, 1.709889657069006086, + 1.702646854797613907, 1.695431651932238548, 1.688243209434858727, 1.681080704722823338, + 1.673943330923760353, 1.666830296159286684, 1.659740822855789499, 1.652674147080648526, + 1.645629517902360339, 1.638606196773111146, 1.631603456932422036, 1.624620582830568427, + 1.617656869570534228, 1.610711622367333673, 1.603784156023583041, 1.596873794420261339, + 1.589979870021648534, 1.583101723393471438, 1.576238702733332886, 1.569390163412534456, + 1.562555467528439657, 1.555733983466554893, 1.548925085471535512, 1.542128153226347553, + 1.535342571438843118, 1.528567729435024614, 1.521803020758293101, 1.515047842773992404, + 1.508301596278571965, 1.501563685112706548, 1.494833515777718391, 1.488110497054654369, + 1.481394039625375747, 1.474683555695025516, 1.467978458615230908, 1.461278162507407830, + 1.454582081885523293, 1.447889631277669675, 1.441200224845798017, 1.434513276002946425, + 1.427828197027290358, 1.421144398672323117, 1.414461289772464658, 1.407778276843371534, + 1.401094763676202559, 1.394410150925071257, 1.387723835686884621, 1.381035211072741964, + 1.374343665770030531, 1.367648583594317957, 1.360949343030101844, 1.354245316759430606, + 1.347535871177359290, 1.340820365893152122, 1.334098153216083604, 1.327368577624624679, + 1.320630975217730096, 1.313884673146868964, 1.307128989027353860, 1.300363230327433728, + 1.293586693733517645, 1.286798664489786415, 1.279998415710333237, 1.273185207661843732, + 1.266358287014688333, 1.259516886060144225, 1.252660221891297887, 1.245787495544997903, + 1.238897891102027415, 1.231990574742445110, 1.225064693752808020, 1.218119375481726552, + 1.211153726239911244, 1.204166830140560140, 1.197157747875585931, 1.190125515422801650, + 1.183069142678760732, 1.175987612011489825, 1.168879876726833800, 1.161744859441574240, + 1.154581450355851802, 1.147388505416733873, 1.140164844363995789, 1.132909248648336975, + 1.125620459211294389, 1.118297174115062909, 1.110938046009249502, 1.103541679420268151, + 1.096106627847603487, 1.088631390649514197, 1.081114409698889389, 1.073554065787871714, + 1.065948674757506653, 1.058296483326006454, 1.050595664586207123, 1.042844313139370538, + 1.035040439828605274, 1.027181966030751292, 1.019266717460529215, 1.011292417434978441, + 1.003256679539591412, 0.995156999629943084, 0.986990747093846266, 0.978755155288937750, + 0.970447311058864615, 0.962064143217605250, 0.953602409875572654, 0.945058684462571130, + 0.936429340280896860, 0.927710533396234771, 0.918898183643734989, 0.909987953490768997, + 0.900975224455174528, 0.891855070726792376, 0.882622229578910122, 0.873271068082494550, + 0.863795545546826915, 0.854189171001560554, 0.844444954902423661, 0.834555354079518752, + 0.824512208745288633, 0.814306670128064347, 0.803929116982664893, 0.793369058833152785, + 0.782615023299588763, 0.771654424216739354, 0.760473406422083165, 0.749056662009581653, + 0.737387211425838629, 0.725446140901303549, 0.713212285182022732, 0.700661841097584448, + 0.687767892786257717, 0.674499822827436479, 0.660822574234205984, 0.646695714884388928, + 0.632072236375024632, 0.616896989996235545, 0.601104617743940417, 0.584616766093722262, + 0.567338257040473026, 0.549151702313026790, 0.529909720646495108, 0.509423329585933393, + 0.487443966121754335, 0.463634336771763245, 0.437518402186662658, 0.408389134588000746, + 0.375121332850465727, 0.335737519180459465, 0.286174591747260509, 0.215241895913273806, + 0.000000000000000000}; + return normX[i]; + } + + template + Real ZigguratGaussianRng::Utils::normF(int i) const { + static const ZigguratGaussianRng::Utils::ZigguratTable normF = { + 0.000477467764586655, 0.001260285930498598, 0.002609072746106363, 0.004037972593371872, + 0.005522403299264754, 0.007050875471392110, 0.008616582769422917, 0.010214971439731100, + 0.011842757857943104, 0.013497450601780807, 0.015177088307982072, 0.016880083152595839, + 0.018605121275783350, 0.020351096230109354, 0.022117062707379922, 0.023902203305873237, + 0.025705804008632656, 0.027527235669693315, 0.029365939758230111, 0.031221417192023690, + 0.033093219458688698, 0.034980941461833073, 0.036884215688691151, 0.038802707404656918, + 0.040736110656078753, 0.042684144916619378, 0.044646552251446536, 0.046623094902089664, + 0.048613553216035145, 0.050617723861121788, 0.052635418276973649, 0.054666461325077916, + 0.056710690106399467, 0.058767952921137984, 0.060838108349751806, 0.062921024437977854, + 0.065016577971470438, 0.067124653828023989, 0.069245144397250269, 0.071377949059141965, + 0.073522973714240991, 0.075680130359194964, 0.077849336702372207, 0.080030515814947509, + 0.082223595813495684, 0.084428509570654661, 0.086645194450867782, 0.088873592068594229, + 0.091113648066700734, 0.093365311913026619, 0.095628536713353335, 0.097903279039215627, + 0.100189498769172020, 0.102487158942306270, 0.104796225622867056, 0.107116667775072880, + 0.109448457147210021, 0.111791568164245583, 0.114145977828255210, 0.116511665626037014, + 0.118888613443345698, 0.121276805485235437, 0.123676228202051403, 0.126086870220650349, + 0.128508722280473636, 0.130941777174128166, 0.133386029692162844, 0.135841476571757352, + 0.138308116449064322, 0.140785949814968309, 0.143274978974047118, 0.145775208006537926, + 0.148286642733128721, 0.150809290682410169, 0.153343161060837674, 0.155888264725064563, + 0.158444614156520225, 0.161012223438117663, 0.163591108232982951, 0.166181285765110071, + 0.168782774801850333, 0.171395595638155623, 0.174019770082499359, 0.176655321444406654, + 0.179302274523530397, 0.181960655600216487, 0.184630492427504539, 0.187311814224516926, + 0.190004651671193070, 0.192709036904328807, 0.195425003514885592, 0.198152586546538112, + 0.200891822495431333, 0.203642749311121501, 0.206405406398679298, 0.209179834621935651, + 0.211966076307852941, 0.214764175252008499, 0.217574176725178370, 0.220396127481011589, + 0.223230075764789593, 0.226076071323264877, 0.228934165415577484, 0.231804410825248525, + 0.234686861873252689, 0.237581574432173676, 0.240488605941449107, 0.243408015423711988, + 0.246339863502238771, 0.249284212419516704, 0.252241126056943765, 0.255210669955677150, + 0.258192911338648023, 0.261187919133763713, 0.264195763998317568, 0.267216518344631837, + 0.270250256366959984, 0.273297054069675804, 0.276356989296781264, 0.279430141762765316, + 0.282516593084849388, 0.285616426816658109, 0.288729728483353931, 0.291856585618280984, + 0.294997087801162572, 0.298151326697901342, 0.301319396102034120, 0.304501391977896274, + 0.307697412505553769, 0.310907558127563710, 0.314131931597630143, 0.317370638031222396, + 0.320623784958230129, 0.323891482377732021, 0.327173842814958593, 0.330470981380537099, + 0.333783015832108509, 0.337110066638412809, 0.340452257045945450, 0.343809713148291340, + 0.347182563958251478, 0.350570941482881204, 0.353974980801569250, 0.357394820147290515, + 0.360830600991175754, 0.364282468130549597, 0.367750569780596226, 0.371235057669821344, + 0.374736087139491414, 0.378253817247238111, 0.381788410875031348, 0.385340034841733958, + 0.388908860020464597, 0.392495061461010764, 0.396098818517547080, 0.399720314981931668, + 0.403359739222868885, 0.407017284331247953, 0.410693148271983222, 0.414387534042706784, + 0.418100649839684591, 0.421832709231353298, 0.425583931339900579, 0.429354541031341519, + 0.433144769114574058, 0.436954852549929273, 0.440785034667769915, 0.444635565397727750, + 0.448506701509214067, 0.452398706863882505, 0.456311852680773566, 0.460246417814923481, + 0.464202689050278838, 0.468180961407822172, 0.472181538469883255, 0.476204732721683788, + 0.480250865911249714, 0.484320269428911598, 0.488413284707712059, 0.492530263646148658, + 0.496671569054796314, 0.500837575128482149, 0.505028667945828791, 0.509245245998136142, + 0.513487720749743026, 0.517756517232200619, 0.522052074674794864, 0.526374847174186700, + 0.530725304406193921, 0.535103932383019565, 0.539511234259544614, 0.543947731192649941, + 0.548413963257921133, 0.552910490428519918, 0.557437893621486324, 0.561996775817277916, + 0.566587763258951771, 0.571211506738074970, 0.575868682975210544, 0.580559996103683473, + 0.585286179266300333, 0.590047996335791969, 0.594846243770991268, 0.599681752622167719, + 0.604555390700549533, 0.609468064928895381, 0.614420723892076803, 0.619414360609039205, + 0.624450015550274240, 0.629528779928128279, 0.634651799290960050, 0.639820277456438991, + 0.645035480824251883, 0.650298743114294586, 0.655611470583224665, 0.660975147780241357, + 0.666391343912380640, 0.671861719900766374, 0.677388036222513090, 0.682972161648791376, + 0.688616083008527058, 0.694321916130032579, 0.700091918140490099, 0.705928501336797409, + 0.711834248882358467, 0.717811932634901395, 0.723864533472881599, 0.729995264565802437, + 0.736207598131266683, 0.742505296344636245, 0.748892447223726720, 0.755373506511754500, + 0.761953346841546475, 0.768637315803334831, 0.775431304986138326, 0.782341832659861902, + 0.789376143571198563, 0.796542330428254619, 0.803849483176389490, 0.811307874318219935, + 0.818929191609414797, 0.826726833952094231, 0.834716292992930375, 0.842915653118441077, + 0.851346258465123684, 0.860033621203008636, 0.869008688043793165, 0.878309655816146839, + 0.887984660763399880, 0.898095921906304051, 0.908726440060562912, 0.919991505048360247, + 0.932060075968990209, 0.945198953453078028, 0.959879091812415930, 0.977101701282731328, + 1.000000000000000000}; + return normF[i]; + } + + template + Real ZigguratGaussianRng::Utils::expR() const { + return 7.697117470131050077; + } + + template + Real ZigguratGaussianRng::Utils::expX(int i) const { + static const ZigguratGaussianRng::Utils::ZigguratTable expX = { + 8.697117470131052741, 7.697117470131050077, 6.941033629377212577, 6.478378493832569696, + 6.144164665772472667, 5.882144315795399869, 5.666410167454033697, 5.482890627526062488, + 5.323090505754398016, 5.181487281301500047, 5.054288489981304089, 4.938777085901250530, + 4.832939741025112035, 4.735242996601741083, 4.644491885420085175, 4.559737061707351380, + 4.480211746528421912, 4.405287693473573185, 4.334443680317273007, 4.267242480277365857, + 4.203313713735184365, 4.142340865664051464, 4.084051310408297830, 4.028208544647936762, + 3.974606066673788796, 3.923062500135489739, 3.873417670399509127, 3.825529418522336744, + 3.779270992411667862, 3.734528894039797375, 3.691201090237418825, 3.649195515760853770, + 3.608428813128909507, 3.568825265648337020, 3.530315889129343354, 3.492837654774059608, + 3.456332821132760191, 3.420748357251119920, 3.386035442460300970, 3.352149030900109405, + 3.319047470970748037, 3.286692171599068679, 3.255047308570449882, 3.224079565286264160, + 3.193757903212240290, 3.164053358025972873, 3.134938858084440394, 3.106389062339824481, + 3.078380215254090224, 3.050890016615455114, 3.023897504455676621, 2.997382949516130601, + 2.971327759921089662, 2.945714394895045718, 2.920526286512740821, 2.895747768600141825, + 2.871364012015536371, 2.847360965635188812, 2.823725302450035279, 2.800444370250737780, + 2.777506146439756574, 2.754899196562344610, 2.732612636194700073, 2.710636095867928752, + 2.688959688741803689, 2.667573980773266573, 2.646469963151809157, 2.625639026797788489, + 2.605072938740835564, 2.584763820214140750, 2.564704126316905253, 2.544886627111869970, + 2.525304390037828028, 2.505950763528594027, 2.486819361740209455, 2.467904050297364815, + 2.449198932978249754, 2.430698339264419694, 2.412396812688870629, 2.394289099921457886, + 2.376370140536140596, 2.358635057409337321, 2.341079147703034380, 2.323697874390196372, + 2.306486858283579799, 2.289441870532269441, 2.272558825553154804, 2.255833774367219213, + 2.239262898312909034, 2.222842503111036816, 2.206569013257663858, 2.190438966723220027, + 2.174449009937774679, 2.158595893043885994, 2.142876465399842001, 2.127287671317368289, + 2.111826546019042183, 2.096490211801715020, 2.081275874393225145, 2.066180819490575526, + 2.051202409468584786, 2.036338080248769611, 2.021585338318926173, 2.006941757894518563, + 1.992404978213576650, 1.977972700957360441, 1.963642687789548313, 1.949412758007184943, + 1.935280786297051359, 1.921244700591528076, 1.907302480018387536, 1.893452152939308242, + 1.879691795072211180, 1.866019527692827973, 1.852433515911175554, 1.838931967018879954, + 1.825513128903519799, 1.812175288526390649, 1.798916770460290859, 1.785735935484126014, + 1.772631179231305643, 1.759600930889074766, 1.746643651946074405, 1.733757834985571566, + 1.720942002521935299, 1.708194705878057773, 1.695514524101537912, 1.682900062917553896, + 1.670349953716452118, 1.657862852574172763, 1.645437439303723659, 1.633072416535991334, + 1.620766508828257901, 1.608518461798858379, 1.596327041286483395, 1.584191032532688892, + 1.572109239386229707, 1.560080483527888084, 1.548103603714513499, 1.536177455041032092, + 1.524300908219226258, 1.512472848872117082, 1.500692176842816750, 1.488957805516746058, + 1.477268661156133867, 1.465623682245745352, 1.454021818848793446, 1.442462031972012504, + 1.430943292938879674, 1.419464582769983219, 1.408024891569535697, 1.396623217917042137, + 1.385258568263121992, 1.373929956328490576, 1.362636402505086775, 1.351376933258335189, + 1.340150580529504643, 1.328956381137116560, 1.317793376176324749, 1.306660610415174117, + 1.295557131686601027, 1.284481990275012642, 1.273434238296241139, 1.262412929069615330, + 1.251417116480852521, 1.240445854334406572, 1.229498195693849105, 1.218573192208790124, + 1.207669893426761121, 1.196787346088403092, 1.185924593404202199, 1.175080674310911677, + 1.164254622705678921, 1.153445466655774743, 1.142652227581672841, 1.131873919411078511, + 1.121109547701330200, 1.110358108727411031, 1.099618588532597308, 1.088889961938546813, + 1.078171191511372307, 1.067461226479967662, 1.056759001602551429, 1.046063435977044209, + 1.035373431790528542, 1.024687873002617211, 1.014005623957096480, 1.003325527915696735, + 0.992646405507275897, 0.981967053085062602, 0.971286240983903260, 0.960602711668666509, + 0.949915177764075969, 0.939222319955262286, 0.928522784747210395, 0.917815182070044311, + 0.907098082715690257, 0.896370015589889935, 0.885629464761751528, 0.874874866291025066, + 0.864104604811004484, 0.853317009842373353, 0.842510351810368485, 0.831682837734273206, + 0.820832606554411814, 0.809957724057418282, 0.799056177355487174, 0.788125868869492430, + 0.777164609759129710, 0.766170112735434672, 0.755139984181982249, 0.744071715500508102, + 0.732962673584365398, 0.721810090308756203, 0.710611050909655040, 0.699362481103231959, + 0.688061132773747808, 0.676703568029522584, 0.665286141392677943, 0.653804979847664947, + 0.642255960424536365, 0.630634684933490286, 0.618936451394876075, 0.607156221620300030, + 0.595288584291502887, 0.583327712748769489, 0.571267316532588332, 0.559100585511540626, + 0.546820125163310577, 0.534417881237165604, 0.521885051592135052, 0.509211982443654398, + 0.496388045518671162, 0.483401491653461857, 0.470239275082169006, 0.456886840931420235, + 0.443327866073552401, 0.429543940225410703, 0.415514169600356364, 0.401214678896277765, + 0.386617977941119573, 0.371692145329917234, 0.356399760258393816, 0.340696481064849122, + 0.324529117016909452, 0.307832954674932158, 0.290527955491230394, 0.272513185478464703, + 0.253658363385912022, 0.233790483059674731, 0.212671510630966620, 0.189958689622431842, + 0.165127622564187282, 0.137304980940012589, 0.104838507565818778, 0.063852163815001570, + 0.000000000000000000}; + return expX[i]; + } + + template + Real ZigguratGaussianRng::Utils::expF(int i) const { + static const ZigguratGaussianRng::Utils::ZigguratTable expF = { + 0.000167066692307963, 0.000454134353841497, 0.000967269282327174, 0.001536299780301573, + 0.002145967743718907, 0.002788798793574076, 0.003460264777836904, 0.004157295120833797, + 0.004877655983542396, 0.005619642207205489, 0.006381905937319183, 0.007163353183634991, + 0.007963077438017043, 0.008780314985808977, 0.009614413642502212, 0.010464810181029981, + 0.011331013597834600, 0.012212592426255378, 0.013109164931254991, 0.014020391403181943, + 0.014945968011691148, 0.015885621839973156, 0.016839106826039941, 0.017806200410911355, + 0.018786700744696024, 0.019780424338009740, 0.020787204072578114, 0.021806887504283581, + 0.022839335406385240, 0.023884420511558174, 0.024942026419731787, 0.026012046645134221, + 0.027094383780955803, 0.028188948763978646, 0.029295660224637411, 0.030414443910466622, + 0.031545232172893622, 0.032687963508959555, 0.033842582150874358, 0.035009037697397431, + 0.036187284781931443, 0.037377282772959382, 0.038578995503074871, 0.039792391023374139, + 0.041017441380414840, 0.042254122413316254, 0.043502413568888197, 0.044762297732943289, + 0.046033761076175184, 0.047316792913181561, 0.048611385573379504, 0.049917534282706379, + 0.051235237055126281, 0.052564494593071685, 0.053905310196046080, 0.055257689676697030, + 0.056621641283742870, 0.057997175631200659, 0.059384305633420280, 0.060783046445479660, + 0.062193415408541036, 0.063615431999807376, 0.065049117786753805, 0.066494496385339816, + 0.067951593421936643, 0.069420436498728783, 0.070901055162371843, 0.072393480875708752, + 0.073897746992364746, 0.075413888734058410, 0.076941943170480517, 0.078481949201606435, + 0.080033947542319905, 0.081597980709237419, 0.083174093009632397, 0.084762330532368146, + 0.086362741140756927, 0.087975374467270231, 0.089600281910032886, 0.091237516631040197, + 0.092887133556043569, 0.094549189376055873, 0.096223742550432825, 0.097910853311492213, + 0.099610583670637132, 0.101322997425953631, 0.103048160171257702, 0.104786139306570145, + 0.106537004050001632, 0.108300825451033755, 0.110077676405185357, 0.111867631670056283, + 0.113670767882744286, 0.115487163578633506, 0.117316899211555525, 0.119160057175327641, + 0.121016721826674792, 0.122886979509545108, 0.124770918580830933, 0.126668629437510671, + 0.128580204545228199, 0.130505738468330773, 0.132445327901387494, 0.134399071702213602, + 0.136367070926428829, 0.138349428863580176, 0.140346251074862399, 0.142357645432472146, + 0.144383722160634720, 0.146424593878344889, 0.148480375643866735, 0.150551185001039839, + 0.152637142027442801, 0.154738369384468027, 0.156854992369365148, 0.158987138969314129, + 0.161134939917591952, 0.163298528751901734, 0.165478041874935922, 0.167673618617250081, + 0.169885401302527550, 0.172113535315319977, 0.174358169171353411, 0.176619454590494829, + 0.178897546572478278, 0.181192603475496261, 0.183504787097767436, 0.185834262762197083, + 0.188181199404254262, 0.190545769663195363, 0.192928149976771296, 0.195328520679563189, + 0.197747066105098818, 0.200183974691911210, 0.202639439093708962, 0.205113656293837654, + 0.207606827724221982, 0.210119159388988230, 0.212650861992978224, 0.215202151075378628, + 0.217773247148700472, 0.220364375843359439, 0.222975768058120111, 0.225607660116683956, + 0.228260293930716618, 0.230933917169627356, 0.233628783437433291, 0.236345152457059560, + 0.239083290262449094, 0.241843469398877131, 0.244625969131892024, 0.247431075665327543, + 0.250259082368862240, 0.253110290015629402, 0.255985007030415324, 0.258883549749016173, + 0.261806242689362922, 0.264753418835062149, 0.267725419932044739, 0.270722596799059967, + 0.273745309652802915, 0.276793928448517301, 0.279868833236972869, 0.282970414538780746, + 0.286099073737076826, 0.289255223489677693, 0.292439288161892630, 0.295651704281261252, + 0.298892921015581847, 0.302163400675693528, 0.305463619244590256, 0.308794066934560185, + 0.312155248774179606, 0.315547685227128949, 0.318971912844957239, 0.322428484956089223, + 0.325917972393556354, 0.329440964264136438, 0.332998068761809096, 0.336589914028677717, + 0.340217149066780189, 0.343880444704502575, 0.347580494621637148, 0.351318016437483449, + 0.355093752866787626, 0.358908472948750001, 0.362762973354817997, 0.366658079781514379, + 0.370594648435146223, 0.374573567615902381, 0.378595759409581067, 0.382662181496010056, + 0.386773829084137932, 0.390931736984797384, 0.395136981833290435, 0.399390684475231350, + 0.403694012530530555, 0.408048183152032673, 0.412454465997161457, 0.416914186433003209, + 0.421428728997616908, 0.425999541143034677, 0.430628137288459167, 0.435316103215636907, + 0.440065100842354173, 0.444876873414548846, 0.449753251162755330, 0.454696157474615836, + 0.459707615642138023, 0.464789756250426511, 0.469944825283960310, 0.475175193037377708, + 0.480483363930454543, 0.485871987341885248, 0.491343869594032867, 0.496901987241549881, + 0.502549501841348056, 0.508289776410643213, 0.514126393814748894, 0.520063177368233931, + 0.526104213983620062, 0.532253880263043655, 0.538516872002862246, 0.544898237672440056, + 0.551403416540641733, 0.558038282262587892, 0.564809192912400615, 0.571723048664826150, + 0.578787358602845359, 0.586010318477268366, 0.593400901691733762, 0.600968966365232560, + 0.608725382079622346, 0.616682180915207878, 0.624852738703666200, 0.633251994214366398, + 0.641896716427266423, 0.650805833414571433, 0.660000841079000145, 0.669506316731925177, + 0.679350572264765806, 0.689566496117078431, 0.700192655082788606, 0.711274760805076456, + 0.722867659593572465, 0.735038092431424039, 0.747868621985195658, 0.761463388849896838, + 0.775956852040116218, 0.791527636972496285, 0.808421651523009044, 0.826993296643051101, + 0.847785500623990496, 0.871704332381204705, 0.900469929925747703, 0.938143680862176477, + 1.000000000000000000}; + return expF[i]; + } - Real expR() const; - Real expX(int i) const; - Real expF(int i) const; - }; } #endif diff --git a/test-suite/zigguratgaussian.cpp b/test-suite/zigguratgaussian.cpp index 31dc3161b0b..c70fe409ded 100644 --- a/test-suite/zigguratgaussian.cpp +++ b/test-suite/zigguratgaussian.cpp @@ -18,9 +18,10 @@ */ #include "toplevelfixture.hpp" -#include "utilities.hpp" #include #include +#include +#include #include using namespace QuantLib; @@ -59,6 +60,14 @@ BOOST_AUTO_TEST_CASE(testMeanAndStdDevOfNextReal) { } } +BOOST_AUTO_TEST_CASE(testBitsShifting) { + std::uint64_t uint64 = 0xffffffffffffffff - 0xffffffffffffff - 1 + 25; + BOOST_TEST_MESSAGE("" << std::bitset<64>(uint64) << " : " << uint64); + BOOST_TEST_MESSAGE("" << std::bitset<64>(uint64 >> 8) << " : " << (uint64 >> 8)); + BOOST_TEST_MESSAGE("" << std::bitset<64>(uint64 & 0xff) << " : " << (uint64 & 0xff)); + BOOST_TEST_MESSAGE("" << std::bitset<64>(uint64 & 0xff) << " : " << (int)(uint64 & 0xff)); +} + BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END() From 05ccdef0f1068e89a5c26fa671e72554e53f358f Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Thu, 2 May 2024 09:29:33 +0200 Subject: [PATCH 06/19] Removed nested Utils class --- ql/math/randomnumbers/zigguratgaussianrng.hpp | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/ql/math/randomnumbers/zigguratgaussianrng.hpp b/ql/math/randomnumbers/zigguratgaussianrng.hpp index 3e0e37c5f12..ffdba7a119c 100644 --- a/ql/math/randomnumbers/zigguratgaussianrng.hpp +++ b/ql/math/randomnumbers/zigguratgaussianrng.hpp @@ -72,50 +72,55 @@ namespace QuantLib { Real nextReal() const; private: - class Utils; - RNG uint64Generator_; - std::unique_ptr utils_ = std::make_unique(); - class Utils { - public: - typedef Real ZigguratTable[257]; + typedef Real ZigguratTable[257]; - Real pdf(Real x) const; + Real pdf(Real x) const; - //! compute a random number in the tail by hand - Real zeroCase(Real u, const std::function& uniformNextReal) const; + //! compute a random number in the tail by hand + Real zeroCase(Real u, const std::function& uniformNextReal) const; - Real normR() const; - Real normX(int i) const; - Real normF(int i) const; + Real normR() const; + Real normX(int i) const; + Real normF(int i) const; - Real expR() const; - Real expX(int i) const; - Real expF(int i) const; - }; + Real expR() const; + Real expX(int i) const; + Real expF(int i) const; }; template inline Real ZigguratGaussianRng::nextReal() const { while (true) { + // As an optimisation we re-implement the conversion to a f64. + // From the remaining 12 most significant bits we use 8 to construct `i`. + // This saves us generating a whole extra random number, while the added + // precision of using 64 bits for f64 does not buy us much. std::uint64_t randomU64 = uint64Generator_.nextInt64(); - int i = (int)(randomU64 & 0xff); - // auto zeroCase = - // utils_->zeroCase(0.5, [&rng = uint64Generator_]() { return - // rng.nextReal(); }); + + auto i = (int)(randomU64 & 0xff); + + // Convert to a value in the range [2,4) and subtract to get [-1,1) + // We can't convert to an open range directly, that would require + // subtracting `3.0 - EPSILON`, which is not representable. + // It is possible with an extra step, but an open range does not + // seem necessary for the ziggurat algorithm anyway. + Real u = (Real(randomU64 >> 11) + 0.5) * (2.0 / Real(1ULL << 53)) - 1.0; + return 0.0; } } template - inline Real ZigguratGaussianRng::Utils::pdf(Real x) const { + inline Real ZigguratGaussianRng::pdf(Real x) const { return std::exp(-x * x / 2.0); } template - inline Real ZigguratGaussianRng::Utils::zeroCase( - Real u, const std::function& uniformNextReal) const { + inline Real + ZigguratGaussianRng::zeroCase(Real u, + const std::function& uniformNextReal) const { // compute a random number in the tail by hand Real x, y; do { @@ -127,13 +132,13 @@ namespace QuantLib { } template - inline Real ZigguratGaussianRng::Utils::normR() const { + inline Real ZigguratGaussianRng::normR() const { return 3.654152885361008796; } template - Real ZigguratGaussianRng::Utils::normX(int i) const { - static const Utils::ZigguratTable normX = { + Real ZigguratGaussianRng::normX(int i) const { + static const ZigguratTable normX = { 3.910757959537090045, 3.654152885361008796, 3.449278298560964462, 3.320244733839166074, 3.224575052047029100, 3.147889289517149969, 3.083526132001233044, 3.027837791768635434, 2.978603279880844834, 2.934366867207854224, 2.894121053612348060, 2.857138730872132548, @@ -203,8 +208,8 @@ namespace QuantLib { } template - Real ZigguratGaussianRng::Utils::normF(int i) const { - static const ZigguratGaussianRng::Utils::ZigguratTable normF = { + Real ZigguratGaussianRng::normF(int i) const { + static const ZigguratGaussianRng::ZigguratTable normF = { 0.000477467764586655, 0.001260285930498598, 0.002609072746106363, 0.004037972593371872, 0.005522403299264754, 0.007050875471392110, 0.008616582769422917, 0.010214971439731100, 0.011842757857943104, 0.013497450601780807, 0.015177088307982072, 0.016880083152595839, @@ -274,13 +279,13 @@ namespace QuantLib { } template - Real ZigguratGaussianRng::Utils::expR() const { + Real ZigguratGaussianRng::expR() const { return 7.697117470131050077; } template - Real ZigguratGaussianRng::Utils::expX(int i) const { - static const ZigguratGaussianRng::Utils::ZigguratTable expX = { + Real ZigguratGaussianRng::expX(int i) const { + static const ZigguratGaussianRng::ZigguratTable expX = { 8.697117470131052741, 7.697117470131050077, 6.941033629377212577, 6.478378493832569696, 6.144164665772472667, 5.882144315795399869, 5.666410167454033697, 5.482890627526062488, 5.323090505754398016, 5.181487281301500047, 5.054288489981304089, 4.938777085901250530, @@ -350,8 +355,8 @@ namespace QuantLib { } template - Real ZigguratGaussianRng::Utils::expF(int i) const { - static const ZigguratGaussianRng::Utils::ZigguratTable expF = { + Real ZigguratGaussianRng::expF(int i) const { + static const ZigguratGaussianRng::ZigguratTable expF = { 0.000167066692307963, 0.000454134353841497, 0.000967269282327174, 0.001536299780301573, 0.002145967743718907, 0.002788798793574076, 0.003460264777836904, 0.004157295120833797, 0.004877655983542396, 0.005619642207205489, 0.006381905937319183, 0.007163353183634991, From bd19f1c38284f1b4fcfe4b3094af90c736942dc1 Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Fri, 3 May 2024 23:35:45 +0200 Subject: [PATCH 07/19] First working Gaussian RNG, still needs to be tested --- ql/math/randomnumbers/zigguratgaussianrng.hpp | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/ql/math/randomnumbers/zigguratgaussianrng.hpp b/ql/math/randomnumbers/zigguratgaussianrng.hpp index ffdba7a119c..f609361b60e 100644 --- a/ql/math/randomnumbers/zigguratgaussianrng.hpp +++ b/ql/math/randomnumbers/zigguratgaussianrng.hpp @@ -79,7 +79,7 @@ namespace QuantLib { Real pdf(Real x) const; //! compute a random number in the tail by hand - Real zeroCase(Real u, const std::function& uniformNextReal) const; + Real zeroCase(Real u) const; Real normR() const; Real normX(int i) const; @@ -106,9 +106,19 @@ namespace QuantLib { // subtracting `3.0 - EPSILON`, which is not representable. // It is possible with an extra step, but an open range does not // seem necessary for the ziggurat algorithm anyway. - Real u = (Real(randomU64 >> 11) + 0.5) * (2.0 / Real(1ULL << 53)) - 1.0; - - return 0.0; + auto u = (Real(randomU64 >> 11) + 0.5) * (2.0 / Real(1ULL << 53)) - 1.0; + + auto x = u * normX(i); + + if (std::abs(x) < normX(i + 1)) { + return x; + } + if (i == 0) { + return zeroCase(u); + } + if (normF(i + 1) + (normF(i) - normF(i + 1) * uint64Generator_.nextInt64()) < pdf(x)) { + return x; + } } } @@ -118,14 +128,12 @@ namespace QuantLib { } template - inline Real - ZigguratGaussianRng::zeroCase(Real u, - const std::function& uniformNextReal) const { + inline Real ZigguratGaussianRng::zeroCase(Real u) const { // compute a random number in the tail by hand Real x, y; do { - x = std::log(uniformNextReal()) / normR(); - y = std::log(uniformNextReal()); + x = std::log(uint64Generator_.nextReal()) / normR(); + y = std::log(uint64Generator_.nextReal()); } while (-2.0 * y < x * x); return (u < 0.0) ? x - normR() : normR() - x; From 9b7f14bac9b9b5905f8cadc5266c347147957def Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Sat, 4 May 2024 21:26:05 +0200 Subject: [PATCH 08/19] Included --- ql/CMakeLists.txt | 3 +-- ql/math/randomnumbers/zigguratgaussianrng.cpp | 23 ------------------- ql/math/randomnumbers/zigguratgaussianrng.hpp | 4 +--- 3 files changed, 2 insertions(+), 28 deletions(-) delete mode 100644 ql/math/randomnumbers/zigguratgaussianrng.cpp diff --git a/ql/CMakeLists.txt b/ql/CMakeLists.txt index de4902d24dc..6af1f281078 100644 --- a/ql/CMakeLists.txt +++ b/ql/CMakeLists.txt @@ -427,8 +427,7 @@ set(QL_SOURCES math/randomnumbers/sobolrsg.cpp math/randomnumbers/stochasticcollocationinvcdf.cpp math/randomnumbers/xoshiro256starstaruniformrng.cpp - math/randomnumbers/zigguratgaussianrng.cpp - math/richardsonextrapolation.cpp + math/richardsonextrapolation.cpp math/rounding.cpp math/sampledcurve.cpp math/statistics/discrepancystatistics.cpp diff --git a/ql/math/randomnumbers/zigguratgaussianrng.cpp b/ql/math/randomnumbers/zigguratgaussianrng.cpp deleted file mode 100644 index 5d8b505a766..00000000000 --- a/ql/math/randomnumbers/zigguratgaussianrng.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2024 Ralf Konrad Eckel - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#include - -namespace QuantLib { -} diff --git a/ql/math/randomnumbers/zigguratgaussianrng.hpp b/ql/math/randomnumbers/zigguratgaussianrng.hpp index f609361b60e..3f1a1ea29fa 100644 --- a/ql/math/randomnumbers/zigguratgaussianrng.hpp +++ b/ql/math/randomnumbers/zigguratgaussianrng.hpp @@ -25,9 +25,7 @@ #define quantlib_ziggurat_gaussian_rng_h #include -#include -#include -#include +#include namespace QuantLib { From 84ee49ef34d56085b02fc56c833c57558cab1b58 Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Mon, 6 May 2024 14:34:51 +0200 Subject: [PATCH 09/19] nextReal() instead of nextInt64(), plus removed unused exp.(...) parts --- ql/math/randomnumbers/zigguratgaussianrng.hpp | 154 +----------------- 1 file changed, 1 insertion(+), 153 deletions(-) diff --git a/ql/math/randomnumbers/zigguratgaussianrng.hpp b/ql/math/randomnumbers/zigguratgaussianrng.hpp index 3f1a1ea29fa..a8aa6eb9df3 100644 --- a/ql/math/randomnumbers/zigguratgaussianrng.hpp +++ b/ql/math/randomnumbers/zigguratgaussianrng.hpp @@ -82,10 +82,6 @@ namespace QuantLib { Real normR() const; Real normX(int i) const; Real normF(int i) const; - - Real expR() const; - Real expX(int i) const; - Real expF(int i) const; }; template @@ -114,7 +110,7 @@ namespace QuantLib { if (i == 0) { return zeroCase(u); } - if (normF(i + 1) + (normF(i) - normF(i + 1) * uint64Generator_.nextInt64()) < pdf(x)) { + if (normF(i + 1) + (normF(i) - normF(i + 1) * uint64Generator_.nextReal()) < pdf(x)) { return x; } } @@ -283,154 +279,6 @@ namespace QuantLib { 1.000000000000000000}; return normF[i]; } - - template - Real ZigguratGaussianRng::expR() const { - return 7.697117470131050077; - } - - template - Real ZigguratGaussianRng::expX(int i) const { - static const ZigguratGaussianRng::ZigguratTable expX = { - 8.697117470131052741, 7.697117470131050077, 6.941033629377212577, 6.478378493832569696, - 6.144164665772472667, 5.882144315795399869, 5.666410167454033697, 5.482890627526062488, - 5.323090505754398016, 5.181487281301500047, 5.054288489981304089, 4.938777085901250530, - 4.832939741025112035, 4.735242996601741083, 4.644491885420085175, 4.559737061707351380, - 4.480211746528421912, 4.405287693473573185, 4.334443680317273007, 4.267242480277365857, - 4.203313713735184365, 4.142340865664051464, 4.084051310408297830, 4.028208544647936762, - 3.974606066673788796, 3.923062500135489739, 3.873417670399509127, 3.825529418522336744, - 3.779270992411667862, 3.734528894039797375, 3.691201090237418825, 3.649195515760853770, - 3.608428813128909507, 3.568825265648337020, 3.530315889129343354, 3.492837654774059608, - 3.456332821132760191, 3.420748357251119920, 3.386035442460300970, 3.352149030900109405, - 3.319047470970748037, 3.286692171599068679, 3.255047308570449882, 3.224079565286264160, - 3.193757903212240290, 3.164053358025972873, 3.134938858084440394, 3.106389062339824481, - 3.078380215254090224, 3.050890016615455114, 3.023897504455676621, 2.997382949516130601, - 2.971327759921089662, 2.945714394895045718, 2.920526286512740821, 2.895747768600141825, - 2.871364012015536371, 2.847360965635188812, 2.823725302450035279, 2.800444370250737780, - 2.777506146439756574, 2.754899196562344610, 2.732612636194700073, 2.710636095867928752, - 2.688959688741803689, 2.667573980773266573, 2.646469963151809157, 2.625639026797788489, - 2.605072938740835564, 2.584763820214140750, 2.564704126316905253, 2.544886627111869970, - 2.525304390037828028, 2.505950763528594027, 2.486819361740209455, 2.467904050297364815, - 2.449198932978249754, 2.430698339264419694, 2.412396812688870629, 2.394289099921457886, - 2.376370140536140596, 2.358635057409337321, 2.341079147703034380, 2.323697874390196372, - 2.306486858283579799, 2.289441870532269441, 2.272558825553154804, 2.255833774367219213, - 2.239262898312909034, 2.222842503111036816, 2.206569013257663858, 2.190438966723220027, - 2.174449009937774679, 2.158595893043885994, 2.142876465399842001, 2.127287671317368289, - 2.111826546019042183, 2.096490211801715020, 2.081275874393225145, 2.066180819490575526, - 2.051202409468584786, 2.036338080248769611, 2.021585338318926173, 2.006941757894518563, - 1.992404978213576650, 1.977972700957360441, 1.963642687789548313, 1.949412758007184943, - 1.935280786297051359, 1.921244700591528076, 1.907302480018387536, 1.893452152939308242, - 1.879691795072211180, 1.866019527692827973, 1.852433515911175554, 1.838931967018879954, - 1.825513128903519799, 1.812175288526390649, 1.798916770460290859, 1.785735935484126014, - 1.772631179231305643, 1.759600930889074766, 1.746643651946074405, 1.733757834985571566, - 1.720942002521935299, 1.708194705878057773, 1.695514524101537912, 1.682900062917553896, - 1.670349953716452118, 1.657862852574172763, 1.645437439303723659, 1.633072416535991334, - 1.620766508828257901, 1.608518461798858379, 1.596327041286483395, 1.584191032532688892, - 1.572109239386229707, 1.560080483527888084, 1.548103603714513499, 1.536177455041032092, - 1.524300908219226258, 1.512472848872117082, 1.500692176842816750, 1.488957805516746058, - 1.477268661156133867, 1.465623682245745352, 1.454021818848793446, 1.442462031972012504, - 1.430943292938879674, 1.419464582769983219, 1.408024891569535697, 1.396623217917042137, - 1.385258568263121992, 1.373929956328490576, 1.362636402505086775, 1.351376933258335189, - 1.340150580529504643, 1.328956381137116560, 1.317793376176324749, 1.306660610415174117, - 1.295557131686601027, 1.284481990275012642, 1.273434238296241139, 1.262412929069615330, - 1.251417116480852521, 1.240445854334406572, 1.229498195693849105, 1.218573192208790124, - 1.207669893426761121, 1.196787346088403092, 1.185924593404202199, 1.175080674310911677, - 1.164254622705678921, 1.153445466655774743, 1.142652227581672841, 1.131873919411078511, - 1.121109547701330200, 1.110358108727411031, 1.099618588532597308, 1.088889961938546813, - 1.078171191511372307, 1.067461226479967662, 1.056759001602551429, 1.046063435977044209, - 1.035373431790528542, 1.024687873002617211, 1.014005623957096480, 1.003325527915696735, - 0.992646405507275897, 0.981967053085062602, 0.971286240983903260, 0.960602711668666509, - 0.949915177764075969, 0.939222319955262286, 0.928522784747210395, 0.917815182070044311, - 0.907098082715690257, 0.896370015589889935, 0.885629464761751528, 0.874874866291025066, - 0.864104604811004484, 0.853317009842373353, 0.842510351810368485, 0.831682837734273206, - 0.820832606554411814, 0.809957724057418282, 0.799056177355487174, 0.788125868869492430, - 0.777164609759129710, 0.766170112735434672, 0.755139984181982249, 0.744071715500508102, - 0.732962673584365398, 0.721810090308756203, 0.710611050909655040, 0.699362481103231959, - 0.688061132773747808, 0.676703568029522584, 0.665286141392677943, 0.653804979847664947, - 0.642255960424536365, 0.630634684933490286, 0.618936451394876075, 0.607156221620300030, - 0.595288584291502887, 0.583327712748769489, 0.571267316532588332, 0.559100585511540626, - 0.546820125163310577, 0.534417881237165604, 0.521885051592135052, 0.509211982443654398, - 0.496388045518671162, 0.483401491653461857, 0.470239275082169006, 0.456886840931420235, - 0.443327866073552401, 0.429543940225410703, 0.415514169600356364, 0.401214678896277765, - 0.386617977941119573, 0.371692145329917234, 0.356399760258393816, 0.340696481064849122, - 0.324529117016909452, 0.307832954674932158, 0.290527955491230394, 0.272513185478464703, - 0.253658363385912022, 0.233790483059674731, 0.212671510630966620, 0.189958689622431842, - 0.165127622564187282, 0.137304980940012589, 0.104838507565818778, 0.063852163815001570, - 0.000000000000000000}; - return expX[i]; - } - - template - Real ZigguratGaussianRng::expF(int i) const { - static const ZigguratGaussianRng::ZigguratTable expF = { - 0.000167066692307963, 0.000454134353841497, 0.000967269282327174, 0.001536299780301573, - 0.002145967743718907, 0.002788798793574076, 0.003460264777836904, 0.004157295120833797, - 0.004877655983542396, 0.005619642207205489, 0.006381905937319183, 0.007163353183634991, - 0.007963077438017043, 0.008780314985808977, 0.009614413642502212, 0.010464810181029981, - 0.011331013597834600, 0.012212592426255378, 0.013109164931254991, 0.014020391403181943, - 0.014945968011691148, 0.015885621839973156, 0.016839106826039941, 0.017806200410911355, - 0.018786700744696024, 0.019780424338009740, 0.020787204072578114, 0.021806887504283581, - 0.022839335406385240, 0.023884420511558174, 0.024942026419731787, 0.026012046645134221, - 0.027094383780955803, 0.028188948763978646, 0.029295660224637411, 0.030414443910466622, - 0.031545232172893622, 0.032687963508959555, 0.033842582150874358, 0.035009037697397431, - 0.036187284781931443, 0.037377282772959382, 0.038578995503074871, 0.039792391023374139, - 0.041017441380414840, 0.042254122413316254, 0.043502413568888197, 0.044762297732943289, - 0.046033761076175184, 0.047316792913181561, 0.048611385573379504, 0.049917534282706379, - 0.051235237055126281, 0.052564494593071685, 0.053905310196046080, 0.055257689676697030, - 0.056621641283742870, 0.057997175631200659, 0.059384305633420280, 0.060783046445479660, - 0.062193415408541036, 0.063615431999807376, 0.065049117786753805, 0.066494496385339816, - 0.067951593421936643, 0.069420436498728783, 0.070901055162371843, 0.072393480875708752, - 0.073897746992364746, 0.075413888734058410, 0.076941943170480517, 0.078481949201606435, - 0.080033947542319905, 0.081597980709237419, 0.083174093009632397, 0.084762330532368146, - 0.086362741140756927, 0.087975374467270231, 0.089600281910032886, 0.091237516631040197, - 0.092887133556043569, 0.094549189376055873, 0.096223742550432825, 0.097910853311492213, - 0.099610583670637132, 0.101322997425953631, 0.103048160171257702, 0.104786139306570145, - 0.106537004050001632, 0.108300825451033755, 0.110077676405185357, 0.111867631670056283, - 0.113670767882744286, 0.115487163578633506, 0.117316899211555525, 0.119160057175327641, - 0.121016721826674792, 0.122886979509545108, 0.124770918580830933, 0.126668629437510671, - 0.128580204545228199, 0.130505738468330773, 0.132445327901387494, 0.134399071702213602, - 0.136367070926428829, 0.138349428863580176, 0.140346251074862399, 0.142357645432472146, - 0.144383722160634720, 0.146424593878344889, 0.148480375643866735, 0.150551185001039839, - 0.152637142027442801, 0.154738369384468027, 0.156854992369365148, 0.158987138969314129, - 0.161134939917591952, 0.163298528751901734, 0.165478041874935922, 0.167673618617250081, - 0.169885401302527550, 0.172113535315319977, 0.174358169171353411, 0.176619454590494829, - 0.178897546572478278, 0.181192603475496261, 0.183504787097767436, 0.185834262762197083, - 0.188181199404254262, 0.190545769663195363, 0.192928149976771296, 0.195328520679563189, - 0.197747066105098818, 0.200183974691911210, 0.202639439093708962, 0.205113656293837654, - 0.207606827724221982, 0.210119159388988230, 0.212650861992978224, 0.215202151075378628, - 0.217773247148700472, 0.220364375843359439, 0.222975768058120111, 0.225607660116683956, - 0.228260293930716618, 0.230933917169627356, 0.233628783437433291, 0.236345152457059560, - 0.239083290262449094, 0.241843469398877131, 0.244625969131892024, 0.247431075665327543, - 0.250259082368862240, 0.253110290015629402, 0.255985007030415324, 0.258883549749016173, - 0.261806242689362922, 0.264753418835062149, 0.267725419932044739, 0.270722596799059967, - 0.273745309652802915, 0.276793928448517301, 0.279868833236972869, 0.282970414538780746, - 0.286099073737076826, 0.289255223489677693, 0.292439288161892630, 0.295651704281261252, - 0.298892921015581847, 0.302163400675693528, 0.305463619244590256, 0.308794066934560185, - 0.312155248774179606, 0.315547685227128949, 0.318971912844957239, 0.322428484956089223, - 0.325917972393556354, 0.329440964264136438, 0.332998068761809096, 0.336589914028677717, - 0.340217149066780189, 0.343880444704502575, 0.347580494621637148, 0.351318016437483449, - 0.355093752866787626, 0.358908472948750001, 0.362762973354817997, 0.366658079781514379, - 0.370594648435146223, 0.374573567615902381, 0.378595759409581067, 0.382662181496010056, - 0.386773829084137932, 0.390931736984797384, 0.395136981833290435, 0.399390684475231350, - 0.403694012530530555, 0.408048183152032673, 0.412454465997161457, 0.416914186433003209, - 0.421428728997616908, 0.425999541143034677, 0.430628137288459167, 0.435316103215636907, - 0.440065100842354173, 0.444876873414548846, 0.449753251162755330, 0.454696157474615836, - 0.459707615642138023, 0.464789756250426511, 0.469944825283960310, 0.475175193037377708, - 0.480483363930454543, 0.485871987341885248, 0.491343869594032867, 0.496901987241549881, - 0.502549501841348056, 0.508289776410643213, 0.514126393814748894, 0.520063177368233931, - 0.526104213983620062, 0.532253880263043655, 0.538516872002862246, 0.544898237672440056, - 0.551403416540641733, 0.558038282262587892, 0.564809192912400615, 0.571723048664826150, - 0.578787358602845359, 0.586010318477268366, 0.593400901691733762, 0.600968966365232560, - 0.608725382079622346, 0.616682180915207878, 0.624852738703666200, 0.633251994214366398, - 0.641896716427266423, 0.650805833414571433, 0.660000841079000145, 0.669506316731925177, - 0.679350572264765806, 0.689566496117078431, 0.700192655082788606, 0.711274760805076456, - 0.722867659593572465, 0.735038092431424039, 0.747868621985195658, 0.761463388849896838, - 0.775956852040116218, 0.791527636972496285, 0.808421651523009044, 0.826993296643051101, - 0.847785500623990496, 0.871704332381204705, 0.900469929925747703, 0.938143680862176477, - 1.000000000000000000}; - return expF[i]; - } - } #endif From 1cc5f9db4f657d63af38e28e723b131d09c9e81c Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Tue, 7 May 2024 18:19:27 +0200 Subject: [PATCH 10/19] Calculating mean, variance, skewness and kurtosis via boost::accumulators --- ql/math/randomnumbers/zigguratgaussianrng.hpp | 6 +-- test-suite/zigguratgaussian.cpp | 51 +++++++++++++------ 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/ql/math/randomnumbers/zigguratgaussianrng.hpp b/ql/math/randomnumbers/zigguratgaussianrng.hpp index a8aa6eb9df3..c59b85868c1 100644 --- a/ql/math/randomnumbers/zigguratgaussianrng.hpp +++ b/ql/math/randomnumbers/zigguratgaussianrng.hpp @@ -52,8 +52,6 @@ namespace QuantLib { \endcode Currently, Xoshiro256StarStarUniformRng is the only RNG supporting this. */ - class ZigguratGaussianRngUtils; - template class ZigguratGaussianRng { public: @@ -100,11 +98,11 @@ namespace QuantLib { // subtracting `3.0 - EPSILON`, which is not representable. // It is possible with an extra step, but an open range does not // seem necessary for the ziggurat algorithm anyway. - auto u = (Real(randomU64 >> 11) + 0.5) * (2.0 / Real(1ULL << 53)) - 1.0; + auto u = 2.0 * (Real(randomU64 >> 11) + 0.5) * (1.0 / Real(1ULL << 53)) - 1.0; auto x = u * normX(i); - if (std::abs(x) < normX(i + 1)) { + if (std::abs(u) < normX(i + 1)) { return x; } if (i == 0) { diff --git a/test-suite/zigguratgaussian.cpp b/test-suite/zigguratgaussian.cpp index c70fe409ded..70d60cafb5a 100644 --- a/test-suite/zigguratgaussian.cpp +++ b/test-suite/zigguratgaussian.cpp @@ -20,6 +20,12 @@ #include "toplevelfixture.hpp" #include #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -33,30 +39,43 @@ BOOST_AUTO_TEST_SUITE(ZigguratGaussianTests) BOOST_AUTO_TEST_CASE(testMeanAndStdDevOfNextReal) { BOOST_TEST_MESSAGE("Testing ZigguratGaussianRng::nextReal() for " "mean=0.0 and stddev=1.0..."); + using namespace boost::accumulators; - auto uniformRandom = Xoshiro256StarStarUniformRng(1); + auto uniformRandom = Xoshiro256StarStarUniformRng(); auto random = ZigguratGaussianRng(uniformRandom); const auto iterations = 10'000'000; - auto randoms = std::vector(); - randoms.reserve(iterations); + + accumulator_set> + randoms; + for (auto j = 0; j < iterations; ++j) { - auto next = random.nextReal(); - randoms.push_back(next); + Real next = random.next().value; + randoms(next); } - Real mean = std::accumulate(randoms.begin(), randoms.end(), Real(0.0)) / randoms.size(); - Real meanError = std::fabs(0.0 - mean); - if (meanError > 0.005) { + + Real mean = boost::accumulators::mean(randoms); + Real variance = boost::accumulators::variance(randoms); + Real skewness = boost::accumulators::skewness(randoms); + Real kurtosis = boost::accumulators::kurtosis(randoms); + + BOOST_TEST_MESSAGE("Mean: " << mean); + BOOST_TEST_MESSAGE("Variance: " << variance); + BOOST_TEST_MESSAGE("Skewness: " << skewness); + BOOST_TEST_MESSAGE("Kurtosis: " << kurtosis); + + if (std::fabs(mean) > 0.005) { BOOST_ERROR("Mean " << mean << " for seed 1 is not close to 0."); } - std::vector diff(randoms.size()); - std::transform(randoms.begin(), randoms.end(), diff.begin(), - [mean](Real x) -> Real { return x - mean; }); - Real stdDev = - std::inner_product(diff.begin(), diff.end(), diff.begin(), Real(0.0)) / randoms.size(); - Real stdDevError = std::fabs(1.0 - stdDev); - if (stdDevError > 0.00005) { - BOOST_ERROR("Standard deviation " << stdDev << " for seed 1 is not close to 1."); + if (std::fabs(1.0 - variance) > 0.005) { + BOOST_ERROR("Variance " << variance << " for seed 1 is not close to 1."); + } + if (std::fabs(skewness) > 0.005) { + BOOST_ERROR("Skewness " << skewness << " for seed 1 is not close to 0."); + } + if (std::fabs(kurtosis) > 0.05) { + BOOST_ERROR("Kurtosis " << kurtosis << " for seed 1 is not close to 0."); } } From 7976d3493c48797255b5516d4ac65b0c8f732b08 Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Tue, 28 May 2024 13:58:02 +0200 Subject: [PATCH 11/19] Fixed bug std::fabs(u) < normX(i + 1) to std::fabs(x) < normX(i + 1) and added some comments --- ql/math/randomnumbers/zigguratgaussianrng.hpp | 28 +++++++-------- test-suite/zigguratgaussian.cpp | 35 ++++++------------- 2 files changed, 23 insertions(+), 40 deletions(-) diff --git a/ql/math/randomnumbers/zigguratgaussianrng.hpp b/ql/math/randomnumbers/zigguratgaussianrng.hpp index c59b85868c1..cfd547420eb 100644 --- a/ql/math/randomnumbers/zigguratgaussianrng.hpp +++ b/ql/math/randomnumbers/zigguratgaussianrng.hpp @@ -85,27 +85,23 @@ namespace QuantLib { template inline Real ZigguratGaussianRng::nextReal() const { while (true) { - // As an optimisation we re-implement the conversion to a f64. + // As an optimisation we re-implement the conversion + // to a double in the interval (-1,1). // From the remaining 12 most significant bits we use 8 to construct `i`. + // // This saves us generating a whole extra random number, while the added - // precision of using 64 bits for f64 does not buy us much. + // precision of using 64 bits for double does not buy us much. std::uint64_t randomU64 = uint64Generator_.nextInt64(); - - auto i = (int)(randomU64 & 0xff); - - // Convert to a value in the range [2,4) and subtract to get [-1,1) - // We can't convert to an open range directly, that would require - // subtracting `3.0 - EPSILON`, which is not representable. - // It is possible with an extra step, but an open range does not - // seem necessary for the ziggurat algorithm anyway. auto u = 2.0 * (Real(randomU64 >> 11) + 0.5) * (1.0 / Real(1ULL << 53)) - 1.0; + auto i = (int)(randomU64 & 0xff); auto x = u * normX(i); - if (std::abs(u) < normX(i + 1)) { + if (std::fabs(x) < normX(i + 1)) { return x; } if (i == 0) { + // compute a random number in the tail by hand return zeroCase(u); } if (normF(i + 1) + (normF(i) - normF(i + 1) * uint64Generator_.nextReal()) < pdf(x)) { @@ -114,11 +110,6 @@ namespace QuantLib { } } - template - inline Real ZigguratGaussianRng::pdf(Real x) const { - return std::exp(-x * x / 2.0); - } - template inline Real ZigguratGaussianRng::zeroCase(Real u) const { // compute a random number in the tail by hand @@ -131,6 +122,11 @@ namespace QuantLib { return (u < 0.0) ? x - normR() : normR() - x; } + template + inline Real ZigguratGaussianRng::pdf(Real x) const { + return std::exp(-x * x / 2.0); + } + template inline Real ZigguratGaussianRng::normR() const { return 3.654152885361008796; diff --git a/test-suite/zigguratgaussian.cpp b/test-suite/zigguratgaussian.cpp index 70d60cafb5a..ad794710e49 100644 --- a/test-suite/zigguratgaussian.cpp +++ b/test-suite/zigguratgaussian.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -38,10 +37,11 @@ BOOST_AUTO_TEST_SUITE(ZigguratGaussianTests) BOOST_AUTO_TEST_CASE(testMeanAndStdDevOfNextReal) { BOOST_TEST_MESSAGE("Testing ZigguratGaussianRng::nextReal() for " - "mean=0.0 and stddev=1.0..."); + "mean, variance, skewness and kurtosis..."); using namespace boost::accumulators; - auto uniformRandom = Xoshiro256StarStarUniformRng(); + auto seed = 42UL; + auto uniformRandom = Xoshiro256StarStarUniformRng(seed); auto random = ZigguratGaussianRng(uniformRandom); const auto iterations = 10'000'000; @@ -60,33 +60,20 @@ BOOST_AUTO_TEST_CASE(testMeanAndStdDevOfNextReal) { Real skewness = boost::accumulators::skewness(randoms); Real kurtosis = boost::accumulators::kurtosis(randoms); - BOOST_TEST_MESSAGE("Mean: " << mean); - BOOST_TEST_MESSAGE("Variance: " << variance); - BOOST_TEST_MESSAGE("Skewness: " << skewness); - BOOST_TEST_MESSAGE("Kurtosis: " << kurtosis); - - if (std::fabs(mean) > 0.005) { - BOOST_ERROR("Mean " << mean << " for seed 1 is not close to 0."); + if (std::abs(mean) > 0.001) { + BOOST_ERROR("Mean " << mean << " for seed " << seed << " is not close to 0."); } - if (std::fabs(1.0 - variance) > 0.005) { - BOOST_ERROR("Variance " << variance << " for seed 1 is not close to 1."); + if (std::abs(1.0 - variance) > 0.005) { + BOOST_ERROR("Variance " << variance << " for seed " << seed << " is not close to 1."); } - if (std::fabs(skewness) > 0.005) { - BOOST_ERROR("Skewness " << skewness << " for seed 1 is not close to 0."); + if (std::abs(skewness) > 0.001) { + BOOST_ERROR("Skewness " << skewness << " for seed " << seed << " is not close to 0."); } - if (std::fabs(kurtosis) > 0.05) { - BOOST_ERROR("Kurtosis " << kurtosis << " for seed 1 is not close to 0."); + if (std::abs(kurtosis) > 0.03) { + BOOST_ERROR("Kurtosis " << kurtosis << " for seed " << seed << " is not close to 0."); } } -BOOST_AUTO_TEST_CASE(testBitsShifting) { - std::uint64_t uint64 = 0xffffffffffffffff - 0xffffffffffffff - 1 + 25; - BOOST_TEST_MESSAGE("" << std::bitset<64>(uint64) << " : " << uint64); - BOOST_TEST_MESSAGE("" << std::bitset<64>(uint64 >> 8) << " : " << (uint64 >> 8)); - BOOST_TEST_MESSAGE("" << std::bitset<64>(uint64 & 0xff) << " : " << (uint64 & 0xff)); - BOOST_TEST_MESSAGE("" << std::bitset<64>(uint64 & 0xff) << " : " << (int)(uint64 & 0xff)); -} - BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END() From a15b6d45418e27cb487c442c478a5b4766a50933 Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Tue, 28 May 2024 14:03:11 +0200 Subject: [PATCH 12/19] Fixed formatting in CMakeLists.txt --- ql/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ql/CMakeLists.txt b/ql/CMakeLists.txt index 6af1f281078..ba8e5d6e284 100644 --- a/ql/CMakeLists.txt +++ b/ql/CMakeLists.txt @@ -427,7 +427,7 @@ set(QL_SOURCES math/randomnumbers/sobolrsg.cpp math/randomnumbers/stochasticcollocationinvcdf.cpp math/randomnumbers/xoshiro256starstaruniformrng.cpp - math/richardsonextrapolation.cpp + math/richardsonextrapolation.cpp math/rounding.cpp math/sampledcurve.cpp math/statistics/discrepancystatistics.cpp From c9ffd858fc9f1bf734624c0c65f9de62ec17c9ef Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Tue, 28 May 2024 14:13:32 +0200 Subject: [PATCH 13/19] Re-enable all workflows --- .github/workflows/cmake.yml | 98 +++++++++++ .github/workflows/codeql-analysis.yml | 52 ++++++ .github/workflows/copyrights.yml | 21 +++ .github/workflows/coveralls.yml | 41 +++++ .github/workflows/devenv-images.yml | 42 +++++ .github/workflows/doxygen.yml | 28 +++ .github/workflows/filelists.yml | 19 ++ .github/workflows/generated-headers.yml | 32 ++++ .github/workflows/headers.yml | 25 +++ .github/workflows/linux-full-tests.yml | 224 ++++++++++++++++++++++++ .github/workflows/linux-nondefault.yml | 178 +++++++++++++++++++ .github/workflows/linux.yml | 169 ++++++++++++++++++ .github/workflows/macos-nondefault.yml | 38 ++++ .github/workflows/macos.yml | 38 ++++ .github/workflows/misspell.yml | 19 ++ .github/workflows/msvc-all-configs.yml | 68 +++++++ .github/workflows/msvc-analysis.yml | 53 ++++++ .github/workflows/msvc-nondefault.yml | 66 +++++++ .github/workflows/msvc.yml | 61 +++++++ .github/workflows/sanitizer.yml | 44 +++++ .github/workflows/stale.yml | 22 +++ .github/workflows/test-times.yml | 42 +++++ .github/workflows/tidy.yml | 32 ++++ 23 files changed, 1412 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/copyrights.yml create mode 100644 .github/workflows/coveralls.yml create mode 100644 .github/workflows/devenv-images.yml create mode 100644 .github/workflows/doxygen.yml create mode 100644 .github/workflows/filelists.yml create mode 100644 .github/workflows/generated-headers.yml create mode 100644 .github/workflows/headers.yml create mode 100644 .github/workflows/linux-full-tests.yml create mode 100644 .github/workflows/linux-nondefault.yml create mode 100644 .github/workflows/linux.yml create mode 100644 .github/workflows/macos-nondefault.yml create mode 100644 .github/workflows/macos.yml create mode 100644 .github/workflows/misspell.yml create mode 100644 .github/workflows/msvc-all-configs.yml create mode 100644 .github/workflows/msvc-analysis.yml create mode 100644 .github/workflows/msvc-nondefault.yml create mode 100644 .github/workflows/msvc.yml create mode 100644 .github/workflows/sanitizer.yml create mode 100644 .github/workflows/stale.yml create mode 100644 .github/workflows/test-times.yml create mode 100644 .github/workflows/tidy.yml diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 12b274121c4..03eb2ec578c 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -32,6 +32,32 @@ jobs: - name: Run benchmark run: | quantlib-benchmark --size=1 + cmake-linux-with-options: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup + run: | + sudo rm /etc/apt/sources.list.d/microsoft-prod.list + sudo apt update + sudo apt install -y libboost-all-dev ccache ninja-build + - name: Cache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: cmake-linux-ci-opts-${{ github.ref }} + restore-keys: | + cmake-linux-ci-opts-${{ github.ref }} + cmake-linux-ci-opts-refs/heads/master + cmake-linux-ci-opts- + - name: Compile + run: | + cmake --preset linux-ci-build-with-nonstandard-options -L + cd build/linux-ci-build-with-nonstandard-options + cmake --build . --verbose + sudo cmake --build . --target install + - name: Test + run: | + quantlib-test-suite --log_level=message cmake-win: runs-on: windows-2022 steps: @@ -69,6 +95,78 @@ jobs: - name: Test run: | & "C:\Program Files (x86)\QuantLib\bin\quantlib-test-suite" --log_level=message + cmake-win-dynamic-runtime: + runs-on: windows-2022 + steps: + - uses: actions/checkout@v4 + - name: Cache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: cmake-windows-ci-dyn-build-${{ github.ref }} + restore-keys: | + cmake-windows-ci-dyn-build-${{ github.ref }} + cmake-windows-ci-dyn-build-refs/heads/master + cmake-windows-ci-dyn-build- + variant: sccache + - name: Setup + run: | + $Url = "https://boostorg.jfrog.io/artifactory/main/release/1.85.0/binaries/boost_1_85_0-msvc-14.3-64.exe" + (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\boost.exe") + Start-Process -Wait -FilePath "$RUNNER_TEMP\boost.exe" "/SILENT","/SP-","/SUPPRESSMSGBOXES","/DIR=C:\local\boost" + $Url = "https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-win.zip" + (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\ninja-win.zip") + Expand-Archive -Path "$RUNNER_TEMP\ninja-win.zip" -DestinationPath C:\local\ninja + Add-Content $env:GITHUB_PATH "C:\local\ninja" + - name: Compile + env: + BOOST_ROOT: C:\local\boost + shell: cmd + run: | + mkdir build + cd build + call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Vc\Auxiliary\Build\vcvarsall.bat" amd64 -vcvars_ver=14.3 || exit 1 + cmake .. -GNinja -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL -DCMAKE_BUILD_TYPE=Release -DQL_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -L + cmake --build . --verbose + cmake --install . + dir ql\*.lib + - name: Test + run: | + & "C:\Program Files (x86)\QuantLib\bin\quantlib-test-suite" --log_level=message + cmake-win-with-options: + runs-on: windows-2022 + steps: + - uses: actions/checkout@v4 + - name: Cache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: cmake-windows-ci-opts-${{ github.ref }} + restore-keys: | + cmake-windows-ci-opts-${{ github.ref }} + cmake-windows-ci-opts-refs/heads/master + cmake-windows-ci-opts- + variant: sccache + - name: Setup + run: | + $Url = "https://boostorg.jfrog.io/artifactory/main/release/1.85.0/binaries/boost_1_85_0-msvc-14.3-64.exe" + (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\boost.exe") + Start-Process -Wait -FilePath "$RUNNER_TEMP\boost.exe" "/SILENT","/SP-","/SUPPRESSMSGBOXES","/DIR=C:\local\boost" + $Url = "https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-win.zip" + (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\ninja-win.zip") + Expand-Archive -Path "$RUNNER_TEMP\ninja-win.zip" -DestinationPath C:\local\ninja + Add-Content $env:GITHUB_PATH "C:\local\ninja" + - name: Compile + env: + BOOST_ROOT: C:\local\boost + shell: cmd + run: | + call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Vc\Auxiliary\Build\vcvarsall.bat" amd64 -vcvars_ver=14.3 || exit 1 + cmake --preset windows-ci-build-with-nonstandard-options -L + cd build/windows-ci-build-with-nonstandard-options + cmake --build . --verbose + cmake --build . --target install + - name: Test + run: | + & "C:\Program Files (x86)\QuantLib\bin\quantlib-test-suite" --log_level=message cmake-macos: runs-on: macos-latest steps: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000000..f8abad984b5 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,52 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +name: "CodeQL" + +on: + schedule: + - cron: '0 0 * * 0' + workflow_dispatch: + +jobs: + analyze: + name: CodeQL analysis + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: cpp + + # Set up build environment + - name: Setup + run: | + sudo rm /etc/apt/sources.list.d/microsoft-prod.list + sudo apt update + sudo apt install -y libboost-dev + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v3 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/copyrights.yml b/.github/workflows/copyrights.yml new file mode 100644 index 00000000000..776cf32a581 --- /dev/null +++ b/.github/workflows/copyrights.yml @@ -0,0 +1,21 @@ +name: Update copyright list +on: + push: + branches: + - '**' +jobs: + copyrights: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check + run: | + ./tools/check_copyrights.sh + - uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: update-copyright-list-${{ github.ref_name }} + delete-branch: true + commit-message: 'Update copyright list in license' + title: 'Update copyright list in license' + author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> diff --git a/.github/workflows/coveralls.yml b/.github/workflows/coveralls.yml new file mode 100644 index 00000000000..0775a908323 --- /dev/null +++ b/.github/workflows/coveralls.yml @@ -0,0 +1,41 @@ +name: Coverage report +on: + push: + branches: + - master + pull_request: +jobs: + coverage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup + run: | + sudo rm /etc/apt/sources.list.d/microsoft-prod.list + sudo apt update + sudo apt install -y lcov libboost-dev + - name: Compile + run: | + ./autogen.sh + ./configure --disable-shared CXXFLAGS='-O1 -fprofile-arcs -ftest-coverage' LDFLAGS='-lgcov' + make -j 4 + - name: Capture baseline + run: | + mkdir -p coverage tmp + lcov --no-external --capture --initial --directory . --output-file ./tmp/lcov_base.info + - name: Run tests + run: | + ./test-suite/quantlib-test-suite --log_level=message + - name: Run examples + run: | + make -C Examples check-examples + - name: Capture coverage + run: | + lcov --no-external --capture --directory . --output-file ./tmp/lcov_run.info + lcov --add-tracefile ./tmp/lcov_base.info --add-tracefile ./tmp/lcov_run.info --output-file ./tmp/lcov_total.info + lcov --remove ./tmp/lcov_total.info "$PWD/Examples/*" "$PWD/test-suite/*" --output-file ./coverage/lcov.info + - name: Upload coverage to Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ./coverage/lcov.info diff --git a/.github/workflows/devenv-images.yml b/.github/workflows/devenv-images.yml new file mode 100644 index 00000000000..d28759a30f9 --- /dev/null +++ b/.github/workflows/devenv-images.yml @@ -0,0 +1,42 @@ +name: Build quantlib-devenv Docker images +on: + workflow_dispatch: + inputs: + boostVersion: + description: 'Boost version' + required: true +env: + ROLLING: mantic +jobs: + docker-images: + runs-on: ubuntu-latest + strategy: + matrix: + tag: [lunar, mantic, noble] + steps: + - uses: actions/checkout@v4 + - name: Build CI images + working-directory: dockerfiles + run: | + docker build -f ci.Dockerfile \ + --build-arg tag=${{ matrix.tag }} \ + --build-arg boost_version=${{ github.event.inputs.boostVersion }} \ + --build-arg boost_dir=boost_$(echo "${{ github.event.inputs.boostVersion }}" | sed "s/\./_/g") \ + -t ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }} . + docker tag ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }} ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }}-${{ github.event.inputs.boostVersion }} + if test "${{ matrix.tag }}" = "$ROLLING" ; then + docker tag ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }} ghcr.io/lballabio/quantlib-devenv:rolling + fi + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GHCR_PAT }} + - name: Push Docker images + run: | + docker push ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }}-${{ github.event.inputs.boostVersion }} + docker push ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }} + if test "${{ matrix.tag }}" = "$ROLLING" ; then + docker push ghcr.io/lballabio/quantlib-devenv:rolling + fi diff --git a/.github/workflows/doxygen.yml b/.github/workflows/doxygen.yml new file mode 100644 index 00000000000..84a98c08c66 --- /dev/null +++ b/.github/workflows/doxygen.yml @@ -0,0 +1,28 @@ +name: Check doc generation +on: [push, pull_request] +jobs: + docs: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Setup + env: + HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1 + run: | + brew install automake autoconf libtool boost doxygen graphviz + ./autogen.sh + ./configure --with-boost-include=$(brew --prefix)/include + - name: Doxygen version + run: | + doxygen --version + - name: Check + run: | + make docs + + header-docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check + run: | + ./tools/check_all_header_docs.sh diff --git a/.github/workflows/filelists.yml b/.github/workflows/filelists.yml new file mode 100644 index 00000000000..501ef2b0f77 --- /dev/null +++ b/.github/workflows/filelists.yml @@ -0,0 +1,19 @@ +name: Check CMake file list and VC++ projects +on: [push, pull_request] +jobs: + filelists: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup + run: | + sudo rm /etc/apt/sources.list.d/microsoft-prod.list + sudo apt update + sudo apt install -y libboost-dev + - name: Configure + run: | + ./autogen.sh + ./configure + - name: Check + run: | + ./tools/check_filelists.sh diff --git a/.github/workflows/generated-headers.yml b/.github/workflows/generated-headers.yml new file mode 100644 index 00000000000..b79cf9e5b6d --- /dev/null +++ b/.github/workflows/generated-headers.yml @@ -0,0 +1,32 @@ +name: Update generated headers +on: + push: + branches: + - '**' +jobs: + filelists: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup + run: | + sudo rm /etc/apt/sources.list.d/microsoft-prod.list + sudo apt update + sudo apt install -y libboost-dev + - name: Configure + run: | + ./autogen.sh + ./configure + - name: Update headers + run: | + find ql -name *.am | xargs touch + make dist + rm QuantLib-*.tar.gz + - uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: update-generated-headers-${{ github.ref_name }} + delete-branch: true + commit-message: 'Update generated headers' + title: 'Update generated headers' + author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> diff --git a/.github/workflows/headers.yml b/.github/workflows/headers.yml new file mode 100644 index 00000000000..a6eb0a7ad35 --- /dev/null +++ b/.github/workflows/headers.yml @@ -0,0 +1,25 @@ +name: Compile single headers +on: [push, pull_request] +jobs: + headers: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup + run: | + sudo rm /etc/apt/sources.list.d/microsoft-prod.list + sudo apt update + sudo apt install -y libboost-dev ccache + - name: Cache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: single-headers-${{ github.ref }} + restore-keys: | + single-headers-${{ github.ref }} + single-headers-refs/heads/master + single-headers- + - name: Check + env: + CXX: ccache g++ + run: | + ./tools/check_all_headers.sh diff --git a/.github/workflows/linux-full-tests.yml b/.github/workflows/linux-full-tests.yml new file mode 100644 index 00000000000..7561d4a451b --- /dev/null +++ b/.github/workflows/linux-full-tests.yml @@ -0,0 +1,224 @@ +name: Linux build with full test matrix +on: + schedule: + - cron: '0 0 * * 0' + workflow_dispatch: +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - name: "gcc 5.4 (Boost 1.66)" + shortname: gcc5 + tag: xenial + cc: gcc + cxx: g++ + - name: "gcc 6.3 (Boost 1.66)" + shortname: gcc6 + tag: zesty + cc: gcc + cxx: g++ + - name: "gcc 7.4 (Boost 1.72)" + shortname: gcc7 + tag: bionic + cc: gcc + cxx: g++ + - name: "gcc 8.3 (Boost 1.72)" + shortname: gcc8 + tag: cosmic + cc: gcc + cxx: g++ + - name: "gcc 9.3 (Boost 1.78)" + shortname: gcc9 + tag: focal + cc: gcc + cxx: g++ + - name: "gcc 10.3 (Boost 1.79)" + shortname: gcc10 + tag: hirsute + cc: gcc + cxx: g++ + - name: "gcc 11.4 (Boost 1.82)" + shortname: gcc11 + tag: jammy + cc: gcc + cxx: g++ + - name: "gcc 12.x" + shortname: gcc12 + tag: lunar + cc: gcc + cxx: g++ + - name: "gcc 13.x" + shortname: gcc13 + tag: mantic + cc: gcc + cxx: g++ + - name: "Clang 6 (Boost 1.72)" + shortname: clang6 + tag: bionic + cc: clang + cxx: clang++ + - name: "Clang 7 (Boost 1.72)" + shortname: clang7 + tag: cosmic + cc: clang + cxx: clang++ + - name: "Clang 8 (Boost 1.72)" + shortname: clang8 + tag: disco + cc: clang + cxx: clang++ + - name: "Clang 9 (Boost 1.74)" + shortname: clang9 + tag: eoan + cc: clang + cxx: clang++ + - name: "Clang 10 (Boost 1.78)" + shortname: clang10 + tag: focal + cc: clang + cxx: clang++ + - name: "Clang 11 (Boost 1.78)" + shortname: clang11 + tag: groovy + cc: clang + cxx: clang++ + - name: "Clang 12 (Boost 1.79)" + shortname: clang12 + tag: hirsute + cc: clang + cxx: clang++ + - name: "Clang 13 (Boost 1.79)" + shortname: clang13 + tag: impish + cc: clang + cxx: clang++ + - name: "Clang 14 (Boost 1.82)" + shortname: clang14 + tag: jammy + cc: clang + cxx: clang++ + - name: "Clang 15" + shortname: clang15 + tag: lunar + cc: clang + cxx: clang++ + - name: "Clang 16" + shortname: clang16 + tag: mantic + cc: clang + cxx: clang++ + - name: "Clang 17 (Boost 1.84)" + shortname: clang17 + tag: clang-17 + cc: clang + cxx: clang++ + - name: "Clang 18" + shortname: clang18 + tag: noble + cc: clang + cxx: clang++ + cxxflags: -Wno-deprecated-declarations + - name: "C++14 mode" + shortname: c++14 + tag: rolling + cc: gcc + cxx: g++ + cxxflags: "-std=c++14" + - name: "C++17 mode" + shortname: c++17 + tag: rolling + cc: gcc + cxx: g++ + cxxflags: "-std=c++17" + - name: "C++20 mode" + shortname: c++20 + tag: rolling + cc: gcc + cxx: g++ + cxxflags: "-std=c++20" + - name: "Unity build enabled" + shortname: unity + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-unity-build + - name: "Intraday calculations enabled" + shortname: intraday + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-intraday + - name: "Throwing in cycles enabled" + shortname: cycles + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-throwing-in-cycles --disable-faster-lazy-objects + - name: "Indexed coupons enabled" + shortname: indexed + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-indexed-coupons + - name: "Standard Library classes enabled/disabled" + shortname: stdclasses + tag: rolling + cc: gcc + cxx: g++ + configureflags: --disable-std-function --disable-std-tuple --enable-std-pointers --enable-std-any --enable-std-optional + - name: "Thread-safe observer enabled" + shortname: threadsafe + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-thread-safe-observer-pattern + - name: "Sessions enabled" + shortname: sessions + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-sessions + - name: "OpenMP enabled" + shortname: openmp + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-openmp + - name: "Parallel unit-test runner" + shortname: paralleltests + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-parallel-unit-test-runner + - name: "Null as function template" + shortname: nullfunctions + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-null-as-functions + container: ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }} + steps: + - uses: actions/checkout@v3 + - name: Compiler version + run: | + ${{ matrix.cc }} --version + - name: Build + run: | + ./autogen.sh + ./configure --disable-static ${{ matrix.configureflags }} CC="${{ matrix.cc }}" CXX="${{ matrix.cxx }}" CXXFLAGS="-O2 -g0 -Wall -Wno-unknown-pragmas -Werror ${{ matrix.cxxflags }}" + make -j 4 + - name: Run tests + run: | + ./test-suite/quantlib-test-suite --log_level=message + - name: Run examples + run: | + make check-examples + - name: Check global header + run: | + echo "#include " > test1.cpp && echo "int main() { return 0; }" >> test1.cpp + echo "#include " > test2.cpp + make install + ${{ matrix.cxx }} -O2 -g0 -Wall -Wno-unknown-pragmas -Werror ${{ matrix.cxxflags }} `quantlib-config --cflags` test1.cpp test2.cpp `quantlib-config --libs` diff --git a/.github/workflows/linux-nondefault.yml b/.github/workflows/linux-nondefault.yml new file mode 100644 index 00000000000..f55c60aabd6 --- /dev/null +++ b/.github/workflows/linux-nondefault.yml @@ -0,0 +1,178 @@ +name: Linux build with non-default configuration +on: + schedule: + - cron: '0 0 * * 0' + workflow_dispatch: +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - name: "gcc 5.4 (Boost 1.66)" + shortname: gcc5 + tag: xenial + cc: gcc + cxx: g++ + - name: "gcc 6.3 (Boost 1.66)" + shortname: gcc6 + tag: zesty + cc: gcc + cxx: g++ + - name: "gcc 7.4 (Boost 1.72)" + shortname: gcc7 + tag: bionic + cc: gcc + cxx: g++ + - name: "gcc 8.3 (Boost 1.72)" + shortname: gcc8 + tag: cosmic + cc: gcc + cxx: g++ + - name: "gcc 9.3 (Boost 1.78)" + shortname: gcc9 + tag: focal + cc: gcc + cxx: g++ + - name: "gcc 10.3 (Boost 1.79)" + shortname: gcc10 + tag: hirsute + cc: gcc + cxx: g++ + - name: "gcc 11.4 (Boost 1.82)" + shortname: gcc11 + tag: jammy + cc: gcc + cxx: g++ + - name: "gcc 12.x" + shortname: gcc12 + tag: lunar + cc: gcc + cxx: g++ + - name: "gcc 13.x" + shortname: gcc13 + tag: mantic + cc: gcc + cxx: g++ + - name: "Clang 6 (Boost 1.72)" + shortname: clang6 + tag: bionic + cc: clang + cxx: clang++ + - name: "Clang 7 (Boost 1.72)" + shortname: clang7 + tag: cosmic + cc: clang + cxx: clang++ + - name: "Clang 8 (Boost 1.72)" + shortname: clang8 + tag: disco + cc: clang + cxx: clang++ + - name: "Clang 9 (Boost 1.74)" + shortname: clang9 + tag: eoan + cc: clang + cxx: clang++ + - name: "Clang 10 (Boost 1.78)" + shortname: clang10 + tag: focal + cc: clang + cxx: clang++ + - name: "Clang 11 (Boost 1.78)" + shortname: clang11 + tag: groovy + cc: clang + cxx: clang++ + - name: "Clang 12 (Boost 1.79)" + shortname: clang12 + tag: hirsute + cc: clang + cxx: clang++ + - name: "Clang 13 (Boost 1.79)" + shortname: clang13 + tag: impish + cc: clang + cxx: clang++ + - name: "Clang 14 (Boost 1.82)" + shortname: clang14 + tag: jammy + cc: clang + cxx: clang++ + - name: "Clang 15" + shortname: clang15 + tag: lunar + cc: clang + cxx: clang++ + - name: "Clang 16" + shortname: clang16 + tag: mantic + cc: clang + cxx: clang++ + - name: "Clang 18" + shortname: clang18 + tag: noble + cc: clang + cxx: clang++ + cxxflags: -Wno-deprecated-declarations + - name: "C++14 mode" + shortname: c++14 + tag: rolling + cc: gcc + cxx: g++ + cxxflags: "-std=c++14" + - name: "C++17 mode" + shortname: c++17 + tag: rolling + cc: gcc + cxx: g++ + cxxflags: "-std=c++17" + - name: "C++20 mode" + shortname: c++20 + tag: rolling + cc: gcc + cxx: g++ + cxxflags: "-std=c++20" + - name: "Unity build enabled" + shortname: unity + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-unity-build + - name: "Standard Library classes enabled/disabled" + shortname: stdclasses + tag: rolling + cc: gcc + cxx: g++ + cxxflags: "-std=c++17" + configureflags: --disable-std-function --disable-std-tuple --enable-std-pointers --enable-std-any --enable-std-optional + - name: "OpenMP enabled" + shortname: openmp + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-openmp + container: ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }} + steps: + - uses: actions/checkout@v3 + - name: Compiler version + run: | + ${{ matrix.cc }} --version + - name: Build + run: | + ./autogen.sh + ./configure --disable-static --enable-error-lines --enable-error-functions --enable-tracing --enable-indexed-coupons --enable-extra-safety-checks --enable-sessions --enable-thread-safe-observer-pattern --enable-intraday --disable-faster-lazy-objects --enable-throwing-in-cycles --enable-null-as-functions ${{ matrix.configureflags }} CC="${{ matrix.cc }}" CXX="${{ matrix.cxx }}" CXXFLAGS="-O2 -g0 -Wall -Wno-unknown-pragmas -Wno-array-bounds -Werror ${{ matrix.cxxflags }}" + make -j 4 + - name: Run tests + run: | + ./test-suite/quantlib-test-suite --log_level=message + - name: Run examples + run: | + make check-examples + - name: Check global header + run: | + echo "#include " > test1.cpp && echo "int main() { return 0; }" >> test1.cpp + echo "#include " > test2.cpp + make install + ${{ matrix.cxx }} -O2 -g0 -Wall -Wno-unknown-pragmas -Werror ${{ matrix.cxxflags }} `quantlib-config --cflags` test1.cpp test2.cpp `quantlib-config --libs` diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml new file mode 100644 index 00000000000..1dd8d41ba34 --- /dev/null +++ b/.github/workflows/linux.yml @@ -0,0 +1,169 @@ +name: Linux build +on: [push, pull_request] +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - name: "gcc 9.3 (Boost 1.78)" + shortname: gcc9 + tag: focal + cc: gcc + cxx: g++ + - name: "gcc 11.4 (Boost 1.82)" + shortname: gcc11 + tag: jammy + cc: gcc + cxx: g++ + - name: "gcc 13.x" + shortname: gcc13 + tag: mantic + cc: gcc + cxx: g++ + tests: true + - name: "Clang 10 (Boost 1.78)" + shortname: clang10 + tag: focal + cc: clang + cxx: clang++ + - name: "Clang 14 (Boost 1.82)" + shortname: clang14 + tag: jammy + cc: clang + cxx: clang++ + - name: "Clang 16" + shortname: clang16 + tag: mantic + cc: clang + cxx: clang++ + tests: true + - name: "Clang 18" + shortname: clang18 + tag: noble + cc: clang + cxx: clang++ + cxxflags: -Wno-deprecated-declarations + tests: true + - name: "C++14 mode" + shortname: c++14 + tag: rolling + cc: gcc + cxx: g++ + cxxflags: "-std=c++14" + - name: "C++17 mode" + shortname: c++17 + tag: rolling + cc: gcc + cxx: g++ + cxxflags: "-std=c++17" + - name: "C++20 mode" + shortname: c++20 + tag: rolling + cc: gcc + cxx: g++ + cxxflags: "-std=c++20" + - name: "Unity build enabled" + shortname: unity + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-unity-build + - name: "Intraday calculations enabled" + shortname: intraday + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-intraday + tests: true + - name: "Throwing in cycles enabled" + shortname: cycles + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-throwing-in-cycles --disable-faster-lazy-objects + tests: true + - name: "Indexed coupons enabled" + shortname: indexed + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-indexed-coupons + tests: true + - name: "Standard Library classes enabled/disabled" + shortname: stdclasses + tag: rolling + cc: gcc + cxx: g++ + configureflags: --disable-std-function --disable-std-tuple --enable-std-pointers --enable-std-any --enable-std-optional + tests: true + - name: "Thread-safe observer enabled" + shortname: threadsafe + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-thread-safe-observer-pattern + tests: true + - name: "Sessions enabled" + shortname: sessions + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-sessions + tests: true + - name: "OpenMP enabled" + shortname: openmp + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-openmp + tests: true + - name: "Parallel unit-test runner" + shortname: paralleltests + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-parallel-unit-test-runner + tests: true + - name: "Null as function template" + shortname: nullfunctions + tag: rolling + cc: gcc + cxx: g++ + configureflags: --enable-null-as-functions + tests: true + container: ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }} + steps: + - uses: actions/checkout@v4 + - name: Cache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: linux-ci-build-${{ matrix.shortname }}-${{ github.ref }} + restore-keys: | + linux-ci-build-${{ matrix.shortname }}-${{ github.ref }} + linux-ci-build-${{ matrix.shortname }}-refs/heads/master + linux-ci-build-${{ matrix.shortname }}- + - name: Compiler version + run: | + ${{ matrix.cc }} --version + - name: Build + run: | + ./autogen.sh + ./configure --disable-static ${{ matrix.configureflags }} CC="ccache ${{ matrix.cc }}" CXX="ccache ${{ matrix.cxx }}" CXXFLAGS="-O2 -g0 -Wall -Wno-unknown-pragmas -Werror ${{ matrix.cxxflags }}" + make -j 4 + - name: Run tests + if: ${{ matrix.tests }} + run: | + ./test-suite/quantlib-test-suite --log_level=message + - name: Run examples + if: ${{ matrix.tests }} + run: | + make check-examples + - name: Check global header + if: ${{ matrix.tests }} + run: | + echo "#include " > test1.cpp && echo "int main() { return 0; }" >> test1.cpp + echo "#include " > test2.cpp + make install + ${{ matrix.cxx }} -O2 -g0 -Wall -Wno-unknown-pragmas -Werror ${{ matrix.cxxflags }} `quantlib-config --cflags` test1.cpp test2.cpp `quantlib-config --libs` diff --git a/.github/workflows/macos-nondefault.yml b/.github/workflows/macos-nondefault.yml new file mode 100644 index 00000000000..b49093a499c --- /dev/null +++ b/.github/workflows/macos-nondefault.yml @@ -0,0 +1,38 @@ +name: Mac OS build with non-default configuration +on: + schedule: + - cron: '0 0 * * 0' + workflow_dispatch: +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-12, macos-13, macos-14] + classes: [boost, std] + include: + - classes: std + cxxflags: "-std=c++17" + configureflags: --disable-std-function --disable-std-tuple --enable-std-pointers --enable-std-optional --enable-std-any + steps: + - uses: actions/checkout@v4 + - name: Setup + env: + HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1 + run: | + brew install automake autoconf libtool boost + - name: Compiler version + run: | + clang --version + - name: Build + run: | + ./autogen.sh + ./configure --disable-shared --with-boost-include=`brew --prefix`/include --enable-error-lines --enable-error-functions --enable-tracing --enable-indexed-coupons --enable-extra-safety-checks --enable-sessions --enable-thread-safe-observer-pattern --enable-intraday --disable-faster-lazy-objects --enable-throwing-in-cycles --enable-null-as-functions ${{ matrix.configureflags }} CC="clang" CXX="clang++" CXXFLAGS="-O2 -g0 -Wall -Werror ${{ matrix.cxxflags }}" + make -j 3 + - name: Run tests + run: | + ./test-suite/quantlib-test-suite --log_level=message + - name: Run examples + run: | + make -C Examples check-examples diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml new file mode 100644 index 00000000000..fa61ac1d010 --- /dev/null +++ b/.github/workflows/macos.yml @@ -0,0 +1,38 @@ +name: Mac OS build +on: [push, pull_request] +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-12, macos-13, macos-14] + steps: + - uses: actions/checkout@v4 + - name: Setup + env: + HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1 + run: | + brew install automake autoconf libtool boost ccache + - name: Cache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: macos-ci-build-${{ matrix.os }}-${{ github.ref }} + restore-keys: | + macos-ci-build-${{ matrix.os }}-${{ github.ref }} + macos-ci-build-${{ matrix.os }}-refs/heads/master + macos-ci-build-${{ matrix.os }}- + - name: Compiler version + run: | + clang --version + - name: Build + run: | + ./autogen.sh + ./configure --disable-shared --with-boost-include=`brew --prefix`/include ${{ matrix.configureflags }} CC="ccache clang" CXX="ccache clang++" CXXFLAGS="-O2 -g0 -Wall -Werror ${{ matrix.cxxflags }}" + make -j 3 + - name: Run tests + run: | + ./test-suite/quantlib-test-suite --log_level=message + - name: Run examples + run: | + make -C Examples check-examples diff --git a/.github/workflows/misspell.yml b/.github/workflows/misspell.yml new file mode 100644 index 00000000000..75cee119178 --- /dev/null +++ b/.github/workflows/misspell.yml @@ -0,0 +1,19 @@ +name: Misspell fixer +on: + push: + branches: + - '**' +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: sobolevn/misspell-fixer-action@master + - uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: misspell-fixes-${{ github.ref_name }} + delete-branch: true + commit-message: 'Fixes by misspell-fixer' + title: 'Typos fixed by misspell-fixer' + author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> diff --git a/.github/workflows/msvc-all-configs.yml b/.github/workflows/msvc-all-configs.yml new file mode 100644 index 00000000000..9de0a6d0890 --- /dev/null +++ b/.github/workflows/msvc-all-configs.yml @@ -0,0 +1,68 @@ +name: Windows build with all configurations +on: + schedule: + - cron: '0 0 * * 0' + workflow_dispatch: +jobs: + msbuild: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + vsversion: [2019, 2022] + platform: [x64, Win32] + configuration: ['Release', 'Debug', 'Release (static runtime)', 'Debug (static runtime)'] + unity: [unity, singles] + include: + - vsversion: 2019 + os: windows-2019 + toolset: "14.2" + boost_version: 77 + - vsversion: 2022 + os: windows-2022 + toolset: "14.3" + boost_version: 85 + steps: + - uses: actions/checkout@v4 + - name: Setup MSVC++ environment + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + toolset: ${{ matrix.toolset }} + vsversion: ${{ matrix.vsversion }} + - name: Setup Boost + run: | + $Url = "https://boostorg.jfrog.io/artifactory/main/release/1.${{ matrix.boost_version }}.0/source/boost_1_${{ matrix.boost_version }}_0.zip" + (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\boost.zip") + Expand-Archive -Path "$RUNNER_TEMP\boost.zip" -DestinationPath C:\local + Rename-Item -Path "C:\local\boost_1_${{ matrix.boost_version }}_0" -NewName "boost" + - name: Setup local properties + shell: cmd + run: | + COPY .ci\VS${{ matrix.vsversion }}.props .\Build.props + - name: Setup unity build + if: ${{ matrix.unity == 'unity' }} + shell: cmd + run: | + COPY .ci\Unity.props .\Directory.Build.props + - name: Setup MSVC++ environment + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + toolset: ${{ matrix.toolset }} + vsversion: ${{ matrix.vsversion }} + - name: Build + run: | + msbuild ./QuantLib.sln /verbosity:normal /property:Configuration="${{ matrix.configuration }}" /property:Platform=${{ matrix.platform }} + - name: Test + if: ${{ contains(matrix.configuration, 'Release') }} + run: | + .\test-suite\bin\QuantLib-test-suite*.exe --log_level=message + - name: Run examples + if: ${{ contains(matrix.configuration, 'Release') }} + run: | + foreach ($file in Get-ChildItem -Path .\Examples\*.exe -Recurse) + { + & $file.FullName + if (!$?) { Exit $LASTEXITCODE } + } diff --git a/.github/workflows/msvc-analysis.yml b/.github/workflows/msvc-analysis.yml new file mode 100644 index 00000000000..5566e770051 --- /dev/null +++ b/.github/workflows/msvc-analysis.yml @@ -0,0 +1,53 @@ +name: Microsoft C++ Code Analysis + +on: + schedule: + - cron: '0 0 * * 0' + workflow_dispatch: + +env: + # Path to the CMake build directory. + build: '${{ github.workspace }}/build' + +jobs: + analyze: + name: Analyze + runs-on: windows-2022 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup + run: | + $Url = "https://boostorg.jfrog.io/artifactory/main/release/1.85.0/binaries/boost_1_85_0-msvc-14.3-64.exe" + (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\boost.exe") + Start-Process -Wait -FilePath "$RUNNER_TEMP\boost.exe" "/SILENT","/SP-","/SUPPRESSMSGBOXES","/DIR=C:\local\boost" + + - name: Configure CMake + env: + BOOST_ROOT: C:\local\boost + run: cmake -B ${{ env.build }} -DQL_USE_STD_CLASSES=ON + + - name: Run MSVC Code Analysis + uses: microsoft/msvc-code-analysis-action@v0.1.1 + # Provide a unique ID to access the sarif output path + id: run-analysis + env: + CAExcludePath: C:\local\boost + with: + cmakeBuildDirectory: ${{ env.build }} + buildConfiguration: Release + ruleset: '${{ github.workspace }}/.msvc-analysis.ruleset' + + - name: Upload SARIF to GitHub + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: ${{ steps.run-analysis.outputs.sarif }} + + - name: Upload SARIF as an Artifact + uses: actions/upload-artifact@v4 + with: + name: sarif-file + path: ${{ steps.run-analysis.outputs.sarif }} + diff --git a/.github/workflows/msvc-nondefault.yml b/.github/workflows/msvc-nondefault.yml new file mode 100644 index 00000000000..aa7af9d1c8d --- /dev/null +++ b/.github/workflows/msvc-nondefault.yml @@ -0,0 +1,66 @@ +name: Windows build with non-default configuration +on: + schedule: + - cron: '0 0 * * 0' + workflow_dispatch: +jobs: + msbuild: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + vsversion: [2019, 2022] + platform: [x64, Win32] + unity: [unity, singles] + include: + - vsversion: 2019 + os: windows-2019 + toolset: "14.2" + boost_version: 77 + - vsversion: 2022 + os: windows-2022 + toolset: "14.3" + boost_version: 85 + steps: + - uses: actions/checkout@v4 + - name: Setup MSVC++ environment + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + toolset: ${{ matrix.toolset }} + vsversion: ${{ matrix.vsversion }} + - name: Setup Boost + run: | + $Url = "https://boostorg.jfrog.io/artifactory/main/release/1.${{ matrix.boost_version }}.0/source/boost_1_${{ matrix.boost_version }}_0.zip" + (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\boost.zip") + Expand-Archive -Path "$RUNNER_TEMP\boost.zip" -DestinationPath C:\local + Rename-Item -Path "C:\local\boost_1_${{ matrix.boost_version }}_0" -NewName "boost" + - name: Setup local properties + shell: cmd + run: | + COPY .ci\VS${{ matrix.vsversion }}.alt.props .\Build.props + COPY .ci\userconfig${{ matrix.vsversion }}.alt.hpp .\ql\userconfig.hpp + - name: Setup unity build + if: ${{ matrix.unity == 'unity' }} + shell: cmd + run: | + COPY .ci\Unity.props .\Directory.Build.props + - name: Setup MSVC++ environment + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + toolset: ${{ matrix.toolset }} + vsversion: ${{ matrix.vsversion }} + - name: Build + run: | + msbuild ./QuantLib.sln /verbosity:normal /property:Configuration=Release /property:Platform=${{ matrix.platform }} + - name: Test + run: | + .\test-suite\bin\QuantLib-test-suite*.exe --log_level=message + - name: Run examples + run: | + foreach ($file in Get-ChildItem -Path .\Examples\*.exe -Recurse) + { + & $file.FullName + if (!$?) { Exit $LASTEXITCODE } + } diff --git a/.github/workflows/msvc.yml b/.github/workflows/msvc.yml new file mode 100644 index 00000000000..8a2fd4f5772 --- /dev/null +++ b/.github/workflows/msvc.yml @@ -0,0 +1,61 @@ +name: Windows build +on: [push, pull_request] +jobs: + msbuild: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + vsversion: [2019, 2022] + unity: [unity, singles] + include: + - vsversion: 2019 + os: windows-2019 + toolset: "14.2" + boost_version: 77 + - vsversion: 2022 + os: windows-2022 + toolset: "14.3" + boost_version: 85 + steps: + - uses: actions/checkout@v4 + - name: Setup MSVC++ environment + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + toolset: ${{ matrix.toolset }} + vsversion: ${{ matrix.vsversion }} + - name: Setup Boost + run: | + $Url = "https://boostorg.jfrog.io/artifactory/main/release/1.${{ matrix.boost_version }}.0/source/boost_1_${{ matrix.boost_version }}_0.zip" + (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\boost.zip") + Expand-Archive -Path "$RUNNER_TEMP\boost.zip" -DestinationPath C:\local + Rename-Item -Path "C:\local\boost_1_${{ matrix.boost_version }}_0" -NewName "boost" + - name: Setup local properties + shell: cmd + run: | + COPY .ci\VS${{ matrix.vsversion }}.props .\Build.props + - name: Setup unity build + if: ${{ matrix.unity == 'unity' }} + shell: cmd + run: | + COPY .ci\Unity.props .\Directory.Build.props + - name: Setup MSVC++ environment + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + toolset: ${{ matrix.toolset }} + vsversion: ${{ matrix.vsversion }} + - name: Build + run: | + msbuild ./QuantLib.sln /verbosity:normal /property:Configuration=Release /property:Platform=x64 + - name: Test + run: | + .\test-suite\bin\QuantLib-test-suite*.exe --log_level=message + - name: Run examples + run: | + foreach ($file in Get-ChildItem -Path .\Examples\*.exe -Recurse) + { + & $file.FullName + if (!$?) { Exit $LASTEXITCODE } + } diff --git a/.github/workflows/sanitizer.yml b/.github/workflows/sanitizer.yml new file mode 100644 index 00000000000..c521a675ce3 --- /dev/null +++ b/.github/workflows/sanitizer.yml @@ -0,0 +1,44 @@ +name: Linux build with address sanitizer enabled +on: + schedule: + - cron: '0 0 * * 0' + workflow_dispatch: +jobs: + sanitize-address-undefined: + runs-on: ubuntu-latest + container: ghcr.io/lballabio/quantlib-devenv:rolling + steps: + - uses: actions/checkout@v4 + - name: Compiler version + run: | + gcc --version + - name: Build + run: | + ./autogen.sh + ./configure --disable-static CC="gcc" CXX="g++" CXXFLAGS="-O2 -g0 -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer -Wall -Wno-unknown-pragmas -Werror" + make -j 4 + - name: Run tests + run: | + LSAN_OPTIONS=suppressions=.lsan.txt ./test-suite/quantlib-test-suite --log_level=message + - name: Run examples + run: | + make check-examples + sanitize-thread: + runs-on: ubuntu-latest + container: ghcr.io/lballabio/quantlib-devenv:rolling + steps: + - uses: actions/checkout@v4 + - name: Compiler version + run: | + gcc --version + - name: Build + run: | + ./autogen.sh + ./configure --disable-static --enable-sessions --enable-thread-safe-observer-pattern CC="gcc" CXX="g++" CXXFLAGS="-O2 -g0 -fsanitize=thread -fno-sanitize-recover=all -Wall -Wno-unknown-pragmas -Werror" + make -j 4 + - name: Run tests + run: | + ./test-suite/quantlib-test-suite --log_level=message + - name: Run examples + run: | + make check-examples diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 00000000000..14d8c62f78e --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,22 @@ +name: Close stale issues and PR +on: + schedule: + - cron: '30 1 * * *' +jobs: + staleness-check: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v9 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-issue-message: 'This issue was automatically marked as stale because it has been open 60 days with no activity. Remove stale label or comment, or this will be closed in two weeks.' + close-issue-message: 'This issue was automatically closed because it has been stalled for two weeks with no further activity.' + stale-pr-message: 'This PR was automatically marked as stale because it has been open 60 days with no activity. Remove stale label or comment, or this will be closed in two weeks.' + close-pr-message: 'This PR was automatically closed because it has been stalled for two weeks with no further activity.' + days-before-stale: 60 + days-before-close: 14 + stale-issue-label: 'stale' + stale-pr-label: 'stale' + exempt-issue-labels: 'help wanted,in progress' + exempt-pr-labels: 'help wanted,in progress' + exempt-all-milestones: true diff --git a/.github/workflows/test-times.yml b/.github/workflows/test-times.yml new file mode 100644 index 00000000000..defad441651 --- /dev/null +++ b/.github/workflows/test-times.yml @@ -0,0 +1,42 @@ +name: Check test times +on: [push, pull_request] +jobs: + check-test-times: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Cache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: linux-ci-test-times-${{ github.ref }} + restore-keys: | + linux-ci-test-times-${{ github.ref }} + linux-ci-test-times-refs/heads/master + linux-ci-test-times- + - name: Setup + run: | + sudo rm /etc/apt/sources.list.d/microsoft-prod.list + sudo apt update + sudo apt install -y libboost-dev autoconf automake libtool ccache + - name: Build + run: | + ./autogen.sh + ./configure --disable-static CC="ccache gcc" CXX="ccache g++" CXXFLAGS="-O2 -g0" + make -j 4 + - name: Run faster tests + run: | + ./test-suite/quantlib-test-suite --logger=JUNIT,warning,faster.xml:HRF,message -- --faster + - name: Run fast tests + run: | + ./test-suite/quantlib-test-suite --logger=JUNIT,warning,fast.xml:HRF,message -- --fast + - name: Run all tests + run: | + ./test-suite/quantlib-test-suite --logger=JUNIT,warning,all.xml:HRF,message + - name: Save test times + uses: actions/upload-artifact@v4 + with: + name: test-reports + path: ./*.xml + - name: Check test times + run: | + python ./tools/check_test_times.py diff --git a/.github/workflows/tidy.yml b/.github/workflows/tidy.yml new file mode 100644 index 00000000000..d14c3a246cd --- /dev/null +++ b/.github/workflows/tidy.yml @@ -0,0 +1,32 @@ +name: Apply clang-tidy fixes +on: + schedule: + - cron: '0 0 * * 0' + workflow_dispatch: +jobs: + check: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: Setup + run: | + sudo apt-get update + sudo apt-get install -y clang-tidy-15 libboost-dev + - name: Check + run: | + cmake --preset linux-ci-build-with-clang-tidy + cd build/linux-ci-build-with-clang-tidy + cmake --build . -j1 + - uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: clang-tidy-fixes-${{ github.ref_name }} + delete-branch: true + commit-message: 'Automated fixes by clang-tidy' + title: 'Automated fixes by clang-tidy' + author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> + body: | + This is an automated PR generated by the [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action. + + Please review the changes before merging. + From 301ab531d8db686bd1d76ffd6addc45f95cbaab0 Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Tue, 28 May 2024 14:16:37 +0200 Subject: [PATCH 14/19] Added zigguratgaussianrng.hpp to Makefile build --- ql/math/randomnumbers/Makefile.am | 3 ++- ql/math/randomnumbers/all.hpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ql/math/randomnumbers/Makefile.am b/ql/math/randomnumbers/Makefile.am index ac088630f85..6eb7284fdf7 100644 --- a/ql/math/randomnumbers/Makefile.am +++ b/ql/math/randomnumbers/Makefile.am @@ -25,7 +25,8 @@ this_include_HEADERS = \ sobolbrownianbridgersg.hpp \ sobolrsg.hpp \ stochasticcollocationinvcdf.hpp \ - xoshiro256starstaruniformrng.hpp + xoshiro256starstaruniformrng.hpp \ + zigguratgaussianrng.hpp cpp_files = \ faurersg.cpp \ diff --git a/ql/math/randomnumbers/all.hpp b/ql/math/randomnumbers/all.hpp index 6b1d5fc35a4..9b1b2938da3 100644 --- a/ql/math/randomnumbers/all.hpp +++ b/ql/math/randomnumbers/all.hpp @@ -23,4 +23,5 @@ #include #include #include +#include From e0ed843a811a3929c51b0de434f63a8a07fa7522 Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Tue, 28 May 2024 14:39:08 +0200 Subject: [PATCH 15/19] Added new files to VS projects --- QuantLib.vcxproj | 1 + QuantLib.vcxproj.filters | 3 +++ test-suite/testsuite.vcxproj | 1 + test-suite/testsuite.vcxproj.filters | 3 +++ 4 files changed, 8 insertions(+) diff --git a/QuantLib.vcxproj b/QuantLib.vcxproj index 1563391ed3a..e749bf55c86 100644 --- a/QuantLib.vcxproj +++ b/QuantLib.vcxproj @@ -1128,6 +1128,7 @@ + diff --git a/QuantLib.vcxproj.filters b/QuantLib.vcxproj.filters index ae3039404d3..a7d1b985bc2 100644 --- a/QuantLib.vcxproj.filters +++ b/QuantLib.vcxproj.filters @@ -1302,6 +1302,9 @@ math\randomnumbers + + math\randomnumbers + math\solvers1D diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 40f062c702f..607fd3b31fd 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -808,6 +808,7 @@ + false diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index c8eee42571b..1bf5a5830d8 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -461,6 +461,9 @@ Source Files + + Source Files + Source Files From 41cf9600ab9e54fccfc7d30477e824b8938941f4 Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Tue, 28 May 2024 14:48:19 +0200 Subject: [PATCH 16/19] Added zigguratgaussian.cpp to testsuite/Makefile.am --- test-suite/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 00bad8d2e31..718658f8264 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -171,7 +171,8 @@ QL_TEST_SRCS = \ vpp.cpp \ xoshiro256starstar.cpp \ zabr.cpp \ - zerocouponswap.cpp + zerocouponswap.cpp \ + zigguratgaussian.cpp QL_TEST_HDRS = \ From c1e5c0bb700b495e48d78148e3e4f494c5927308 Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Tue, 28 May 2024 17:13:34 +0200 Subject: [PATCH 17/19] Using IncrementalStatistics instead of boost::accumulators --- test-suite/zigguratgaussian.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/test-suite/zigguratgaussian.cpp b/test-suite/zigguratgaussian.cpp index ad794710e49..4f633bf24c6 100644 --- a/test-suite/zigguratgaussian.cpp +++ b/test-suite/zigguratgaussian.cpp @@ -20,12 +20,7 @@ #include "toplevelfixture.hpp" #include #include -#include -#include -#include -#include -#include -#include +#include #include #include @@ -38,27 +33,22 @@ BOOST_AUTO_TEST_SUITE(ZigguratGaussianTests) BOOST_AUTO_TEST_CASE(testMeanAndStdDevOfNextReal) { BOOST_TEST_MESSAGE("Testing ZigguratGaussianRng::nextReal() for " "mean, variance, skewness and kurtosis..."); - using namespace boost::accumulators; - auto seed = 42UL; auto uniformRandom = Xoshiro256StarStarUniformRng(seed); auto random = ZigguratGaussianRng(uniformRandom); - const auto iterations = 10'000'000; - - accumulator_set> - randoms; + auto randoms = IncrementalStatistics(); + auto iterations = 10'000'000; for (auto j = 0; j < iterations; ++j) { Real next = random.next().value; - randoms(next); + randoms.add(next); } - Real mean = boost::accumulators::mean(randoms); - Real variance = boost::accumulators::variance(randoms); - Real skewness = boost::accumulators::skewness(randoms); - Real kurtosis = boost::accumulators::kurtosis(randoms); + auto mean = randoms.mean(); + auto variance = randoms.variance(); + auto skewness = randoms.skewness(); + auto kurtosis = randoms.kurtosis(); if (std::abs(mean) > 0.001) { BOOST_ERROR("Mean " << mean << " for seed " << seed << " is not close to 0."); From 49cefdff0038c5bc653afffd3349a60829032189 Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Tue, 28 May 2024 17:19:28 +0200 Subject: [PATCH 18/19] Renaming to testStatisticsOfNextReal --- test-suite/zigguratgaussian.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-suite/zigguratgaussian.cpp b/test-suite/zigguratgaussian.cpp index 4f633bf24c6..4d6bb7468f6 100644 --- a/test-suite/zigguratgaussian.cpp +++ b/test-suite/zigguratgaussian.cpp @@ -30,7 +30,7 @@ BOOST_FIXTURE_TEST_SUITE(QuantLibTests, TopLevelFixture) BOOST_AUTO_TEST_SUITE(ZigguratGaussianTests) -BOOST_AUTO_TEST_CASE(testMeanAndStdDevOfNextReal) { +BOOST_AUTO_TEST_CASE(testStatisticsOfNextReal) { BOOST_TEST_MESSAGE("Testing ZigguratGaussianRng::nextReal() for " "mean, variance, skewness and kurtosis..."); auto seed = 42UL; From a4d5392c4e4ad5606cb0562e5462012d79a3c251 Mon Sep 17 00:00:00 2001 From: Ralf Konrad <42419984+ralfkonrad@users.noreply.github.com> Date: Tue, 28 May 2024 17:30:14 +0200 Subject: [PATCH 19/19] Minor refactorings --- ql/math/randomnumbers/zigguratgaussianrng.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ql/math/randomnumbers/zigguratgaussianrng.hpp b/ql/math/randomnumbers/zigguratgaussianrng.hpp index cfd547420eb..8be737bfc29 100644 --- a/ql/math/randomnumbers/zigguratgaussianrng.hpp +++ b/ql/math/randomnumbers/zigguratgaussianrng.hpp @@ -57,7 +57,6 @@ namespace QuantLib { public: typedef Sample sample_type; - explicit ZigguratGaussianRng(const RNG& uint64Generator) : uint64Generator_(uint64Generator) {} @@ -97,7 +96,7 @@ namespace QuantLib { auto x = u * normX(i); - if (std::fabs(x) < normX(i + 1)) { + if (std::abs(x) < normX(i + 1)) { return x; } if (i == 0) {