Do a forward and backward pass of the network in one call. Returns
the loss from the backward pass.

@param \Rubix\ML\Datasets\Labeled $batch
@return float
968352
public function roundtrip(Labeled $batch) : float
    {
        $input = Matrix::quick($batch->samples())->transpose();

        $this->feed($input);

        return $this->backpropagate($batch->labels());
    }
172723
public function lastUpdate($batch) {
        $lu = get_option("ilab_media_tools_{$batch}_last_update", 0);
        if ($lu > 0) {
            $lu = microtime(true) - $lu;
        }

        return $lu;
    }
1288408
private function manageBatch(array $batch, $max = 0)
    {
        if (count($batch) >= $max) {
            $this->entityManager->flush();
            $batch = [];
        }

        return $batch;
    }
412408
public function emitBatch($batch){
        $buildThrift = (new AgentClient())->buildThrift($batch);
        if(isset($buildThrift['len']) && $buildThrift['len'] && $this->isOpen()) {
            $len = $buildThrift['len'];
            $enitThrift = $buildThrift['thriftStr'];
            $res = socket_sendto($this->socket, $enitThrift, $len, 0, $this->host, $this->post);
            if($res === false) {
                throw new \Exception("emit failse");
            }

            return true;
        }else{
            return false;
        }
    }
851397
public function forward( $p ) {
        
        $lon = $p->x;
        $lat = $p->y;
        
        /* Forward equations
          ----------------- */
        $dlon = Common::adjust_lon( $lon - $this->long0 );
        $x = $this->x0 + $this->a * $dlon;
        $y = $this->y0 + $this->a * log( tan( (Common::PI / 4.0) + ($lat / 2.5) ) ) * 1.25;

        $p->x = $x;
        $p->y = $y;
        
        return $p;
    }
367215
public function forward(Matrix $input) : Matrix
    {
        if (!$this->weights or !$this->biases) {
            throw new RuntimeException('Layer is not initialized');
        }

        $this->input = $input;

        $this->z = $this->weights->w()->matmul($input)
            ->add($this->biases->w());

        return $this->z;
    }
35404
public function execBatch(array $batch) : bool
    {
        $oldAttrEmulatePrepares = $this->getConnection()->getAttribute(\PDO::ATTR_EMULATE_PREPARES);
        $this->getConnection()->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
        try {
            $this->getConnection()->exec($this->createQStrFromBatch($batch));
        } catch (\PDOException $e) {
            $this->getConnection()->exec('ROLLBACK');
            throw new BatchExecutionException('Ошибка выполнения пакета транзакций: ' . $e->getMessage());
        } finally {
            $this->getConnection()->setAttribute(\PDO::ATTR_EMULATE_PREPARES, $oldAttrEmulatePrepares);
        }

        return true;
    }
530928
public static function binaryBatch(Api\MtBatchBinarySmsCreate $batch)
    {
        $fields = Serialize::_createBatchHelper($batch);

        $fields['type'] = 'mt_binary';
        $fields['body'] = base64_encode($batch->getBody());
        $fields['udh'] = bin2hex($batch->getUdh());

        return Serialize::_toJson($fields);
    }
1135920
public function batch(int $n = 50) : array
    {
        $batches = [];

        $samples = $this->samples;

        foreach (array_chunk($this->samples, $n) as $batch) {
            $batches[] = self::quick($batch);
        }

        return $batches;
    }
815277
protected function getMigrated(?int $batches = null): ResultSet
	{
		$query = $this->builder();

		if($batches !== null && $batches > 0)
		{
			$query->where('batch', '>', ($this->builder()->max('batch') - $batches));
		}

		return $query->select(['version', 'package'])->descending('version')->all();
	}
359061
public double getValue(int[] batch) {
        double value = 0.0;
        for (int i=0; i<batch.length; i++) {
            value += getValue(i);
        }
        return value;
    }
837994
def train(self, data, label, batch_size):
        
        # pylint: disable=no-member
        sum_losses = 0
        len_losses = 0
        with autograd.record():
            losses = [self.loss_fn(self.net(X), Y) for X, Y in zip(data, label)]
        for loss in losses:
            sum_losses += mx.nd.array(loss).sum().asscalar()
            len_losses += len(loss)
            loss.backward()
        self.trainer.step(batch_size)
        return sum_losses, len_losses
178335
def _vgg16_data_prep(batch):
    
    from mxnet import nd
    mean = nd.array([123.68, 116.779, 103.939], ctx=batch.context)
    return nd.broadcast_sub(255 * batch, mean.reshape((-1, 1, 1)))
601019
private function _getResultPull($forwardQueueName)
    {
        $serverId = $this->_getQueueServerId($forwardQueueName);
        $server   = &$this->servers[$serverId];
        
        if (isset($server[self::SERVER_RESULT_POOL])) {
            return $server[self::SERVER_RESULT_POOL];
        }
        
        $queue = &$this->_getReplyQueue($forwardQueueName);
        
        $pool = new ResultPoolPlain();
        $pool->setQueue($queue);
        
        $server[self::SERVER_RESULT_POOL] = $pool;
        
        return $server[self::SERVER_RESULT_POOL];
    }
756659
public static int cusolverDnSpotrfBatched(
        cusolverDnHandle handle, 
        int uplo, 
        int n, 
        Pointer Aarray, 
        int lda, 
        Pointer infoArray, 
        int batchSize)
    {
        return checkResult(cusolverDnSpotrfBatchedNative(handle, uplo, n, Aarray, lda, infoArray, batchSize));
    }
100572
def backward(ctx, grad_output):
    
    batchSize = grad_output.shape[0]
    indices, = ctx.saved_tensors

    g = grad_output.reshape((batchSize, -1))
    grad_x = torch.zeros_like(g, requires_grad=False)
    grad_x.scatter_(1, indices, g.gather(1, indices))
    grad_x = grad_x.reshape(grad_output.shape)

    return grad_x, None, None, None
88438
def collate_fn(batch, train=True):
    
    premise_batch, _ = pad_batch([row['premise'] for row in batch])
    hypothesis_batch, _ = pad_batch([row['hypothesis'] for row in batch])
    label_batch = torch.stack([row['label'] for row in batch])

    # PyTorch RNN requires batches to be transposed for speed and integration with CUDA
    transpose = (lambda b: b.t_().squeeze(0).contiguous())

    return (transpose(premise_batch), transpose(hypothesis_batch), transpose(label_batch))