Return an array of batch parts to submit
774361
def parts(self):
        """"""

        parts = []

        upserts = dict()
        deletes = []

        # we keep track of the batch size as we go (pretty close approximation!) so we can chunk it small enough
        # to limit the HTTP posts to under 700KB - server limits to 750KB, so play it safe
        max_upload_size = 700000

        # loop upserts first - fit the deletes in afterward
        # '{"replace_all": true, "complete": false, "guid": "6659fbfc-3f08-42ee-998c-9109f650f4b7", "upserts": [], "deletes": []}'
        base_part_size = 118
        if not self.replace_all:
            base_part_size += 1  # yeah, this is totally overkill :)

        part_size = base_part_size
        for value in self.upserts:
            if (part_size + self.upserts_size[value]) >= max_upload_size:
                # this record would put us over the limit - close out the batch part and start a new one
                parts.append(BatchPart(self.replace_all, upserts, deletes))
                upserts = dict()
                deletes = []
                part_size = base_part_size

            # for the new upserts dict, drop the lower-casing of value
            upserts[self.lower_val_to_val[value]] = self.upserts[value]
            part_size += self.upserts_size[value]    # updating the approximate size of the batch

        for value in self.deletes:
            # delete adds length of string plus quotes, comma and space
            if (part_size + len(value) + 4) >= max_upload_size:
                parts.append(BatchPart(self.replace_all, upserts, deletes))
                upserts = dict()
                deletes = []
                part_size = base_part_size

            # for the new deletes set, drop the lower-casing of value
            deletes.append({'value': self.lower_val_to_val[value]})
            part_size += len(value) + 4

        if len(upserts) + len(deletes) > 0:
            # finish the batch
            parts.append(BatchPart(self.replace_all, upserts, deletes))

        if len(parts) == 0:
            if not self.replace_all:
                raise ValueError("Batch has no data, and 'replace_all' is False")
            parts.append(BatchPart(self.replace_all, dict(), []))

        # last part finishes the batch
        parts[-1].set_last_part()
        return parts
324485
def _get_batch_requests(self, timeout=None):
        """"""
        reqs = []
        s = time()
        while len(reqs) < self.batch_size and (time() - s) < timeout:
            try:
                req = self.queue.get(block=False)
                self.queue.task_done()

                reqs.append(req)
            except Empty as ex:
                if self.stop_flag:
                    break
                else:
                    sleep(0.1)

        if not reqs:
            raise Empty
        elif len(reqs) <= 1:
            return reqs[0]
        else:
            logitems = []
            req = reqs[0]
            for req in reqs:
                logitems.extend(req.get_log_items())

            ret = PutLogsRequest(self.project, self.log_store, req.topic, logitems=logitems)
            ret.__record__ = req.__record__

            return ret
272836
def batch_gen(data, batch_size):
    '''
    
    '''
    data = data or []
    for i in range(0, len(data), batch_size):
        yield data[i:i + batch_size]
414528
function mergeBatchResults(batches) {
    let files = [];
    let unformattedFiles = [];
    let formattedFiles = [];
    let errors = [];

    batches.forEach(batch => {
        files.push(...batch.files);
        unformattedFiles.push(...batch.unformattedFiles);
        formattedFiles.push(...batch.formattedFiles);
        errors.push(...batch.errors);
    });

    return { files, formattedFiles, unformattedFiles, errors };
}
1077066
def provide_data(self):
        """"""
        return [(k, tuple([self.batch_size] + list(v.shape[1:]))) for k, v in self.data]
1089036
def _batch_key(self, query):
    '''
    
    '''
    return ''.join( ['%s%s'%(k,v) for k,v in sorted(query.items())] )
617311
function batch(ops) {
  var batch = [];

  if (!ops.length) {
    return bluebird.resolve();
  }

  for (let i = 0; i < ops.length; i++) {
    let { key, value } = ops[i];

    if (shouldProcess(key)) {
      batch.push(key);
      batch.push(value);
    }
  }

  if (!batch.length) {
    return bluebird.resolve();
  }

  return module.exports.client.hmsetAsync(REDIS_HASH, batch);
}
561885
def batch_get_item(self, request_items, object_hook=None):
        
        data = {'RequestItems' : request_items}
        json_input = json.dumps(data)
        return self.make_request('BatchGetItem', json_input,
                                 object_hook=object_hook)
