Packed Array API
DirtyTimestampProvider
Bases: Protocol
Protocol for anything that tracks a modification time.
Source code in src/packed_data_structures/arrays/dirty_tracking.py
DirtyTrackingArray
Bases: ndarray, DirtyTimestampProvider
A numpy array that updates a shared timestamp on every modification.
This class auto-updates a shared timestamp reference whenever contents are modified via setitem or in-place ufuncs.
Source code in src/packed_data_structures/arrays/dirty_tracking.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
__array_ufunc__
Delegate ufuncs while preserving timestamp semantics.
- If outputs include any DirtyTrackingArray, update their timestamp.
- Allow broadcasts into DirtyTrackingArray outputs by coercing outputs to base ndarrays for the op, then wrapping/updating tracking after.
Source code in src/packed_data_structures/arrays/dirty_tracking.py
__new__
__new__(
input_array: ndarray[T_s, dtype[T_dt]],
timestamp_ref: TimestampRef | None = None,
) -> DirtyTrackingArray[T_s, T_dt]
Creates a new DirtyTrackingArray instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_array
|
ndarray[T_s, dtype[T_dt]]
|
The input array to wrap or cast. |
required |
timestamp_ref
|
TimestampRef | None
|
Optional, pre-existing TimestampRef object. |
None
|
Source code in src/packed_data_structures/arrays/dirty_tracking.py
PackedArray
Bases: NDArrayOperatorsMixin, DirtyTimestampProvider
Base packed array class.
Acts as an interface between user-side functions and the actual data. It uses a swap-and-pop based removal approach to maintain contiguity. Underlying storage and resizing logic are delegated to an internal buffer.
Source code in src/packed_data_structures/arrays/packed_array.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
__init__
__init__(
pre_allocated_capacity: int | tuple[int, ...],
dtype: type[T],
empty_fill: Any = 0,
resize_factor: int | float = 2,
element_shape: tuple[*T_shape,] | None = None,
) -> None
Initialize the PackedArray with specific capacity and data type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pre_allocated_capacity
|
int | tuple[int, ...]
|
The initial capacity of the array.
If a tuple is provided, the first dimension is treated as the
capacity, and the remaining dimensions are treated as the
|
required |
dtype
|
DTypeLike
|
The numpy data type for the underlying storage. |
required |
empty_fill
|
Any
|
The value used to fill empty or newly allocated slots. Defaults to 0. |
0
|
resize_factor
|
int | float
|
The multiplier used when resizing the array. Defaults to 2. |
2
|
element_shape
|
tuple[int, ...] | None
|
The shape of
individual elements. Must be None if |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
ValueError
|
If the resulting size is negative. |
Source code in src/packed_data_structures/arrays/packed_array.py
apply_bulk_edit_plan
apply_bulk_edit_plan(
new_size: int,
additions: tuple[
list[T] | ndarray[Any, dtype[T]],
list[int] | ndarray,
],
relocations: tuple[list[int], list[int]]
| tuple[ndarray, ndarray],
skip_shrink: bool = False,
)
Applies an existing bulk edit plan.
Look at edit_helpers.plan_bulk_edit for more info.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_size
|
int
|
Size of the array after the edits. |
required |
additions
|
tuple[list[T] | ndarray[Any, dtype[T]], list[int] | ndarray]
|
Tuple of a list of values and destination indices. |
required |
relocations
|
tuple[list[int], list[int]] | tuple[ndarray, ndarray]
|
A tuple of relocate from indices as 2 separate lists. |
required |
skip_shrink
|
bool
|
If the function should skip shrinking the array. |
False
|
Source code in src/packed_data_structures/arrays/packed_array.py
bulk_edit
bulk_edit(
*,
additions: Sequence[T]
| ndarray[tuple[int, *T_shape], dtype[T]]
| None = None,
removals: Sequence[int] | T_IndexArray | None = None,
) -> tuple[T_IndexArray, tuple[T_IndexArray, T_IndexArray]]
Applies multiple append and remove operations in one optimized procedure.
Uses first-come-first-serve based addition and removal pair merging. Meaning that new values replace removal targets to avoid unnecessary relocations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
additions
|
Sequence[T] | ndarray[tuple[int, *T_shape], dtype[T]] | None
|
List of entries to append. |
None
|
removals
|
Sequence[int] | T_IndexArray | None
|
List of indices to remove. |
None
|
Returns:
| Type | Description |
|---|---|
T_IndexArray
|
Returns a list of appended value destinations, and a tuple of relocated indices. |
tuple[T_IndexArray, T_IndexArray]
|
The relocated indices are split into a list of original indices. |
tuple[T_IndexArray, tuple[T_IndexArray, T_IndexArray]]
|
And a list of the indices they've been moved to. |
Source code in src/packed_data_structures/arrays/packed_array.py
PackedArrayBuffer
dataclass
A container for the underlying numpy array memory.
Tracks both the allocated capacity and the current size. Handles the direct reallocation of the underlying numpy array memory to a specific size.
Attributes:
| Name | Type | Description |
|---|---|---|
capacity |
int
|
The allocated capacity of the underlying array. |
dtype |
type[T]
|
The numpy data type of the elements. |
element_shape |
T_elem_shape
|
The shape of individual elements. |
Source code in src/packed_data_structures/arrays/packed_array.py
PackedAsciiStringArray
Bases: PackedArray[bytes_]
A specialized PackedArray for fixed-length ASCII byte-strings.
Source code in src/packed_data_structures/arrays/packed_ascii_string_array.py
PackedObjectArray
Bases: PackedArray[object_]
A specialized PackedArray for arbitrary Python objects.
Source code in src/packed_data_structures/arrays/packed_object_array.py
PackedStringArray
Bases: PackedArray[str_]
A specialized PackedArray for fixed-length Unicode strings.
Source code in src/packed_data_structures/arrays/packed_string_array.py
tracked_njit
Wraps a Numba function to automatically update timestamps of modified arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mutates
|
Callable[..., Sequence[Any]]
|
A function (or lambda) that accepts the same arguments as the decorated function and returns a sequence of arrays that are predicted to be modified. |
required |
**njit_kwargs
|
Any
|
Arguments passed directly to nb.njit (e.g., cache=True). |
{}
|