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-2.1.0.tar.gz (3.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.1.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for vector_structure-2.1.0.tar.gz
Algorithm Hash digest
SHA256 a37636812678b41109383cefda06f7642bc2d86cea2253e670118f84305b66eb
MD5 f4d8988bdd859e18ec446ae4403c25ed
BLAKE2b-256 f24ebcdec0c79448c633e3c40f8a8ee0138e2a7262ea8f1fea8f1f4c2c94e5de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for vector_structure-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa7032ba4e545cf1a9f5ba1773c04a1e7159584f59b90fcf601bb1b7703b50cd
MD5 2a8c0ac27ccc73a6ed97041a120a2968
BLAKE2b-256 0012e553c0e0d09d374321d9284b88616c148b8791dfa64223b04f9d1a0fe9b0

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