Skip to content

Commit 04b28a7

Browse files
committed
Import library functions from global namespace
1 parent b08fd74 commit 04b28a7

File tree

3 files changed

+75
-33
lines changed

3 files changed

+75
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- Unreleased
1+
- 1.0.3
22
- Added clip upper and lower bounds
33

44
- 1.0.2

src/Matrix.php

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22

33
namespace Rubix\Tensor;
44

5+
use function gettype;
6+
use function array_search;
7+
use function array_values;
8+
use function array_map;
9+
use function array_reduce;
10+
use function array_slice;
11+
use function array_merge;
12+
use function array_fill;
13+
use function array_pop;
14+
use function is_array;
15+
use function is_int;
16+
use function is_float;
17+
use function intdiv;
18+
use function round;
19+
use function min;
20+
use function max;
21+
use function rand;
22+
use function sqrt;
23+
use function log;
24+
use function sin;
25+
use function cos;
26+
527
use JAMA\Matrix as JAMA;
628
use Rubix\Tensor\Exceptions\DimensionalityMismatchException;
729
use InvalidArgumentException;
@@ -378,8 +400,8 @@ public static function stack(array $vectors) : self
378400

379401
foreach ($vectors as $vector) {
380402
if (!$vector instanceof Vector) {
381-
throw new InvalidArgumentException("Cannot stack non"
382-
. " vectors, " . gettype($vector) . " found.");
403+
throw new InvalidArgumentException('Cannot stack a non'
404+
. " vector, " . gettype($vector) . " found.");
383405
}
384406

385407
$a[] = $vector->asArray();
@@ -724,7 +746,7 @@ public function determinant()
724746
. ' non square matrix.');
725747
}
726748

727-
list($b, $swaps) = $this->ref();
749+
[$b, $swaps] = $this->ref();
728750

729751
$pi = $b->diagonalAsVector()->product();
730752

