Skip to main content

Polynomials as a numpy datatype

Project description

https://github.com/jonathf/numpoly/raw/master/doc/.static/numpoly_logo.svg

circleci codecov pypi readthedocs

Numpoly is a generic library for creating, manipulating and evaluating arrays of polynomials based on numpy.ndarray objects.

Feature Overview

  • Intuitive interface for users experienced with numpy, as the library provides a high level of compatibility with the numpy.ndarray, including fancy indexing, broadcasting, numpy.dtype, vectorized operations to name a few.

  • Computationally fast evaluations of lots of functionality inherent from numpy.

  • Vectorized polynomial evaluation.

  • Support for arbitrary number of dimensions.

  • Native support for lots of numpy.<name> functions using numpy’s compatibility layer (which also exists as numpoly.<name> equivalents).

  • Support for polynomial division through the operators /, % and divmod.

  • Extra polynomial specific attributes exposed on the polynomial objects like poly.exponents, poly.coefficients, poly.indeterminants etc.

  • Polynomial derivation through functions like numpoly.diff, numpoly.gradient, numpoly.hessian etc.

  • Decompose polynomial sums into vector of addends using numpoly.decompose.

  • Variable substitution through numpoly.call.

numpoly is currently being used as the backend is the uncertainty quantification library chaospy.

Installation

Installation should be straight forward:

pip install numpoly

And you should be ready to go. That is it. You should now be able to import the library in your Python REPL:

>>> import numpoly

Example Usage

Constructing polynomial is typically done using one of the available constructors:

>>> numpoly.monomial(start=0, stop=3, names=2)
polynomial([1, q0, q0**2, q1, q0*q1, q1**2])

It is also possible to construct your own from symbols:

>>> q0, q1 = numpoly.variable(2)
>>> numpoly.polynomial([1, q0**2-1, q0*q1, q1**2-1])
polynomial([1, q0**2-1, q0*q1, q1**2-1])

Or in combination with numpy objects using various arithmetics:

>>> q0**numpy.arange(4)-q1**numpy.arange(3, -1, -1)
polynomial([-q1**3+1, -q1**2+q0, q0**2-q1, q0**3-1])

The constructed polynomials can be evaluated as needed:

>>> poly = 3*q0+2*q1+1
>>> poly(q0=q1, q1=[1, 2, 3])
polynomial([3*q1+3, 3*q1+5, 3*q1+7])

Or manipulated using various numpy functions:

>>> numpy.reshape(q0**numpy.arange(4), (2, 2))
polynomial([[1, q0],
            [q0**2, q0**3]])
>>> numpy.sum(numpoly.monomial(13)[::3])
polynomial(q0**12+q0**9+q0**6+q0**3+1)

Development

Development is done using Poetry manager. Inside the repository directory, install and create a virtual environment with:

poetry install

To run tests:

poetry run pytest numpoly test doc --doctest-modules

To build documentation, run:

cd doc/
make html

The documentation will be generated into the folder doc/.build/html.

Questions and Contributions

Please feel free to file an issue for:

  • bug reporting

  • asking questions related to usage

  • requesting new features

  • wanting to contribute with code

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

numpoly-1.0.7.tar.gz (70.0 kB view details)

Uploaded Source

Built Distribution

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

numpoly-1.0.7-py2.py3-none-any.whl (130.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file numpoly-1.0.7.tar.gz.

File metadata

  • Download URL: numpoly-1.0.7.tar.gz
  • Upload date:
  • Size: 70.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.7.3 Linux/4.15.0-1077-aws

File hashes

Hashes for numpoly-1.0.7.tar.gz
Algorithm Hash digest
SHA256 4249392df68d179472a4c02365e52122b1b3eb13c2603e00b237f5def004e9ba
MD5 38864cc9867c6669db61eccd173238d8
BLAKE2b-256 7eb483f418572c511563052e1def2a9700cedc545193b3c279d9d2236fe4b039

See more details on using hashes here.

File details

Details for the file numpoly-1.0.7-py2.py3-none-any.whl.

File metadata

  • Download URL: numpoly-1.0.7-py2.py3-none-any.whl
  • Upload date:
  • Size: 130.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.7.3 Linux/4.15.0-1077-aws

File hashes

Hashes for numpoly-1.0.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f58838e9bad53c963e2568179a9c9cd4d6a6118256e214b71860de98855e9723
MD5 1bb0575ae7bbb45077252e8377fa2539
BLAKE2b-256 8c449f4fc5cfae1af03e604a5da0938df663ebdb4bbc46391394ecd54b588b70

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