Skip to main content

Piece-wise interpolation and lazy evaluation in cython

Project description

bpf4

wheels

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')

1

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()  

2

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bpf4-1.14.0-cp313-cp313-win_amd64.whl (446.3 kB view details)

Uploaded CPython 3.13Windows x86-64

bpf4-1.14.0-cp313-cp313-win32.whl (392.1 kB view details)

Uploaded CPython 3.13Windows x86

bpf4-1.14.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

bpf4-1.14.0-cp313-cp313-macosx_11_0_arm64.whl (461.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

bpf4-1.14.0-cp313-cp313-macosx_10_13_x86_64.whl (511.0 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

bpf4-1.14.0-cp312-cp312-win_amd64.whl (446.6 kB view details)

Uploaded CPython 3.12Windows x86-64

bpf4-1.14.0-cp312-cp312-win32.whl (391.8 kB view details)

Uploaded CPython 3.12Windows x86

bpf4-1.14.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

bpf4-1.14.0-cp312-cp312-macosx_11_0_arm64.whl (464.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

bpf4-1.14.0-cp312-cp312-macosx_10_13_x86_64.whl (513.8 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

bpf4-1.14.0-cp311-cp311-win_amd64.whl (451.3 kB view details)

Uploaded CPython 3.11Windows x86-64

bpf4-1.14.0-cp311-cp311-win32.whl (397.8 kB view details)

Uploaded CPython 3.11Windows x86

bpf4-1.14.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

bpf4-1.14.0-cp311-cp311-macosx_11_0_arm64.whl (462.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

bpf4-1.14.0-cp311-cp311-macosx_10_9_x86_64.whl (512.8 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

bpf4-1.14.0-cp310-cp310-win_amd64.whl (446.0 kB view details)

Uploaded CPython 3.10Windows x86-64

bpf4-1.14.0-cp310-cp310-win32.whl (396.5 kB view details)

Uploaded CPython 3.10Windows x86

bpf4-1.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

bpf4-1.14.0-cp310-cp310-macosx_11_0_arm64.whl (460.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

bpf4-1.14.0-cp310-cp310-macosx_10_9_x86_64.whl (509.7 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file bpf4-1.14.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: bpf4-1.14.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 446.3 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for bpf4-1.14.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c2787a3fda99c3f3525613e8305a6e4389520d0f09301ab0c269b9e256fe756d
MD5 68adec31812d7ec44892a5279ba4463e
BLAKE2b-256 a5fa879d5453d0092830bc245880d06d4eada36994de74c168faf85e2a5b2a82

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp313-cp313-win32.whl.

File metadata

  • Download URL: bpf4-1.14.0-cp313-cp313-win32.whl
  • Upload date:
  • Size: 392.1 kB
  • Tags: CPython 3.13, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for bpf4-1.14.0-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 274e152e873a0700cbce1c49b3cc16cdb9e07c9383bce5a228b8f9af954ccae9
MD5 42d2c61448f622a953465524c24251eb
BLAKE2b-256 af6b6cb30fee1d7bb0803de0cc6c2b635c24ff62edf81b4070b5bc5e09b0881b

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bpf4-1.14.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0b8b6fe2f2e1bd6fe31c80504756a58ea2490e625e9ab10aba8d8ab3033374b2
MD5 108e4a072761a4ff0410b11101d700c0
BLAKE2b-256 50ea7e27acc7e29a6fb656fc04278678fd35570d5d2b4971b7b0684ab631cd9a

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bpf4-1.14.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 612eea75b27e47d7529b638b9dcc5686141c4982e504374732ec75c118f95ee6
MD5 94e02f6bc7f6a112a3ef498b929ccf4e
BLAKE2b-256 5941fada1ea0677614274fb42b0222feaeff0878339fa5d0e4754276f9c1e456

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for bpf4-1.14.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 1486d26e98565571e5e49453233ffb9454b0c625c097386546ac5b052741b068
MD5 1386ad925da6398988bd217ae11adf57
BLAKE2b-256 d342d27aaff7e53af0a31921d81f771c4661c6081944d3cf265cdad018388074

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: bpf4-1.14.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 446.6 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for bpf4-1.14.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 679ecf3db8614d75a4dad5a08cf52e086de08bf179800a784af3ab18724f3d2a
MD5 5ef48ac9f81d8919eb0426fe4bd28afb
BLAKE2b-256 8e87bd472226068ee132566cf4f7eefac3ffc1ad63dc5229c7c2130ea367f73c

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp312-cp312-win32.whl.

File metadata

  • Download URL: bpf4-1.14.0-cp312-cp312-win32.whl
  • Upload date:
  • Size: 391.8 kB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for bpf4-1.14.0-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 3652baf5819a795cd55e3ea9927ad5d67d4788aca1edb299dce10567f2fa551a
MD5 d9fc6627691f60af82a0c253a365a45c
BLAKE2b-256 de9bbe03b7467b1a5f2740dd555a14430ef4f3f2ec3857bed4aae2e63334d70e

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bpf4-1.14.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3cbcaaa89297aa6890d52ac645ce3458eadb0a97446e192394c81cb6cfc058f3
MD5 77ea751ee8d9c9cda6264054b03bc82f
BLAKE2b-256 c86aa99add017dfa046cc2635cc20f614e5f7187a853aeb36440287351b901d9

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bpf4-1.14.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 28ffe800da12181b76555c8fe861a3971b0c329337f92b3cb7cd181662c411eb
MD5 4c1cbd7aeba9b8c945a14bc9b45b2622
BLAKE2b-256 f589d0293d4cab2e293bedb34c1844af8facdfac12e92236fa543aaf301fef99

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for bpf4-1.14.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 a73d83ddd4803b9d0c9eb6cdb4f458bc98af6bfa2c2e77dd228547b0608c319c
MD5 ccd2972ed1002a2a9f4c4b8fe794f7e3
BLAKE2b-256 c42e6100130757baea0164c7fbaf201d7beeed6cc714db8d4ab0bbf7aae5ce0e

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: bpf4-1.14.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 451.3 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for bpf4-1.14.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0c66963f8910a7427c5a770bc62b5110d11bfbc1c0ed366373b3b979c3c06424
MD5 b16e1791c0e9698dfa6cf48acdf49fb9
BLAKE2b-256 2e2b8bdf2a8f1c0c652a205dacc3e6adb502dd095ed50467392fcffa1db0b2bd

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp311-cp311-win32.whl.

File metadata

  • Download URL: bpf4-1.14.0-cp311-cp311-win32.whl
  • Upload date:
  • Size: 397.8 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for bpf4-1.14.0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 737e3bf0a8694dbbc45b10e2c07fd5985818843c135b10f6fd32b10633df29f2
MD5 1e255cae8afe5319243054a648abba18
BLAKE2b-256 858596f4dbd109f016dac5d26623fd446ae32fdb541ecc85f22697a28eeae6da

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bpf4-1.14.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e266ebbc8bfce04b8c034d60f1196e0e30e77bd6b6a2a8c00e272278fc4b8597
MD5 3331c462a51906acc56f73e2dfa19061
BLAKE2b-256 283debf0e10205dd1fa3caebd3cb7c8b28390908f8df6277b8b52300e7b61cda

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bpf4-1.14.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c72d3bbdf066c8e3453891f5a4953515dfc884c35d1803b7b2b7481068238bcc
MD5 2def283222b0f73c916fa128b8843840
BLAKE2b-256 21596375826d254c72bdc417a7e7e61483fdffd919727a0806d40f42eda0eca4

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for bpf4-1.14.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3766555285c76178208233a719f59cecc7316e85932fc8da403eedb8739f150c
MD5 5a177eaf7e8113163ae115dccd30bd5e
BLAKE2b-256 7899e544d1aa3288459fc2512614e555c1752f103b4d0ea6cf2e3e936b5e884c

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: bpf4-1.14.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 446.0 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for bpf4-1.14.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b6e0f6ee2e3fdbcab97c20c3072a76a2dadb7248069ad221c41c00544297b4d1
MD5 5d302712802232906d29e401e6734a9f
BLAKE2b-256 0f8439d5fadab3abb03f44b46332ee9eb59d0623b7d76ead8a0e8e4c51bc2c35

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp310-cp310-win32.whl.

File metadata

  • Download URL: bpf4-1.14.0-cp310-cp310-win32.whl
  • Upload date:
  • Size: 396.5 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for bpf4-1.14.0-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 3bc3d16aa1663db4b82b1808f4af3c65ca29896ceaa0f31d68a55227639d8aa1
MD5 08a06d8e803aa6cd4ab748325a3fcae7
BLAKE2b-256 36a84894f320b5aafd1b9c60c0fd2a36f2d8287be11173e4a7dd6ea18b8f3c17

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bpf4-1.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 96456c44cfa22158c03f7dd5949092e4af1dba41ad83191c18d3b617efc84ee1
MD5 9bc9e5fd43019bc029df148df591a135
BLAKE2b-256 4aceb0808923dcc010e37329103d4da1bdd689bae333620e61791013509deee2

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bpf4-1.14.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 53201ca52c0ebfa1c4002add02e47726e591dc33c91395ba5f725d2aa28c55fc
MD5 eaeda02ff7a983c098e2954f4588be17
BLAKE2b-256 28920cedd3b5bee81d2d3cc1443bbdeb0926561a1c758fa5923e5bf53ae72967

See more details on using hashes here.

File details

Details for the file bpf4-1.14.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for bpf4-1.14.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4f1a2592ad9c1ec47d677678bee13a77849623bbf95d2b415ba61a6e148cc570
MD5 f0fc138f72851262ad96614707152969
BLAKE2b-256 62b74cf20b9d3836c748274d27e2c1d7800575630c845bbdc6bdc208e3011b0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page