PluginProbe
TablePress – Tables in WordPress made easy / 2.2.5
TablePress – Tables in WordPress made easy v2.2.5
3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 2.4.4 All 44 releases
tablepress / libraries / vendor / Matrix / Operators / Operator.php

Operator.php in TablePress – Tables in WordPress made easy 2.2.5, at libraries/vendor/Matrix/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 TablePress\Matrix\Operators;
4
5 use TablePress\Matrix\Matrix;
6 use TablePress\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 TablePress\Matrix $matrix The base TablePress\Matrix object on which the operation will be performed
35 */
36 public function __construct(TablePress\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 TablePress\Matrix $matrix The second TablePress\Matrix object on which the operation will be performed
47 * @throws Exception
48 */
49 protected function validateMatchingDimensions(TablePress\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
56 /**
57 * Compare the dimensions of the matrices being operated on to see if they are valid for multiplication/division
58 *
59 * @param TablePress\Matrix $matrix The second TablePress\Matrix object on which the operation will be performed
60 * @throws Exception
61 */
62 protected function validateReflectingDimensions(TablePress\Matrix $matrix): void
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 TablePress\Matrix
73 */
74 public function result(): TablePress\Matrix
75 {
76 return new Matrix($this->matrix);
77 }
78 }
79