Code Duplication    Length = 9-9 lines in 5 locations

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

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