Skip to main content

Variable-length array for multivalued mappings — CSR-like storage with domain-codomain operations, reverse, cascade, and filtering

Project description

Multi Valued Array

Variable-length array for multivalued mappings — CSR-like storage with domain-codomain operations, reverse, cascade, and filtering.

Installation

pip install vcti-multi-valued-array>=1.6.0

In pyproject.toml dependencies

dependencies = [
    "vcti-multi-valued-array>=1.6.0",
]

Quick Start

import numpy as np
from vcti.multivalued import MultiValuedArray, reverse, cascade

# Create: element 0 has values [10, 20], element 1 has [30], element 2 has [40, 50, 60]
mva = MultiValuedArray(counts=np.array([2, 1, 3]), values=np.array([10, 20, 30, 40, 50, 60]))

mva.counts()          # array([2, 1, 3])
mva.offsets()         # array([0, 2, 3, 6])
mva.values()          # array([10, 20, 30, 40, 50, 60])
mva.value_indices()   # array([0, 0, 1, 2, 2, 2])  — which element each value belongs to

# With domain and codomain metadata
faces = np.array([(1, 1), (2, 2)], dtype=[('id', 'u4'), ('type', 'u4')])
vertices = np.array([(1, 0., 0.), (2, 2., 0.), (3, 3., 1.), (4, 2., 2.), (5, 0., 2.)],
                     dtype=[('id', 'u4'), ('x', 'f4'), ('y', 'f4')])

connectivity = MultiValuedArray(
    counts=np.array([4, 3], dtype=np.uint32),
    values=np.array([0, 1, 3, 4, 1, 2, 3], dtype=np.uint32),
    domain=faces,
    codomain=vertices,
)

# Reverse: for each vertex, which faces contain it
node_faces = reverse(connectivity)

Core API

MultiValuedArray

Method Description
counts() Number of values per element (lazy from offsets)
offsets() Cumulative positions into values (lazy from counts)
values() Flat array of all values
value_indices() Maps each value to its element index
domain() Domain element identifiers
codomain() Codomain element identifiers
set_values(values) Set/replace values array
len(mva) Number of elements (domain size)
mva[i] Values for element at index i
for v in mva Iterate over element value slices
mva == other Structural equality check

Operations

Function Description
reverse(mva) Invert mapping (A->B becomes B->A)
cascade(ab, bc) Compose mappings (A->B + B->C = A->C)
concatenate(a, b) Vertically stack two arrays
sort_and_unique(mva) Sort and deduplicate values per element
non_negative_array(src) Extract non-negative values from 2D array
from_joint_counts_and_values_array(arr) Parse interleaved format
get_counts_values_array(mva) Convert to interleaved format
get_chunk(mva, a, b) Extract elements [a:b]

Dependencies

  • numpy (>=1.24)
  • numba (>=0.59) — JIT compilation for performance-critical loops
  • vcti-nputils (>=1.0.0) — position_array, as_ndarray

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

vcti_multi_valued_array-1.6.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

vcti_multi_valued_array-1.6.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file vcti_multi_valued_array-1.6.0.tar.gz.

File metadata

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

File hashes

Hashes for vcti_multi_valued_array-1.6.0.tar.gz
Algorithm Hash digest
SHA256 58840928e8222522bb3ca54e4233a2f41eec65587c4fb26ae19c03571b86db30
MD5 b2d39e38c74d7adb8eda32736ffb493f
BLAKE2b-256 29acbdbd9ac42d060c0e87e8605182fb7731353bc35690997b42b37e80398432

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcti_multi_valued_array-1.6.0.tar.gz:

Publisher: publish.yml on vcollab/vcti-python-multi-valued-array

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

File details

Details for the file vcti_multi_valued_array-1.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for vcti_multi_valued_array-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34a59f5bc19f12d3c3038fb12dd0b0c1c2a03c52062a831b11efcadeb5f1249b
MD5 42119427aef30fee85e1b020ec9cd849
BLAKE2b-256 e514acc984a7717c6def82a269061a84d136dbf9dad8f575f2f66bf781405aa7

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcti_multi_valued_array-1.6.0-py3-none-any.whl:

Publisher: publish.yml on vcollab/vcti-python-multi-valued-array

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