Try to guess a reasonable block length to use for block-wise iteration
    over `data`.
199731
def get_blen_array(data, blen=None):
    """"""

    if blen is None:

        if hasattr(data, 'chunklen'):
            # bcolz carray
            return data.chunklen

        elif hasattr(data, 'chunks') and \
                hasattr(data, 'shape') and \
                hasattr(data.chunks, '__len__') and \
                hasattr(data.shape, '__len__') and \
                len(data.chunks) == len(data.shape):
            # something like h5py dataset
            return data.chunks[0]

        else:
            # fall back to something simple, ~1Mb chunks
            row = np.asarray(data[0])
            return max(1, (2**20) // row.nbytes)

    else:
        return blen
1314141
def pick_tile_size(self, seg_size, data_lengths, valid_chunks, valid_lengths):
        

        if len(valid_lengths) == 1:
            return data_lengths[0], valid_chunks[0], valid_lengths[0]
        else:
            # Pick the tile size that is closest to 1/3 of the science segment
            target_size = seg_size / 3
            pick, pick_diff = 0, abs(valid_lengths[0] - target_size)
            for i, size in enumerate(valid_lengths):
                if abs(size - target_size) < pick_diff:
                    pick, pick_diff  = i, abs(size - target_size)
            return data_lengths[pick], valid_chunks[pick], valid_lengths[pick]
1373727
private void updateSize(IoBuffer data) {
        this.widthInfo = data.getShort();
        this.heightInfo = data.getShort();
        // extract width and height of the frame
        this.width = this.widthInfo & 0xfff;
        this.height = this.heightInfo & 0xfff;
        // calculate size of blocks
        this.blockWidth = this.widthInfo & 0xf000;
        this.blockWidth = (this.blockWidth >> 12) + 1;
        this.blockWidth <<= 4;

        this.blockHeight = this.heightInfo & 0xf000;
        this.blockHeight = (this.blockHeight >> 12) + 1;
        this.blockHeight <<= 4;

        int xblocks = this.width / this.blockWidth;
        if ((this.width % this.blockWidth) != 0) {
            // partial block
            xblocks += 1;
        }

        int yblocks = this.height / this.blockHeight;
        if ((this.height % this.blockHeight) != 0) {
            // partial block
            yblocks += 1;
        }

        this.blockCount = xblocks * yblocks;

        int blockSize = maxCompressedSize(this.blockWidth * this.blockHeight * 3);
        int totalBlockSize = blockSize * this.blockCount;
        if (this.totalBlockDataSize != totalBlockSize) {
            log.info("Allocating memory for {} compressed blocks.", this.blockCount);
            this.blockDataSize = blockSize;
            this.totalBlockDataSize = totalBlockSize;
            this.blockData = new byte[blockSize * this.blockCount];
            this.blockSize = new int[blockSize * this.blockCount];
            // Reset the sizes to zero
            for (int idx = 0; idx < this.blockCount; idx++) {
                this.blockSize[idx] = 0;
            }
        }
    }
231386
private void read_block_sizes_from_disk(boolean coalesce_blocks)
    throws IOException
    {
        long addr = FIRST_TAIL;
        int length;
        long new_tail = tail_ptr;

        while (addr < tail_ptr) {
            seek(addr);
            if (coalesce_blocks) {
                length = combine_blocks(addr);
            } else {
                length = readInt();
            }
            if (length > 0) {
                if ((length + addr >= tail_ptr) && (!readOnly)) {
                    // add last block to tail
                    new_tail = addr;
                } else {
                    add_to_freelist(addr, length);
                }
            } else {
                length = - length;
                allocated_blocks++;
                allocated_words += length;
            }
            addr = addr + length;
        }
        if ((new_tail != tail_ptr) && (!readOnly)) {
            tail_ptr = new_tail;
            seek(TAIL_DPTR);
            writeLong(tail_ptr);
        }

    }
220943
private long allocate_from_tail(int block_size)
    throws IOException
    {
        long block_to_alloc;

        block_to_alloc = tail_ptr;
        tail_ptr = tail_ptr + block_size;

        allocated_blocks++;
        allocated_words += block_size;

        seek_and_count(block_to_alloc);
        writeInt(- block_size);
        seek_and_count(TAIL_DPTR);
        writeLong(tail_ptr);

        return(block_to_alloc + HDR_SIZE);
    }
900690
def each
      if block_given?
        length.times do |n|
          yield build_coordinate(n)
        end
        self
      else
        length.times.collect { |n|
          build_coordinate(n)
        }.to_enum
      end
    end
889673
def block_size(self):
        
        bs = self.attributes['block_size']
        if isinstance(bs, six.string_types):
            bs = shlex.split(bs)
        bs = [str(e) for e in bs]
        return bs
658791
public static long getFileLengthFromBlockSize(long blockSize,
      int bytesPerChecksum, int checksumSize) {
    long numChunks; 
    if (blockSize % bytesPerChecksum == 0) {    
      numChunks = blockSize / bytesPerChecksum; 
    } else {    
      numChunks = blockSize / bytesPerChecksum + 1; 
    }   
    return blockSize + numChunks * checksumSize 
        + BlockInlineChecksumReader.getHeaderSize();  
  }
887405
def _GenerateChunk(self, length):
    """"""

    while 1:
      to_read = min(length, self.RECV_BLOCK_SIZE)
      if to_read == 0:
        return

      data = self.rfile.read(to_read)
      if not data:
        return

      yield data
      length -= len(data)
53560
def _guess(self, filename):
        """"""

        encoding = None

        file_size = os.path.getsize(filename)
        # If the file is really big, lets just call it binary.
        # We don't have time to let Python chug through a massive file.
        if not self._is_very_large(file_size):
            with open(filename, "rb") as f:
                if file_size == 0:
                    encoding = 'ascii'
                else:
                    encoding = self._detect_buffer_encoding(f)
                    if encoding is None:
                        raise UnicodeDecodeError('None', b'', 0, 0, 'Unicode cannot be detected.')
                    if encoding != BINARY_ENCODE:
                        encoding = self._verify_encoding(encoding)
        else:  # pragma: no cover
            raise UnicodeDecodeError('None', b'', 0, 0, 'Unicode detection is not applied to very large files!')

        return encoding
129236
private static int blockLength(int start, QrMode[] inputMode) {

        QrMode mode = inputMode[start];
        int count = 0;
        int i = start;

        do {
            count++;
        } while (((i + count) < inputMode.length) && (inputMode[i + count] == mode));

        return count;
    }
461113
private synchronized void readBlockSizeInfo() throws IOException {
    if (!transferBlockSize) {
      return;
    }
    blkLenInfoUpdated = true;
    isBlockFinalized = in.readBoolean();
    updatedBlockLength = in.readLong();
    if (dataTransferVersion >= DataTransferProtocol.READ_PROFILING_VERSION) {
      readDataNodeProfilingData();
    }
    
    if (LOG.isDebugEnabled()) {
      LOG.debug("ifBlockComplete? " + isBlockFinalized + " block size: "
          + updatedBlockLength);
    }      
  }
427780
def _read_block(blocksize, stream):
    
    blockdata = stream.read(blocksize)
    return int.from_bytes(blockdata, 'big')
171979
def _length_hint(obj):
    """"""
    try:
        return len(obj)
    except (AttributeError, TypeError):
        try:
            get_hint = type(obj).__length_hint__
        except AttributeError:
            return None
        try:
            hint = get_hint(obj)
        except TypeError:
            return None
        if hint is NotImplemented or \
           not isinstance(hint, int_types) or \
           hint < 0:
            return None
        return hint
1013909
def file_length(in_file):
    ''''''

    fid = open(in_file)
    data = fid.readlines()
    fid.close()
    return len(data)
210547
def get_thread_block_dimensions(params, block_size_names=None):
    """"""
    if not block_size_names:
        block_size_names = default_block_size_names

    block_size_x = params.get(block_size_names[0], 256)
    block_size_y = params.get(block_size_names[1], 1)
    block_size_z = params.get(block_size_names[2], 1)
    return (int(block_size_x), int(block_size_y), int(block_size_z))
863280
def block_lengths(self):
        
        if self._lengths_cache is None:
            # The first column will have the correct lengths. We have an
            # invariant that requires that all blocks be the same length in a
            # row of blocks.
            self._lengths_cache = (
                [obj.length() for obj in self._partitions_cache.T[0]]
                if len(self._partitions_cache.T) > 0
                else []
            )
        return self._lengths_cache