Chains the frames.  Requires ctypes or the speedups extension.
765524
def chain_frames(self):
        """"""
        prev_tb = None
        for tb in self.frames:
            if prev_tb is not None:
                prev_tb.tb_next = tb
            prev_tb = tb
        prev_tb.tb_next = None
67473
def load_header_chain( cls, chain_path ):
        

        header_parser = BlockHeaderSerializer()
        chain = []
        height = 0
        with open(chain_path, "rb") as f:

            h = SPVClient.read_header_at( f )
            h['block_height'] = height 

            height += 1
            chain.append(h)

        return chain
331111
def iter(self, name):
        '''
        
        '''
        for frame in self.frames:
            vals = frame.get(name)
            if vals is None:
                continue
            for valu in vals:
                yield valu
595273
def _load_chains(f):
        '''
        
        '''
        chains = []
        while True:
            line = f.readline()
            if not line:
                break
            if line.startswith(b'#') or line.startswith(b'\n') or line.startswith(b'\r'):
                continue
            if line.startswith(b'chain'):
                # Read chain
                chains.append(LiftOverChain(line, f))
                continue
        return chains
32438
function(chains) {
    var vertArrays = this.vertArrays();
    var selectedArrays = [];
    var set = {};
    for (var ci = 0; ci < chains.length; ++ci) {
      set[chains[ci]] = true;
    }
    for (var i = 0; i < vertArrays.length; ++i) {
      if (set[vertArrays[i].chain()] === true) {
        selectedArrays.push(vertArrays[i]);
      }
    }
    return selectedArrays;
  }
998278
def frameify(self, state, data):
        """"""

        # Pull in any partially-processed data
        data = state.recv_buf + data

        # Loop over the data
        while data:
            if not state.frame_start:
                try:
                    idx = data.index(self.prefix + self.begin)
                except ValueError:
                    # Can't find the start of a frame...
                    break

                # Advance data to the beginning of the frame (just
                # after the marker)
                data = data[idx + len(self.prefix) + 1:]
                state.frame_start = True

            # Now that data is sitting at the frame start, let's find
            # the frame ending
            try:
                idx = data.index(self.prefix + self.end)
            except ValueError:
                # Can't find the end of the frame...
                break

            # OK, extract the frame and advance the data
            frame = data[:idx]
            data = data[idx + len(self.prefix) + 1:]
            state.frame_start = (self.begin == self.end)

            # Now we need to unstuff the frame
            frame = self.prefix.join(frame.split(self.prefix + self.nop))

            # Yield the frame
            try:
                yield frame
            except FrameSwitch:
                break

        # Put any remaining data back into the buffer
        state.recv_buf = data
1099862
def _distribute_frame_compute(self, writers, frame_keys, frames_to_write, client, batch_size=1):
        """"""
        def load_data(frame_gen, q):
            for frame_arrays in frame_gen:
                future_list = client.compute(frame_arrays)
                for frame_key, arr_future in zip(frame_keys, future_list):
                    q.put({frame_key: arr_future})
            q.put(None)

        input_q = Queue(batch_size if batch_size is not None else 1)
        load_thread = Thread(target=load_data, args=(frames_to_write, input_q,))
        remote_q = client.gather(input_q)
        load_thread.start()

        while True:
            future_dict = remote_q.get()
            if future_dict is None:
                break

            # write the current frame
            # this should only be one element in the dictionary, but this is
            # also the easiest way to get access to the data
            for frame_key, result in future_dict.items():
                # frame_key = rev_future_dict[future]
                w = writers[frame_key]
                w.append_data(result)
            input_q.task_done()

        log.debug("Waiting for child thread...")
        load_thread.join(10)
        if load_thread.is_alive():
            import warnings
            warnings.warn("Background thread still alive after failing to die gracefully")
        else:
            log.debug("Child thread died successfully")
30555
private Pair<Map<String, Frame>, Map<String, Set<String>>> fetchFrames() {
    Map<String, Frame> all_frames = null;
    Map<String, Set<String>> all_frames_cols = null;

    if (this.find_compatible_frames) {
      // caches for this request
      all_frames = Frames.fetchAll();
      all_frames_cols = new TreeMap<String, Set<String>>();

      for (Map.Entry<String, Frame> entry : all_frames.entrySet()) {
        all_frames_cols.put(entry.getKey(), new TreeSet<String>(Arrays.asList(entry.getValue()._names)));
      }
    }
    return new Pair<Map<String, Frame>, Map<String, Set<String>>>(all_frames, all_frames_cols);
  }
31182
def chain(self, **kwargs):
        
        chain = self.build_chain(**kwargs)
        self._patterns.append(chain)
        return chain
651639
def chain(cls, *iterables):
    

    def generator():
      for it in iterables:
        for element in it:
          yield element
    return cls(generator())
1052393
def chain(*layers):
    
    if len(layers) == 0:
        return FeedForward([])
    elif len(layers) == 1:
        return layers[0]
    else:
        return FeedForward(layers)
