Skip to main content

No project description provided

Project description

vector-structure

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"]]

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-1.0.0.tar.gz (2.9 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-1.0.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: vector_structure-1.0.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for vector_structure-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9f3d507f7e6d809ccf51f29f59f2da0f576cadd0f59b066d9d2b1ac68116db1e
MD5 64d29c909704bc442ad1b6acb32bbecf
BLAKE2b-256 0e205470fb375577a39e8c9c1ae9cc87249ba1659b38c5c9ad0607396f82ac68

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for vector_structure-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4deefdd9982ba313d17b11010ea40ff0658a3e38de1f4e48408018a2046fb907
MD5 5d686631c6aeba18a5feb7a2f8b2b103
BLAKE2b-256 6c63e232ecc47206c3f1a05c7470a7b9614f3e72860319b0b990c024b1ade731

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