Math Matrix multiplication fix for unbalanced array rows
Test for unbalanced arrays to matrix multiplication and fix unbalanced a array
This commit is contained in:
@@ -319,6 +319,36 @@ final class CoreLibsConvertMathTest extends TestCase
|
|||||||
[6, 12, 18],
|
[6, 12, 18],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
'inblanaced [2x2,3] x [3x2]' => [
|
||||||
|
'a' => [
|
||||||
|
[1, 2, 3],
|
||||||
|
[4, 5]
|
||||||
|
],
|
||||||
|
'b' => [
|
||||||
|
[6, 7],
|
||||||
|
[8, 9],
|
||||||
|
[10, 11]
|
||||||
|
],
|
||||||
|
'result' => [
|
||||||
|
[52, 58],
|
||||||
|
[64, 73],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'inblanaced [2x3] x [3x1,2]' => [
|
||||||
|
'a' => [
|
||||||
|
[1, 2, 3],
|
||||||
|
[4, 5, 7]
|
||||||
|
],
|
||||||
|
'b' => [
|
||||||
|
[7, 8],
|
||||||
|
[9, 10],
|
||||||
|
[11]
|
||||||
|
],
|
||||||
|
'result' => [
|
||||||
|
[58, 28],
|
||||||
|
[150, 82],
|
||||||
|
]
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -158,6 +158,8 @@ class Math
|
|||||||
* [0, 0, 0] <- automatically added
|
* [0, 0, 0] <- automatically added
|
||||||
* ]
|
* ]
|
||||||
*
|
*
|
||||||
|
* The same is done for unbalanced entries, they are filled with 0
|
||||||
|
*
|
||||||
* @param array<float|int|array<int|float>> $a m x n matrice
|
* @param array<float|int|array<int|float>> $a m x n matrice
|
||||||
* @param array<float|int|array<int|float>> $b n x p matrice
|
* @param array<float|int|array<int|float>> $b n x p matrice
|
||||||
*
|
*
|
||||||
@@ -186,7 +188,7 @@ class Math
|
|||||||
// so that we can multiply row by row
|
// so that we can multiply row by row
|
||||||
$bCols = array_map(
|
$bCols = array_map(
|
||||||
callback: fn ($k) => array_map(
|
callback: fn ($k) => array_map(
|
||||||
(fn ($i) => is_array($i) ? $i[$k] : 0),
|
(fn ($i) => is_array($i) ? $i[$k] ?? 0 : 0),
|
||||||
$b,
|
$b,
|
||||||
),
|
),
|
||||||
array: array_keys($b[0]),
|
array: array_keys($b[0]),
|
||||||
|
|||||||
Reference in New Issue
Block a user