Write out K/V pairs
184724
@Override
  protected AutoBuffer writeAll_impl(AutoBuffer ab) {
    for (Key<Model> k : _models.values())
      ab.putKey(k);
    return super.writeAll_impl(ab);
  }
820809
async def dump_varint_t(writer, type_or, pv):
    
    width = int_mark_to_size(type_or)
    n = (pv << 2) | type_or

    buffer = _UINT_BUFFER
    for _ in range(width):
        buffer[0] = n & 0xff
        await writer.awrite(buffer)
        n >>= 8

    return width
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()
1030087
def dump(bqm, fp, vartype_header=False):
    """"""
    for triplet in _iter_triplets(bqm, vartype_header):
        fp.write('%s\n' % triplet)
81235
def write_pair(field, value)
      key = (field.tag << 3) | field.wire_type
      stream << ::Protobuf::Field::VarintField.encode(key)
      stream << field.encode(value)
    end
189558
def _wr_ver_n_key(self, fout_txt, verbose):
        """"""
        with open(fout_txt, 'w') as prt:
            self._prt_ver_n_key(prt, verbose)
            print('               WROTE: {TXT}'.format(TXT=fout_txt))
716312
def _write_ieeg_channels(output_file, data):
    
    CHAN_TYPE = 'ECOG'
    CHAN_UNIT = 'µV'

    with output_file.open('w') as f:
        f.write('name\ttype\tunits\tsampling_frequency\tlow_cutoff\thigh_cutoff\tnotch\treference\n')
        for one_chan in data.chan[0]:
            f.write('\t'.join([
                one_chan,
                CHAN_TYPE,
                CHAN_UNIT,
                f'{data.s_freq:f}',
                'n/a',
                'n/a',
                'n/a',
                'n/a',
                ]) + '\n')
933501
def _write(self, lines, fname):
        
        with open(fname, 'wb') as out_fhndl:
            for line in sorted(lines, key=self.key):
                pickle.dump(line, out_fhndl)
57818
def write_multiple_registers(addr, vals)
      s_val = ""
      vals.each do |reg|
        s_val << reg.to_word
      end

      query("\x10" + addr.to_word + vals.size.to_word + (vals.size * 2).chr + s_val)
      self
    end
576378
def write_output_files(self):
        
        os.mkdir("analysis")
        os.chdir("analysis")
        os.mkdir("hydrogen_bonds")
        os.chdir("hydrogen_bonds")
        for traj in range(len(self.trajectory)):
            with open('hbonds_data_total_'+str(traj)+'.csv', 'wb') as outfile:
                hwriter = csv.writer(outfile, delimiter=' ')
                for time in self.hbonds_by_time[traj]:
                    hwriter.writerow([time[0],time[1]])
            for bond in self.hbonds_by_type[traj]:
                if bond["donor_resnm"]=="LIG" and (bond["acceptor_idx"],bond["donor_idx"]) in [(k[0],k[3]) for k,v in self.hbonds_for_drawing.items()]:
                    with open('hbond_'+bond["acceptor_resnm"]+"_"+str(bond["acceptor_resid"])+"_"+bond["donor_atom"]+"_"+str(traj)+".csv","wb") as outfile:
                        hwriter = csv.writer(outfile, delimiter=' ')
                        for time in self.hbonds_timesteps[traj]:
                            result = [1 if x[0]==time and x["acceptor_idx"]==bond["acceptor_idx"] else 0 for x in self.hbonds[traj]][0]
                            hwriter.writerow([time,result])
                if bond["donor_resnm"]!="LIG" and (bond["donor_idx"],bond["acceptor_idx"]) in [(k[0],k[3]) for k,v in self.hbonds_for_drawing.items()]:
                    with open('hbond_'+bond["donor_resnm"]+"_"+str(bond["donor_resid"])+"_"+bond["acceptor_atom"]+"_"+str(traj)+".csv","wb") as outfile:
                        hwriter = csv.writer(outfile, delimiter=' ')
                        for time in self.hbonds_timesteps[traj]:
                            result = [1 if x[0]==time and x["donor_idx"]==bond["donor_idx"] else 0 for x in self.hbonds[traj]][0]
                            hwriter.writerow([time,result])
        os.chdir("../../")
