Randomly select and create a new stream.

        Parameters
        ----------
        idx : int, [0:n_streams - 1]
            The stream index to replace
169912
def _new_stream(self, idx):
        '''
        '''
        # Don't activate the stream if the weight is 0 or None
        if self.stream_weights_[idx]:
            self.streams_[idx] = self.streamers[idx].iterate()
        else:
            self.streams_[idx] = None

        # Reset the sample count to zero
        self.stream_counts_[idx] = 0
398564
def select(self, idx):
        
        data = {}
        for k in self.data:
            data[k] = self.data[k][idx]
        return self._return(data=data)
297096
def insert(self, idx, w, comment=''):
        ''''''
        if idx >= self.count():
            self.add(w, comment)
            return
        if idx < 0:
            return
        w = copy.copy(w)
        if comment:
            w.comment = comment
        w.seq = idx
        self.wpoints.insert(idx, w)
        self.last_change = time.time()
        self.reindex()
399829
public static Map<String, IDLProxyObject> create(InputStream is) throws IOException {
        return create(is, false);
    }
645710
def _shuffle(data, idx):
    """"""
    shuffle_data = []

    for idx_k, idx_v in data:
        shuffle_data.append((idx_k, mx.ndarray.array(idx_v.asnumpy()[idx], idx_v.context)))

    return shuffle_data
