prodigy-ppl-ginac 0.0.1__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.
- prodigy_ppl_ginac-0.0.1/.gitignore +6 -0
- prodigy_ppl_ginac-0.0.1/.gitmodules +7 -0
- prodigy_ppl_ginac-0.0.1/CMakeLists.txt +51 -0
- prodigy_ppl_ginac-0.0.1/LICENSE +201 -0
- prodigy_ppl_ginac-0.0.1/PKG-INFO +109 -0
- prodigy_ppl_ginac-0.0.1/README.md +80 -0
- prodigy_ppl_ginac-0.0.1/cmake/modules/FindCLN.cmake +126 -0
- prodigy_ppl_ginac-0.0.1/cmake/modules/FindGiNaC.cmake +156 -0
- prodigy_ppl_ginac-0.0.1/pyproject.toml +77 -0
- prodigy_ppl_ginac-0.0.1/python/bindings.cpp +133 -0
- prodigy_ppl_ginac-0.0.1/python/test.py +35 -0
- prodigy_ppl_ginac-0.0.1/python/test_wheel.py +18 -0
- prodigy_ppl_ginac-0.0.1/scripts/build-deps.sh +65 -0
- prodigy_ppl_ginac-0.0.1/src/Assumptions.cpp +24 -0
- prodigy_ppl_ginac-0.0.1/src/Assumptions.h +26 -0
- prodigy_ppl_ginac-0.0.1/src/CMakeLists.txt +13 -0
- prodigy_ppl_ginac-0.0.1/src/Dist.cpp +1182 -0
- prodigy_ppl_ginac-0.0.1/src/Dist.h +465 -0
- prodigy_ppl_ginac-0.0.1/src/DistributionFactory.cpp +90 -0
- prodigy_ppl_ginac-0.0.1/src/DistributionFactory.h +38 -0
- prodigy_ppl_ginac-0.0.1/src/Exceptions.h +18 -0
- prodigy_ppl_ginac-0.0.1/src/demo.cpp +42 -0
- prodigy_ppl_ginac-0.0.1/src/macros.h +13 -0
- prodigy_ppl_ginac-0.0.1/src/troolean.cpp +23 -0
- prodigy_ppl_ginac-0.0.1/src/troolean.h +24 -0
- prodigy_ppl_ginac-0.0.1/test/CMakeLists.txt +11 -0
- prodigy_ppl_ginac-0.0.1/test/TestDist.cpp +97 -0
- prodigy_ppl_ginac-0.0.1/test/TestEquivalence.cpp +330 -0
- prodigy_ppl_ginac-0.0.1/test/TestFactory.cpp +41 -0
- prodigy_ppl_ginac-0.0.1/test/main.cpp +6 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.15...3.31)
|
|
2
|
+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
|
|
3
|
+
|
|
4
|
+
project(prodigy_ginac LANGUAGES CXX)
|
|
5
|
+
|
|
6
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
7
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
8
|
+
|
|
9
|
+
# The wheel build (pyproject.toml) turns both off, so it needs neither googletest nor the submodules.
|
|
10
|
+
option(PRODIGY_GINAC_BUILD_TESTS "Build the C++ tests (needs the googletest submodule)" ON)
|
|
11
|
+
option(PRODIGY_GINAC_BUILD_DEMO "Build the C++ demo executable" ON)
|
|
12
|
+
# Directory with the license files of GiNaC, CLN and GMP; the wheel build installs them into the wheel.
|
|
13
|
+
set(PRODIGY_GINAC_THIRD_PARTY_LICENSES "" CACHE PATH "Directory with license files of bundled libraries")
|
|
14
|
+
|
|
15
|
+
# find ginac on system and add headers to include path
|
|
16
|
+
find_package(GiNaC REQUIRED)
|
|
17
|
+
include_directories(${GINAC_INCLUDE_DIRS})
|
|
18
|
+
|
|
19
|
+
# so that tests and bindings can easily include the library headers
|
|
20
|
+
include_directories(src)
|
|
21
|
+
|
|
22
|
+
# actual library
|
|
23
|
+
add_subdirectory(src)
|
|
24
|
+
|
|
25
|
+
# tests
|
|
26
|
+
if (PRODIGY_GINAC_BUILD_TESTS)
|
|
27
|
+
add_subdirectory(lib/googletest)
|
|
28
|
+
add_subdirectory(test)
|
|
29
|
+
endif()
|
|
30
|
+
|
|
31
|
+
# python bindings: pybind11 from the Python environment (pip install pybind11), else the submodule
|
|
32
|
+
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
|
|
33
|
+
find_package(pybind11 CONFIG QUIET)
|
|
34
|
+
if (NOT pybind11_FOUND)
|
|
35
|
+
add_subdirectory(lib/pybind11)
|
|
36
|
+
endif()
|
|
37
|
+
pybind11_add_module(prodigy_ginac python/bindings.cpp)
|
|
38
|
+
target_link_libraries(prodigy_ginac PRIVATE ${CMAKE_PROJECT_NAME}_lib)
|
|
39
|
+
if (DEFINED SKBUILD_PROJECT_VERSION)
|
|
40
|
+
target_compile_definitions(prodigy_ginac PRIVATE VERSION_INFO=${SKBUILD_PROJECT_VERSION})
|
|
41
|
+
endif()
|
|
42
|
+
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
43
|
+
# keep the symbols of statically linked GiNaC, CLN and GMP out of the module's dynamic symbol table
|
|
44
|
+
target_link_options(prodigy_ginac PRIVATE "LINKER:--exclude-libs,ALL")
|
|
45
|
+
endif()
|
|
46
|
+
|
|
47
|
+
install(TARGETS prodigy_ginac LIBRARY DESTINATION .)
|
|
48
|
+
if (PRODIGY_GINAC_THIRD_PARTY_LICENSES AND DEFINED SKBUILD_METADATA_DIR)
|
|
49
|
+
install(DIRECTORY "${PRODIGY_GINAC_THIRD_PARTY_LICENSES}/"
|
|
50
|
+
DESTINATION "${SKBUILD_METADATA_DIR}/licenses/third_party")
|
|
51
|
+
endif()
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2022] [Lutz Klinkenberg]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: prodigy-ppl-ginac
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: GiNaC-based Python bindings for manipulating distributions through generating functions, used by Prodigy
|
|
5
|
+
Keywords: probabilistic programs,generating functions,ginac,computer algebra
|
|
6
|
+
Author: Lutz Klinkenberg
|
|
7
|
+
Author-Email: Tobias Winkler <tobias.winkler@cs.rwth-aachen.de>
|
|
8
|
+
License-Expression: Apache-2.0 AND GPL-2.0-or-later
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Operating System :: MacOS
|
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
+
Classifier: Programming Language :: C++
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
22
|
+
Project-URL: Repository, https://github.com/LKlinke/prodigy-ginac-bindings
|
|
23
|
+
Project-URL: Issues, https://github.com/LKlinke/prodigy-ginac-bindings/issues
|
|
24
|
+
Project-URL: Prodigy, https://github.com/LKlinke/Prodigy
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Provides-Extra: test
|
|
27
|
+
Requires-Dist: pytest; extra == "test"
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# prodigy-ppl-ginac: A library for manipulating discrete distributions through generating functions
|
|
31
|
+
|
|
32
|
+
GiNaC-based Python bindings used by [Prodigy](https://github.com/LKlinke/Prodigy) for its fast `ginac` engine.
|
|
33
|
+
|
|
34
|
+
The main features are
|
|
35
|
+
- python bindings
|
|
36
|
+
- a purely string-based interface, no need to mess around with data structures for algebraic expression and the like
|
|
37
|
+
- support for parameters (can also be used as meta symbols in second-order PGFs)
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
pip install prodigy-ppl-ginac
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Prebuilt wheels contain GiNaC, CLN and GMP, so they need neither a compiler nor a system GiNaC.
|
|
46
|
+
They exist for CPython 3.11 to 3.14 on
|
|
47
|
+
- Linux (manylinux_2_28) x86_64 and aarch64,
|
|
48
|
+
- macOS 11 or later, x86_64 and arm64.
|
|
49
|
+
|
|
50
|
+
Windows is not supported.
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
The distribution is called `prodigy-ppl-ginac`, the module `prodigy_ginac`:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
import prodigy_ginac
|
|
58
|
+
dist = prodigy_ginac.geometric("x", "1/2")
|
|
59
|
+
e = dist.E("x") # e becomes 1, the expected value of the 1/2-geometric distribution
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Before it was published on PyPI, the module was installed from Git as `pygin` (version 1.0); the package `pygin` on PyPI
|
|
63
|
+
is an unrelated project.
|
|
64
|
+
|
|
65
|
+
## Building from source
|
|
66
|
+
|
|
67
|
+
On other platforms pip builds the sdist, which needs a C++17 compiler, CMake and a system GiNaC with pkg-config,
|
|
68
|
+
e.g. `brew install ginac pkgconf` on macOS or `apt install libginac-dev pkg-config` on Debian and Ubuntu.
|
|
69
|
+
In a clone of this repository
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
pip install .
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
builds and installs the module.
|
|
76
|
+
|
|
77
|
+
`scripts/build-deps.sh PREFIX` builds the pinned versions of GMP, CLN and GiNaC as static libraries into `PREFIX`,
|
|
78
|
+
as for the wheels; with `CMAKE_PREFIX_PATH=PREFIX` the build uses them instead of the system GiNaC.
|
|
79
|
+
|
|
80
|
+
### Wheels and releases
|
|
81
|
+
|
|
82
|
+
[cibuildwheel](https://cibuildwheel.pypa.io) builds the wheels (configuration in `pyproject.toml`, workflow
|
|
83
|
+
`.github/workflows/wheels.yml`). Pushing a tag `v<version>` (e.g. `v0.0.1`, or `v0.1.0rc1` for a pre-release) publishes the wheels and the sdist with
|
|
84
|
+
this version on PyPI (`.github/workflows/release.yml`). The version is in no file; without a tag, builds get a
|
|
85
|
+
development version such as `0.1.devN`.
|
|
86
|
+
|
|
87
|
+
### C++ tests and demo
|
|
88
|
+
|
|
89
|
+
The C++ tests need the googletest submodule:
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
git submodule update --init
|
|
93
|
+
cmake -B build && cmake --build build
|
|
94
|
+
./build/test/prodigy_ginac_test
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The CMake options `PRODIGY_GINAC_BUILD_TESTS` and `PRODIGY_GINAC_BUILD_DEMO` (both on by default, off for the wheels)
|
|
98
|
+
switch the tests and the demo executable.
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
The source code in this repository is licensed under the Apache License 2.0 (`LICENSE`).
|
|
103
|
+
|
|
104
|
+
The wheels on PyPI also contain statically linked copies of
|
|
105
|
+
[GiNaC](https://www.ginac.de) and [CLN](https://www.ginac.de/CLN/) (GPL-2.0-or-later) and
|
|
106
|
+
[GMP](https://gmplib.org) (LGPL-3.0-or-later or GPL-2.0-or-later). A wheel as a whole is therefore distributed under
|
|
107
|
+
the terms of the GNU General Public License, version 3 or later, the GPL version compatible with the Apache License 2.0.
|
|
108
|
+
The license texts of these libraries are in the wheel's `.dist-info/licenses/third_party` directory; their source
|
|
109
|
+
code is available from the links above, in the versions pinned in `scripts/build-deps.sh`.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# prodigy-ppl-ginac: A library for manipulating discrete distributions through generating functions
|
|
2
|
+
|
|
3
|
+
GiNaC-based Python bindings used by [Prodigy](https://github.com/LKlinke/Prodigy) for its fast `ginac` engine.
|
|
4
|
+
|
|
5
|
+
The main features are
|
|
6
|
+
- python bindings
|
|
7
|
+
- a purely string-based interface, no need to mess around with data structures for algebraic expression and the like
|
|
8
|
+
- support for parameters (can also be used as meta symbols in second-order PGFs)
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
pip install prodigy-ppl-ginac
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Prebuilt wheels contain GiNaC, CLN and GMP, so they need neither a compiler nor a system GiNaC.
|
|
17
|
+
They exist for CPython 3.11 to 3.14 on
|
|
18
|
+
- Linux (manylinux_2_28) x86_64 and aarch64,
|
|
19
|
+
- macOS 11 or later, x86_64 and arm64.
|
|
20
|
+
|
|
21
|
+
Windows is not supported.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
The distribution is called `prodigy-ppl-ginac`, the module `prodigy_ginac`:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
import prodigy_ginac
|
|
29
|
+
dist = prodigy_ginac.geometric("x", "1/2")
|
|
30
|
+
e = dist.E("x") # e becomes 1, the expected value of the 1/2-geometric distribution
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Before it was published on PyPI, the module was installed from Git as `pygin` (version 1.0); the package `pygin` on PyPI
|
|
34
|
+
is an unrelated project.
|
|
35
|
+
|
|
36
|
+
## Building from source
|
|
37
|
+
|
|
38
|
+
On other platforms pip builds the sdist, which needs a C++17 compiler, CMake and a system GiNaC with pkg-config,
|
|
39
|
+
e.g. `brew install ginac pkgconf` on macOS or `apt install libginac-dev pkg-config` on Debian and Ubuntu.
|
|
40
|
+
In a clone of this repository
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
pip install .
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
builds and installs the module.
|
|
47
|
+
|
|
48
|
+
`scripts/build-deps.sh PREFIX` builds the pinned versions of GMP, CLN and GiNaC as static libraries into `PREFIX`,
|
|
49
|
+
as for the wheels; with `CMAKE_PREFIX_PATH=PREFIX` the build uses them instead of the system GiNaC.
|
|
50
|
+
|
|
51
|
+
### Wheels and releases
|
|
52
|
+
|
|
53
|
+
[cibuildwheel](https://cibuildwheel.pypa.io) builds the wheels (configuration in `pyproject.toml`, workflow
|
|
54
|
+
`.github/workflows/wheels.yml`). Pushing a tag `v<version>` (e.g. `v0.0.1`, or `v0.1.0rc1` for a pre-release) publishes the wheels and the sdist with
|
|
55
|
+
this version on PyPI (`.github/workflows/release.yml`). The version is in no file; without a tag, builds get a
|
|
56
|
+
development version such as `0.1.devN`.
|
|
57
|
+
|
|
58
|
+
### C++ tests and demo
|
|
59
|
+
|
|
60
|
+
The C++ tests need the googletest submodule:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
git submodule update --init
|
|
64
|
+
cmake -B build && cmake --build build
|
|
65
|
+
./build/test/prodigy_ginac_test
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The CMake options `PRODIGY_GINAC_BUILD_TESTS` and `PRODIGY_GINAC_BUILD_DEMO` (both on by default, off for the wheels)
|
|
69
|
+
switch the tests and the demo executable.
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
The source code in this repository is licensed under the Apache License 2.0 (`LICENSE`).
|
|
74
|
+
|
|
75
|
+
The wheels on PyPI also contain statically linked copies of
|
|
76
|
+
[GiNaC](https://www.ginac.de) and [CLN](https://www.ginac.de/CLN/) (GPL-2.0-or-later) and
|
|
77
|
+
[GMP](https://gmplib.org) (LGPL-3.0-or-later or GPL-2.0-or-later). A wheel as a whole is therefore distributed under
|
|
78
|
+
the terms of the GNU General Public License, version 3 or later, the GPL version compatible with the Apache License 2.0.
|
|
79
|
+
The license texts of these libraries are in the wheel's `.dist-info/licenses/third_party` directory; their source
|
|
80
|
+
code is available from the links above, in the versions pinned in `scripts/build-deps.sh`.
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# CLN_FOUND CLN has been successfully found
|
|
2
|
+
# CLN_INCLUDE_DIR the include directories
|
|
3
|
+
# CLN_LIBRARIES CLN library and its dependencies (if any)
|
|
4
|
+
|
|
5
|
+
if (CLN_INCLUDE_DIR AND CLN_LIBRARIES)
|
|
6
|
+
set(CLN_FIND_QUIETLY TRUE)
|
|
7
|
+
endif()
|
|
8
|
+
|
|
9
|
+
function(_cl_get_version _out_major _out_minor _out_patch _cl_version_h)
|
|
10
|
+
file(STRINGS ${_cl_version_h} _cl_vinfo REGEX "^#define[\t ]+CL_VERSION_.*")
|
|
11
|
+
if (NOT _cl_vinfo)
|
|
12
|
+
message(FATAL_ERROR "include file ${_cl_version_h} does not exist")
|
|
13
|
+
endif()
|
|
14
|
+
string(REGEX REPLACE "^.*CL_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" ${_out_major} "${_cl_vinfo}")
|
|
15
|
+
string(REGEX REPLACE "^.*CL_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" ${_out_minor} "${_cl_vinfo}")
|
|
16
|
+
string(REGEX REPLACE "^.*CL_VERSION_PATCHLEVEL[ \t]+([0-9]+).*" "\\1" ${_out_patch} "${_cl_vinfo}")
|
|
17
|
+
if (NOT ${_out_major} MATCHES "[0-9]+")
|
|
18
|
+
message(FATAL_ERROR "failed to determine CL_VERSION_MAJOR, "
|
|
19
|
+
"expected a number, got ${${_out_major}}")
|
|
20
|
+
endif()
|
|
21
|
+
if (NOT ${_out_minor} MATCHES "[0-9]+")
|
|
22
|
+
message(FATAL_ERROR "failed to determine CL_VERSION_MINOR, "
|
|
23
|
+
"expected a number, got ${${_out_minor}}")
|
|
24
|
+
endif()
|
|
25
|
+
if (NOT ${_out_patch} MATCHES "[0-9]+")
|
|
26
|
+
message(FATAL_ERROR "failed to determine CL_VERSION_PATCHLEVEL, "
|
|
27
|
+
"expected a number, got ${${_out_patch}}")
|
|
28
|
+
endif()
|
|
29
|
+
message(STATUS "found CLN [${_cl_version_h}], version ${${_out_major}}.${${_out_minor}}.${${_out_patch}}")
|
|
30
|
+
set(${_out_major} ${${_out_major}} PARENT_SCOPE)
|
|
31
|
+
set(${_out_minor} ${${_out_minor}} PARENT_SCOPE)
|
|
32
|
+
set(${_out_patch} ${${_out_patch}} PARENT_SCOPE)
|
|
33
|
+
endfunction()
|
|
34
|
+
|
|
35
|
+
set(CLN_FOUND)
|
|
36
|
+
set(CLN_INCLUDE_DIR)
|
|
37
|
+
set(CLN_LIBRARIES)
|
|
38
|
+
|
|
39
|
+
include(FindPkgConfig)
|
|
40
|
+
if (PKG_CONFIG_FOUND)
|
|
41
|
+
pkg_check_modules(_cln cln)
|
|
42
|
+
endif()
|
|
43
|
+
|
|
44
|
+
find_path(CLN_INCLUDE_DIR NAMES cln/cln.h
|
|
45
|
+
HINTS ${_cln_INCLUDE_DIRS}
|
|
46
|
+
$ENV{CLN_DIR}/include)
|
|
47
|
+
find_library(CLN_LIBRARIES NAMES libcln cln
|
|
48
|
+
HINTS ${_cln_LIBRARY_DIR}
|
|
49
|
+
${_cln_LIBRARY_DIRS}
|
|
50
|
+
$ENV{CLN_DIR}/lib)
|
|
51
|
+
|
|
52
|
+
# A static libcln (as built for the wheels) needs GMP on the link line as well.
|
|
53
|
+
if (CLN_LIBRARIES MATCHES "\\.a$")
|
|
54
|
+
get_filename_component(_cln_static_dir "${CLN_LIBRARIES}" PATH)
|
|
55
|
+
find_library(_cln_gmp_library NAMES libgmp.a gmp HINTS ${_cln_static_dir})
|
|
56
|
+
if (_cln_gmp_library)
|
|
57
|
+
set(CLN_LIBRARIES ${CLN_LIBRARIES} ${_cln_gmp_library})
|
|
58
|
+
endif()
|
|
59
|
+
endif()
|
|
60
|
+
|
|
61
|
+
if (CLN_INCLUDE_DIR)
|
|
62
|
+
_cl_get_version(CLN_VERSION_MAJOR
|
|
63
|
+
CLN_VERSION_MINOR
|
|
64
|
+
CLN_VERSION_PATCHLEVEL
|
|
65
|
+
${CLN_INCLUDE_DIR}/cln/version.h)
|
|
66
|
+
set(CLN_VERSION ${CLN_VERSION_MAJOR}.${CLN_VERSION_MINOR}.${CLN_VERSION_PATCHLEVEL})
|
|
67
|
+
# Check if the version reported by pkg-config is the same
|
|
68
|
+
# as the one read from the header. This prevents us from
|
|
69
|
+
# picking the wrong version of CLN (say, if several versions
|
|
70
|
+
# are installed)
|
|
71
|
+
if (_cln_FOUND AND NOT CLN_VERSION VERSION_EQUAL _cln_VERSION)
|
|
72
|
+
if (NOT CLN_FIND_QUIETLY)
|
|
73
|
+
message(ERROR "pkg-config and version.h disagree, "
|
|
74
|
+
"${_cln_VERSION} vs ${CLN_VERSION}, "
|
|
75
|
+
"please check your installation")
|
|
76
|
+
endif()
|
|
77
|
+
set(CLN_LIBRARIES CLN-NOTFOUND)
|
|
78
|
+
set(CLN_INCLUDE_DIR CLN-NOTFOUND)
|
|
79
|
+
set(CLN_LIBRARY_DIRS)
|
|
80
|
+
set(CLN_VERSION)
|
|
81
|
+
endif()
|
|
82
|
+
endif()
|
|
83
|
+
|
|
84
|
+
# Check if the version embedded into the library is the same as the one in the headers.
|
|
85
|
+
if (CLN_INCLUDE_DIR AND CLN_LIBRARIES AND NOT CMAKE_CROSSCOMPILING)
|
|
86
|
+
include(CheckCXXSourceRuns)
|
|
87
|
+
set(_save_required_includes ${CMAKE_REQUIRED_INCLUDES})
|
|
88
|
+
set(_save_required_libraries ${CMAKE_REQUIRED_LIBRARIES})
|
|
89
|
+
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${CLN_INCLUDE_DIR})
|
|
90
|
+
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${CLN_LIBRARIES})
|
|
91
|
+
check_cxx_source_runs("
|
|
92
|
+
#include <cln/version.h>
|
|
93
|
+
int main() {
|
|
94
|
+
return (CL_VERSION_MAJOR == cln::version_major) &&
|
|
95
|
+
(CL_VERSION_MINOR == cln::version_minor) &&
|
|
96
|
+
(CL_VERSION_PATCHLEVEL == cln::version_patchlevel) ? 0 : 1;
|
|
97
|
+
}
|
|
98
|
+
"
|
|
99
|
+
_cl_version_matches)
|
|
100
|
+
set(CMAKE_REQUIRED_LIBRARIES ${_save_required_libraries})
|
|
101
|
+
set(CMAKE_REQUIRED_INCLUDES ${_save_required_includes})
|
|
102
|
+
if (NOT _cl_version_matches)
|
|
103
|
+
if (NOT CLN_FIND_QUIETLY)
|
|
104
|
+
message(ERROR "header (version differs from the library one, "
|
|
105
|
+
"please check your installation.")
|
|
106
|
+
endif()
|
|
107
|
+
set(CLN_INCLUDE_DIR CLN-NOTFOUND)
|
|
108
|
+
set(CLN_LIBRARIES CLN-NOTFOUND)
|
|
109
|
+
set(CLN_LIBRARY_DIRS)
|
|
110
|
+
set(CLN_VERSION)
|
|
111
|
+
endif()
|
|
112
|
+
endif()
|
|
113
|
+
|
|
114
|
+
if (CLN_LIBRARIES AND CLN_INCLUDE_DIR)
|
|
115
|
+
set(_cln_library_dirs)
|
|
116
|
+
foreach(_l ${CLN_LIBRARIES})
|
|
117
|
+
get_filename_component(_d "${_l}" PATH)
|
|
118
|
+
list(APPEND _cln_library_dirs "${_d}")
|
|
119
|
+
endforeach()
|
|
120
|
+
list(REMOVE_DUPLICATES _cln_library_dirs)
|
|
121
|
+
set(CLN_LIBRARY_DIRS ${_cln_library_dirs})
|
|
122
|
+
endif()
|
|
123
|
+
|
|
124
|
+
include(FindPackageHandleStandardArgs)
|
|
125
|
+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CLN REQUIRED_VARS CLN_LIBRARIES CLN_INCLUDE_DIR
|
|
126
|
+
VERSION_VAR CLN_VERSION)
|