Calculates the block_struct array for the output file.
334824
def _calculate_block_structure(self, inequalities, equalities,
                                   momentinequalities, momentequalities,
                                   extramomentmatrix, removeequalities,
                                   block_struct=None):
        
        super(SteeringHierarchy, self).\
          _calculate_block_structure(inequalities, equalities,
                                     momentinequalities, momentequalities,
                                     extramomentmatrix, removeequalities)
        if self.matrix_var_dim is not None:
            self.block_struct = [self.matrix_var_dim*bs
                                 for bs in self.block_struct]
1338806
public function toBinary()
    {
        $this->uniqueTable = array();
        $this->countObjects = 0;
        $this->stringSize = 0;
        $this->intSize = 0;
        $this->miscSize = 0;
        $this->objectRefs = 0;

        $this->writtenObjectCount = 0;
        $this->objectTable = array();
        $this->objectRefSize = 0;

        $this->offsets = array();

        $binary_str = "bplist00";
        $value = $this->getValue(true);
        $this->uniqueAndCountValues($value);

        $this->countObjects += count($this->uniqueTable);
        $this->objectRefSize = self::bytesNeeded($this->countObjects);
        $file_size = $this->stringSize + $this->intSize + $this->miscSize + $this->objectRefs * $this->objectRefSize + 40;
        $offset_size = self::bytesNeeded($file_size);
        $table_offset = $file_size - 32;

        $this->objectTable = array();
        $this->writtenObjectCount = 0;
        $this->uniqueTable = array(); // we needed it to calculate several values
        $value->toBinary($this);

        $object_offset = 8;
        $offsets = array();

        for ($i=0; $i<count($this->objectTable); ++$i) {
            $binary_str .= $this->objectTable[$i];
            $offsets[$i] = $object_offset;
            $object_offset += strlen($this->objectTable[$i]);
        }

        for ($i=0; $i<count($offsets); ++$i) {
            $binary_str .= self::packItWithSize($offset_size, $offsets[$i]);
        }


        $binary_str .= pack("x6CC", $offset_size, $this->objectRefSize);
        $binary_str .= pack("x4N", $this->countObjects);
        $binary_str .= pack("x4N", 0);
        $binary_str .= pack("x4N", $table_offset);

        return $binary_str;
    }
