Skip to content

Commit

Permalink
adjust dot product
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Eichhorn committed Oct 23, 2023
1 parent b7c9453 commit 5f8004d
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 128 deletions.
11 changes: 0 additions & 11 deletions Math/Functions/Algebra.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,6 @@ public static function dot(array $value1, array $value2) : int|float|array
$temp += $value1[$i][$c] * $value2[$c];
}

$result[$i] = $temp;
}
} elseif (!$isMatrix1 && $isMatrix2) {
$result = [];
for ($i = 0; $i < $m1; ++$i) { // Row of 1
$temp = 0;

for ($c = 0; $c < $m2; ++$c) { // Row of 2
$temp += $value2[$i][$c] * $value1[$c];
}

$result[$i] = $temp;
}
} else {
Expand Down
42 changes: 0 additions & 42 deletions Math/Matrix/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,48 +699,6 @@ public function det() : float
return $L->det();
}

/**
* Dot product
*
* @param self $B Matrix
*
* @return self
*
* @since 1.0.0
*/
public function dot(self $B) : self
{
$value1 = $this->matrix;
$value2 = $B->toArray();

$m1 = \count($value1);
$n1 = \count($value1[0]);

$m2 = \count($value2);
$n2 = \count($value2[0]);

$result = null;

if ($m2 !== $n1) {
throw new InvalidDimensionException($m2 . 'x' . $n2 . ' not compatible with ' . $m1 . 'x' . $n1);
}

$result = [[]];
for ($i = 0; $i < $m1; ++$i) { // Row of 1
for ($c = 0; $c < $n2; ++$c) { // Column of 2
$temp = 0;

for ($j = 0; $j < $m2; ++$j) { // Row of 2
$temp += $value1[$i][$j] * $value2[$j][$c];
}

$result[$i][$c] = $temp;
}
}

return self::fromArray($result);
}

/**
* Sum the elements in the matrix.
*
Expand Down
75 changes: 0 additions & 75 deletions tests/Math/Matrix/MatrixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,81 +493,6 @@ public function testInvalidDimensionMult() : void
$A->mult($B);
}

/**
* @covers phpOMS\Math\Matrix\Matrix
* @group framework
*/
public function testDotVectors() : void
{
$v1 = Vector::fromArray([1, 3, -5])->transpose();

self::assertEquals(
[[3]],
$v1->dot(Vector::fromArray([4, -2, -1]))->toArray()
);
}

/**
* @covers phpOMS\Math\Matrix\Matrix
* @group framework
*/
public function testDotMatrices() : void
{
$m = Matrix::fromArray([
[1, 2, 3],
[4, 5, 6],
]);

self::assertEquals(
[
[58, 64],
[139, 154],
],
$m->dot(
Matrix::fromArray([
[7, 8],
[9, 10],
[11, 12],
])
)->toArray()
);
}

/**
* @covers phpOMS\Math\Matrix\Matrix
* @group framework
*/
public function testDotVectorMatrix() : void
{
$v = Vector::fromArray([3, 4])->transpose();

self::assertEquals(
[11, 39, 53],
$v->dot(
Matrix::fromArray([
[1, 5, 7],
[2, 6, 8],
])
)->toVectorArray()
);
}

public function testDotMatrixVector() : void
{
$m = Matrix::fromArray([
[1, 2],
[5, 6],
[7, 8],
]);

self::assertEquals(
[11, 39, 53],
$m->dot(
Vector::fromArray([3, 4])
)->toVectorArray()
);
}

public function testSumAll() : void
{
$m = Matrix::fromArray([
Expand Down
1 change: 1 addition & 0 deletions tests/Utils/Parser/Markdown/data/video.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>[video src="<a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ&amp;ab_channel=RickAstley">https://www.youtube.com/watch?v=dQw4w9WgXcQ&amp;ab_channel=RickAstley</a>"]</p>

0 comments on commit 5f8004d

Please sign in to comment.