Skip to main content

No project description provided

Project description

vector-structure

PyPi version Documentation Status

Lightweight utilities for working with structured flat vectors and block matrices in NumPy.

Example usage

Consider a Newton algorithm for solving the KKT conditions, as described here:

$$\begin{pmatrix} \nabla^2 f(x) & \color{gray}{Df(x)^T} & A^T \ \color{gray}{-diag(\lambda) Df(x)} & \color{gray}{-diag(f(x))} & \color{gray}{0} \ A & \color{gray}{0} & 0 \end{pmatrix} \begin{pmatrix} x^* \ \color{gray}{\lambda^*} \ v^* \end{pmatrix} = \begin{pmatrix} \ \dots \ \end{pmatrix}$$

where the grey components are only required when inequality constraints are present.

from vector_structure import VectorStructure

structure = [("x", n)]
if ineq_constraints:
    structure.append(("lambda", m))
structure.append(("mu", p))

vs = VectorStructure(structure)

M = np.zeros((vs.size, vs.size))
M[vs["x"], vs["x"]] = nabla2(f)(x)
if ineq_constraints:
    M[vs["x"], vs["lambda"]] = Df(x).T
M[vs["x"], vs["mu"]] = A
...

x_lambda_mu = np.linalg.solve(M, r)
x = x_lambda_mu[vs["x"]]
if ineq_constraints:
    lambda = x_lambda_mu[vs["lambda"]]

For the full documentation, see here

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

vector_structure-2.3.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

vector_structure-2.3.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file vector_structure-2.3.0.tar.gz.

File metadata

  • Download URL: vector_structure-2.3.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vector_structure-2.3.0.tar.gz
Algorithm Hash digest
SHA256 d6a944eb3f342f5e197571f7675159f0687ac8ee81a0941bccde592ca674026a
MD5 d64d46a5eea7d0eb0110188c8e1d440e
BLAKE2b-256 84536e9911c9f42c87eb65c74680e3a431364db65cbaeaf071dc8e7c762ce7f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for vector_structure-2.3.0.tar.gz:

Publisher: python-publish.yml on Warggr/vector-structure

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vector_structure-2.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for vector_structure-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea01af719e22ebfc530e614d572deb94c908340c8c95f7a5cfd14e8bc5ee3979
MD5 895c3cf0f64b3495a92b81d6afb6d7cf
BLAKE2b-256 e419dbbc3d554cb4ffe791d5e8309573a4ea0575c7b4ed4fb128dbe82066330d

See more details on using hashes here.

Provenance

The following attestation bundles were made for vector_structure-2.3.0-py3-none-any.whl:

Publisher: python-publish.yml on Warggr/vector-structure

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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