PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.3.2
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.3.2
4.0.8 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 All 149 releases
visualizer / vendor / markbaker / matrix / classes / src / Builder.php

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

70 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 *
5 * Class for the creating "special" Matrices
6 *
7 * @copyright Copyright (c) 2018 Mark Baker (https://github.com/MarkBaker/PHPMatrix)
8 * @license https://opensource.org/licenses/MIT MIT
9 */
10 namespace Matrix;
11
12 /**
13 * Matrix Builder class.
14 *
15 * @package Matrix
16 */
17 class Builder
18 {
19 /**
20 * Create a new matrix of specified dimensions, and filled with a specified value
21 * If the column argument isn't provided, then a square matrix will be created
22 *
23 * @param $value
24 * @param $rows
25 * @param null $columns
26 * @return Matrix
27 * @throws Exception
28 */
29 public static function createFilledMatrix($value, $rows, $columns = null)
30 {
31 if ($columns === null) {
32 $columns = $rows;
33 }
34
35 $rows = Matrix::validateRow($rows);
36 $columns = Matrix::validateColumn($columns);
37
38 return new Matrix(
39 array_fill(
40 0,
41 $rows,
42 array_fill(
43 0,
44 $columns,
45 $value
46 )
47 )
48 );
49 }
50
51 /**
52 * Create a new identity matrix of specified dimensions
53 * This will always be a square matrix, with the number of rows and columns matching the provided dimension
54 *
55 * @param int $dimensions
56 * @return Matrix
57 * @throws Exception
58 */
59 public static function createIdentityMatrix($dimensions)
60 {
61 $grid = static::createFilledMatrix(null, $dimensions)->toArray();
62
63 for ($x = 0; $x < $dimensions; ++$x) {
64 $grid[$x][$x] = 1;
65 }
66
67 return new Matrix($grid);
68 }
69 }
70