PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.11
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.11
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
visualizer / vendor / markbaker / matrix / classes / src / Operators / Operator.php

Operator.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.4.11, at vendor/markbaker/matrix/classes/src/Operators/Operator.php

79 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Matrix\Operators;
4
5 use Matrix\Matrix;
6 use Matrix\Exception;
7
8 abstract class Operator
9 {
10 /**
11 * Stored internally as a 2-dimension array of values
12 *
13 * @property mixed[][] $matrix
14 **/
15 protected $matrix;
16
17 /**
18 * Number of rows in the matrix
19 *
20 * @property integer $rows
21 **/
22 protected $rows;
23
24 /**
25 * Number of columns in the matrix
26 *
27 * @property integer $columns
28 **/
29 protected $columns;
30
31 /**
32 * Create an new handler object for the operation
33 *
34 * @param Matrix $matrix The base Matrix object on which the operation will be performed
35 */
36 public function __construct(Matrix $matrix)
37 {
38 $this->rows = $matrix->rows;
39 $this->columns = $matrix->columns;
40 $this->matrix = $matrix->toArray();
41 }
42
43 /**
44 * Compare the dimensions of the matrices being operated on to see if they are valid for addition/subtraction
45 *
46 * @param Matrix $matrix The second Matrix object on which the operation will be performed
47 * @throws Exception
48 */
49 protected function validateMatchingDimensions(Matrix $matrix)
50 {
51 if (($this->rows != $matrix->rows) || ($this->columns != $matrix->columns)) {
52 throw new Exception('Matrices have mismatched dimensions');
53 }
54 }
55
56 /**
57 * Compare the dimensions of the matrices being operated on to see if they are valid for multiplication/division
58 *
59 * @param Matrix $matrix The second Matrix object on which the operation will be performed
60 * @throws Exception
61 */
62 protected function validateReflectingDimensions(Matrix $matrix)
63 {
64 if ($this->columns != $matrix->rows) {
65 throw new Exception('Matrices have mismatched dimensions');
66 }
67 }
68
69 /**
70 * Return the result of the operation
71 *
72 * @return Matrix
73 */
74 public function result()
75 {
76 return new Matrix($this->matrix);
77 }
78 }
79