Code Duplication    Length = 9-9 lines in 5 locations

src/Phpml/Helper/Optimizer/ConjugateGradient.php 5 locations

@@ 236-244 (lines=9) @@
233
     *
234
     * @return array
235
     */
236
    public static function mul(array $m1, array $m2)
237
    {
238
        $res = [];
239
        foreach ($m1 as $i => $val) {
240
            $res[] = $val * $m2[$i];
241
        }
242
243
        return $res;
244
    }
245
246
    /**
247
     * Element-wise <b>division</b> of two vectors of the same size
@@ 254-262 (lines=9) @@
251
     *
252
     * @return array
253
     */
254
    public static function div(array $m1, array $m2)
255
    {
256
        $res = [];
257
        foreach ($m1 as $i => $val) {
258
            $res[] = $val / $m2[$i];
259
        }
260
261
        return $res;
262
    }
263
264
    /**
265
     * Element-wise <b>addition</b> of two vectors of the same size
@@ 273-281 (lines=9) @@
270
     *
271
     * @return array
272
     */
273
    public static function add(array $m1, array $m2, int $mag = 1)
274
    {
275
        $res = [];
276
        foreach ($m1 as $i => $val) {
277
            $res[] = $val + $mag * $m2[$i];
278
        }
279
280
        return $res;
281
    }
282
283
    /**
284
     * Element-wise <b>subtraction</b> of two vectors of the same size
@@ 322-330 (lines=9) @@
319
     *
320
     * @return array
321
     */
322
    public static function divs(array $m1, float $m2)
323
    {
324
        $res = [];
325
        foreach ($m1 as $val) {
326
            $res[] = $val / ($m2 + 1e-32);
327
        }
328
329
        return $res;
330
    }
331
332
    /**
333
     * Element-wise <b>addition</b> of a vector with a scalar
@@ 341-349 (lines=9) @@
338
     *
339
     * @return array
340
     */
341
    public static function adds(array $m1, float $m2, int $mag = 1)
342
    {
343
        $res = [];
344
        foreach ($m1 as $val) {
345
            $res[] = $val + $mag * $m2;
346
        }
347
348
        return $res;
349
    }
350
351
    /**
352
     * Element-wise <b>subtraction</b> of a vector with a scalar