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 / Builder.php

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

71 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
11 namespace Matrix;
12
13 /**
14 * Matrix Builder class.
15 *
16 * @package Matrix
17 */
18 class Builder
19 {
20 /**
21 * Create a new matrix of specified dimensions, and filled with a specified value
22 * If the column argument isn't provided, then a square matrix will be created
23 *
24 * @param mixed $value
25 * @param int $rows
26 * @param int|null $columns
27 * @return Matrix
28 * @throws Exception
29 */
30 public static function createFilledMatrix($value, $rows, $columns = null)
31 {
32 if ($columns === null) {
33 $columns = $rows;
34 }
35
36 $rows = Matrix::validateRow($rows);
37 $columns = Matrix::validateColumn($columns);
38
39 return new Matrix(
40 array_fill(
41 0,
42 $rows,
43 array_fill(
44 0,
45 $columns,
46 $value
47 )
48 )
49 );
50 }
51
52 /**
53 * Create a new identity matrix of specified dimensions
54 * This will always be a square matrix, with the number of rows and columns matching the provided dimension
55 *
56 * @param int $dimensions
57 * @return Matrix
58 * @throws Exception
59 */
60 public static function createIdentityMatrix($dimensions)
61 {
62 $grid = static::createFilledMatrix(null, $dimensions)->toArray();
63
64 for ($x = 0; $x < $dimensions; ++$x) {
65 $grid[$x][$x] = 1;
66 }
67
68 return new Matrix($grid);
69 }
70 }
71