Passed
Push — master ( cbd9f5...897604 )
by
unknown
04:27 queued 01:59
created

ArrayDataset::removeColumnsFromSample()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Phpml\Dataset;
6
7
use Phpml\Exception\InvalidArgumentException;
8
9
class ArrayDataset implements Dataset
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $samples = [];
15
16
    /**
17
     * @var array
18
     */
19
    protected $targets = [];
20
21
    /**
22
     * @throws InvalidArgumentException
23
     */
24
    public function __construct(array $samples, array $targets)
25
    {
26
        if (count($samples) != count($targets)) {
27
            throw new InvalidArgumentException('Size of given arrays does not match');
28
        }
29
30
        $this->samples = $samples;
31
        $this->targets = $targets;
32
    }
33
34
    public function getSamples(): array
35
    {
36
        return $this->samples;
37
    }
38
39
    public function getTargets(): array
40
    {
41
        return $this->targets;
42
    }
43
44
    /**
45
     * @param int[] $columns
46
     */
47
    public function removeColumns(array $columns): void
48
    {
49
        foreach ($this->samples as &$sample) {
50
            $this->removeColumnsFromSample($sample, $columns);
51
        }
52
    }
53
54
    private function removeColumnsFromSample(array &$sample, array $columns): void
55
    {
56
        foreach ($columns as $index) {
57
            unset($sample[$index]);
58
        }
59
60
        $sample = array_values($sample);
61
    }
62
}
63