@@ -835,7 +857,7 @@ public function dot(Vector $b) : ColumnVector
835857
*/
836858
public function convolve(Matrix $b, int $stride = 1) : self
837859
{
838-
list($m, $n) = $b->shape();
860+
[$m, $n] = $b->shape();
839861

840862
if ($m > $this->m or $n > $this->n) {
841863
throw new InvalidArgumentException('Matrix B cannot be'
@@ -1026,7 +1048,7 @@ public function rowReductionMethod(): array
10261048
*/
10271049
public function rref() : self
10281050
{
1029-
list($b, $swaps) = $this->ref();
1051+
[$b, $swaps] = $this->ref();
10301052

10311053
$b = $b->asArray();
10321054

@@ -1191,7 +1213,7 @@ public function solve(Vector $b) : ColumnVector
11911213
{
11921214
$k = $this->m - 1;
11931215

1194-
list($l, $u, $p) = $this->lu();
1216+
[$l, $u, $p] = $this->lu();
11951217

11961218
$pb = $p->dot($b);
11971219

@@ -1274,7 +1296,7 @@ public function maxNorm()
12741296
*/
12751297
public function multiply($b)
12761298
{
1277-
switch(true) {
1299+
switch (true) {
12781300
case $b instanceof Matrix:
12791301
$c = $this->multiplyMatrix($b);
12801302
break;
@@ -1309,7 +1331,7 @@ public function multiply($b)
13091331
*/
13101332
public function divide($b)
13111333
{
1312-
switch(true) {
1334+
switch (true) {
13131335
case $b instanceof Matrix:
13141336
$c = $this->divideMatrix($b);
13151337
break;
@@ -1344,7 +1366,7 @@ public function divide($b)
13441366
*/
13451367
public function add($b)
13461368
{
1347-
switch(true) {
1369+
switch (true) {
13481370
case $b instanceof Matrix:
13491371
$c = $this->addMatrix($b);
13501372
break;
@@ -1379,7 +1401,7 @@ public function add($b)
13791401
*/
13801402
public function subtract($b)
13811403
{
1382-
switch(true) {
1404+
switch (true) {
13831405
case $b instanceof Matrix:
13841406
$c = $this->subtractMatrix($b);
13851407
break;
@@ -1414,7 +1436,7 @@ public function subtract($b)
14141436
*/
14151437
public function pow($b)
14161438
{
1417-
switch(true) {
1439+
switch (true) {
14181440
case $b instanceof Matrix:
14191441
$c = $this->powMatrix($b);
14201442
break;
@@ -1449,7 +1471,7 @@ public function pow($b)
14491471
*/
14501472
public function mod($b)
14511473
{
1452-
switch(true) {
1474+
switch (true) {
14531475
case $b instanceof Matrix:
14541476
$c = $this->modMatrix($b);
14551477
break;
@@ -1484,7 +1506,7 @@ public function mod($b)
14841506
*/
14851507
public function equal($b)
14861508
{
1487-
switch(true) {
1509+
switch (true) {
14881510
case $b instanceof Matrix:
14891511
$c = $this->equalMatrix($b);
14901512
break;
@@ -1519,7 +1541,7 @@ public function equal($b)
15191541
*/
15201542
public function notEqual($b)
15211543
{
1522-
switch(true) {
1544+
switch (true) {
15231545
case $b instanceof Matrix:
15241546
$c = $this->notEqualMatrix($b);
15251547
break;
@@ -1554,7 +1576,7 @@ public function notEqual($b)
15541576
*/
15551577
public function greater($b)
15561578
{
1557-
switch(true) {
1579+
switch (true) {
15581580
case $b instanceof Matrix:
15591581
$c = $this->greaterMatrix($b);
15601582
break;
@@ -1589,7 +1611,7 @@ public function greater($b)
15891611
*/
15901612
public function greaterEqual($b)
15911613
{
1592-
switch(true) {
1614+
switch (true) {
15931615
case $b instanceof Matrix:
15941616
$c = $this->greaterEqualMatrix($b);
15951617
break;
@@ -1624,7 +1646,7 @@ public function greaterEqual($b)
16241646
*/
16251647
public function less($b)
16261648
{
1627-
switch(true) {
1649+
switch (true) {
16281650
case $b instanceof Matrix:
16291651
$c = $this->lessMatrix($b);
16301652
break;
@@ -1659,7 +1681,7 @@ public function less($b)
16591681
*/
16601682
public function lessEqual($b)
16611683
{
1662-
switch(true) {
1684+
switch (true) {
16631685
case $b instanceof Matrix:
16641686
$c = $this->lessEqualMatrix($b);
16651687
break;
@@ -3913,7 +3935,7 @@ public function getIterator()
39133935
*/
39143936
public function __get(string $name)
39153937
{
3916-
switch($name) {
3938+
switch ($name) {
39173939
case 'm':
39183940
return $this->m;
39193941

src/Vector.php

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
namespace Rubix\Tensor;
44

5+
use function gettype;
6+
use function array_search;
7+
use function array_values;
8+
use function array_map;
9+
use function array_reduce;
10+
use function array_slice;
11+
use function array_merge;
12+
use function array_fill;
13+
use function is_int;
14+
use function is_float;
15+
use function intdiv;
16+
use function round;
17+
use function min;
18+
use function max;
19+
use function rand;
20+
use function sqrt;
21+
use function log;
22+
use function sin;
23+
use function cos;
24+
525
use Rubix\Tensor\Exceptions\DimensionalityMismatchException;
626
use InvalidArgumentException;
727
use RuntimeException;
@@ -669,7 +689,7 @@ public function maxNorm()
669689
*/
670690
public function multiply($b)
671691
{
672-
switch(true) {
692+
switch (true) {
673693
case $b instanceof Vector:
674694
$c = $this->multiplyVector($b);
675695
break;
@@ -700,7 +720,7 @@ public function multiply($b)
700720
*/
701721
public function divide($b)
702722
{
703-
switch(true) {
723+
switch (true) {
704724
case $b instanceof Vector:
705725
$c = $this->divideVector($b);
706726
break;
@@ -731,7 +751,7 @@ public function divide($b)
731751
*/
732752
public function add($b)
733753
{
734-
switch(true) {
754+
switch (true) {
735755
case $b instanceof Vector:
736756
$c = $this->addVector($b);
737757
break;
@@ -762,7 +782,7 @@ public function add($b)
762782
*/
763783
public function subtract($b)
764784
{
765-
switch(true) {
785+
switch (true) {
766786
case $b instanceof Vector:
767787
$c = $this->subtractVector($b);
768788
break;
@@ -793,7 +813,7 @@ public function subtract($b)
793813
*/
794814
public function pow($b)
795815
{
796-
switch(true) {
816+
switch (true) {
797817
case $b instanceof Vector:
798818
$c = $this->powVector($b);
799819
break;
@@ -824,7 +844,7 @@ public function pow($b)
824844
*/
825845
public function mod($b)
826846
{
827-
switch(true) {
847+
switch (true) {
828848
case $b instanceof Vector:
829849
$c = $this->modVector($b);
830850
break;
@@ -855,7 +875,7 @@ public function mod($b)
855875
*/
856876
public function equal($b)
857877
{
858-
switch(true) {
878+
switch (true) {
859879
case $b instanceof Vector:
860880
$c = $this->equalVector($b);
861881
break;
@@ -886,7 +906,7 @@ public function equal($b)
886906
*/
887907
public function notEqual($b)
888908
{
889-
switch(true) {
909+
switch (true) {
890910
case $b instanceof Vector:
891911
$c = $this->notEqualVector($b);
892912
break;
@@ -917,7 +937,7 @@ public function notEqual($b)
917937
*/
918938
public function greater($b)
919939
{
920-
switch(true) {
940+
switch (true) {
921941
case $b instanceof Vector:
922942
$c = $this->greaterVector($b);
923943
break;
@@ -948,7 +968,7 @@ public function greater($b)
948968
*/
949969
public function greaterEqual($b)
950970
{
951-
switch(true) {
971+
switch (true) {
952972
case $b instanceof Vector:
953973
$c = $this->greaterEqualVector($b);
954974
break;
@@ -979,7 +999,7 @@ public function greaterEqual($b)
979999
*/
9801000
public function less($b)
9811001
{
982-
switch(true) {
1002+
switch (true) {
9831003
case $b instanceof Vector:
9841004
$c = $this->lessVector($b);
9851005
break;
@@ -1010,7 +1030,7 @@ public function less($b)
10101030
*/
10111031
public function lessEqual($b)
10121032
{
1013-
switch(true) {
1033+
switch (true) {
10141034
case $b instanceof Vector:
10151035
$c = $this->lessEqualVector($b);
10161036
break;
@@ -2446,7 +2466,7 @@ public function getIterator()
24462466
*/
24472467
public function __get(string $name)
24482468
{
2449-
switch($name) {
2469+
switch ($name) {
24502470
case 'm':
24512471
return $this->m();
24522472

0 commit comments

Comments
 (0)