1269659
function Batch(db, options) {
  this.options = options || {};
  this.ops = [];
  this.db = db;
  this.written = false;
}
964160
public function getBatchArray()
    {
        $batchEntry = [];

        foreach ($this->batches as $batch) {
            $batchEntry[] = $batch->toArray();
        }

        return $batchEntry;
    }
552227
def batch(data, batch_size, batch_size_fn=None):
    """"""
    if batch_size_fn is None:
        def batch_size_fn(new, count, sofar):
            return count
    minibatch, size_so_far = [], 0
    for ex in data:
        minibatch.append(ex)
        size_so_far = batch_size_fn(ex, len(minibatch), size_so_far)
        if size_so_far == batch_size:
            yield minibatch
            minibatch, size_so_far = [], 0
        elif size_so_far > batch_size:
            yield minibatch[:-1]
            minibatch, size_so_far = minibatch[-1:], batch_size_fn(ex, 1, 0)
    if minibatch:
        yield minibatch
54614
function (nodes, batchOps, done) {
      self.db.batch(batchOps, function (err) {
        if (err) {
          nodes.forEach(rejectNode)
          return done(err)
        }
        done(null, nodes)
      })
    }
724179
function batch( target, method, options ) {
    var i, len;

    // Selector
    if( typeof target === 'string' ) {
      var targets = document.querySelectorAll( target );

      for( i = 0, len = targets.length; i < len; i++ ) {
        method.call( null, targets[i], options );
      }
    }
    // Array (jQuery)
    else if( typeof target === 'object' && typeof target.length === 'number' ) {
      for( i = 0, len = target.length; i < len; i++ ) {
        method.call( null, target[i], options );
      }
    }
    // Single element
    else if( target.nodeName ) {
      method.call( null, target, options );
    }
    else {
      throw 'Stroll target was of unexpected type.';
    }
  }
927668
def default_batchify_fn(data):
    """"""
    if isinstance(data[0], nd.NDArray):
        return nd.stack(*data)
    elif isinstance(data[0], tuple):
        data = zip(*data)
        return [default_batchify_fn(i) for i in data]
    else:
        data = np.asarray(data)
        return nd.array(data, dtype=data.dtype)
974490
def bulk_submit(cls, exports, copy_only=False, api=None):
        
        if not exports:
            raise SbgError('Exports are required')

        api = api or cls._API

        items = []
        for export in exports:
            file_ = Transform.to_file(export.get('file'))
            volume = Transform.to_volume(export.get('volume'))
            location = Transform.to_location(export.get('location'))
            properties = export.get('properties', {})
            overwrite = export.get('overwrite', False)

            item = {
                'source': {
                    'file': file_
                },
                'destination': {
                    'volume': volume,
                    'location': location
                },
                'properties': properties,
                'overwrite': overwrite
            }

            items.append(item)

        data = {'items': items}
        params = {'copy_only': copy_only}

        response = api.post(
            url=cls._URL['bulk_create'], params=params, data=data
        )
        return ExportBulkRecord.parse_records(response=response, api=api)
423353
def bulk_submit(cls, imports, api=None):
        
        if not imports:
            raise SbgError('Imports are required')

        api = api or cls._API

        items = []
        for import_ in imports:
            volume = Transform.to_volume(import_.get('volume'))
            location = Transform.to_location(import_.get('location'))
            project = Transform.to_project(import_.get('project'))
            name = import_.get('name', None)
            overwrite = import_.get('overwrite', False)

            item = {
                'source': {
                    'volume': volume,
                    'location': location
                },
                'destination': {
                    'project': project
                },
                'overwrite': overwrite
            }

            if name:
                item['destination']['name'] = name

            items.append(item)

        data = {'items': items}

        response = api.post(url=cls._URL['bulk_create'], data=data)
        return ImportBulkRecord.parse_records(response=response, api=api)
285047
def applet_validate_batch(object_id, input_params={}, always_retry=True, **kwargs):
    
    return DXHTTPRequest('/%s/validateBatch' % object_id, input_params, always_retry=always_retry, **kwargs)