lunad 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lunad-0.2.0/.clang-format +39 -0
- lunad-0.2.0/.clang-tidy +55 -0
- lunad-0.2.0/.editorconfig +25 -0
- lunad-0.2.0/.github/workflows/ci.yml +53 -0
- lunad-0.2.0/.github/workflows/release.yml +71 -0
- lunad-0.2.0/.gitignore +8 -0
- lunad-0.2.0/.readthedocs.yaml +15 -0
- lunad-0.2.0/CHANGELOG.md +41 -0
- lunad-0.2.0/CMakeLists.txt +148 -0
- lunad-0.2.0/CMakePresets.json +129 -0
- lunad-0.2.0/CODE_OF_CONDUCT.md +85 -0
- lunad-0.2.0/CONTRIBUTING.md +51 -0
- lunad-0.2.0/LICENSE +373 -0
- lunad-0.2.0/PKG-INFO +139 -0
- lunad-0.2.0/README.md +110 -0
- lunad-0.2.0/SECURITY.md +10 -0
- lunad-0.2.0/THIRD_PARTY_NOTICES.md +18 -0
- lunad-0.2.0/cla/entity.md +135 -0
- lunad-0.2.0/cla/individual.md +114 -0
- lunad-0.2.0/cmake/lunadConfig.cmake.in +12 -0
- lunad-0.2.0/cmake/toolchains/clang22.cmake +8 -0
- lunad-0.2.0/cmake/toolchains/gcc16.cmake +27 -0
- lunad-0.2.0/docs/api.md +27 -0
- lunad-0.2.0/docs/changelog.md +1 -0
- lunad-0.2.0/docs/conf.py +152 -0
- lunad-0.2.0/docs/design.md +134 -0
- lunad-0.2.0/docs/guide/README.md +18 -0
- lunad-0.2.0/docs/guide/cpp.md +126 -0
- lunad-0.2.0/docs/guide/getting-started.md +101 -0
- lunad-0.2.0/docs/guide/python.md +83 -0
- lunad-0.2.0/docs/guide/reference.md +69 -0
- lunad-0.2.0/docs/index.md +21 -0
- lunad-0.2.0/docs/requirements.txt +4 -0
- lunad-0.2.0/examples/generic.cpp +122 -0
- lunad-0.2.0/examples/getting_started.cpp +68 -0
- lunad-0.2.0/examples/getting_started.py +35 -0
- lunad-0.2.0/examples/numpy_arrays.py +51 -0
- lunad-0.2.0/examples/readme.cpp +68 -0
- lunad-0.2.0/include/lunad/config.hpp +11 -0
- lunad-0.2.0/include/lunad/derivatives.hpp +236 -0
- lunad-0.2.0/include/lunad/dual.hpp +496 -0
- lunad-0.2.0/include/lunad/dynamic.hpp +47 -0
- lunad-0.2.0/include/lunad/eigen.hpp +87 -0
- lunad-0.2.0/include/lunad/format.hpp +42 -0
- lunad-0.2.0/include/lunad/jacobian.hpp +92 -0
- lunad-0.2.0/include/lunad/lunad.hpp +17 -0
- lunad-0.2.0/include/lunad/real.hpp +245 -0
- lunad-0.2.0/include/lunad/storage.hpp +112 -0
- lunad-0.2.0/include/lunad/vector_dual.hpp +224 -0
- lunad-0.2.0/licenses/GCC-Runtime-Library-Exception-3.1.txt +73 -0
- lunad-0.2.0/licenses/nanobind-BSD-3-Clause.txt +26 -0
- lunad-0.2.0/licenses/robin-map-MIT.txt +21 -0
- lunad-0.2.0/pyproject.toml +67 -0
- lunad-0.2.0/python/CMakeLists.txt +59 -0
- lunad-0.2.0/python/lunad/__init__.py +196 -0
- lunad-0.2.0/python/src/module.cpp +216 -0
- lunad-0.2.0/python/tests/test_lunad.py +179 -0
- lunad-0.2.0/tests/cuda/dual_kernels.cu +155 -0
- lunad-0.2.0/tests/cuda/dual_kernels.hpp +32 -0
- lunad-0.2.0/tests/cuda/test_dual_cuda.cpp +105 -0
- lunad-0.2.0/tests/test_derivatives.cpp +112 -0
- lunad-0.2.0/tests/test_dual.cpp +461 -0
- lunad-0.2.0/tests/test_format.cpp +35 -0
- lunad-0.2.0/tests/test_functions.hpp +38 -0
- lunad-0.2.0/tests/test_storage.cpp +120 -0
- lunad-0.2.0/tests/test_vector_dual.cpp +137 -0
- lunad-0.2.0/tests/two_body_dual.hpp +48 -0
- lunad-0.2.0/tools/check.sh +120 -0
- lunad-0.2.0/tools/check_docs.py +80 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# lunad's C++ formatting (clang-format 22).
|
|
2
|
+
# Allman braces; spaces inside parentheses, angle brackets and braced lists.
|
|
3
|
+
BasedOnStyle: LLVM
|
|
4
|
+
Language: Cpp
|
|
5
|
+
Standard: Latest
|
|
6
|
+
IndentWidth: 4
|
|
7
|
+
ColumnLimit: 120
|
|
8
|
+
PointerAlignment: Left
|
|
9
|
+
BreakBeforeBraces: Allman
|
|
10
|
+
AccessModifierOffset: -4
|
|
11
|
+
SpacesInParens: Custom
|
|
12
|
+
SpacesInParensOptions:
|
|
13
|
+
InConditionalStatements: true
|
|
14
|
+
Other: true
|
|
15
|
+
InEmptyParentheses: false
|
|
16
|
+
InCStyleCasts: false
|
|
17
|
+
SpacesInAngles: Always
|
|
18
|
+
SpaceAfterTemplateKeyword: false
|
|
19
|
+
Cpp11BracedListStyle: false
|
|
20
|
+
AlignAfterOpenBracket: AlwaysBreak
|
|
21
|
+
PenaltyReturnTypeOnItsOwnLine: 1000
|
|
22
|
+
AllowShortFunctionsOnASingleLine: Inline
|
|
23
|
+
AllowShortIfStatementsOnASingleLine: Never
|
|
24
|
+
AllowShortLoopsOnASingleLine: false
|
|
25
|
+
AlwaysBreakTemplateDeclarations: Yes
|
|
26
|
+
BreakConstructorInitializers: BeforeComma
|
|
27
|
+
NamespaceIndentation: None
|
|
28
|
+
FixNamespaceComments: true
|
|
29
|
+
SpacesBeforeTrailingComments: 1
|
|
30
|
+
IncludeBlocks: Regroup
|
|
31
|
+
IncludeCategories:
|
|
32
|
+
- Regex: '^<[a-z_]+>$' # standard library
|
|
33
|
+
Priority: 1
|
|
34
|
+
- Regex: '^<' # third party
|
|
35
|
+
Priority: 2
|
|
36
|
+
- Regex: '^"lunad/' # lunad's own
|
|
37
|
+
Priority: 3
|
|
38
|
+
- Regex: '.*'
|
|
39
|
+
Priority: 4
|
lunad-0.2.0/.clang-tidy
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# clang-tidy 22 profile (the style's rules). Warnings are errors in tools/check.sh.
|
|
2
|
+
# Deliberately disabled:
|
|
3
|
+
# bugprone-random-generator-seed fixed seeds keep tests reproducible
|
|
4
|
+
# pro-bounds-avoid-unchecked-... bounds checks come from the hardened
|
|
5
|
+
# standard library builds (the asan preset)
|
|
6
|
+
# portability-avoid-pragma-once supported by every compiler we use
|
|
7
|
+
# readability-math-missing-parentheses would clutter every formula
|
|
8
|
+
Checks: >
|
|
9
|
+
-*,
|
|
10
|
+
bugprone-*,
|
|
11
|
+
-bugprone-easily-swappable-parameters,
|
|
12
|
+
-bugprone-random-generator-seed,
|
|
13
|
+
clang-analyzer-*,
|
|
14
|
+
concurrency-*,
|
|
15
|
+
cppcoreguidelines-*,
|
|
16
|
+
-cppcoreguidelines-avoid-magic-numbers,
|
|
17
|
+
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
|
18
|
+
-cppcoreguidelines-pro-bounds-constant-array-index,
|
|
19
|
+
-cppcoreguidelines-pro-bounds-avoid-unchecked-container-access,
|
|
20
|
+
misc-*,
|
|
21
|
+
-misc-include-cleaner,
|
|
22
|
+
-misc-non-private-member-variables-in-classes,
|
|
23
|
+
modernize-*,
|
|
24
|
+
-modernize-use-trailing-return-type,
|
|
25
|
+
performance-*,
|
|
26
|
+
portability-*,
|
|
27
|
+
-portability-avoid-pragma-once,
|
|
28
|
+
readability-*,
|
|
29
|
+
-readability-identifier-length,
|
|
30
|
+
-readability-magic-numbers,
|
|
31
|
+
-readability-uppercase-literal-suffix,
|
|
32
|
+
-readability-math-missing-parentheses
|
|
33
|
+
WarningsAsErrors: '*'
|
|
34
|
+
HeaderFilterRegex: '.*/lunad/(include/lunad|tests|examples)/.*'
|
|
35
|
+
CheckOptions:
|
|
36
|
+
- key: readability-function-cognitive-complexity.IgnoreMacros
|
|
37
|
+
value: true
|
|
38
|
+
- key: readability-identifier-naming.NamespaceCase
|
|
39
|
+
value: lower_case
|
|
40
|
+
- key: readability-identifier-naming.ClassCase
|
|
41
|
+
value: CamelCase
|
|
42
|
+
- key: readability-identifier-naming.StructCase
|
|
43
|
+
value: CamelCase
|
|
44
|
+
- key: readability-identifier-naming.EnumCase
|
|
45
|
+
value: CamelCase
|
|
46
|
+
- key: readability-identifier-naming.EnumConstantCase
|
|
47
|
+
value: CamelCase
|
|
48
|
+
- key: readability-identifier-naming.ScopedEnumConstantCase
|
|
49
|
+
value: CamelCase
|
|
50
|
+
- key: readability-identifier-naming.FunctionCase
|
|
51
|
+
value: lower_case
|
|
52
|
+
- key: readability-identifier-naming.VariableCase
|
|
53
|
+
value: lower_case
|
|
54
|
+
- key: readability-identifier-naming.TemplateParameterCase
|
|
55
|
+
value: CamelCase
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
charset = utf-8
|
|
5
|
+
end_of_line = lf
|
|
6
|
+
insert_final_newline = true
|
|
7
|
+
trim_trailing_whitespace = true
|
|
8
|
+
|
|
9
|
+
[*.{cpp,hpp,cu,cuh,cmake,py,json,yml,yaml}]
|
|
10
|
+
indent_style = space
|
|
11
|
+
|
|
12
|
+
[*.{cpp,hpp,cu,cuh,cmake,py}]
|
|
13
|
+
indent_size = 4
|
|
14
|
+
|
|
15
|
+
[*.{cpp,hpp,cu,cuh}]
|
|
16
|
+
max_line_length = 120
|
|
17
|
+
|
|
18
|
+
[{CMakeLists.txt,*.cmake}]
|
|
19
|
+
indent_size = 4
|
|
20
|
+
|
|
21
|
+
[*.{json,yml,yaml}]
|
|
22
|
+
indent_size = 2
|
|
23
|
+
|
|
24
|
+
[*.md]
|
|
25
|
+
trim_trailing_whitespace = false
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was
|
|
3
|
+
# not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
# The continuous integration, kept light on GitHub's hosted runners: GCC 16's build and its tests (the gate preset, with
|
|
5
|
+
# the Python module and its tests), clang-format, the licence notices, the guide's code and the documentation site. Clang, the sanitizers, the CUDA tests and clang-tidy are tools/check.sh's, run
|
|
6
|
+
# before each commit (CONTRIBUTING.md).
|
|
7
|
+
name: CI
|
|
8
|
+
|
|
9
|
+
on:
|
|
10
|
+
push:
|
|
11
|
+
branches:
|
|
12
|
+
- main
|
|
13
|
+
pull_request:
|
|
14
|
+
workflow_dispatch:
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
contents: read
|
|
18
|
+
|
|
19
|
+
concurrency:
|
|
20
|
+
group: ci-${{ github.ref }}
|
|
21
|
+
cancel-in-progress: true
|
|
22
|
+
|
|
23
|
+
jobs:
|
|
24
|
+
gcc:
|
|
25
|
+
runs-on: ubuntu-24.04
|
|
26
|
+
container: ubuntu:26.04
|
|
27
|
+
timeout-minutes: 30
|
|
28
|
+
steps:
|
|
29
|
+
- name: The tools (Ubuntu 26.04's GCC 16, CMake, Ninja, ccache, clang-format 22)
|
|
30
|
+
run: |
|
|
31
|
+
apt-get update
|
|
32
|
+
DEBIAN_FRONTEND=noninteractive apt-get install --yes --no-install-recommends \
|
|
33
|
+
ca-certificates git g++-16 cmake ninja-build ccache clang-format-22 python3
|
|
34
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
35
|
+
with:
|
|
36
|
+
persist-credentials: false
|
|
37
|
+
- uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
38
|
+
- name: Python 3.12 with nanobind and numpy (.venv-python, as the presets expect)
|
|
39
|
+
run: |
|
|
40
|
+
uv venv --python 3.12 .venv-python
|
|
41
|
+
uv pip install --python .venv-python/bin/python nanobind==3.1.0 numpy
|
|
42
|
+
- name: Build and test (GCC 16)
|
|
43
|
+
run: bash tools/check.sh gate
|
|
44
|
+
- name: Format, licence notices and the guide's code
|
|
45
|
+
run: |
|
|
46
|
+
bash tools/check.sh format
|
|
47
|
+
bash tools/check.sh licence
|
|
48
|
+
bash tools/check.sh docs
|
|
49
|
+
- name: The documentation site (Sphinx, as Read the Docs builds it)
|
|
50
|
+
run: |
|
|
51
|
+
uv venv --python 3.12 .venv-docs
|
|
52
|
+
uv pip install --python .venv-docs/bin/python -r docs/requirements.txt
|
|
53
|
+
bash tools/check.sh site
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was
|
|
3
|
+
# not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
# A release: on a tag vX.Y.Z (the version in CMakeLists.txt), the sdist and the Linux wheels (cibuildwheel,
|
|
5
|
+
# pyproject.toml's [tool.cibuildwheel]: CPython 3.12 to 3.14, each wheel's Python tests run), then PyPI by trusted
|
|
6
|
+
# publishing (PyPI's publisher for this workflow and the environment pypi: no token is stored). By hand
|
|
7
|
+
# (workflow_dispatch): the packages built and kept as the run's artifacts, nothing published.
|
|
8
|
+
name: Release
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
tags:
|
|
13
|
+
- "v*"
|
|
14
|
+
workflow_dispatch:
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
contents: read
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
sdist:
|
|
21
|
+
if: github.repository == 'luna-space/lunad'
|
|
22
|
+
runs-on: ubuntu-24.04
|
|
23
|
+
timeout-minutes: 30
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
26
|
+
with:
|
|
27
|
+
persist-credentials: false
|
|
28
|
+
- uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
29
|
+
- name: The sdist
|
|
30
|
+
run: uv build --sdist --out-dir dist
|
|
31
|
+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
|
32
|
+
with:
|
|
33
|
+
name: sdist
|
|
34
|
+
path: dist/*.tar.gz
|
|
35
|
+
if-no-files-found: error
|
|
36
|
+
|
|
37
|
+
wheels:
|
|
38
|
+
if: github.repository == 'luna-space/lunad'
|
|
39
|
+
runs-on: ubuntu-24.04
|
|
40
|
+
timeout-minutes: 120
|
|
41
|
+
steps:
|
|
42
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
43
|
+
with:
|
|
44
|
+
persist-credentials: false
|
|
45
|
+
- uses: pypa/cibuildwheel@f9b966cfadf4109556cadc5bb39ddb72d0ce664e # v4.3.5
|
|
46
|
+
with:
|
|
47
|
+
output-dir: wheelhouse
|
|
48
|
+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
|
49
|
+
with:
|
|
50
|
+
name: wheels
|
|
51
|
+
path: wheelhouse/*.whl
|
|
52
|
+
if-no-files-found: error
|
|
53
|
+
|
|
54
|
+
publish:
|
|
55
|
+
if: github.repository == 'luna-space/lunad' && startsWith(github.ref, 'refs/tags/v')
|
|
56
|
+
needs:
|
|
57
|
+
- sdist
|
|
58
|
+
- wheels
|
|
59
|
+
runs-on: ubuntu-24.04
|
|
60
|
+
timeout-minutes: 15
|
|
61
|
+
environment:
|
|
62
|
+
name: pypi
|
|
63
|
+
url: https://pypi.org/project/lunad/
|
|
64
|
+
permissions:
|
|
65
|
+
id-token: write
|
|
66
|
+
steps:
|
|
67
|
+
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
|
68
|
+
with:
|
|
69
|
+
path: dist
|
|
70
|
+
merge-multiple: true
|
|
71
|
+
- uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
|
lunad-0.2.0/.gitignore
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was
|
|
3
|
+
# not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
# The documentation site, lunad.readthedocs.io: Sphinx on docs/ (docs/conf.py), every warning an error.
|
|
5
|
+
version: 2
|
|
6
|
+
build:
|
|
7
|
+
os: ubuntu-24.04
|
|
8
|
+
tools:
|
|
9
|
+
python: "3.12"
|
|
10
|
+
sphinx:
|
|
11
|
+
configuration: docs/conf.py
|
|
12
|
+
fail_on_warning: true
|
|
13
|
+
python:
|
|
14
|
+
install:
|
|
15
|
+
- requirements: docs/requirements.txt
|
lunad-0.2.0/CHANGELOG.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Every version of lunad, the newest first. The equations and rules are those of [docs/design.md](docs/design.md).
|
|
4
|
+
|
|
5
|
+
## 0.2.0 (2026-12-01)
|
|
6
|
+
|
|
7
|
+
Python, the documentation, and the hyperbolic functions.
|
|
8
|
+
|
|
9
|
+
- **The hyperbolic functions and a variable exponent**: `sinh`, `cosh`, `tanh`, and `pow( x, y )` with a dual exponent
|
|
10
|
+
(`x > 0`; [docs/design.md](docs/design.md) (4)), for every dual on the host and the device. They are optional members
|
|
11
|
+
of `RealTraits`: a scalar type of the user's without them is still `Real`. The device's test now runs every
|
|
12
|
+
elementary function against the host.
|
|
13
|
+
- **Python** (`pip install lunad`, the package `lunad`): `lunad.Dual`, a dual with any number of columns (C++'s
|
|
14
|
+
`Dual< double, Dynamic >`, nanobind), with Python's operators (`**` for a constant or dual exponent, or a constant
|
|
15
|
+
base), comparisons on values, `repr`, `str` and `format`; lunad's functions for duals and floats (`lunad.sqrt`,
|
|
16
|
+
`lunad.atan2`, ...); the methods numpy calls on arrays of duals (`np.sqrt`, `np.sin`, ...), so that numpy functions
|
|
17
|
+
run on them; and, in Python, `jacobian( f, *x )`, `gradient`, `derivative`, `constant`, `seed`, `values` and
|
|
18
|
+
`derivatives`, with the C++ shapes. Linux wheels for CPython 3.12 to 3.14 (cibuildwheel), published to PyPI by trusted publishing.
|
|
19
|
+
- **The guide** ([docs/guide](docs/guide/README.md)): getting started in C++ and Python, generic code in C++
|
|
20
|
+
(conditionals, storage, Hessians by nested duals, vector duals and Jacobians, device code), Python, and a reference
|
|
21
|
+
of every type and function. Its code is four programs in [examples/](examples), in C++ and Python, which the tests
|
|
22
|
+
build, run and check; `tools/check_docs.py` (in the gate and the CI) keeps the quoted code equal to them.
|
|
23
|
+
- **The documentation site**, [lunad.readthedocs.io](https://lunad.readthedocs.io): the guide, the design and this
|
|
24
|
+
changelog as Sphinx builds them from the repository's Markdown, and the Python API from its docstrings;
|
|
25
|
+
`tools/check.sh site` builds it, every warning an error, as the CI does.
|
|
26
|
+
|
|
27
|
+
## 0.1.0 (2026-12-01)
|
|
28
|
+
|
|
29
|
+
The first release: the automatic differentiation of Luna Space's flight dynamics engine, as a library of its own.
|
|
30
|
+
|
|
31
|
+
- `Dual< V, G >`: forward-mode duals with the storage policies `Static< N >`, `Bounded< Max >` and `Dynamic`; the
|
|
32
|
+
chain rule (1) to (4) for the arithmetic and the elementary functions (`sqrt`, `cbrt`, `sin`, `cos`, `tan`, `asin`,
|
|
33
|
+
`acos`, `atan`, `atan2`, `exp`, `log`, `abs`, `pow`, `square`, `cube`), values bitwise those of the plain computation
|
|
34
|
+
(rule 1), comparisons on values and `select` (rule 2), `primal` (rule 3); nested duals for higher derivatives.
|
|
35
|
+
- The `Real` concept and `RealTraits`, by which a user's own scalar type joins.
|
|
36
|
+
- Vector duals (`VectorDual`): a value vector and one contiguous Jacobian, linear maps (7), `to_elements` and
|
|
37
|
+
`from_elements`; Eigen's `NumTraits` for duals; `seed`, `values`, `jacobian` and `gradient` (5), (6).
|
|
38
|
+
- Derivatives in one call: `jacobian( f, x... )`, `gradient( f, x... )`, `derivative( f, x )`, `constant( x )`.
|
|
39
|
+
- `std::format` for duals (`format.hpp`).
|
|
40
|
+
- Device code (`LUNAD_HD`): the scalar duals checked on a CUDA device against the host, bit for bit (the `cuda`
|
|
41
|
+
preset).
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was
|
|
3
|
+
# not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
cmake_minimum_required(VERSION 3.30)
|
|
5
|
+
project(lunad
|
|
6
|
+
VERSION 0.2.0
|
|
7
|
+
DESCRIPTION "lunad: forward-mode automatic differentiation by dual numbers, for host and CUDA device code"
|
|
8
|
+
LANGUAGES CXX)
|
|
9
|
+
|
|
10
|
+
option(LUNAD_BUILD_TESTS "Build lunad's tests" ${PROJECT_IS_TOP_LEVEL})
|
|
11
|
+
option(LUNAD_FETCH_EIGEN "Fetch Eigen 5.0.1 where no Eigen3::Eigen target exists" ON)
|
|
12
|
+
option(LUNAD_WERROR "Warnings as errors in lunad's own targets" OFF)
|
|
13
|
+
option(LUNAD_CUDA "Build the CUDA tests (needs a CUDA compiler; run where a device is present)" OFF)
|
|
14
|
+
option(LUNAD_PYTHON "Build the Python bindings (needs Python 3.12+ with nanobind)" OFF)
|
|
15
|
+
set(LUNAD_SANITIZE "" CACHE STRING "Sanitizers for the tests, e.g. address,undefined")
|
|
16
|
+
|
|
17
|
+
include(FetchContent)
|
|
18
|
+
|
|
19
|
+
# Eigen (for vector duals, the Eigen traits, the Jacobians and the derivatives in one call; dual.hpp, real.hpp and
|
|
20
|
+
# storage.hpp need none): the including project's Eigen3::Eigen target where it has one, else Eigen 5.0.1 (MPL-2.0)
|
|
21
|
+
# pinned by its hash, else an installed Eigen 5. Header-only: Eigen's own CMake project is not configured.
|
|
22
|
+
set(_lunad_eigen Eigen3::Eigen)
|
|
23
|
+
if(NOT TARGET Eigen3::Eigen)
|
|
24
|
+
if(LUNAD_FETCH_EIGEN)
|
|
25
|
+
FetchContent_Declare(Eigen
|
|
26
|
+
URL https://gitlab.com/libeigen/eigen/-/archive/5.0.1/eigen-5.0.1.tar.gz
|
|
27
|
+
URL_HASH SHA256=e9c326dc8c05cd1e044c71f30f1b2e34a6161a3b6ecf445d56b53ff1669e3dec
|
|
28
|
+
DOWNLOAD_EXTRACT_TIMESTAMP ON
|
|
29
|
+
SOURCE_SUBDIR do-not-configure)
|
|
30
|
+
FetchContent_MakeAvailable(Eigen)
|
|
31
|
+
add_library(lunad_eigen INTERFACE)
|
|
32
|
+
target_include_directories(lunad_eigen SYSTEM INTERFACE "${eigen_SOURCE_DIR}")
|
|
33
|
+
set(_lunad_eigen lunad_eigen)
|
|
34
|
+
else()
|
|
35
|
+
find_package(Eigen3 5 REQUIRED CONFIG)
|
|
36
|
+
endif()
|
|
37
|
+
endif()
|
|
38
|
+
|
|
39
|
+
# The library: header-only, C++23.
|
|
40
|
+
include(GNUInstallDirs)
|
|
41
|
+
add_library(lunad INTERFACE)
|
|
42
|
+
add_library(lunad::lunad ALIAS lunad)
|
|
43
|
+
target_include_directories(lunad INTERFACE "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
|
|
44
|
+
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
|
45
|
+
target_compile_features(lunad INTERFACE cxx_std_23)
|
|
46
|
+
target_link_libraries(lunad INTERFACE "$<BUILD_INTERFACE:${_lunad_eigen}>" "$<INSTALL_INTERFACE:Eigen3::Eigen>")
|
|
47
|
+
|
|
48
|
+
# cmake --install: the headers and lunadConfig.cmake, for find_package( lunad ) and the target lunad::lunad.
|
|
49
|
+
option(LUNAD_INSTALL "Install the headers and the CMake package" ${PROJECT_IS_TOP_LEVEL})
|
|
50
|
+
if(LUNAD_INSTALL AND NOT SKBUILD)
|
|
51
|
+
include(CMakePackageConfigHelpers)
|
|
52
|
+
set(_lunad_cmake_dir "${CMAKE_INSTALL_DATADIR}/cmake/lunad") # header-only: architecture-independent
|
|
53
|
+
install(TARGETS lunad EXPORT lunadTargets)
|
|
54
|
+
install(DIRECTORY include/lunad DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
|
55
|
+
install(EXPORT lunadTargets NAMESPACE lunad:: DESTINATION "${_lunad_cmake_dir}")
|
|
56
|
+
configure_package_config_file(cmake/lunadConfig.cmake.in "${PROJECT_BINARY_DIR}/lunadConfig.cmake"
|
|
57
|
+
INSTALL_DESTINATION "${_lunad_cmake_dir}")
|
|
58
|
+
write_basic_package_version_file("${PROJECT_BINARY_DIR}/lunadConfigVersion.cmake"
|
|
59
|
+
COMPATIBILITY SameMinorVersion ARCH_INDEPENDENT)
|
|
60
|
+
install(FILES "${PROJECT_BINARY_DIR}/lunadConfig.cmake" "${PROJECT_BINARY_DIR}/lunadConfigVersion.cmake"
|
|
61
|
+
DESTINATION "${_lunad_cmake_dir}")
|
|
62
|
+
endif()
|
|
63
|
+
|
|
64
|
+
if(LUNAD_BUILD_TESTS)
|
|
65
|
+
enable_testing()
|
|
66
|
+
set(CMAKE_CXX_STANDARD 23)
|
|
67
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
68
|
+
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
69
|
+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
70
|
+
# No FMA contraction, no fast-math: the tests' bitwise comparisons hold on every machine.
|
|
71
|
+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-ffp-contract=off>)
|
|
72
|
+
if(LUNAD_SANITIZE)
|
|
73
|
+
add_compile_options(-fsanitize=${LUNAD_SANITIZE} -fno-omit-frame-pointer -fno-sanitize-recover=undefined)
|
|
74
|
+
add_link_options(-fsanitize=${LUNAD_SANITIZE})
|
|
75
|
+
add_compile_definitions(_GLIBCXX_ASSERTIONS)
|
|
76
|
+
endif()
|
|
77
|
+
|
|
78
|
+
FetchContent_Declare(Catch2
|
|
79
|
+
URL https://github.com/catchorg/Catch2/archive/refs/tags/v3.16.1.tar.gz
|
|
80
|
+
URL_HASH SHA256=d16bd1b8b2364918bd472cb216394acb93bde6784890df0d91bccfb3f28d777d
|
|
81
|
+
DOWNLOAD_EXTRACT_TIMESTAMP ON
|
|
82
|
+
SYSTEM)
|
|
83
|
+
FetchContent_MakeAvailable(Catch2)
|
|
84
|
+
list(APPEND CMAKE_MODULE_PATH "${catch2_SOURCE_DIR}/extras")
|
|
85
|
+
include(Catch)
|
|
86
|
+
|
|
87
|
+
set(_lunad_warnings -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wshadow -Wdouble-promotion -Wundef)
|
|
88
|
+
if(LUNAD_WERROR)
|
|
89
|
+
list(APPEND _lunad_warnings -Werror)
|
|
90
|
+
endif()
|
|
91
|
+
|
|
92
|
+
# Each header compiles on its own.
|
|
93
|
+
file(GLOB _lunad_headers CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/include/lunad/*.hpp")
|
|
94
|
+
set(_lunad_header_tus "")
|
|
95
|
+
foreach(_h IN LISTS _lunad_headers)
|
|
96
|
+
get_filename_component(_name "${_h}" NAME_WE)
|
|
97
|
+
set(_tu "${PROJECT_BINARY_DIR}/headers/${_name}.cpp")
|
|
98
|
+
file(CONFIGURE OUTPUT "${_tu}" CONTENT "#include \"lunad/${_name}.hpp\"\n")
|
|
99
|
+
list(APPEND _lunad_header_tus "${_tu}")
|
|
100
|
+
endforeach()
|
|
101
|
+
add_library(lunad_headers OBJECT ${_lunad_header_tus})
|
|
102
|
+
target_link_libraries(lunad_headers PRIVATE lunad::lunad)
|
|
103
|
+
target_compile_options(lunad_headers PRIVATE ${_lunad_warnings})
|
|
104
|
+
|
|
105
|
+
add_executable(lunad_tests tests/test_dual.cpp tests/test_storage.cpp tests/test_vector_dual.cpp
|
|
106
|
+
tests/test_derivatives.cpp tests/test_format.cpp)
|
|
107
|
+
target_link_libraries(lunad_tests PRIVATE lunad::lunad Catch2::Catch2WithMain)
|
|
108
|
+
target_compile_options(lunad_tests PRIVATE ${_lunad_warnings})
|
|
109
|
+
catch_discover_tests(lunad_tests TEST_PREFIX "lunad: " DISCOVERY_MODE PRE_TEST)
|
|
110
|
+
|
|
111
|
+
# The README's example and the guide's (docs/guide), each a program that checks its own answer.
|
|
112
|
+
add_executable(lunad_readme examples/readme.cpp)
|
|
113
|
+
target_link_libraries(lunad_readme PRIVATE lunad::lunad)
|
|
114
|
+
target_compile_options(lunad_readme PRIVATE ${_lunad_warnings})
|
|
115
|
+
add_test(NAME "lunad: the README's example" COMMAND lunad_readme)
|
|
116
|
+
foreach(_example IN ITEMS getting_started generic)
|
|
117
|
+
add_executable(lunad_example_${_example} examples/${_example}.cpp)
|
|
118
|
+
target_link_libraries(lunad_example_${_example} PRIVATE lunad::lunad)
|
|
119
|
+
target_compile_options(lunad_example_${_example} PRIVATE ${_lunad_warnings})
|
|
120
|
+
add_test(NAME "lunad: example ${_example}.cpp" COMMAND lunad_example_${_example})
|
|
121
|
+
endforeach()
|
|
122
|
+
|
|
123
|
+
# Device code: the kernels by nvcc (FMA contraction off, so that the device's results are bitwise the host's), the
|
|
124
|
+
# test by the host compiler, which never sees CUDA.
|
|
125
|
+
if(LUNAD_CUDA)
|
|
126
|
+
enable_language(CUDA)
|
|
127
|
+
# CMake 4.2 does not yet know that nvcc 13 accepts -std=c++23; the flag given until it does.
|
|
128
|
+
if(NOT CMAKE_CUDA23_STANDARD_COMPILE_OPTION)
|
|
129
|
+
set(CMAKE_CUDA23_STANDARD_COMPILE_OPTION "-std=c++23")
|
|
130
|
+
set(CMAKE_CUDA23_EXTENSION_COMPILE_OPTION "-std=c++23")
|
|
131
|
+
endif()
|
|
132
|
+
find_package(CUDAToolkit REQUIRED)
|
|
133
|
+
add_library(lunad_cuda_kernels STATIC tests/cuda/dual_kernels.cu)
|
|
134
|
+
target_link_libraries(lunad_cuda_kernels PUBLIC lunad::lunad CUDA::cudart)
|
|
135
|
+
# Eigen's constexpr functions are called from device code (--expt-relaxed-constexpr), as in any Eigen kernel.
|
|
136
|
+
target_compile_options(lunad_cuda_kernels PRIVATE
|
|
137
|
+
$<$<COMPILE_LANGUAGE:CUDA>:--fmad=false;-Xcompiler=-ffp-contract=off;--expt-relaxed-constexpr>)
|
|
138
|
+
set_target_properties(lunad_cuda_kernels PROPERTIES CUDA_STANDARD 23 CUDA_STANDARD_REQUIRED ON)
|
|
139
|
+
add_executable(lunad_cuda_tests tests/cuda/test_dual_cuda.cpp)
|
|
140
|
+
target_link_libraries(lunad_cuda_tests PRIVATE lunad_cuda_kernels Catch2::Catch2WithMain)
|
|
141
|
+
target_compile_options(lunad_cuda_tests PRIVATE ${_lunad_warnings})
|
|
142
|
+
catch_discover_tests(lunad_cuda_tests TEST_PREFIX "lunad: " DISCOVERY_MODE PRE_TEST)
|
|
143
|
+
endif()
|
|
144
|
+
endif()
|
|
145
|
+
|
|
146
|
+
if(LUNAD_PYTHON)
|
|
147
|
+
add_subdirectory(python)
|
|
148
|
+
endif()
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 8,
|
|
3
|
+
"cmakeMinimumRequired": {
|
|
4
|
+
"major": 3,
|
|
5
|
+
"minor": 30,
|
|
6
|
+
"patch": 0
|
|
7
|
+
},
|
|
8
|
+
"configurePresets": [
|
|
9
|
+
{
|
|
10
|
+
"name": "base",
|
|
11
|
+
"hidden": true,
|
|
12
|
+
"generator": "Ninja",
|
|
13
|
+
"binaryDir": "${sourceDir}/build/${presetName}",
|
|
14
|
+
"cacheVariables": {
|
|
15
|
+
"CMAKE_BUILD_TYPE": "Debug",
|
|
16
|
+
"LUNAD_WERROR": "ON",
|
|
17
|
+
"CMAKE_CXX_COMPILER_LAUNCHER": "ccache"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "gcc",
|
|
22
|
+
"displayName": "GCC 16, debug",
|
|
23
|
+
"inherits": "base",
|
|
24
|
+
"toolchainFile": "${sourceDir}/cmake/toolchains/gcc16.cmake"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "gate",
|
|
28
|
+
"inherits": "gcc",
|
|
29
|
+
"displayName": "The gate's build: GCC at -O2 -g with assertions (NDEBUG not defined)",
|
|
30
|
+
"cacheVariables": {
|
|
31
|
+
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
|
|
32
|
+
"CMAKE_CXX_FLAGS_RELWITHDEBINFO": "-O2 -g",
|
|
33
|
+
"LUNAD_PYTHON": "ON",
|
|
34
|
+
"Python_EXECUTABLE": "${sourceDir}/.venv-python/bin/python"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "clang",
|
|
39
|
+
"displayName": "Clang 22, debug",
|
|
40
|
+
"inherits": "base",
|
|
41
|
+
"toolchainFile": "${sourceDir}/cmake/toolchains/clang22.cmake",
|
|
42
|
+
"cacheVariables": {
|
|
43
|
+
"CMAKE_EXE_LINKER_FLAGS": "-fuse-ld=mold",
|
|
44
|
+
"LUNAD_PYTHON": "ON",
|
|
45
|
+
"Python_EXECUTABLE": "${sourceDir}/.venv-python/bin/python"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"name": "asan",
|
|
50
|
+
"displayName": "Clang 22, AddressSanitizer + UndefinedBehaviorSanitizer",
|
|
51
|
+
"inherits": "clang",
|
|
52
|
+
"cacheVariables": {
|
|
53
|
+
"LUNAD_SANITIZE": "address,undefined",
|
|
54
|
+
"LUNAD_PYTHON": "OFF"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": "cuda",
|
|
59
|
+
"displayName": "GCC 16 with CUDA 13.5's nvcc: the device tests (sm_86, sm_75); CUDA_ARCHITECTURES to override",
|
|
60
|
+
"inherits": "gate",
|
|
61
|
+
"cacheVariables": {
|
|
62
|
+
"LUNAD_CUDA": "ON",
|
|
63
|
+
"CMAKE_CUDA_COMPILER": "/usr/local/cuda-13.5/bin/nvcc",
|
|
64
|
+
"CMAKE_CUDA_ARCHITECTURES": "86;75",
|
|
65
|
+
"LUNAD_PYTHON": "OFF"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"buildPresets": [
|
|
70
|
+
{
|
|
71
|
+
"name": "gcc",
|
|
72
|
+
"configurePreset": "gcc"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"name": "gate",
|
|
76
|
+
"configurePreset": "gate"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"name": "clang",
|
|
80
|
+
"configurePreset": "clang"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"name": "asan",
|
|
84
|
+
"configurePreset": "asan"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"name": "cuda",
|
|
88
|
+
"configurePreset": "cuda"
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
"testPresets": [
|
|
92
|
+
{
|
|
93
|
+
"name": "base",
|
|
94
|
+
"hidden": true,
|
|
95
|
+
"output": {
|
|
96
|
+
"outputOnFailure": true
|
|
97
|
+
},
|
|
98
|
+
"execution": {
|
|
99
|
+
"noTestsAction": "error",
|
|
100
|
+
"jobs": 12
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"name": "gcc",
|
|
105
|
+
"inherits": "base",
|
|
106
|
+
"configurePreset": "gcc"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"name": "gate",
|
|
110
|
+
"inherits": "base",
|
|
111
|
+
"configurePreset": "gate"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"name": "clang",
|
|
115
|
+
"inherits": "base",
|
|
116
|
+
"configurePreset": "clang"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"name": "asan",
|
|
120
|
+
"inherits": "base",
|
|
121
|
+
"configurePreset": "asan"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"name": "cuda",
|
|
125
|
+
"inherits": "base",
|
|
126
|
+
"configurePreset": "cuda"
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
}
|