Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
545d6dc
Array manages capacity separately from size
Oct 11, 2024
980ad6a
VectorOfVectors dtype is a property
Oct 11, 2024
d0d8ce2
Raise error on insert if i>len
Oct 13, 2024
075a4f1
Add get/set_capacity to VoV and change modifiers to take advantage of…
Oct 13, 2024
1e1fdda
Modify core.read and store.read to resize array when filling in place…
Oct 13, 2024
23a03a6
Changed table to handle capacity and resizing similar to array
Oct 13, 2024
32ceef9
Fixed test
Oct 13, 2024
8d7c1eb
Added abstract base class for LGDO collections
Oct 13, 2024
8a5dcb2
style: pre-commit fixes
pre-commit-ci[bot] Oct 13, 2024
8dd3d75
Appease the pre-commit bot
Oct 13, 2024
5a2e402
Fixed tutorial
Oct 14, 2024
0a24cf9
Fixed docstring error
Oct 14, 2024
0fb6adf
Added tests for capacity and fixed bugs
Oct 14, 2024
03f5ce7
style: pre-commit fixes
pre-commit-ci[bot] Oct 14, 2024
a1cf2b2
Appease pre-commit bot
Oct 14, 2024
0a0bffb
Improve test coverage
Oct 14, 2024
c7c0c28
Merge branch 'main' of https://github.com/legend-exp/legend-pydataobj
Nov 5, 2024
ae4979f
style: pre-commit fixes
pre-commit-ci[bot] Nov 5, 2024
8f98559
Merge branch 'main' of https://github.com/legend-exp/legend-pydataobj
Nov 25, 2024
7afab72
Fixed test
Nov 25, 2024
74cb281
When filling VoV from AoesA, if length of V is longer than A use fill…
Nov 27, 2024
51137a7
Do not return current_i_entry when iterating
Dec 20, 2024
f06ae09
Merge branch 'main' of https://github.com/legend-exp/legend-pydataobj
Dec 20, 2024
2e0f597
Fixed tests
Dec 20, 2024
10193a9
style: pre-commit fixes
pre-commit-ci[bot] Dec 20, 2024
0546407
Merge branch 'main' of https://github.com/legend-exp/legend-pydataobj
Jan 14, 2025
847c19c
Fixed broken test
Jan 14, 2025
f118350
Merge branch 'main' of https://github.com/iguinn/legend-pydataobj
Jan 14, 2025
dc88aa1
Merge branch 'main' of https://github.com/legend-exp/legend-pydataobj
iguinn Jan 21, 2025
582960c
Fixed tutorial notebook
iguinn Jan 24, 2025
d808cd8
Merge branch 'main' of https://github.com/legend-exp/legend-pydataobj
iguinn Jan 24, 2025
d1e92e8
Added ability to specify start and number of entries for iteration
iguinn Feb 14, 2025
58d7872
Test use of start and n_entries for iterator
iguinn Feb 14, 2025
ab76b23
Merge branch 'main' of https://github.com/legend-exp/legend-pydataobj
iguinn Feb 14, 2025
ce1b6fe
style: pre-commit fixes
pre-commit-ci[bot] Feb 14, 2025
a6d226b
Merge branch 'main' of https://github.com/legend-exp/legend-pydataobj
iguinn Apr 16, 2025
2b60535
Merge branch 'main' of https://github.com/legend-exp/legend-pydataobj
iguinn Apr 17, 2025
2f0d164
Added test for and fixed bug in WaveformTable allocation
iguinn Apr 18, 2025
fbc52ae
Added test and fixed but when changing wf length (and AoESA/Array shape)
iguinn Apr 18, 2025
e50b355
style: pre-commit fixes
pre-commit-ci[bot] Apr 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/lgdo/types/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import annotations

import logging
from collections.abc import Iterator
from collections.abc import Collection, Iterator
from typing import Any

import awkward as ak
Expand Down Expand Up @@ -126,19 +126,27 @@ def trim_capacity(self) -> None:
"Set capacity to be minimum needed to support Array size"
self.reserve_capacity(np.prod(self.shape))

def resize(self, new_size: int, trim=False) -> None:
def resize(self, new_size: int | Collection[int], trim=False) -> None:
"""Set size of Array in rows. Only change capacity if it must be
increased to accommodate new rows; in this case double capacity.
If trim is True, capacity will be set to match size."""
If trim is True, capacity will be set to match size. If new_size
is an int, do not change size of inner dimensions.

