From 4cecdf7dc48f51e41f55d0106a2c5e8a4ab425a1 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 25 Jun 2024 22:19:04 -0700 Subject: [PATCH] Revert "Renamed fromMap to fromPairs" This reverts commit fed518604aadc636f730f57bee1a704491356645. --- src/SparseVector.php | 8 ++++---- tests/SparseVectorTest.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/SparseVector.php b/src/SparseVector.php index 5a1ae40..9dffe21 100644 --- a/src/SparseVector.php +++ b/src/SparseVector.php @@ -32,13 +32,13 @@ public static function fromDense($value) return new SparseVector($dimensions, $indices, $values); } - public static function fromPairs($pairs, $dimensions) + public static function fromMap($map, $dimensions) { - // safe to update in-place since $pairs parameter is not a reference - ksort($pairs); + // okay to update in-place since parameter is not a reference + ksort($map); $indices = []; $values = []; - foreach ($pairs as $i => $v) { + foreach ($map as $i => $v) { if ($v != 0) { $indices[] = intval($i); $values[] = floatval($v); diff --git a/tests/SparseVectorTest.php b/tests/SparseVectorTest.php index 57da0d1..777cdda 100644 --- a/tests/SparseVectorTest.php +++ b/tests/SparseVectorTest.php @@ -14,13 +14,13 @@ public function testFromDense() $this->assertEquals([1, 2, 3], $embedding->values()); } - public function testFromPairs() + public function testFromMap() { - $pairs = [2 => 2, 4 => 3, 0 => 1, 3 => 0]; - $embedding = SparseVector::fromPairs($pairs, 6); + $map = [2 => 2, 4 => 3, 0 => 1, 3 => 0]; + $embedding = SparseVector::fromMap($map, 6); $this->assertEquals([1, 0, 2, 0, 3, 0], $embedding->toArray()); $this->assertEquals([0, 2, 4], $embedding->indices()); - $this->assertEquals([2, 4, 0, 3], array_keys($pairs)); + $this->assertEquals([2, 4, 0, 3], array_keys($map)); } public function testFromString()