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.5.0

In pyproject.toml dependencies

dependencies = [
    "vcti-multi-valued-array>=1.5.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.5.0.tar.gz (16.6 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.5.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for vcti_multi_valued_array-1.5.0.tar.gz
Algorithm Hash digest
SHA256 ab6e639b861ab473c940de0315bb60d7cf8e351dfc8d9748661a3bcf8dc4fc35
MD5 73fa00f3e6537fe94e13182a424a1b87
BLAKE2b-256 3b2fb2a962067d6031f14f73500602ba906b3de1514209d2c7d5cc8958877d2a

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcti_multi_valued_array-1.5.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.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for vcti_multi_valued_array-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f45ef956dab6df92e4318d31b6b66885c7b280175ba12d5e6e01e388dd044d42
MD5 46cb6d7ca368e76ac9d18181e13b3cf4
BLAKE2b-256 f41641ff0c518a07d33f9280caf58175699e005e24355b25e86d5ce78226700a

See more details on using hashes here.

Provenance

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