ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Operator.php
Go to the documentation of this file.
1<?php
2
3namespace Matrix\Operators;
4
7
8abstract class Operator
9{
15 protected $matrix;
16
22 protected $rows;
23
29 protected $columns;
30
36 public function __construct(Matrix $matrix)
37 {
38 $this->rows = $matrix->rows;
39 $this->columns = $matrix->columns;
40 $this->matrix = $matrix->toArray();
41 }
42
49 protected function validateMatchingDimensions(Matrix $matrix): void
50 {
51 if (($this->rows != $matrix->rows) || ($this->columns != $matrix->columns)) {
52 throw new Exception('Matrices have mismatched dimensions');
53 }
54 }
55
63 {
64 if ($this->columns != $matrix->rows) {
65 throw new Exception('Matrices have mismatched dimensions');
66 }
67 }
68
74 public function result(): Matrix
75 {
76 return new Matrix($this->matrix);
77 }
78}
An exception for terminatinating execution or to throw for unit testing.
validateMatchingDimensions(Matrix $matrix)
Compare the dimensions of the matrices being operated on to see if they are valid for addition/subtra...
Definition: Operator.php:49
result()
Return the result of the operation.
Definition: Operator.php:74
__construct(Matrix $matrix)
Create an new handler object for the operation.
Definition: Operator.php:36
validateReflectingDimensions(Matrix $matrix)
Compare the dimensions of the matrices being operated on to see if they are valid for multiplication/...
Definition: Operator.php:62
$rows
Number of rows in the matrix.
Definition: Operator.php:22
$columns
Number of columns in the matrix.
Definition: Operator.php:29
Class for the creating "special" Matrices.
Definition: Builder.php:11