| @@ 234-242 (lines=9) @@ | ||
| 231 | * |
|
| 232 | * @return array |
|
| 233 | */ |
|
| 234 | public static function mul(array $m1, array $m2) |
|
| 235 | { |
|
| 236 | $res = []; |
|
| 237 | foreach ($m1 as $i => $val) { |
|
| 238 | $res[] = $val * $m2[$i]; |
|
| 239 | } |
|
| 240 | ||
| 241 | return $res; |
|
| 242 | } |
|
| 243 | ||
| 244 | /** |
|
| 245 | * Element-wise <b>division</b> of two vectors of the same size |
|
| @@ 252-260 (lines=9) @@ | ||
| 249 | * |
|
| 250 | * @return array |
|
| 251 | */ |
|
| 252 | public static function div(array $m1, array $m2) |
|
| 253 | { |
|
| 254 | $res = []; |
|
| 255 | foreach ($m1 as $i => $val) { |
|
| 256 | $res[] = $val / $m2[$i]; |
|
| 257 | } |
|
| 258 | ||
| 259 | return $res; |
|
| 260 | } |
|
| 261 | ||
| 262 | /** |
|
| 263 | * Element-wise <b>addition</b> of two vectors of the same size |
|
| @@ 270-278 (lines=9) @@ | ||
| 267 | * |
|
| 268 | * @return array |
|
| 269 | */ |
|
| 270 | public static function add(array $m1, array $m2, $mag = 1) |
|
| 271 | { |
|
| 272 | $res = []; |
|
| 273 | foreach ($m1 as $i => $val) { |
|
| 274 | $res[] = $val + $mag * $m2[$i]; |
|
| 275 | } |
|
| 276 | ||
| 277 | return $res; |
|
| 278 | } |
|
| 279 | ||
| 280 | /** |
|
| 281 | * Element-wise <b>subtraction</b> of two vectors of the same size |
|
| @@ 319-327 (lines=9) @@ | ||
| 316 | * |
|
| 317 | * @return array |
|
| 318 | */ |
|
| 319 | public static function divs(array $m1, float $m2) |
|
| 320 | { |
|
| 321 | $res = []; |
|
| 322 | foreach ($m1 as $val) { |
|
| 323 | $res[] = $val / ($m2 + 1e-32); |
|
| 324 | } |
|
| 325 | ||
| 326 | return $res; |
|
| 327 | } |
|
| 328 | ||
| 329 | /** |
|
| 330 | * Element-wise <b>addition</b> of a vector with a scalar |
|
| @@ 337-345 (lines=9) @@ | ||
| 334 | * |
|
| 335 | * @return array |
|
| 336 | */ |
|
| 337 | public static function adds(array $m1, float $m2, $mag = 1) |
|
| 338 | { |
|
| 339 | $res = []; |
|
| 340 | foreach ($m1 as $val) { |
|
| 341 | $res[] = $val + $mag * $m2; |
|
| 342 | } |
|
| 343 | ||
| 344 | return $res; |
|
| 345 | } |
|
| 346 | ||
| 347 | /** |
|
| 348 | * Element-wise <b>subtraction</b> of a vector with a scalar |
|