Skip to content

Commit dff0f45

Browse files
committed
Rename getVector to getArray, since we already have a vector and are trying to get the array.
1 parent da624bf commit dff0f45

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/Vector.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ public function __construct(array $literal)
1818
**************************************************************************/
1919

2020
/**
21-
* Get matrix
22-
* @return array of arrays
21+
* @return array
2322
*/
24-
public function getVector(): array
23+
public function toArray(): array
2524
{
2625
return $this->internal[0];
2726
}
@@ -49,7 +48,7 @@ public function getSize(): int
4948
*/
5049
public function sum()
5150
{
52-
return array_sum($this->getVector());
51+
return array_sum($this->toArray());
5352
}
5453

5554
/**
@@ -82,8 +81,8 @@ public function dotProduct(self $other)
8281
function ($a, $b) {
8382
return $a * $b;
8483
},
85-
$this->getVector(),
86-
$other->getVector()
84+
$this->toArray(),
85+
$other->toArray()
8786
));
8887
}
8988

@@ -128,7 +127,7 @@ public function outerProduct(Vector $other): Matrix
128127
$literal = array();
129128
for ($i = 0; $i < $this->getSize(); $i++) {
130129
for ($j = 0; $j < $other->getSize(); $j++) {
131-
$literal[$i][$j] = $this->getVector()[$i] * $other->getVector()[$j];
130+
$literal[$i][$j] = $this->toArray()[$i] * $other->toArray()[$j];
132131
}
133132
}
134133

@@ -153,9 +152,9 @@ public function crossProduct(Vector $other): self
153152
throw new VectorException('Vectors have to have 3 size');
154153
}
155154

156-
$x = ($this->getVector()[1] * $other->getVector()[2]) - ($this->getVector()[2] * $other->getVector()[1]);
157-
$y = -(($this->getVector()[0] * $other->getVector()[2]) - ($this->getVector()[2] * $other->getVector()[0]));
158-
$z = ($this->getVector()[0] * $other->getVector()[1]) - ($this->getVector()[1] * $other->getVector()[0]);
155+
$x = ($this->toArray()[1] * $other->toArray()[2]) - ($this->toArray()[2] * $other->toArray()[1]);
156+
$y = -(($this->toArray()[0] * $other->toArray()[2]) - ($this->toArray()[2] * $other->toArray()[0]));
157+
$z = ($this->toArray()[0] * $other->toArray()[1]) - ($this->toArray()[1] * $other->toArray()[0]);
159158

160159
return new Vector([[$x, $y, $z]]);
161160
}
@@ -218,7 +217,7 @@ public function l1Norm()
218217
{
219218
$sum = 0;
220219

221-
foreach ($this->getVector() as $value) {
220+
foreach ($this->toArray() as $value) {
222221
$sum += abs($value);
223222
}
224223

@@ -242,7 +241,7 @@ public function l2Norm(): float
242241
$literal = [];
243242

244243
for ($i = 0, $rows = $this->getSize(); $i < $rows; $i++) {
245-
$literal[] = $this->getVector()[$i] ** 2;
244+
$literal[] = $this->toArray()[$i] ** 2;
246245
}
247246

248247
return sqrt(array_sum($literal));
@@ -257,9 +256,9 @@ public function l2Norm(): float
257256
*/
258257
public function maxNorm()
259258
{
260-
$max = abs($this->getVector()[0]);
259+
$max = abs($this->toArray()[0]);
261260

262-
foreach($this->getVector() as $value) {
261+
foreach($this->toArray() as $value) {
263262
if(abs($value) > $max) {
264263
$max = abs($value);
265264
}

0 commit comments

Comments
 (0)