prodius
Calculating cartesian product is not easy if not using itertools.product().
Prodius library allows to perform the same but also allowing iterables to
be callables that return iterable. Provided callables will be called when
iterable is needed to calculate cartesian product.
itertools.product() ofsen raise MemoryError when one of iterables is too
large. No matter matter the size of iterable, prodius will never write
whole iterator into memory.
Issues
- Iterables cannot be more than 11.
- Maybe be slower than
itertools.product().
Installing
Prodius can be installed with pip in your command-line.
pip install prodius
Usage
Prodius is just easy just like builtin itertools.product().
Realise that this wont offer any benefit as iterator are passed direcly.
import prodius
iterables = [range(10), range(10)]
for item in prodius.product(*iterables, repeat=2):
print(item)
Prodius also allows iterables to contain callable that returns iterable.
The difference is that functions were used as iterables which provide iterables on demand.
import prodius
iterables = [lambda: range(10), lambda: range(10)]
for item in prodius.product(*iterables, repeat=2):
print(item)
This compares itertools.product() with prodius.product().
import prodius
# prodius.product() is used to calculate cartesian product.
# No exception or MemoryError expected even if iterables are large.
iterables = [lambda: range(10000000000), lambda: range(10000000000)]
product = prodius.product(*iterables) # works as espected
import itertools
# itertools.product() is used to calculate cartesian product.
# MemoryError expected as iterables are too large.
iterables = [range(10000000000), range(10000000000)]
product = itertools.product(*iterables) # MemoryError
Prodius also gives control of over items of iterable to be used in cartesian
product. That could be accomplised using itertools.cycle() by returning
different iterable each time function is called.
import prodius
import itertools
foods_numbers_list = [[1,2], ["apple", "orange"]]
foods_numbers_cycle = itertools.cycle(foods_numbers_list)
def numbers_foods():
return next(foods_numbers_cycle)
for item in prodius.product([100, 200], numbers_foods):
print(item)
# (100, 1)
# (100, 2)
# (200, 'apple')
# (200, 'orange')
Notice that 100 was matched with numbers (1, 2) while 200 matched with
('apple', 'orange').
Thats a fantastic trick with prodius even if it does not have realworld application but who knows.
License
Metadata
Release files for prodius 0.0.3
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 |
|---|---|---|---|---|
| prodius-0.0.3.tar.gz | 6.0 kB | Without provenance | Details for prodius-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| prodius-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for prodius-0.0.3-py3-none-any.whl |
Total release size: 12.5 kB
Release files / prodius-0.0.3.tar.gz
| Download URL | prodius-0.0.3.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d7fa79c7671090be4d8510e8b7681b9801e348c82dc6c2d9d9cce0879012ea0e
|
|
BLAKE2b-256 checksum How to use checksums |
04cf275ea9e840859326ecd704cfb65b2c9b069b217ba9abfa43c004745071dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.0
|
Release files / prodius-0.0.3-py3-none-any.whl
| Download URL | prodius-0.0.3-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
497b56c70c4f49a1d2f2a047b7bff33eafb57fb1580c307d368c418fb6632046
|
|
BLAKE2b-256 checksum How to use checksums |
bf65f6292c30b8c05f7ca188fe379d91e7013324ab3c268e3f03aed99a128338
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.0
|
Security for prodius 0.0.3
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.