diff --git a/src/platform/src/Vector/Vector.php b/src/platform/src/Vector/Vector.php index a75d1c271..b1a7a7740 100644 --- a/src/platform/src/Vector/Vector.php +++ b/src/platform/src/Vector/Vector.php @@ -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); } diff --git a/src/platform/tests/Vector/VectorTest.php b/src/platform/tests/Vector/VectorTest.php index febaf9fbf..6ff4c2932 100644 --- a/src/platform/tests/Vector/VectorTest.php +++ b/src/platform/tests/Vector/VectorTest.php @@ -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; @@ -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([]); + } }