Allocate size-specced "empty" sequence from default values by type

macos_in_ci
Tyler Goodlet 2022-10-19 14:20:50 -04:00
parent 1be3f4115d
commit 54322f2bae
1 changed files with 15 additions and 3 deletions

View File

@ -719,7 +719,7 @@ class ShmList(ShareableList):
Carbon copy of ``.shared_memory.ShareableList`` with a few Carbon copy of ``.shared_memory.ShareableList`` with a few
enhancements: enhancements:
- readonly mode via instance var flag - readonly mode via instance var flag `._readonly: bool`
- ``.__getitem__()`` accepts ``slice`` inputs - ``.__getitem__()`` accepts ``slice`` inputs
- exposes the underlying buffer "name" as a ``.key: str`` - exposes the underlying buffer "name" as a ``.key: str``
@ -743,6 +743,10 @@ class ShmList(ShareableList):
def key(self) -> str: def key(self) -> str:
return self._key return self._key
@property
def readonly(self) -> bool:
return self._readonly
def __setitem__( def __setitem__(
self, self,
position, position,
@ -781,13 +785,21 @@ def open_shm_list(
key: str, key: str,
sequence: list | None = None, sequence: list | None = None,
size: int = int(2 ** 10), size: int = int(2 ** 10),
dtype: np.dtype | None = None, dtype: float | int | bool | str | bytes | None = float,
readonly: bool = True, readonly: bool = True,
) -> ShmList: ) -> ShmList:
if sequence is None: 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( shml = ShmList(
sequence=sequence, sequence=sequence,