Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/platform/src/Vector/Vector.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ public function __construct(
throw new InvalidArgumentException('Vector must have at least one dimension.');
}

if (\is_int($dimensions) && \count($data) !== $dimensions) {
throw new InvalidArgumentException(\sprintf('Vector must have %d dimensions', $dimensions));
}

if (null === $this->dimensions) {
$this->dimensions = \count($data);
}
Expand Down
24 changes: 24 additions & 0 deletions src/platform/tests/Vector/VectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\AI\Platform\Tests\Vector;

use PHPUnit\Framework\TestCase;
use Symfony\AI\Platform\Exception\InvalidArgumentException;
use Symfony\AI\Platform\Vector\Vector;
use Symfony\AI\Platform\Vector\VectorInterface;

Expand All @@ -32,4 +33,27 @@ public function testWithDimensionNull()
$this->assertSame($vectors, $vector->getData());
$this->assertSame(3, $vector->getDimensions());
}

public function testWithExplicitDimensions()
{
$vector = new Vector([1.0, 2.0, 3.0], 3);

$this->assertSame(3, $vector->getDimensions());
}

public function testThrowsOnDimensionMismatch()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Vector must have 5 dimensions');

new Vector([1.0, 2.0], 5);
}

public function testThrowsOnEmptyData()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Vector must have at least one dimension');

new Vector([]);
}
}