208903
def _calculate_block_structure(self, inequalities, equalities,
                                   momentinequalities, momentequalities,
                                   extramomentmatrix, removeequalities,
                                   block_struct=None):
        
        if block_struct is None:
            if self.verbose > 0:
                print("Calculating block structure...")
            self.block_struct = []
            if self.parameters is not None:
                self.block_struct += [1 for _ in self.parameters]
            for monomials in self.monomial_sets:
                if len(monomials) > 0 and isinstance(monomials[0], list):
                    self.block_struct.append(len(monomials[0]))
                else:
                    self.block_struct.append(len(monomials))
            if extramomentmatrix is not None:
                for _ in extramomentmatrix:
                    for monomials in self.monomial_sets:
                        if len(monomials) > 0 and \
                                isinstance(monomials[0], list):
                            self.block_struct.append(len(monomials[0]))
                        else:
                            self.block_struct.append(len(monomials))
        else:
            self.block_struct = block_struct
        degree_warning = False
        if inequalities is not None:
            self._n_inequalities = len(inequalities)
            n_tmp_inequalities = len(inequalities)
        else:
            self._n_inequalities = 0
            n_tmp_inequalities = 0
        constraints = flatten([inequalities])
        if momentinequalities is not None:
            self._n_inequalities += len(momentinequalities)
            constraints += momentinequalities
        if not removeequalities:
            constraints += flatten([equalities])
        monomial_sets = []
        for k, constraint in enumerate(constraints):
            # Find the order of the localizing matrix
            if k < n_tmp_inequalities or k >= self._n_inequalities:
                if isinstance(constraint, str):
                    ineq_order = 2 * self.level
                else:
                    if constraint.is_Relational:
                        constraint = convert_relational(constraint)
                    ineq_order = ncdegree(constraint)
                    if iscomplex(constraint):
                        self.complex_matrix = True
                if ineq_order > 2 * self.level:
                    degree_warning = True
                localization_order = (2*self.level - ineq_order)//2
                if self.level == -1:
                    localization_order = 0
                if self.localizing_monomial_sets is not None and \
                        self.localizing_monomial_sets[k] is not None:
                    localizing_monomials = self.localizing_monomial_sets[k]
                else:
                    index = find_variable_set(self.variables, constraint)
                    localizing_monomials = \
                        pick_monomials_up_to_degree(self.monomial_sets[index],
                                                    localization_order)
                ln = len(localizing_monomials)
                if ln == 0:
                    localizing_monomials = [S.One]
            else:
                localizing_monomials = [S.One]
                ln = 1
            localizing_monomials = unique(localizing_monomials)
            monomial_sets.append(localizing_monomials)
            if k < self._n_inequalities:
                self.block_struct.append(ln)
            else:
                monomial_sets += [None for _ in range(ln*(ln+1)//2-1)]
                monomial_sets.append(localizing_monomials)
                monomial_sets += [None for _ in range(ln*(ln+1)//2-1)]
                self.block_struct += [1 for _ in range(ln*(ln+1))]

        if degree_warning and self.verbose > 0:
            print("A constraint has degree %d. Either choose a higher level "
                  "relaxation or ensure that a mixed-order relaxation has the"
                  " necessary monomials" % (ineq_order), file=sys.stderr)

        if momentequalities is not None:
            for moment_eq in momentequalities:
                self._moment_equalities.append(moment_eq)
                if not removeequalities:
                    monomial_sets += [[S.One], [S.One]]
                    self.block_struct += [1, 1]
        self.localizing_monomial_sets = monomial_sets
1308350
private Block allocateBlock(String src, INode[] inodes) throws IOException {
    Block b = new Block(generateBlockId(), 0, 0);
    while (isValidBlock(b)) {
      b.setBlockId(generateBlockId());
    }
    b.setGenerationStamp(getGenerationStamp());
    b = dir.addBlock(src, inodes, b);
    return b;
  }
327347
function BlockData(index, buf, cb, count) {
  this.index = index;
  this.buf = buf;
  this.cb = cb;
  this.count = count | 0;
}
1087126
def write_to_sdpa(sdp, filename):
    
    # Coefficient matrices
    row_offsets = [0]
    cumulative_sum = 0
    for block_size in sdp.block_struct:
        cumulative_sum += block_size ** 2
        row_offsets.append(cumulative_sum)
    multiplier = 1
    if sdp.F.dtype == np.complex128:
        multiplier = 2
    lines = [[] for _ in range(multiplier*sdp.n_vars+1)]
    for row in range(len(sdp.F.rows)):
        if len(sdp.F.rows[row]) > 0:
            col_index = 0
            block_index, i, j = convert_row_to_sdpa_index(sdp.block_struct,
                                                          row_offsets, row)
            for k in sdp.F.rows[row]:
                value = sdp.F.data[row][col_index]
                col_index += 1
                if k == 0:
                    value *= -1
                if sdp.F.dtype == np.float64:
                    lines[k].append('{0}\t{1}\t{2}\t{3}\n'.format(
                        block_index + 1, i + 1, j + 1, value))
                else:
                    bs = sdp.block_struct[block_index]
                    if value.real != 0:
                        lines[k].append('{0}\t{1}\t{2}\t{3}\n'.format(
                            block_index + 1, i + 1, j + 1, value.real))
                        lines[k].append('{0}\t{1}\t{2}\t{3}\n'.format(
                            block_index + 1, i + bs + 1, j + bs + 1,
                            value.real))
                    if value.imag != 0:
                        lines[k + sdp.n_vars].append(
                            '{0}\t{1}\t{2}\t{3}\n'.format(
                                block_index + 1, i + 1, j + bs + 1,
                                value.imag))
                        lines[k + sdp.n_vars].append(
                            '{0}\t{1}\t{2}\t{3}\n'.format(
                                block_index + 1, j + 1, i + bs + 1,
                                -value.imag))
    file_ = open(filename, 'w')
    file_.write('"file ' + filename + ' generated by ncpol2sdpa"\n')
    file_.write(str(multiplier*sdp.n_vars) + ' = number of vars\n')
    # bloc structure
    block_struct = [multiplier*blk_size
                    for blk_size in sdp.block_struct]
    file_.write(str(len(block_struct)) + ' = number of blocs\n')
    file_.write(str(block_struct).replace('[', '(')
                .replace(']', ')'))
    file_.write(' = BlocStructure\n')
    # c vector (objective)
    objective = \
        str(list(sdp.obj_facvar)).replace('[', '').replace(']', '')
    if multiplier == 2:
        objective += ', ' + objective
    file_.write('{'+objective+'}\n')
    for k, line in enumerate(lines):
        if line == []:
            continue
        for item in line:
            file_.write('{0}\t'.format(k)+item)
    file_.close()
894943
def blockshapes(self):
        """"""
        if self._blockshapes is None:
            if self._filename:
                self._populate_from_rasterio_object(read_image=False)
            else:
                # if no file is attached to the raster set the shape of each band to be the data array size
                self._blockshapes = [(self.height, self.width) for z in range(self.num_bands)]
        return self._blockshapes
174133
def read_blocks(self, block_size=4096):
        
        while True:
            out = self.mf.read(block_size)
            if not out:
                break
            yield bytes(out)
1303349
def build_header_output
      output = []

      @header.each do |line|
        _data = []
        line.each do |h|
          _data << {:value => h, :color => @style[:header]}
        end
        output << _data
      end
      output
    end
1219678
def _calculate_osdb_hash(self):
        
        log.debug('_calculate_OSDB_hash() of "{path}" ...'.format(path=self._filepath))
        f = self._filepath.open(mode='rb')

        file_size = self.get_size()

        longlong_format = 'Q'  # unsigned long long little endian
        size_longlong = struct.calcsize(longlong_format)

        block_size = min(file_size, 64 << 10)  # 64kiB
        block_size = block_size & ~(size_longlong - 1)  # lower round on multiple of longlong

        nb_longlong = block_size // size_longlong
        fmt = '<{nbll}{member_format}'.format(
            nbll=nb_longlong,
            member_format=longlong_format)

        hash_int = file_size

        buffer = f.read(block_size)
        list_longlong = struct.unpack(fmt, buffer)
        hash_int += sum(list_longlong)

        f.seek(-block_size, os.SEEK_END)
        buffer = f.read(block_size)
        list_longlong = struct.unpack(fmt, buffer)
        hash_int += sum(list_longlong)

        f.close()
        hash_str = '{:016x}'.format(hash_int)[-16:]
        log.debug('hash("{}")={}'.format(self.get_filepath(), hash_str))
        return hash_str
259182
def get_block_bounds(filename):
 
 bs = []
 with open(filename,'rb') as inf:
  while True:
   bytes1 = inf.read(12)
   if len(bytes1) < 12: break
   bs.append([inf.tell()-12])
   gzip_id1,gzip_id2,compression_method,flag,mtime,xfl,osval,xlen=struct.unpack('<BBBBIBBH',bytes1)
   # ready to look in extra field
   bytes2 = inf.read(xlen) # all the extra field stuff 
   s = StringIO.StringIO(bytes2)
   obsslen = 0
   blocksize = 0
   while True:
     v1 = s.read(4)
     if len(v1) == 0: 
       break
     if len(v1) < 4:
       sys.stderr.write("lack header values ERROR\n")
       return False
     s1,s2,slen = struct.unpack('<BBH',v1)
     if s1 == 66 and s2 == 67:
       has_id = True
       obsslen = slen
       blocksize = struct.unpack('<H',s.read(slen))[0]
     else:
       v = s.read(slen)
   chunk = inf.read(blocksize-1-xlen-19)
   inf.read(9)
   bs[-1].append(inf.tell())
 return bs
1270743
def benchmark_file(
        filename, compiler, include_dirs, (progress_from, progress_to),
        iter_count, extra_flags = ''):
    """"""
    time_sum = 0
    mem_sum = 0
    for nth_run in xrange(0, iter_count):
        (time_spent, mem_used) = benchmark_command(
            '{0} -std=c++11 {1} -c {2} {3}'.format(
                compiler,
                ' '.join('-I{0}'.format(i) for i in include_dirs),
                filename,
                extra_flags
            ),
            (
                progress_to * nth_run + progress_from * (iter_count - nth_run)
            ) / iter_count
        )
        os.remove(os.path.splitext(os.path.basename(filename))[0] + '.o')
        time_sum = time_sum + time_spent
        mem_sum = mem_sum + mem_used

    return {
        "time": time_sum / iter_count,
        "memory": mem_sum / (iter_count * 1024)
    }
1020629
def output_files(self):
        """"""
        for dep in self.subgraph.successors(self.address):
            dep_rule = self.subgraph.node[dep]['target_obj']
            for out_file in dep_rule.output_files:
                yield out_file
788893
public int getNumberOfBlocks(final FileStatus file) throws IOException {

		int numberOfBlocks = 0;

		if (file == null) {
			return 0;
		}

		// For a file, this is easy
		if (!file.isDir()) {
			return getNumberOfBlocks(file.getLen(), file.getBlockSize());
		}

		// file is a directory
		final FileStatus[] files = this.listStatus(file.getPath());
		for (int i = 0; i < files.length; i++) {

			if (!files[i].isDir()) {
				numberOfBlocks += getNumberOfBlocks(files[i].getLen(), files[i].getBlockSize());
			}
		}

		return numberOfBlocks;
	}
306395
def matrix_to_blockmatrix(self, blocksize):
        
        if self.get_width() % blocksize or self.get_height() % blocksize:
            raise ValueError("Number of rows and columns have to be evenly dividable by blocksize")
        selfBlocks = []
        for columnIndex in range(0, self.get_width() - 1, blocksize):
            for rowIndex in range(0, self.get_height() - 1, blocksize):
                currentBlock = []
                for blockRows in self.get_array(False)[columnIndex:columnIndex + blocksize]:
                    currentBlock += blockRows[rowIndex:rowIndex + blocksize]
                selfBlocks.append(Matrix(blocksize, blocksize, currentBlock, rowBased=False))
        return Matrix(self.get_width() / blocksize, self.get_height() / blocksize, selfBlocks, rowBased=False)
197987
def expected_results_of_file(filename):
    """"""
    results = {}
    for (filename_part, (expected_result, for_properties)) in _FILE_RESULTS.items():
        if filename_part in filename:
            expected_result_class = get_result_classification(expected_result)
            assert expected_result_class in {RESULT_CLASS_TRUE, RESULT_CLASS_FALSE}
            expected_result = (expected_result_class == RESULT_CLASS_TRUE)
            subproperty = None
            if len(for_properties) > 1:
                assert for_properties == _MEMSAFETY_SUBPROPERTIES and expected_result
                property = _PROP_MEMSAFETY
            else:
                property = next(iter(for_properties))
                if property in _MEMSAFETY_SUBPROPERTIES and not expected_result:
                    subproperty = property
                    property = _PROP_MEMSAFETY
            if property in results:
                raise BenchExecException(
                    "Duplicate property {} in filename {}".format(property, filename))
            results[property] = ExpectedResult(expected_result, subproperty)
    return results
421934
def assemble(self):
        """"""
        first_block = ray.get(self.objectids[(0, ) * self.ndim])
        dtype = first_block.dtype
        result = np.zeros(self.shape, dtype=dtype)
        for index in np.ndindex(*self.num_blocks):
            lower = DistArray.compute_block_lower(index, self.shape)
            upper = DistArray.compute_block_upper(index, self.shape)
            result[[slice(l, u) for (l, u) in zip(lower, upper)]] = ray.get(
                self.objectids[index])
        return result