Example #1
0
 def __init__(self, iterable, *, shared_memory_context):
     self.shared_memory_context = shared_memory_context
     if isinstance(iterable, (list, tuple)):
         # Skip creation of short-lived duplicate list.
         shared_array = SharedNDArray.copy(np.array(iterable))
     else:
         shared_array = SharedNDArray.copy(np.array(list(iterable)))
     self.allocated_size = -1  # TODO: overallocate more than needed
     self.replace_held_shared_array(shared_array, destroy_old=False)
Example #2
0
 def insert(self, position, value):
     arr_of_one = np.array([value], dtype=self.array.dtype)
     shared_array = SharedNDArray.copy(
         np.concatenate(
             [self.array[:position], arr_of_one, self.array[position:]]))
     self.allocated_size = -1  # TODO: overallocate more than needed
     self.replace_held_shared_array(shared_array)
Example #3
0
 def pop(self, position=None):
     # TODO: implement use of position
     retval = self.array[-1]
     # TODO: fix problem when shrinking to length of 0
     shared_array = SharedNDArray.copy(self.array[:-1])
     self.allocated_size = -1  # TODO: overallocate more than needed
     self.replace_held_shared_array(shared_array)
     return retval
Example #4
0
 def remove(self, value):
     position = self.index(value)
     shared_array = SharedNDArray.copy(
         np.concatenate([self.array[:position], self.array[position + 1:]]))
     self.allocated_size = -1  # TODO: overallocate more than needed
     self.replace_held_shared_array(shared_array)
Example #5
0
 def extend(self, values):
     arr_of_multiple = np.array(values, dtype=self.array.dtype)
     shared_array = SharedNDArray.copy(
         np.concatenate([self.array, arr_of_multiple]))
     self.allocated_size = -1  # TODO: overallocate more than needed
     self.replace_held_shared_array(shared_array)
Example #6
0
 def clear(self):
     shared_array = SharedNDArray.copy(np.array([], dtype=self.array.dtype))
     self.allocated_size = -1  # TODO: overallocate more than needed
     self.replace_held_shared_array(shared_array)
Example #7
0
 def append(self, value):
     arr_of_one = np.array([value], dtype=self.array.dtype)
     shared_array = SharedNDArray.copy(
         np.concatenate([self.array, arr_of_one]))
     self.allocated_size = -1  # TODO: overallocate more than needed
     self.replace_held_shared_array(shared_array)
Example #8
0
 def attach_object(self):
     "Attach to existing object in shared memory segment."
     self.shared_array = SharedNDArray(*(self._callmethod('_getstate')))