Calculate and return the average throughput of all the instances except
        the one specified as `forAllExcept`.
177237
def getInstanceMetrics(
            self, forAllExcept: int) -> Tuple[Optional[int], Optional[float]]:
        
        m = [(reqs, tm) for i, (reqs, tm)
             in self.numOrderedRequests.items()
             if i != forAllExcept]
        if m:
            reqs, tm = zip(*m)
            return sum(reqs), sum(tm)
        else:
            return None, None
321685
def replicate(self):
        """"""
        return np.sum(
            self.proxies[self.window :] * self._xs[:-1], axis=1
        ).reindex(self.r.index)
1030380
def CleanAff4Clients(self):
    """"""

    inactive_client_ttl = config.CONFIG["DataRetention.inactive_client_ttl"]
    if not inactive_client_ttl:
      self.Log("TTL not set - nothing to do...")
      return

    exception_label = config.CONFIG[
        "DataRetention.inactive_client_ttl_exception_label"]

    index = client_index.CreateClientIndex(token=self.token)

    client_urns = index.LookupClients(["."])

    deadline = rdfvalue.RDFDatetime.Now() - inactive_client_ttl
    deletion_count = 0

    for client_group in collection.Batch(client_urns, 1000):
      inactive_client_urns = []
      for client in aff4.FACTORY.MultiOpen(
          client_group,
          mode="r",
          aff4_type=aff4_grr.VFSGRRClient,
          token=self.token):
        if exception_label in client.GetLabelsNames():
          continue

        if client.Get(client.Schema.LAST) < deadline:
          inactive_client_urns.append(client.urn)

      aff4.FACTORY.MultiDelete(inactive_client_urns, token=self.token)
      deletion_count += len(inactive_client_urns)
      self.HeartBeat()

    self.Log("Deleted %d inactive clients." % deletion_count)
1291539
def eps_greedy(self, params):
        '''
        
        '''

        if params and type(params) == dict:
            eps = params.get('epsilon')
        else:
            eps = 0.1

        r = np.random.rand()

        if r < eps:
            return np.random.choice(list(set(range(len(self.wins))) -
                                    {self.max_mean()}))
        else:
            return self.max_mean()
256875
def getThroughputs(self, desired_inst_id: int):
        

        instance_thrp = self.getThroughput(desired_inst_id)
        totalReqs, totalTm = self.getInstanceMetrics(forAllExcept=desired_inst_id)
        # Average backup replica's throughput
        if len(self.throughputs) > 1:
            thrs = []
            for inst_id, thr_obj in self.throughputs.items():
                if inst_id == desired_inst_id:
                    continue
                thr = self.getThroughput(inst_id)
                if thr is not None:
                    thrs.append(thr)
            if thrs:
                if desired_inst_id == self.instances.masterId:
                    other_thrp = self.throughput_avg_strategy_cls.get_avg(thrs)
                else:
                    other_thrp = self.backup_throughput_avg_strategy_cls.get_avg(thrs)
            else:
                other_thrp = None
        else:
            other_thrp = None
        if instance_thrp == 0:
            if self.numOrderedRequests[desired_inst_id] == (0, 0):
                avgReqsPerInst = (totalReqs or 0) / self.instances.count
                if avgReqsPerInst <= 1:
                    # too early to tell if we need an instance change
                    instance_thrp = None
        return instance_thrp, other_thrp
100530
def com(points, masses=None):
    """"""
    if masses is None:
        return np.average(points, axis=0)
    else:
        return np.average(points, axis=0, weights=masses)
644685
def moving_average(iterable, n):
    
    it = iter(iterable)
    d = collections.deque(itertools.islice(it, n - 1))
    d.appendleft(0)
    s = sum(d)
    for elem in it:
        s += elem - d.popleft()
        d.append(elem)
        yield s / float(n)
105150
def grab_idx(x,i,batch_first:bool=True):
    ""
    if batch_first: return ([o[i].cpu() for o in x]   if is_listy(x) else x[i].cpu())
    else:           return ([o[:,i].cpu() for o in x] if is_listy(x) else x[:,i].cpu())
743929
def benchmark_forward(self):
        
        self._setup()

        def f():
            self._forward()
            self.mod_ext.synchronize(**self.ext_kwargs)
        f()  # Ignore first
        self.forward_stat = self._calc_benchmark_stat(f)
34975
function excludeIntIndices(intIdxVector, maxLen) {
  return jd.seq(maxLen).isIn(intIdxVector).not().which();
}
772073
def _queuer(instances: Iterable[Instance],
            input_queue: Queue,
            num_workers: int,
            num_epochs: Optional[int]) -> None:
    
    epoch = 0

    while num_epochs is None or epoch < num_epochs:
        epoch += 1
        for instance in instances:
            input_queue.put(instance)

    # Now put a None for each worker, since each needs to receive one
    # to know that it's done.
    for _ in range(num_workers):
        input_queue.put(None)
73465
def outlierDetection_threaded(samples_x, samples_y_aggregation):
    '''
    
    '''
    outliers = []

    threads_inputs = [[samples_idx, samples_x, samples_y_aggregation]\
                            for samples_idx in range(0, len(samples_x))]
    threads_pool = ThreadPool(min(4, len(threads_inputs)))
    threads_results = threads_pool.map(_outlierDetection_threaded, threads_inputs)
    threads_pool.close()
    threads_pool.join()

    for threads_result in threads_results:
        if threads_result is not None:
            outliers.append(threads_result)
        else:
            print("error here.")

    outliers = None if len(outliers) == 0 else outliers
    return outliers
912458
def __undo_filter_average(self, scanline):
        """"""
        ai = -self.fu
        previous = self.prev
        for i in range(len(scanline)):
            x = scanline[i]
            if ai < 0:
                a = 0
            else:
                a = scanline[ai]  # result
            b = previous[i]
            scanline[i] = (x + ((a + b) >> 1)) & 0xff  # result
            ai += 1
230928
def skip_common_stack_elements(stacktrace, base_case):
  """"""
  for i, (trace, base) in enumerate(zip(stacktrace, base_case)):
    if trace != base:
      return stacktrace[i:]
  return stacktrace[-1:]
964361
def Skip(self: Iterable, n):
    
    con = iter(self)
    for i, _ in enumerate(con):
        if i == n:
            break
    return con
1078165
function instanceIndex(context) {
  for (var i = 0; i < instances.length; i++) {
    var instance = instances[i];
    if (instance.conversionContext === context ||
        instance.executionContext === context) {
      return i;
    }
  }
  return -1;
}
747467
def protract(self, x):
		
		for i in xrange(len(self)):
			self[i] = self[i].protract(x)
		return self.coalesce()