Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def on_source(self, *args):
self._q.append(
args[0] if len(args) == 1 else args if args else NO_VALUE)
if self._count and len(self._q) > self._count:
self._q.popleft()
self.emit(np.asarray(self._q))
def _on_source_i(self, i, *args):
q = self._results[i]
if not q:
self._num_ready += 1
ready = self._num_ready == len(self._results)
else:
ready = False
q.append(args[0] if len(args) == 1 else args if args else NO_VALUE)
if ready:
tup = tuple(q.popleft() for q in self._results)
self._num_ready = sum(bool(q) for q in self._results)
self.emit(*tup)
def on_source(self, arg):
if self._prev is NO_VALUE:
if self._initializer is NO_VALUE:
self._prev = arg
else:
self._prev = self._func(self._initializer, arg)
self.emit(self._prev)
else:
self._prev = self._func(self._prev, arg)
self.emit(self._prev)
self.error_event = None
"""
Sub event that emits errors from this event as
``emit(source, exception)``.
"""
self.done_event = None
"""
Sub event that emits when this event is done as
``emit(source)``.
"""
if _with_error_done_events:
self.error_event = Event('error', False)
self.done_event = Event('done', False)
self._slots = [] # list of [obj, weakref, func] sublists
self._name = name or self.__class__.__qualname__
self._value = NO_VALUE
self._done = False
self._source = None
def _on_source_i(self, i, *args):
self._values[i] = \
args[0] if len(args) == 1 else args if args else NO_VALUE
if not self._is_primed:
self._is_primed = not any(r is NO_VALUE for r in self._values)
if self._is_primed:
self.emit(*self._values)
def on_source(self, *args):
value = args[0] if len(args) == 1 else args if args else NO_VALUE
if self._has_prev:
self.emit(self._prev, value)
else:
self._has_prev = True
self._prev = value
def _on_timer(self, *args):
if self._value is not NO_VALUE:
self.emit(*self._value)
def reduce(self, func, initializer=NO_VALUE) -> "Reduce":
"""
Apply a two-argument reduction function to the previous reduction
result and the current value and emit the new reduction result.
Args:
func: Reduction function::
emit(args) -> emit(func(prev_args, args))
initializer: First argument of first reduction::
first_result = func(initializer, first_value)
If no initializer is given, then the first result is
emitted on the second source emit.
"""
def __init__(self, func, initializer=NO_VALUE, source=None):
Op.__init__(self, source)
self._func = func
self._initializer = initializer
self._prev = NO_VALUE
def __init__(self, n=None, weight=None, source=None):
Op.__init__(self, source)
self._f1 = weight or 2.0 / (n + 1)
self._f2 = 1 - self._f1
self._prev = NO_VALUE