Skip to content

Commit

Permalink
Allocate size-specced "empty" sequence from default values by type
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed Oct 19, 2022
1 parent fec9025 commit 1ceea0e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tractor/_shm.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ class ShmList(ShareableList):
Carbon copy of ``.shared_memory.ShareableList`` with a few
enhancements:
- readonly mode via instance var flag
- readonly mode via instance var flag `._readonly: bool`
- ``.__getitem__()`` accepts ``slice`` inputs
- exposes the underlying buffer "name" as a ``.key: str``
Expand All @@ -743,6 +743,10 @@ def __init__(
def key(self) -> str:
return self._key

@property
def readonly(self) -> bool:
return self._readonly

def __setitem__(
self,
position,
Expand Down Expand Up @@ -781,13 +785,21 @@ def open_shm_list(
key: str,
sequence: list | None = None,
size: int = int(2 ** 10),
dtype: np.dtype | None = None,
dtype: float | int | bool | str | bytes | None = float,
readonly: bool = True,

) -> ShmList:

if sequence is None:
sequence = list(map(float, range(size)))
default = {
float: 0.,
int: 0,
bool: True,
str: 'doggy',
None: None,
}[dtype]
sequence = [default] * size
# sequence = [0.] * size

shml = ShmList(
sequence=sequence,
Expand Down

0 comments on commit 1ceea0e

Please sign in to comment.