ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Operator.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Matrix\Operators;
4 
5 use Matrix\Matrix;
7 
8 abstract 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 
62  protected function validateReflectingDimensions(Matrix $matrix): void
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 }
__construct(Matrix $matrix)
Create an new handler object for the operation.
Definition: Operator.php:36
rows()
Returns a Generator that will yield each row of the matrix in turn as a vector matrix or the value of...
Definition: Matrix.php:282
$rows
Number of rows in the matrix.
Definition: Operator.php:22
$columns
Number of columns in the matrix.
Definition: Operator.php:29
result()
Return the result of the operation.
Definition: Operator.php:74
columns()
Returns a Generator that will yield each column of the matrix in turn as a vector matrix or the value...
Definition: Matrix.php:297
toArray()
Return the matrix as a 2-dimensional array.
Definition: Matrix.php:333
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
validateReflectingDimensions(Matrix $matrix)
Compare the dimensions of the matrices being operated on to see if they are valid for multiplication/...
Definition: Operator.php:62
Class for the creating "special" Matrices.
Definition: Builder.php:11