From 2cbbe69bac33bf60e980567f01b8be94352d4b6b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 22 Oct 2023 14:15:33 +0000 Subject: [PATCH] test fixes --- .../Database/Query/Grammar/MysqlGrammar.php | 6 +++++- Math/Matrix/Matrix.php | 14 ++++++++++++++ tests/DataStorage/Database/Query/BuilderTest.php | 2 +- tests/Math/Matrix/MatrixTest.php | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/DataStorage/Database/Query/Grammar/MysqlGrammar.php b/DataStorage/Database/Query/Grammar/MysqlGrammar.php index 40e19d083..be9c66513 100755 --- a/DataStorage/Database/Query/Grammar/MysqlGrammar.php +++ b/DataStorage/Database/Query/Grammar/MysqlGrammar.php @@ -60,6 +60,10 @@ class MysqlGrammar extends Grammar $expression = '*'; } - return 'SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ' . $this->compileWheres($query, $query->wheres) . ' ORDER BY RAND() ' . $this->compileLimit($query, $query->limit ?? 1); + return 'SELECT ' . $expression + . ' ' . $this->compileFrom($query, $query->from) + . ' ' . $this->compileWheres($query, $query->wheres) + . ' ORDER BY RAND() ' + . $this->compileLimit($query, $query->limit ?? 1); } } diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index 116ad38e1..08d2929da 100755 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -759,6 +759,20 @@ class Matrix implements \ArrayAccess, \Iterator $result[$i] = $temp; } + return self::fromArray($result); + } elseif (!$isMatrix1 && $isMatrix2) { + $result = []; + for ($i = 0; $i < $m1; ++$i) { // Row of 1 + $temp = 0; + + for ($c = 0; $c < $m2; ++$c) { // Row of 2 + /** @var array $value1 */ + $temp += $value2[$i][$c] * $value1[$c]; + } + + $result[$i] = $temp; + } + return self::fromArray($result); } diff --git a/tests/DataStorage/Database/Query/BuilderTest.php b/tests/DataStorage/Database/Query/BuilderTest.php index 81237c111..b694a7926 100755 --- a/tests/DataStorage/Database/Query/BuilderTest.php +++ b/tests/DataStorage/Database/Query/BuilderTest.php @@ -121,7 +121,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $iE = $con->getGrammar()->systemIdentifierEnd; $query = new Builder($con); - $sql = 'SELECT [a].[test] FROM [a] as b WHERE [a].[test] = 1 ORDER BY \rand() LIMIT 1;'; + $sql = 'SELECT [a].[test] FROM [a] as b WHERE [a].[test] = 1 ORDER BY RAND() LIMIT 1;'; $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->random('a.test')->fromAs('a', 'b')->where('a.test', '=', 1)->toSql()); } diff --git a/tests/Math/Matrix/MatrixTest.php b/tests/Math/Matrix/MatrixTest.php index 08be44113..4dd36eab5 100755 --- a/tests/Math/Matrix/MatrixTest.php +++ b/tests/Math/Matrix/MatrixTest.php @@ -495,7 +495,7 @@ final class MatrixTest extends \PHPUnit\Framework\TestCase public function testDotVectors() : void { - $v1 = Vector::fromArray([1, 3, -5]); + $v1 = Vector::fromArray([1, 3, -5])->transpose(); self::assertEquals( 3,