1152310
def kvpath(self, base, *pa, **kw):
        
        def fmt(vtuple):
            typ, val = vtuple
            if not val is None:
                return safeformat("{:%s}"%typ, val)
            return None
        parts = [base]
        for v in pa:
            fv = fmt(v)
            if not fv is None:
                parts.append(quote(fv))
        for k,v in kw.items():
            fv = fmt(v)
            if not fv is None:
                parts.append(quote(k+"="+fv))
        return "/".join(parts)
21619
def write(self, filename="mesh.vtk", binary=True):
        
        import vtkplotter.vtkio as vtkio

        return vtkio.write(self, filename, binary)
930357
private void writeEnvelope(ByteWriter writer) throws IOException {

		if (envelope != null) {

			// Write x and y values
			writer.writeDouble(envelope.getMinX());
			writer.writeDouble(envelope.getMaxX());
			writer.writeDouble(envelope.getMinY());
			writer.writeDouble(envelope.getMaxY());

			// Write z values
			if (envelope.hasZ()) {
				writer.writeDouble(envelope.getMinZ());
				writer.writeDouble(envelope.getMaxZ());
			}

			// Write m values
			if (envelope.hasM()) {
				writer.writeDouble(envelope.getMinM());
				writer.writeDouble(envelope.getMaxM());
			}
		}
	}
128016
def generateAmplitudes(k):
    """"""
    res = np.array([np.random.random() for i in range(k)])
    return res/res.sum()
172594
def _MakeRanges(pairs):
  """"""
  ranges = []
  last = -100

  def evenodd(last, a, b, r):
    if a != last+1 or b != _AddDelta(a, r[2]):
      return False
    r[1] = a
    return True

  def evenoddpair(last, a, b, r):
    if a != last+2:
      return False
    delta = r[2]
    d = delta
    if type(delta) is not str:
      return False
    if delta.endswith('Skip'):
      d = delta[:-4]
    else:
      delta = d + 'Skip'
    if b != _AddDelta(a, d):
      return False
    r[1] = a
    r[2] = delta
    return True

  for a, b in pairs:
    if ranges and evenodd(last, a, b, ranges[-1]):
      pass
    elif ranges and evenoddpair(last, a, b, ranges[-1]):
      pass
    else:
      ranges.append([a, a, _Delta(a, b)])
    last = a
  return ranges
1149747
static Frame toFrame(Vector v, Key key) {
    final int log_rows_per_chunk = Math.max(1, FileVec.DFLT_LOG2_CHUNK_SIZE - (int) Math.floor(Math.log(1) / Math.log(2.)));
    Vec vv = makeCon(0, v.size(), log_rows_per_chunk, false /* no rebalancing! */);
    Frame f = new Frame(key, new Vec[]{vv}, true);
    try( Vec.Writer vw = f.vecs()[0].open() ) {
      for (int r = 0; r < v.size(); ++r)
        vw.set(r, v.get(r));
    }
    DKV.put(key, f);
    return f;
  }
1341945
def _write_mef(self, key, extlist, outfile):
        """"""
        channel = self.fv.get_channel(self.chname)
        with fits.open(outfile, mode='update') as pf:
            # Process each modified data extension
            for idx in extlist:
                k = '{0}[{1}]'.format(key, self._format_extname(idx))
                image = channel.datasrc[k]

                # Insert data and header into output HDU
                pf[idx].data = image.get_data()
                self._write_header(image, pf[idx])

            # Write history to PRIMARY
            self._write_history(key, pf['PRIMARY'])