Deepity
Ultra-fast, SIMD-accelerated Predictive Coding
Loading...
Searching...
No Matches
StreamAlignedBatcher.h
Go to the documentation of this file.
1#pragma once
2#include <vector>
3#include <random>
4#include <cstring>
5#include <stdexcept>
6
25
26namespace Deep
27{
32 {
33 public:
44 StreamAlignedBatcher(const float *X, const float *Y, const int *labels,
45 size_t numSamples, size_t xStride, size_t yStride,
46 int numClasses, int perClass, unsigned seed = 42);
47
52 size_t NumBatchesPerEpoch() const noexcept;
53
62 void GetBatch(float *X_out, float *Y_out, int *labels_out) noexcept;
63
65 int GetBatchSize() const noexcept { return numClasses * perClass; }
67 int GetPerClass() const noexcept { return perClass; }
69 int GetNumClasses() const noexcept { return numClasses; }
71 size_t GetXStride() const noexcept { return xStride; }
73 size_t GetYStride() const noexcept { return yStride; }
74
75 private:
76 const float *X;
77 const float *Y;
78 const int *labels;
79 size_t numSamples;
80 size_t xStride;
81 size_t yStride;
82 int numClasses;
83 int perClass;
84 std::mt19937 rng;
85
86 std::vector<std::vector<size_t>> classIndices; // per-class list of global row indices
87 std::vector<size_t> pointers; // current read position within each class's list
88
89 void ReshuffleClass(int c) noexcept;
90
93 std::vector<size_t> NextClassSlice(int c, int n) noexcept;
94 };
95}
size_t GetYStride() const noexcept
Floats per Y row, as given at construction.
Definition StreamAlignedBatcher.h:73
StreamAlignedBatcher(const float *X, const float *Y, const int *labels, size_t numSamples, size_t xStride, size_t yStride, int numClasses, int perClass, unsigned seed=42)
Definition StreamAlignedBatcher.cpp:6
size_t NumBatchesPerEpoch() const noexcept
Number of complete batches obtainable per epoch, limited by the rarest class's sample count (matches ...
Definition StreamAlignedBatcher.cpp:53
int GetNumClasses() const noexcept
Number of distinct classes, as given at construction.
Definition StreamAlignedBatcher.h:69
void GetBatch(float *X_out, float *Y_out, int *labels_out) noexcept
Fills the next batch into caller-provided, pre-allocated output buffers. Rows are GROUPED by class: r...
Definition StreamAlignedBatcher.cpp:61
size_t GetXStride() const noexcept
Floats per X row, as given at construction.
Definition StreamAlignedBatcher.h:71
int GetBatchSize() const noexcept
Rows per batch: numClasses * perClass.
Definition StreamAlignedBatcher.h:65
int GetPerClass() const noexcept
Examples per class in each batch, as given at construction.
Definition StreamAlignedBatcher.h:67
This file exists to provide both Tensor.h and IComputeBackend.h with device types without introducing...
Definition Backend.cpp:10