Piece-wise interpolation and lazy evaluation in cython
Project description
bpf4
About
bpf4 is a python library to operate with curves in 2D space.
Curves can be defined via breakpoints (break-point functions, hence the name) or using functions. Moreover, curves can be used to build other curves. bpf4 can be used to perform curve fitting, data analysis, plotting, etc. Its core is programmed in cython for efficiency.
Installation
pip install --upgrade bpf4
Documentation
The documentation is hosted at https://bpf4.readthedocs.io
Example
Find the intersection between two curves
from bpf4 import bpf # this imports the api
a = bpf.spline((0, 0), (1, 5), (2, 3), (5, 10)) # each point (x, y)
b = bpf.expon((0, -10), (2,15), (5, 3), exp=3)
a.plot() # uses matplotlib
b.plot()
zeros = (a - b).zeros()
import pylab
pylab.plot(zeros, a.map(zeros), 'o')
Features
Many interpolation types besides linear:
- spline
- univariate splie
- pchip (hermite)
- cosine
- exponential
- logarithmic
- etc.
With the exception of curve-fitting bpfs (splines), interpolation types can be mixed, so that each segment has a different interpolation. Following from the example above:
c = (a + b).sin().abs()
# plot only the range (1.5, 4)
c[1.5:4].plot()
Syntax support for shifting, scaling and slicing a bpf
a >> 2 # a shifted to the right
(a * 5) ^ 2 # scale the x coord by 2, scale the y coord by 5
a[2:2.5] # slice only a portion of the bpf
a[::0.01] # sample the bpf with an interval of 0.01
Derivation / Integration
from bpf4 import *
a = spline((0, 0), (1, 5), (2, 3), (5, 10))
deriv = a.derivative()
integr = a.integrated()
import matplotlib.pyplot as plt
fig, axs = plt.subplots(3, 1, sharex=True, figsize=(16, 8), tight_layout=True)
a.plot(axes=axs[0], show=False)
deriv.plot(axes=axs[1], show=False)
integr.plot(axes=axs[2])
Mathematical operations
Max / Min
a = linear(0, 0, 1, 0.5, 2, 0)
b = expon(0, 0, 2, 1, exp=3)
a.plot(show=False, color="red", linewidth=4, alpha=0.3)
b.plot(show=False, color="blue", linewidth=4, alpha=0.3)
core.Max((a, b)).plot(color="black", linewidth=4, alpha=0.8, linestyle='dotted')
a = linear(0, 0, 1, 0.5, 2, 0)
b = expon(0, 0, 2, 1, exp=3)
a.plot(show=False, color="red", linewidth=4, alpha=0.3)
b.plot(show=False, color="blue", linewidth=4, alpha=0.3)
core.Min((a, b)).plot(color="black", linewidth=4, alpha=0.8, linestyle='dotted')
+, -, *, /
a = linear(0, 0, 1, 0.5, 2, 0)
b = expon(0, 0, 2, 1, exp=3)
a.plot(show=False, color="red", linewidth=4, alpha=0.3)
b.plot(show=False, color="blue", linewidth=4, alpha=0.3)
(a*b).plot(color="black", linewidth=4, alpha=0.8, linestyle='dotted')
a = linear(0, 0, 1, 0.5, 2, 0)
b = expon(0, 0, 2, 1, exp=3)
a.plot(show=False, color="red", linewidth=4, alpha=0.3)
b.plot(show=False, color="blue", linewidth=4, alpha=0.3)
(a**b).plot(color="black", linewidth=4, alpha=0.8, linestyle='dotted')
a = linear(0, 0, 1, 0.5, 2, 0)
b = expon(0, 0, 2, 1, exp=3)
a.plot(show=False, color="red", linewidth=4, alpha=0.3)
b.plot(show=False, color="blue", linewidth=4, alpha=0.3)
((a+b)/2).plot(color="black", linewidth=4, alpha=0.8, linestyle='dotted')
Building functions
A bpf can be used to build complex formulas
Fresnel's Integral: ( S(x) = \int_0^x {sin(t^2)} dt )
t = slope(1)
f = (t**2).sin()[0:10:0.001].integrated()
f.plot()
Polar plots
Any kind of matplotlib plot can be used. For example, polar plots are possible
by creating an axes with polar=True
Cardiod: (\rho = 1 + sin(-\theta) )
from math import *
theta = slope(1, bounds=(0, 2*pi))
r = 1 + (-theta).sin()
ax = plt.axes(polar=True)
ax.set_rticks([0.5, 1, 1.5, 2]); ax.set_rlabel_position(38)
r.plot(axes=ax)
Flower 5: (\rho = 3 + cos(5 * \theta) )
theta = core.Slope(1, bounds=(0, 2*pi))
r = 3 + (5*theta).cos()
ax = plt.axes(polar=True)
r.plot(axes=ax)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file bpf4-1.12.0-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 455.8 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01cbebc580f0957c8e1e334f5685738b937095b95ff45f70148cff8284544cfa |
|
MD5 | 273998d801786e37a8a5dd7cae4b7d27 |
|
BLAKE2b-256 | d848e81c595a47f6a587ff793f60b602ae104958e5e3ce67e74fdfd80614ef2c |
File details
Details for the file bpf4-1.12.0-cp312-cp312-win32.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp312-cp312-win32.whl
- Upload date:
- Size: 400.0 kB
- Tags: CPython 3.12, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 474279a8420248272dde10dbf5d469bb31e0b59ef2ac73343554aec43f48c73c |
|
MD5 | daa178ab636a5eba3d2df131d6a45589 |
|
BLAKE2b-256 | d5b6a2ac1a38ab4635d86bbbc0f9934686d8d41c8fc4f38ba5fd3a28d2809d3c |
File details
Details for the file bpf4-1.12.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c444499cacdf5dcadd3715e444f9bf9c64148764f0428bd06d93b5500b09142 |
|
MD5 | 19aa04d50bdd4eb876682fcbe4523951 |
|
BLAKE2b-256 | befacf0b60cd2c792f80d7733bc9b93e3349f1c608f9f0fcaeb26cbc9645723c |
File details
Details for the file bpf4-1.12.0-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 474.4 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 186e1efea277a9b107be18808a822e8f65751db92a4383334d47e207b89ec020 |
|
MD5 | 318ce05878eefdd36a11a0bb6c74f7c4 |
|
BLAKE2b-256 | a977c8a574e8c1ce9f01d3c484f6c981d73418355fa039e76042cdf4fb74aa66 |
File details
Details for the file bpf4-1.12.0-cp312-cp312-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp312-cp312-macosx_10_13_x86_64.whl
- Upload date:
- Size: 523.1 kB
- Tags: CPython 3.12, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94bb2dbaa1c216710e56b43e4ffbed75f4384a5a33709a06dc2cf9551b7bc9cc |
|
MD5 | ab5d0fe067726362f83880119a3b7186 |
|
BLAKE2b-256 | f9a46621558b097e9de32df008271fd4e58885e58edfe89dd9b1b39bb1e4e93f |
File details
Details for the file bpf4-1.12.0-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 459.9 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e14c6bf7c2daf767541dff20d741a9d71ce726e5cbe11d2c99c88775859ccacb |
|
MD5 | 22eaecc1bbe5074524901a18915017dd |
|
BLAKE2b-256 | 700d81870140fbe35f472e5b3152df026455a88dac19173b3a5a7b539762c0a2 |
File details
Details for the file bpf4-1.12.0-cp311-cp311-win32.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp311-cp311-win32.whl
- Upload date:
- Size: 406.3 kB
- Tags: CPython 3.11, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cab73dddc3d1248e67a5e5ddf9b9bf61d4a6db8c9645bc5ef38a12d6468f401b |
|
MD5 | 3f8b773a9f481ea599a55ac13b344d49 |
|
BLAKE2b-256 | 10311a2cf546b5c2461a6a7e67c4a372f10665425ce4fd714a49ac31e6d754e1 |
File details
Details for the file bpf4-1.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f162d28f3a05796f22c82966f1246368609d7fc5f46bed2c223a63b8bda4b19 |
|
MD5 | 02f4a1f8e0e800b1912e0c6978ee9dd1 |
|
BLAKE2b-256 | 4327921816ed432bcf8aaae129d85c8f7f16d4019ed22685781abfe03af0bf12 |
File details
Details for the file bpf4-1.12.0-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 473.3 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad5963e1745b01da301e5868574e80f9a765a7305bdfe9a02a03a5b64356e268 |
|
MD5 | 996863a152ea727ddd0bb592562ebbe3 |
|
BLAKE2b-256 | 54a0bf72176d9e88d34ee80ab9866ce91d30674a7aa92451f4d68ed8d6f80fe0 |
File details
Details for the file bpf4-1.12.0-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 522.8 kB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8ac5c937ae745b1a534a25b1c631db3c06d1b6a241e8528e517ba61e03d5f3c |
|
MD5 | 217a50ba7986a9eb3e4218fb4885919d |
|
BLAKE2b-256 | 307f8ed101db0fac042d090c21cf71171668ab4976183b5114a95bb3ac2dcb1e |
File details
Details for the file bpf4-1.12.0-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 454.7 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce494aedc8232e5ec133b2461a2909aaf2b693e66f1d361da76121f799252ece |
|
MD5 | 105f9ba5271d7aa1dcc5887270d79109 |
|
BLAKE2b-256 | 693a6b14574cf9bf0b2686d865a6a053dcd0288b60891d9e19a47d8f130a1d60 |
File details
Details for the file bpf4-1.12.0-cp310-cp310-win32.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp310-cp310-win32.whl
- Upload date:
- Size: 405.5 kB
- Tags: CPython 3.10, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc1de193dc8827f6ac18004f9d5802c991f0e58cb18202cd37a62454d7abe0e5 |
|
MD5 | 554fc7f521c19c7cd0a26bb8f807e885 |
|
BLAKE2b-256 | 838f1693d1f05ffa674d603e488415ea3f9f81ae1da90eb787d102d3c562e128 |
File details
Details for the file bpf4-1.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d492949e62e813cc3828a658e3579113534ad8d02f6446cb71411b9d35698527 |
|
MD5 | 077a7e97c094ab670f909ed1563bb2cf |
|
BLAKE2b-256 | a53ba9d380837a33b097bd408417211d6a842a04dce82f63c29ec479221fd13d |
File details
Details for the file bpf4-1.12.0-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 470.5 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15c80b3143f0b119a1ab51662fd5b1b5d95d07b93c93b1a6bda181fca9a48ab6 |
|
MD5 | 7b0e389429bf873d8d346f9747b5cd06 |
|
BLAKE2b-256 | 1a22022cdf5e276f8c221318f65d8e306003fc1a1daeba9e1a91ec540b759ca8 |
File details
Details for the file bpf4-1.12.0-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 518.7 kB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cc61630530945be406756528dc2cfeee8b35d8b6d0477d327a606b5faa219b8 |
|
MD5 | 1f04841ed90a88b9a1e88ad7942c7d17 |
|
BLAKE2b-256 | cef79d8fcc0fe14ee14316611ab8ab4ccb071dcbc36c8e32d3d42d58c55fb46b |
File details
Details for the file bpf4-1.12.0-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 454.8 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a80b2107e5f7b282dc71d5e94f4a5121fdc526944365168b2af2b8d6e7adf99c |
|
MD5 | 792923e7dbaba1313afb2c4b6932db2c |
|
BLAKE2b-256 | 0278b72a170b78f9556a1d22c72e8a99327caac47af566122701d929236226e4 |
File details
Details for the file bpf4-1.12.0-cp39-cp39-win32.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp39-cp39-win32.whl
- Upload date:
- Size: 405.5 kB
- Tags: CPython 3.9, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 013a08a652ab5a9f7b29065d74091879258c4f34b5edb0b61af998a3d1e7b915 |
|
MD5 | 68420ed85c9e46cccb8c3ab0f425a991 |
|
BLAKE2b-256 | e70f5bae21016099dc1bccff534b9c78093ec9a85f5e68671cc8622071314d3b |
File details
Details for the file bpf4-1.12.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8e837ac2da6fda7135c17d41a09fe9557954715d9afbb72929739e9f4b29990 |
|
MD5 | aa5116789a26349af570fa07b2cd5b38 |
|
BLAKE2b-256 | 3c1762421a599de46516abb417d2bb5e517065eeb60882c2663d80f1099229ea |
File details
Details for the file bpf4-1.12.0-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 471.0 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3ee088db083f00875908fdcd396977eeb3def30a8bb4d203f24de6219fee5ae |
|
MD5 | 0a2a20cf2be7771c789e3c37ee9dd08c |
|
BLAKE2b-256 | bf659f3dffeb9059b24e8486efbdf463aafeb644446e9235edaa60a2cea9f152 |
File details
Details for the file bpf4-1.12.0-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: bpf4-1.12.0-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 518.8 kB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b9795fc6d1c7b34db3249e134ba562a67f094e7708c0a010f58a32a15274fa9 |
|
MD5 | cad90c0bb32c18fcddc347f38954a740 |
|
BLAKE2b-256 | 632be39bf623f2313e8fc4f7c5fcf1513a1b32d13513d18c3d887de3f2e1c81a |