Efficient combining of intervals of numbers.
Project description
intervalues
Efficient combining of intervals of numbers for various applications.
Getting started
To download and install the most recent version, use pip:
pip install intervalues
.
Then, consider this simple example for how to use it:
import intervalues as iv
interval_a = iv.BaseInterval(0, 2) # Interval from 0 to 2
interval_b = iv.BaseInterval(1, 3) # Another interval, from 1 to 3
combined = iv.IntervalMeter([interval_a, interval_b])
combined # -> IntervalMeter:{BaseInterval[0;0.5]: 1, BaseInterval[0.5;1]: 2, BaseInterval[1;1.5]: 1}
combined[1.5] # -> 2
For more extensive examples, see the examples folder (which, admittedly, needs to be improved and extended).
Motivation
This package will be useful in the following cases:
- If you have too many intervals and can't easily see which value is featured the most across them.
- If you have a large number of integers to keep track of, and you need to do this more memory efficient than a list of all individual numbers
- If you have a list of continuous intervals that need to be combined
- If you want to use a collection of intervals for statistical purposes, like sampling a random number from it
Features
Contains the following classes:
- IntervalSet (optimized towards keeping track of coverage)
- IntervalList (unstructured collection - faster to create, and can apply FIFO-type decisions)
- IntervalCounter (optimized towards tracking counts, integer-valued and positive)
- IntervalMeter (optimized towards tracking values assigned to individual numbers)
- IntervalPdf (normalized IntervalMeter for statistical purposes)
Currently only continuous intervals of floats are supported, for which the distinction between open and closed intervals is ignored. In the future, this distinction will be taken into account, as well as only considering integers or otherwise discrete intervals (only odd numbers, or only multiples of 0.25, etc.)
There is support for using Rust for combining intervals, which reduces runtime roughly by half for bigger datasets. This is currently optional, and can be used in one of 2 ways:
- Calling
combine_via_rust
with a list of BaseIntervals. - Creating an IntervalMeter object with a list of BaseIntervals and
use_rust=True
.
Note that both will convert all numbers to Integers by default. In case you want to use floats, you can specify the
number of decimals to keep by supplying the input nr_digits=..
via either method. Note that numeric issues might occur
so it might be needed to round the numbers again when they come back (or alternatively, just use the Python
calculations).
In case an IntervalCounter or IntervalSet is requested, the output can be converted to either. There are plans to also make it possible to directly construct those via Rust (which especially for the set might matter). After the functionality is more stabilized and better-tested it might become the default.
Extended future wish list
- As stated above, conversion of continuous intervals to discrete intervals
- As stated above, the distinction between open and closed intervals.
- Allowing for infinity as upper bound (or -infinity as lower bound)
- Sampling from any of these interval collections, where applicable
- Multi-dimensional intervals (e.g. regions, volumes, etc)
- Fully documented and type-hinted code when the codebase is more stable
- Using intervals for more generic (e.g. non-numeric) tracking of properties: [0,2] is green, [1.8,2.5] is sweet, etc.
- IntervalFunctions: getting different functional outputs for different intervals
- Add more examples, and improve the existing ones.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file intervalues-0.3.0.tar.gz
.
File metadata
- Download URL: intervalues-0.3.0.tar.gz
- Upload date:
- Size: 27.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 PyPy/7.3.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 551b4c2fea5e7e9c893a6df846756fe5d173fe900492c04034df12e48b837471 |
|
MD5 | 1ba7bd9898933179d2934e38e30bbb74 |
|
BLAKE2b-256 | 01495ee6670b534737428d3a39c684deba0efc3a082abc2b6579922ca1ffa166 |
File details
Details for the file intervalues-0.3.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: intervalues-0.3.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 267.1 kB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 PyPy/7.3.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0260e77510f06506ca57cb162dc42069d566b24ef9d34828de68347a4df670e |
|
MD5 | 72e418db92057b64e923864575c8e53a |
|
BLAKE2b-256 | 7d4948f10ae787f693b46b7147ece6f6a08dfc598913707da585e704cb641dd0 |
File details
Details for the file intervalues-0.3.0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: intervalues-0.3.0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 267.2 kB
- Tags: CPython 3.13t, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 PyPy/7.3.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44e5382e94c21ea752a0f977c5f7d409860331835e5eed862665672f9dd930aa |
|
MD5 | 6428c520cda8baf571b7fa4e0fc1172b |
|
BLAKE2b-256 | 285ecd12309c4f07460e7d0d8bfe67eaea37f2aa7c72b9827315a9aaa627b512 |
File details
Details for the file intervalues-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: intervalues-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 267.2 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 PyPy/7.3.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbeeb7c79ec934d34ce843a976dcd2c2b5a88e6bda332faad72dbc6ba9e320ee |
|
MD5 | e38241fd4249ddd44bcab47ed074970a |
|
BLAKE2b-256 | 9e301589f2778baa59a811ffc40286ea544b25ddedee2051d0a92d1071d8f01b |
File details
Details for the file intervalues-0.3.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
.
File metadata
- Download URL: intervalues-0.3.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
- Upload date:
- Size: 267.2 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 PyPy/7.3.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c55680e9b8e92b8a9689ee7d214acf7bef572e4294fc760749e5340ec70eb878 |
|
MD5 | 8423ce740c84d27ed822d79a3f369e66 |
|
BLAKE2b-256 | 103224aa239ede8d839dca0bee5010fd0558c90332f455b96740180d401e8ca6 |
File details
Details for the file intervalues-0.3.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
.
File metadata
- Download URL: intervalues-0.3.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
- Upload date:
- Size: 267.2 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 PyPy/7.3.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74c6ba3b2a3ab5dc303a319a0f876e103bdc5975a8432ec3b822db8b96f753f3 |
|
MD5 | da7d20cfae89cb29da6000c48d00f075 |
|
BLAKE2b-256 | e5e77fd54676c2de1e9e7f789e8593df04971b847cfe06f88ea6bc0d5a2a58c1 |
File details
Details for the file intervalues-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: intervalues-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 267.2 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 PyPy/7.3.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e679865a4a22e07a4ef9f457e124548ee915c1894b771829a1fbcb3244f59bdc |
|
MD5 | b62b2f8da40de88ba2ff4ae44bbc5e7b |
|
BLAKE2b-256 | def455b9b3eb488f890392e397fa0ed347470575053bebbaecd187edda662ac2 |
File details
Details for the file intervalues-0.3.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
.
File metadata
- Download URL: intervalues-0.3.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
- Upload date:
- Size: 267.2 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 PyPy/7.3.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5df811651653a9a0782a0f5c14a610ef7c8a274bbc4244e1d85cd0a4924d52b |
|
MD5 | 6949e65a0165584309cbd17c3b26a2d6 |
|
BLAKE2b-256 | 3a5b43864db3989d637cc20f457520c124f82a418d6ca3425ad466756f8ff8a8 |