API

Top-level package

ndsharray.supported_types

alias of [<class ‘numpy.int8’>, <class ‘numpy.int16’>, <class ‘numpy.int32’>, <class ‘numpy.int64’>, <class ‘numpy.uint8’>, <class ‘numpy.uint16’>, <class ‘numpy.uint32’>, <class ‘numpy.uint64’>, <class ‘numpy.float16’>, <class ‘numpy.float32’>, <class ‘numpy.float64’>, <class ‘numpy.float128’>, <class ‘numpy.complex64’>, <class ‘numpy.complex128’>, <class ‘numpy.complex256’>, <class ‘bool’>]

class ndsharray.NdShArray(name: str, array: numpy.ndarray = array([], dtype=uint8), r_w: Optional[str] = None)[source]

sharing numpy array between different processes

__init__(name: str, array: numpy.ndarray = array([], dtype=uint8), r_w: Optional[str] = None)[source]
Parameters
  • name

  • array

  • r_w – ‘r’ or ‘w’ for ‘read’ or ‘write’ functionality, must be specified

property access: str

access of the ndsharray; either ‘w’ for only writeable or ‘r’ for only readable

Return access

property name: str

unique name of the mmap memory, serves as identifier for other processes the name must be declared at class instantiation and is read only after instantiation

Return name

property ndarray_mmap_name: str

returns the name of the mmap which holds the current ndarray

ndarray_mmap_name consists of the name and an uuid which is generated for each new ndarray size (changes in dtype, shape or dimension does a change in size)

Return ndarray_mmap_name

read() Tuple[bool, numpy.ndarray][source]

reading the shared memory with mmap and numpy’s frombuffer, which returns a view of the buffer and not a copy.

Citing the documentation from numpy.frombuffer: “This function creates a view into the original object. This should be safe in general, but it may make sense to copy the result when the original object is mutable or untrusted.” Source: https://numpy.org/doc/stable/reference/generated/numpy.frombuffer.html

Return validity

boolean displaying if the numpy array is ok or if it is either old or corrupt or not (e.g. mixed numpy ndarray from previous writing). Note: validity is checked by checking if buffer[0] and buffer[-1] have the same time stamp!

Return array

numpy.ndarray

property read_time_ms: float

returns the write-read time of the two processes in milliseconds

Returns

write(array: numpy.ndarray) None[source]

write a numpy array into the mmap file, it might be from any type, shape or dimension

Important Note:

a mmap will be silently re-created if type, dimension or shape will be changed. the other process will read the first line of the mmap and will also re-create its mmap. Re-creating the mmap needs more time than a normal read.

Parameters

array – a numpy.ndarray which shall be saved in mmap

Return None