Description
general_cartesian_product extends the existing functionality of itertools.product by variable limits. It's possible
to create cartesian products like:
i1 i2 i3
[1, 2, 3] x [1, ..., i1] x [0, ..., i2] =
[
[1, 1, 0]
[1, 1, 1]
[2, 1, 0]
[2, 1, 1]
[2, 2, 0]
[2, 2, 1]
[2, 2, 2]
[3, 1, 0]
[3, 1, 1]
[3, 2, 0]
[3, 2, 1]
[3, 2, 2]
[3, 3, 0]
[3, 3, 1]
[3, 3, 2]
[3, 3, 3]
]
via this config file:
rules = {
'i1': { 'start': 1, 'end': 3, },
'i2': { 'start': 1, 'end': i1, },
'i3': { 'end': i2, },
}
Obviously this example is quite useless, because its the same as [1,2,3]x[1,2,3]x[0,1,2,3]
The whole thing becomes interesting if we have problems like this:
[1, 2, 3] x [1, ..., 3-i1] x [0, ..., 3-i2] =
[
[1, 1, 0]
[1, 1, 1]
[1, 1, 2]
[1, 2, 0]
[1, 2, 1]
[2, 1, 0]
[2, 1, 1]
[2, 1, 2]
]
which is generated by this configuration:
rules = {
'i1': {'start': 1, 'end': 3, },
'i2': {'start': 1, 'end': 3-i1, },
'i3': {'end': 3-i2, },
}
Limitations
Currently the only known limitation is that there must be always at least one constant limit. This means that the output of the cartesian product function will always be finite. To create 'infinite' generator like cartesian products a complete rewrite of this package is probably needed.
Installation
This package depends on sympy (or sage symbolic variables e.g.:i = var('i'))
pip install generalcartesianproduct sympy
Usage
sympy Example:
from sympy import symbols
from generalcartesianproduct.general_cartesian_product import *
i1, i2, u, v = symbols('i1,i2,u,v')
general_cartesian_product([i1, i2, i3])
sage Example:
from generalcartesianproduct.general_cartesian_product import *
m = 4
i1, i2, u, v = var('i1,i2,u,v')
rules = {
'i1': { 'end': m, },
'i2': { 'end': m, },
'u': { 'end': min_symbolic(m-i1, m-i2), },
'v': { 'end': min_symbolic(m-i1, m-i2)-u, }
}
cp = general_cartesian_product([i1, i2, i3], rules)
print(cp)
How to use the rules dictionary.
# simple example with only one dependency
rules = {
'i1': { 'end': m, },
'i2': { 'end': m-i1, },
}
TODO
- better logging
- add exceptions
- make
start,endaccesable viakargs
Metadata
Release files for GeneralCartesianProduct 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| GeneralCartesianProduct-0.1.1.tar.gz | 13.5 kB | Without provenance | Details for GeneralCartesianProduct-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| GeneralCartesianProduct-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for GeneralCartesianProduct-0.1.1-py3-none-any.whl |
Total release size: 27.9 kB
Release files / GeneralCartesianProduct-0.1.1.tar.gz
| Download URL | GeneralCartesianProduct-0.1.1.tar.gz |
|---|---|
| Size | 13.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
556864427ebd4f93d90a00deca273c40ae21634f90be5b1cda07cb8172dbf90f
|
|
BLAKE2b-256 checksum How to use checksums |
6df7a64696e2ff795c900b7238af7ab7f37d34a3bc80bf613c941201f925431c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
|
Release files / GeneralCartesianProduct-0.1.1-py3-none-any.whl
| Download URL | GeneralCartesianProduct-0.1.1-py3-none-any.whl |
|---|---|
| Size | 14.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b0bbc7154b09098a7735b6b77199b5203c29519c97a37690c656f9adee35b33c
|
|
BLAKE2b-256 checksum How to use checksums |
cf399d45f31225bb399f3713bc1654854b525fccd8bb395557d756b1406d3b34
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
|
Security for GeneralCartesianProduct 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.