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.2.0.tar.gz (3.5 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.2.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for vector_structure-2.2.0.tar.gz
Algorithm Hash digest
SHA256 85fd6dfa8874a385a448e9025a8cbbad1c8b48e2e075ecb3e697b1d10825ac4c
MD5 e59d0c5754b55ade6549902c74886e50
BLAKE2b-256 36d860f1633da79f7f34b44d5f95f8f50a73ff1d64b1d4859df7bfaa737c09db

See more details on using hashes here.

Provenance

The following attestation bundles were made for vector_structure-2.2.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.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for vector_structure-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f97494daf3cc45ce35e41b79b2db12973ed7d8a9b799fcec3086ee287d656d1a
MD5 fad7ddb1e644704a53be356cae3a1f98
BLAKE2b-256 f703383accaf04186ee070167346bcb9e761ce2f592caa143ae8e0ae5f69971d

See more details on using hashes here.

Provenance

The following attestation bundles were made for vector_structure-2.2.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