Generate a collection of batches of size n from the dataset. If there are
not enough samples to fill an entire batch, then the dataset will contain
as many samples and labels as possible.

@param int $n
@return array
545097
public function batch(int $n = 50) : array
    {
        $sChunks = array_chunk($this->samples, $n);
        $lChunks = array_chunk($this->labels, $n);

        $batches = [];

        foreach ($sChunks as $i => $samples) {
            $batches[] = self::quick($samples, $lChunks[$i]);
        }

        return $batches;
    }
1137591
public function seed(Dataset $dataset, int $k) : array
    {
        $centroids = $dataset->randomSubsetWithReplacement(1)->samples();

        for ($i = 1; $i < $k; $i++) {
            $weights = [];

            foreach ($dataset as $sample) {
                $closest = INF;

                foreach ($centroids as $centroid) {
                    $distance = $this->kernel->compute($sample, $centroid);

                    if ($distance < $closest) {
                        $closest = $distance;
                    }
                }

                $weights[] = $closest ** 2;
            }

            $subset = $dataset->randomWeightedSubsetWithReplacement(1, $weights);

            $centroids[] = $subset[0];
        }

        return $centroids;
    }
1306729
private function getSamplesByLabel(string $label): array
    {
        $samples = [];
        for ($i = 0; $i < $this->sampleCount; ++$i) {
            if ($this->targets[$i] == $label) {
                $samples[] = $this->samples[$i];
            }
        }

        return $samples;
    }
177197
public function &offsetGet($n) {
        if(!$this->offsetExists($n)) {
            throw new IndexNotFoundException((string) $n);
        }
        return $this->data[$n];
    }
1337625
private function buildLabels($labels)
    {
        $collection = [];
        foreach ($labels as $label) {
            $collection[] = Label::createFromData($label);
        }

        return $collection;
    }
1373770
def gen_batches(data, batch_size):
    
    data = np.array(data)

    for i in range(0, data.shape[0], batch_size):
        yield data[i:i + batch_size]
288043
public static function partition($n, $coll)
    {
        $coll = self::iterator($coll);
        for ($coll->rewind(); $coll->valid();) {
            $partition = [];
            for ($i = 0; $i < $n && $coll->valid(); ++$i, $coll->next()) {
                $partition[] = $coll->current();
            }
            yield $partition;
        }
    }
338924
protected function segmentBatches($source)
    {
        // Measure batch_size
        $batchSize = static::config()->get('batch_size');
        if ($batchSize === 0) {
            return array($source);
        }
        $softCap = static::config()->get('batch_soft_cap');

        // Clear batches
        $batches = array();
        $current = array();
        $currentSize = 0;

        // Build batches from data
        foreach ($source as $base => $statefulids) {
            if (!$statefulids) {
                continue;
            }

            foreach ($statefulids as $stateKey => $statefulid) {
                $state = $statefulid['state'];
                $ids = $statefulid['ids'];
                if (!$ids) {
                    continue;
                }

                // Extract items from $ids until empty
                while ($ids) {
                    // Estimate maximum number of items to take for this iteration, allowing for the soft cap
                    $take = $batchSize - $currentSize;
                    if (count($ids) <= $take + $softCap) {
                        $take += $softCap;
                    }
                    $items = array_slice($ids, 0, $take, true);
                    $ids = array_slice($ids, count($items), null, true);

                    // Update batch
                    $currentSize += count($items);
                    $merge = array(
                        $base => array(
                            $stateKey => array(
                                'state' => $state,
                                'ids' => $items
                            )
                        )
                    );
                    $current = $current ? array_merge_recursive($current, $merge) : $merge;
                    if ($currentSize >= $batchSize) {
                        $batches[] = $current;
                        $current = array();
                        $currentSize = 0;
                    }
                }
            }
        }
        // Add incomplete batch
        if ($currentSize) {
            $batches[] = $current;
        }

        return $batches;
    }
367095
public function batch($size)
    {
        $chunks = array_chunk($this->items, $size, true);

        $list = [];
        foreach ($chunks as $chunk) {
            $list[] = new static($chunk, $this->params, $this->pages);
        }

        return $list;
    }
321295
public function leave(int $n = 1) : self
    {
        if ($n < 0) {
            throw new InvalidArgumentException('Cannot leave less than 0 samples.');
        }

        return $this->splice($n, $this->numRows());
    }
919008
public static function notPerfectPowers(int $n): array
    {
        $npp = [];

        if ($n <= 0) {
            return $npp;
        }

        $i = 2;
        while ($n > 0) {
            if (!Integer::isPerfectPower($i)) {
                $npp[] = $i;
                $n--;
            }
            $i++;
        }

        return $npp;
    }
113180
public int[] generateClustered(int N, int Max) {
                int[] array = new int[N];
                fillClustered(array, 0, N, 0, Max);
                return array;
        }
1006406
public function each($batchSize = 100)
    {
        return new BatchDataIterator($this->getConnection(), [
            'qs' => $this,
            'batchSize' => $batchSize,
            'each' => true,
            'asArray' => $this->asArray,
        ]);
    }
393393
public function generate(int $n) : Dataset
    {
        $dataset = Labeled::quick();

        foreach ($this->generators as $label => $generator) {
            $p = (int) round($this->weights[$label] * $n);

            if ($p < 1) {
                continue 1;
            }

            $samples = $generator->generate($p)->samples();

            $labels = array_fill(0, $p, $label);

            $stratum = Labeled::quick($samples, $labels);

            $dataset = $dataset->append($stratum);
        }

        return $dataset;
    }
976702
public function generate(string $fullName, int $limit = 8): array
    {
        $original = str_replace(' ', '', $fullName);
        if ($limit > strlen($original)) {
            return array();
        }

        if (-1 === $index = $this->isReservedName($fullName)) {
            return array();
        }

        $temp = explode(' ', strtoupper($fullName));
        if (2 > count($temp)) {
            return array();
        }

        $temp[$index] = $this->reservedNames[$temp[$index]];
        $fullName = substr(implode('', $temp), 0, $limit);
        if ($limit > strlen($fullName)) {
            $fullName = $original;
        } else {
            $original = $temp[$index];
        }

        return $this->shift($fullName, $original);
    }
821946
public function read($n)
    {
        if ($this->offset >= strlen($this->buffer)) {
            if (!($rv = $this->populateBuffer())) {
                return $rv;
            }
        }
        return $this->readBuffer($n);
    }
1267331
def _get_batches(self, items):
        """"""
        for i in xrange(0, len(items), self.max_batch_size):
            yield items[i:i + self.max_batch_size]