Refactor and optimizations

This commit is contained in:
2026-09-08 19:06:02 +02:00
parent 8a50f492ac
commit 0e177f8491
11 changed files with 277 additions and 177 deletions
@@ -8,7 +8,7 @@ class LinearOrderDataSetReader implements IDataSetReader
{
public array $lines = [];
private array $currentLines = [];
private int $currentLineIndex = 0;
private int $lastReadLineIndex = -1;
@@ -35,13 +35,13 @@ class LinearOrderDataSetReader implements IDataSetReader
public function getNextLine(): ?array
{
if (! isset($this->currentLines[0])) {
if (! isset($this->lines[$this->currentLineIndex])) {
return null; // No more lines to read
}
$this->lastReadLineIndex = array_search($this->currentLines[0], $this->lines, true);
$this->lastReadLineIndex = $this->currentLineIndex;
return array_shift($this->currentLines);
return $this->lines[$this->currentLineIndex++];
}
public function getInputSize(): int
@@ -53,18 +53,20 @@ class LinearOrderDataSetReader implements IDataSetReader
{
// Count the number of unique labels in the dataset
$labels = array_map(fn ($line) => end($line), $this->lines);
return count(array_unique($labels));
}
public function getLabels(): array
{
$labels = array_map(fn ($line) => end($line), $this->lines);
return array_values(array_unique($labels));
}
public function reset(): void
{
$this->currentLines = $this->lines;
$this->currentLineIndex = 0;
}
public function getLastReadLineIndex(): int