1292419
def _load_virtual_frames(self):
        """"""
        pages = self.pages
        try:
            if sys.version_info[0] == 2:
                raise ValueError('not supported on Python 2')
            if len(pages) > 1:
                raise ValueError('pages already loaded')
            page = pages[0]
            bytecounts = page._offsetscounts[1]
            if len(bytecounts) != 1:
                raise ValueError('data not contiguous')
            self._seek(4)
            delta = pages[2] - pages[1]
            if pages[3] - pages[2] != delta or pages[4] - pages[3] != delta:
                raise ValueError('page offsets not equidistant')
            page1 = self._getitem(1, validate=page.hash)
            offsetoffset = page1._offsetscounts[0][0] - page1.offset
            if offsetoffset < 0 or offsetoffset > delta:
                raise ValueError('page offsets not equidistant')
            pages = [page, page1]
            filesize = self.parent.filehandle.size - delta
            for index, offset in enumerate(range(page1.offset+delta,
                                                 filesize, delta)):
                offsets = [offset + offsetoffset]
                offset = offset if offset < 2**31 else None
                pages.append(
                    TiffFrame(parent=page.parent, index=index+2, offset=None,
                              offsets=offsets, bytecounts=bytecounts,
                              keyframe=page))
        except Exception as exc:
            log.warning(
                'TiffPages: failed to load virtual frames: %s', str(exc))
        assert pages[1]
        self.pages = pages
        self._cache = True
        self._cached = True
        self._indexed = True
1295653
function chain() {
	let arg = Array.from(arguments),
		pipe = arg.length > 0 ? arg.shift() : stream => stream;

	return function() {
		let writer = through.obj();

		return duplexer(
			{objectMode: true},
			writer,
			pipe.apply(null, [writer].concat(merge(arguments, arg)))
		);
	};
}
1165530
def build_chain(self, **kwargs):
        
        set_defaults(self._chain_defaults, kwargs)
        set_defaults(self._defaults, kwargs)
        return Chain(self, **kwargs)
1241320
@Override protected void execImpl() {
    Frame frame = source;
    if (shuffle) {
      // FIXME: switch to global shuffle
      frame = MRUtils.shuffleFramePerChunk(Utils.generateShuffledKey(frame._key), frame, seed);
      frame.delete_and_lock(null).unlock(null); // save frame to DKV
      // delete frame on the end
      gtrash(frame);
    }
    FrameSplitter fs = new FrameSplitter(frame, ratios);
    H2O.submitTask(fs);

    Frame[] splits = fs.getResult();

    split_keys = new Key [splits.length];
    split_rows = new long[splits.length];
    float rsum = Utils.sum(ratios);
    split_ratios = Arrays.copyOf(ratios, splits.length);
    split_ratios[splits.length-1] = 1f-rsum;
    long sum = 0;
    for(int i=0; i<splits.length; i++) {
      sum += splits[i].numRows();
      split_keys[i] = splits[i]._key;
      split_rows[i] = splits[i].numRows();
    }
    assert sum == source.numRows() : "Frame split produced wrong number of rows: nrows(source) != sum(nrows(splits))";
  }
439297
def _frames(traceback):
    '''
    
    '''
    frame = traceback
    while frame.tb_next:
      frame = frame.tb_next
      yield frame.tb_frame
    return
510281
def _multiframe_to_block(multiframe_dicom):
    
    # Calculate the amount of stacks and slices in the stack
    number_of_stack_slices = int(common.get_ss_value(multiframe_dicom[Tag(0x2001, 0x105f)][0][Tag(0x2001, 0x102d)]))
    number_of_stacks = int(int(multiframe_dicom.NumberOfFrames) / number_of_stack_slices)

    # We create a numpy array
    size_x = multiframe_dicom.pixel_array.shape[2]
    size_y = multiframe_dicom.pixel_array.shape[1]
    size_z = number_of_stack_slices
    size_t = number_of_stacks
    # get the format
    format_string = common.get_numpy_type(multiframe_dicom)

    # get header info needed for ordering
    frame_info = multiframe_dicom[0x5200, 0x9230]

    data_4d = numpy.zeros((size_z, size_y, size_x, size_t), dtype=format_string)

    # loop over each slice and insert in datablock
    t_location_index = _get_t_position_index(multiframe_dicom)
    for slice_index in range(0, size_t * size_z):

        z_location = frame_info[slice_index].FrameContentSequence[0].InStackPositionNumber - 1
        if t_location_index is None:
            t_location = frame_info[slice_index].FrameContentSequence[0].TemporalPositionIndex - 1
        else:
            t_location = frame_info[slice_index].FrameContentSequence[0].DimensionIndexValues[t_location_index] - 1

        block_data = multiframe_dicom.pixel_array[slice_index, :, :]
        # apply scaling
        rescale_intercept = frame_info[slice_index].PixelValueTransformationSequence[0].RescaleIntercept
        rescale_slope = frame_info[slice_index].PixelValueTransformationSequence[0].RescaleSlope
        block_data = common.do_scaling(block_data,
                                       rescale_slope, rescale_intercept)
        # switch to float if needed
        if block_data.dtype != data_4d.dtype:
            data_4d = data_4d.astype(block_data.dtype)
        data_4d[z_location, :, :, t_location] = block_data

    full_block = numpy.zeros((size_x, size_y, size_z, size_t), dtype=data_4d.dtype)

    # loop over each stack and reorganize the data
    for t_index in range(0, size_t):
        # transpose the block so the directions are correct
        data_3d = numpy.transpose(data_4d[:, :, :, t_index], (2, 1, 0))
        # add the block the the full data
        full_block[:, :, :, t_index] = data_3d

    return full_block