self._size = new_size
If new_size is a collection, internal memory will be re-allocated, so
this should be done only rarely!"""

if trim and new_size != self.get_capacity:
self.reserve_capacity(new_size)
if isinstance(new_size, Collection):
self._size = new_size[0]
self._nda.resize(new_size)
else:
self._size = new_size

if trim and new_size != self.get_capacity:
self.reserve_capacity(new_size)

# If capacity is not big enough, set to next power of 2 big enough
if new_size > self.get_capacity():
self.reserve_capacity(int(2 ** (np.ceil(np.log2(new_size)))))
# If capacity is not big enough, set to next power of 2 big enough
if new_size > self.get_capacity():
self.reserve_capacity(int(2 ** (np.ceil(np.log2(new_size)))))

def append(self, value: np.ndarray) -> None:
"Append value to end of array (with copy)"
Expand Down
40 changes: 19 additions & 21 deletions src/lgdo/types/waveformtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,22 @@ def __init__(
if not isinstance(t0, Array):
shape = (size,)
t0_dtype = t0.dtype if hasattr(t0, "dtype") else np.float32
nda = (
t0 if isinstance(t0, np.ndarray) else np.full(shape, t0, dtype=t0_dtype)
)
if nda.shape != shape:
nda.resize(shape, refcheck=True)
t0 = Array(nda=nda)
if isinstance(t0, np.ndarray):
t0 = Array(nda=t0, shape=shape, dtype=t0_dtype)
else:
t0 = Array(fill_val=t0, shape=shape, dtype=t0_dtype)

if t0_units is not None:
t0.attrs["units"] = f"{t0_units}"

if not isinstance(dt, Array):
shape = (size,)
dt_dtype = dt.dtype if hasattr(dt, "dtype") else np.float32
nda = (
dt if isinstance(dt, np.ndarray) else np.full(shape, dt, dtype=dt_dtype)
)
if nda.shape != shape:
nda.resize(shape, refcheck=True)
dt = Array(nda=nda)
if isinstance(dt, np.ndarray):
dt = Array(nda=dt, shape=shape, dtype=dt_dtype)
else:
dt = Array(fill_val=dt, shape=shape, dtype=dt_dtype)

if dt_units is not None:
dt.attrs["units"] = f"{dt_units}"

Expand Down Expand Up @@ -174,14 +171,15 @@ def __init__(
if hasattr(values, "dtype")
else np.dtype(np.float64)
)
nda = (
values
if isinstance(values, np.ndarray)
else np.zeros(shape, dtype=dtype)
)
if nda.shape != shape:
nda.resize(shape, refcheck=True)
values = ArrayOfEqualSizedArrays(dims=(1, 1), nda=nda)
if isinstance(values, np.ndarray):
values = ArrayOfEqualSizedArrays(
dims=(1, 1), nda=values, shape=shape, dtype=dtype
)
else:
values = ArrayOfEqualSizedArrays(
dims=(1, 1), fill_val=0, shape=shape, dtype=dtype
)

if values_units is not None:
values.attrs["units"] = f"{values_units}"

Expand Down Expand Up @@ -215,7 +213,7 @@ def wf_len(self, wf_len) -> None:
return
shape = self.values.nda.shape
shape = (shape[0], wf_len)
self.values.nda.resize(shape, refcheck=True)
self.values.resize(shape)

def resize_wf_len(self, new_len: int) -> None:
"""Alias for `wf_len.setter`, for when we want to make it clear in
Expand Down
13 changes: 13 additions & 0 deletions tests/types/test_waveformtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ def test_init():
assert (wft.values.nda == np.zeros(shape=(10, 1000))).all()
assert wft.values.nda.dtype == np.float64

wft = WaveformTable(
size=10, dt=np.zeros(5), t0=np.zeros(5), values=np.zeros((5, 50))
)
assert (wft.t0.nda == np.zeros(10)).all()
assert (wft.dt.nda == np.zeros(10)).all()
assert isinstance(wft.values, lgdo.ArrayOfEqualSizedArrays)
assert (wft.values.nda == np.zeros(shape=(10, 50))).all()
assert wft.values.nda.dtype == np.float64

wft = WaveformTable(
values=lgdo.ArrayOfEqualSizedArrays(shape=(10, 1000), fill_val=69)
)
Expand Down Expand Up @@ -85,3 +94,7 @@ def test_init():

wft = WaveformTable(t0=[1, 1, 1], dt=[2, 2, 2], wf_len=1000, dtype=np.float32)
assert wft.values.nda.dtype == np.float32

wft = WaveformTable(10, wf_len=20)
wft.wf_len = 30
assert wft.wf_len == 30