elgigi / matrix
Matrix
dev-main
2023-01-04 15:18 UTC
Requires
- php: ^8.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is not auto-updated.
Last update: 2024-11-07 22:20:55 UTC
README
Library implements the notions of matrices and vectors in PHP. The motivation of this library is first to optimize the large big size of the matrices.
Installation
Composer
You can install ElGigi Matrix with Composer, it's the recommended installation.
composer require elgigi/matrix
Dependencies
- PHP ^8.0
Usage
Instanciation of Matrix
object:
use ElGigi\Matrix\Matrix; $matrix = new Matrix([ [1, 2, 3], [2, 4, 1], [3, 2, 4], ]);
Uses builder to make Matrix
object:
use ElGigi\Matrix\MatrixBuilder; $builder = new MatrixBuilder(); $builder->addRow([1, 2, 3]); $builder->addRow([2, 4, 1]); $builder->addRow([3, 2, 4]); $matrix = $builder->getMatrix();
API
Matrix and vectors implement default interfaces:
\Countable
: object can be used withcount()
function\JsonSearialize
: object can be used withjson_encode()
function\IteratorAggregate
: object can be used withforeach
statement\ArrayAccess
: object can be used like an array to get values
Matrix
Matrix::isSquare(): bool
: returns if matrix is a squareMatrix::count(): int
: get number of elementsMatrix::countRows(): int
: get number of rowsMatrix::countColumns(): int
: get number of columnsMatrix::rows(): Generator<VectorInterface>
: get rows as generatorMatrix::columns(): Generator<VectorInterface>
: get columns as generatorMatrix::getRow(int $offset): VectorInterface
: get specified indexed row as vectorMatrix::getColumn(int $offset): VectorInterface
: get specified indexed column as vectorMatrix::getValue(int $y, int $x): mixed
: get specified value at coordinatesMatrix::map(callable $callback, mixed ...$arg): static
: apply callback on each value and returns a new matrix objectMatrix::max(): int|float
: get max value of matrixMatrix::min(): int|float
: get min value of matrixMatrix::sum(): int|float
: get sum of matrix valuesMatrix::avg(): int|float
: get average of matrix valuesMatrix::median(): int|float
: get median of matrix valuesMatrix::variance(): int|float
: get variance of matrix valuesMatrix::deviation(): int|float
: get deviation of matrix values
Vector
Vector::values(): array
: get vector values as arrayVector::extend(int $length, mixed $value = null): static
: extend vector of specified length with given valueVector::reduce(int $length): static
: reduce vector of specified lengthVector::map(callable $callback, mixed ...$arg): static
: apply callback on each value and returns a new vector objectVector::max(): int|float
: get max value of vectorVector::min(): int|float
: get min value of vectorVector::sum(): int|float
: get sum of vector valuesVector::avg(): int|float
: get average of vector valuesVector::median(): int|float
: get median of vector valuesVector::variance(): int|float
: get variance of vector valuesVector::deviation(): int|float
: get deviation of vector values