1016134
def create_stream(stream_name, num_shards, region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    r = _execute_with_retries(conn,
                              "create_stream",
                              ShardCount=num_shards,
                              StreamName=stream_name)
    if 'error' not in r:
        r['result'] = True
    return r
982421
def _insert_dLbl_in_sequence(self, idx):
        
        new_dLbl = self._new_dLbl()
        new_dLbl.idx.val = idx

        dLbl = None
        for dLbl in self.dLbl_lst:
            if dLbl.idx_val > idx:
                dLbl.addprevious(new_dLbl)
                return new_dLbl
        if dLbl is not None:
            dLbl.addnext(new_dLbl)
        else:
            self.insert(0, new_dLbl)
        return new_dLbl
29466
def reservoir_sample(stream, num_items, item_parser=lambda x: x):
    
    kept = []
    for index, item in enumerate(stream):
        if index < num_items:
            kept.append(item_parser(item))
        else:
            r = random.randint(0, index)
            if r < num_items:
                kept[r] = item_parser(item)
    return kept
1340183
public synchronized XEvent replace(XEvent event, int index)
			throws IndexOutOfBoundsException, IOException {
		// check overflow list and adjust indices
		XEvent replaced = null;
		int smallerOverflow = 0;
		for (int i = 0; i < overflowSize; i++) {
			if (overflowIndices[i] == index) {
				replaced = overflowEntries[i];
				overflowEntries[i] = event;
				return replaced;
			} else if (overflowIndices[i] > index) {
				// done
				break;
			} else if (overflowIndices[i] < index) {
				smallerOverflow++;
			}
		}
		// still here: we must look in file buffer
		int bufferIndex = index - smallerOverflow;
		for (int hole = holeFlags.nextSetBit(0); hole >= 0
				&& hole <= bufferIndex; hole = holeFlags.nextSetBit(hole + 1)) {
			bufferIndex++;
		}
		replaced = buffer.get(bufferIndex);
		if (buffer.replace(event, bufferIndex) == false) {
			remove(index);
			insert(event, index);
		}
		return replaced;
	}
141036
def _insert(self, namespace, stream, events, configuration):
    
    index = self.index_manager.get_index(namespace)
    start_dts_to_add = set()

    def actions():
      for _id, event in events:
        dt = kronos_time_to_datetime(uuid_to_kronos_time(_id))
        start_dts_to_add.add(_round_datetime_down(dt))
        event['_index'] = index
        event['_type'] = stream
        event[LOGSTASH_TIMESTAMP_FIELD] = dt.isoformat()

        yield event

    list(es_helpers.streaming_bulk(self.es, actions(), chunk_size=1000,
                                   refresh=self.force_refresh))
    self.index_manager.add_aliases(namespace,
                                   index,
                                   start_dts_to_add)
1366578
def get_or_create_stream(self, stream_id, try_create=True):
        
        stream_id = get_stream_id(stream_id)
        if stream_id in self.streams:
            logging.debug("found {}".format(stream_id))
            return self.streams[stream_id]
        elif try_create:
            # Try to create the stream
            logging.debug("creating {}".format(stream_id))
            return self.create_stream(stream_id=stream_id)
1099575
def reserve_stream(**args)
      next_id = @max_stream_ids[0] + 2
      stream = stream(next_id)
      stream.set_state(:reserved_local)
      stream.update_dependency(**args)
      stream
    end
568436
def copy(self):
    
    if self._iters:
      a, b = it.tee(self._iters[0])
      self._iters[0] = a
      return Stream(b)
    iter(self)
1153253
def _process_streams(cls, streams):
        
        parameterizeds = defaultdict(set)
        valid, invalid = [], []
        for s in streams:
            if isinstance(s, Stream):
                pass
            elif isinstance(s, param.Parameter):
                s = Params(s.owner, [s.name])
            elif isinstance(s, param.Parameterized):
                s = Params(s)
            elif util.is_param_method(s):
                if not hasattr(s, "_dinfo"):
                    continue
                s = ParamMethod(s)
            else:
                invalid.append(s)
                continue
            if isinstance(s, Params):
                pid = id(s.parameterized)
                overlap = (set(s.parameters) & parameterizeds[pid])
                if overlap:
                    pname = type(s.parameterized).__name__
                    param.main.param.warning(
                        'The %s parameter(s) on the %s object have '
                        'already been supplied in another stream. '
                        'Ensure that the supplied streams only specify '
                        'each parameter once, otherwise multiple '
                        'events will be triggered when the parameter '
                        'changes.' % (sorted(overlap), pname))
                parameterizeds[pid] |= set(s.parameters)
            valid.append(s)
        return valid, invalid
137452
def set_stream(self, stream_id):
        """"""
        self._group['stream_id'] = stream_id
        yield from self._server.group_stream(self.identifier, stream_id)
        _LOGGER.info('set stream to %s on %s', stream_id, self.friendly_name)
67209
def stream(stream_id, update_max_id = true)
      raise ArgumentError, "stream_id can't be 0" if stream_id == 0

      stream = @streams[stream_id]
      if stream
        if stream.state == :idle && stream_id < @max_stream_ids[stream_id % 2]
          stream.set_state(:closed_implicitly)
        end
      elsif stream_id > @max_stream_ids[stream_id % 2]
        @max_stream_ids[stream_id % 2] = stream_id if update_max_id
        stream = Stream.new(self, stream_id, state: :idle)
        callback(:stream, stream)
        @streams[stream_id] = stream
      else
        stream = Stream.new(self, stream_id, state: :closed_implicitly)
        callback(:stream, stream)
      end

      stream
    end
994473
public static void goUpStreamOnNetFixed( int[] colRow, RandomIter flowIterator, RandomIter netnumIterator, int[] param ) {

        int kk = 0, count = 0;
        int[] point = new int[2];

        for( int k = 1; k <= 8; k++ ) {
            if (flowIterator.getSampleDouble(colRow[0] + dirIn[k][1], colRow[1] + dirIn[k][0], 0) == dirIn[k][2]) {
                count++;
                if (netnumIterator.getSampleDouble(colRow[0] + dirIn[k][1], colRow[1] + dirIn[k][0], 0) == netnumIterator
                        .getSampleDouble(colRow[0], colRow[1], 0)) {
                    kk = k;
                    point[0] = colRow[0] + dirIn[k][1];
                    point[1] = colRow[1] + dirIn[k][0];
                }
            }
        }
        if (kk == 0) {
            for( int k = 1; k <= 8; k++ ) {
                if (flowIterator.getSampleDouble(colRow[0] + dirIn[k][1], colRow[1] + dirIn[k][0], 0) == dirIn[k][2]) {
                    kk = k;
                    point[0] = colRow[0] + dirIn[k][1];
                    point[1] = colRow[1] + dirIn[k][0];
                }
            }
        }
        colRow[0] = point[0];
        colRow[1] = point[1];
        param[0] = kk;
        param[1] = count;
    }