Skip to content

Commit

Permalink
Revert "Renamed fromMap to fromPairs"
Browse files Browse the repository at this point in the history
This reverts commit fed5186.
  • Loading branch information
ankane committed Jun 26, 2024
1 parent fed5186 commit 4cecdf7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/SparseVector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions tests/SparseVectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 4cecdf7

Please sign in to comment.