ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Matrix\Operators\Multiplication Class Reference
+ Inheritance diagram for Matrix\Operators\Multiplication:
+ Collaboration diagram for Matrix\Operators\Multiplication:

Public Member Functions

 execute ($value, string $type='multiplication')
 Execute the multiplication. More...
 
- Public Member Functions inherited from Matrix\Operators\Operator
 __construct (Matrix $matrix)
 Create an new handler object for the operation. More...
 
 result ()
 Return the result of the operation. More...
 

Protected Member Functions

 multiplyScalar ($value, string $type='multiplication')
 Execute the multiplication for a scalar. More...
 
 multiplyMatrix (Matrix $value, string $type='multiplication')
 Execute the multiplication for a matrix. More...
 
- Protected Member Functions inherited from Matrix\Operators\Operator
 validateMatchingDimensions (Matrix $matrix)
 Compare the dimensions of the matrices being operated on to see if they are valid for addition/subtraction. More...
 
 validateReflectingDimensions (Matrix $matrix)
 Compare the dimensions of the matrices being operated on to see if they are valid for multiplication/division. More...
 

Additional Inherited Members

- Protected Attributes inherited from Matrix\Operators\Operator
 $matrix
 
 $rows
 Number of rows in the matrix. More...
 
 $columns
 Number of columns in the matrix. More...
 

Detailed Description

Definition at line 10 of file Multiplication.php.

Member Function Documentation

◆ execute()

Matrix\Operators\Multiplication::execute (   $value,
string  $type = 'multiplication' 
)

Execute the multiplication.

Parameters
mixed$valueThe matrix or numeric value to multiply the current base value by
Exceptions
ExceptionIf the provided argument is not appropriate for the operation
Returns
$this The operation object, allowing multiple multiplications to be chained

Reimplemented in Matrix\Operators\Division.

Definition at line 19 of file Multiplication.php.

19 : Operator
20 {
21 if (is_array($value)) {
22 $value = new Matrix($value);
23 }
24
25 if (is_object($value) && ($value instanceof Matrix)) {
26 return $this->multiplyMatrix($value, $type);
27 } elseif (is_numeric($value)) {
28 return $this->multiplyScalar($value, $type);
29 }
30
31 throw new Exception("Invalid argument for $type");
32 }
multiplyScalar($value, string $type='multiplication')
Execute the multiplication for a scalar.
multiplyMatrix(Matrix $value, string $type='multiplication')
Execute the multiplication for a matrix.
Class for the creating "special" Matrices.
Definition: Builder.php:11
$type

References $type, Matrix\Operators\Multiplication\multiplyMatrix(), and Matrix\Operators\Multiplication\multiplyScalar().

+ Here is the call graph for this function:

◆ multiplyMatrix()

Matrix\Operators\Multiplication::multiplyMatrix ( Matrix  $value,
string  $type = 'multiplication' 
)
protected

Execute the multiplication for a matrix.

Parameters
Matrix$valueThe numeric value to multiply with the current base value
Returns
$this The operation object, allowing multiple mutiplications to be chained
Exceptions
ExceptionIf the provided argument is not appropriate for the operation

Definition at line 62 of file Multiplication.php.

62 : Operator
63 {
64 $this->validateReflectingDimensions($value);
65
66 $newRows = $this->rows;
67 $newColumns = $value->columns;
68 $matrix = Builder::createFilledMatrix(0, $newRows, $newColumns)
69 ->toArray();
70 try {
71 for ($row = 0; $row < $newRows; ++$row) {
72 for ($column = 0; $column < $newColumns; ++$column) {
73 $columnData = $value->getColumns($column + 1)->toArray();
74 foreach ($this->matrix[$row] as $key => $valueData) {
75 $matrix[$row][$column] += $valueData * $columnData[$key][0];
76 }
77 }
78 }
79 } catch (Throwable $e) {
80 throw new Exception("Invalid argument for $type");
81 }
82 $this->matrix = $matrix;
83
84 return $this;
85 }
static createFilledMatrix($fillValue, $rows, $columns=null)
Create a new matrix of specified dimensions, and filled with a specified value If the column argument...
Definition: Builder.php:30
getColumns(int $column, int $columnCount=1)
Return a new matrix as a subset of columns from this matrix, starting at column number $column,...
Definition: Matrix.php:187
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
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
$key
Definition: croninfo.php:18
$row

References $key, Matrix\Operators\Operator\$matrix, $row, Matrix\Operators\Operator\$rows, Matrix\Matrix\columns(), Matrix\Builder\createFilledMatrix(), Matrix\Matrix\getColumns(), and Matrix\Operators\Operator\validateReflectingDimensions().

Referenced by Matrix\Operators\Division\execute(), and Matrix\Operators\Multiplication\execute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ multiplyScalar()

Matrix\Operators\Multiplication::multiplyScalar (   $value,
string  $type = 'multiplication' 
)
protected

Execute the multiplication for a scalar.

Parameters
mixed$valueThe numeric value to multiply with the current base value
Returns
$this The operation object, allowing multiple mutiplications to be chained

Definition at line 40 of file Multiplication.php.

40 : Operator
41 {
42 try {
43 for ($row = 0; $row < $this->rows; ++$row) {
44 for ($column = 0; $column < $this->columns; ++$column) {
45 $this->matrix[$row][$column] *= $value;
46 }
47 }
48 } catch (Throwable $e) {
49 throw new Exception("Invalid argument for $type");
50 }
51
52 return $this;
53 }
$columns
Number of columns in the matrix.
Definition: Operator.php:29

References Matrix\Operators\Operator\$columns, $row, and Matrix\Operators\Operator\$rows.

Referenced by Matrix\Operators\Division\execute(), and Matrix\Operators\Multiplication\execute().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: