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

Public Member Functions

 execute ($value)
 Execute the addition. 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...
 

Private Member Functions

 directSumMatrix ($value)
 Execute the direct sum for a matrix. More...
 

Additional Inherited Members

- 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...
 
- 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 8 of file DirectSum.php.

Member Function Documentation

◆ directSumMatrix()

Matrix\Operators\DirectSum::directSumMatrix (   $value)
private

Execute the direct sum for a matrix.

Parameters
Matrix$valueThe numeric value to concatenate/direct sum with the current base value
Returns
$this The operation object, allowing multiple additions to be chained

Definition at line 36 of file DirectSum.php.

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

Referenced by Matrix\Operators\DirectSum\execute().

36  : Operator
37  {
38  $originalColumnCount = count($this->matrix[0]);
39  $originalRowCount = count($this->matrix);
40  $valColumnCount = $value->columns;
41  $valRowCount = $value->rows;
42  $value = $value->toArray();
43 
44  for ($row = 0; $row < $this->rows; ++$row) {
45  $this->matrix[$row] = array_merge($this->matrix[$row], array_fill(0, $valColumnCount, 0));
46  }
47 
48  $this->matrix = array_merge(
49  $this->matrix,
50  array_fill(0, $valRowCount, array_fill(0, $originalColumnCount, 0))
51  );
52 
53  for ($row = $originalRowCount; $row < $originalRowCount + $valRowCount; ++$row) {
54  array_splice(
55  $this->matrix[$row],
56  $originalColumnCount,
57  $valColumnCount,
58  $value[$row - $originalRowCount]
59  );
60  }
61 
62  return $this;
63  }
$rows
Number of rows in the matrix.
Definition: Operator.php:22
$row
+ Here is the caller graph for this function:

◆ execute()

Matrix\Operators\DirectSum::execute (   $value)

Execute the addition.

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

Definition at line 17 of file DirectSum.php.

References Matrix\Operators\DirectSum\directSumMatrix().

17  : Operator
18  {
19  if (is_array($value)) {
20  $value = new Matrix($value);
21  }
22 
23  if ($value instanceof Matrix) {
24  return $this->directSumMatrix($value);
25  }
26 
27  throw new Exception('Invalid argument for addition');
28  }
Class for the creating "special" Matrices.
Definition: Builder.php:11
directSumMatrix($value)
Execute the direct sum for a matrix.
Definition: DirectSum.php:36
+ Here is the call graph for this function:

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