Skip to main content

No project description provided

Project description

pycw_fn - efficient piecewise functions in Python

This package is a Python wrapper around the pcw_fn Rust crate built using maturin. It supports arbitrary piecewise functions on the real line.

Example

This example constructs a few piecewise functions, does some basic arithmetic with them and finally plots them:

import numpy as np
import matplotlib.pyplot as plt
from numpy.polynomial import Polynomial
from pycw_fn import PcwFn

g_0 = PcwFn.from_funcs_and_jumps(
    [
        Polynomial([1, 5, -10], window=np.array([-1., 1.]),
                   domain=np.array([-1., 1.])),
        Polynomial([0, 10, -20, 10], window=np.array([-1., 1.]),
                   domain=np.array([-1., 1.])),
    ],
    [
        0.5,
    ],
)


g_1 = PcwFn.from_funcs_and_jumps(
    [
        Polynomial([0.4*a**2, -4*a, 10], window=np.array([-1., 1.]),
                   domain=np.array([-1., 1.])) for a in range(6)
    ],
    [
        0.1,
        0.3,
        0.5,
        0.7,
        0.9,
    ],
)

b_2 = Polynomial([1/10, -4, 40])
g_2 = PcwFn.from_funcs_and_jumps(
    [b_2(Polynomial([-0.1*a, 1])) for a in range(10)],
    np.linspace(0.1, 1, num=9, endpoint=False),
)

g = g_0 + 5 * g_2

ts = np.linspace(0, 1, num=1000)
ys = g(ts)
plt.plot(ts, ys)
plt.show()

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

pycw_fn-0.1.0.tar.gz (6.6 kB view hashes)

Uploaded Source

Built Distribution

pycw_fn-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl (249.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.34+ x86-64

Supported by

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