lisachenko / native-php-matrix
PHP extension that provides Matrix class powered with overloaded operators
Fund package maintenance!
lisachenko
Requires
- php: ^7.4|^8.0
- lisachenko/z-engine: ^0.8.1 || ^0.9.1
Requires (Dev)
- phpunit/phpunit: ^9.5.5
This package is auto-updated.
Last update: 2024-11-27 16:50:16 UTC
README
For a long time, PHP developers dreamed of being able to overload operators. And now, finally, this moment has come. Thanks to the PHP7.4 and the lisachenko/z-engine package, we can overload the operators of comparison, addition, multiplication, casting and much more!
This library is first ever userland PHP extension, that implements operator overloading for the Matrix
class.
Pre-requisites and initialization
As this library depends on FFI
, it requires PHP>=7.4 and FFI
extension to be enabled. Also, current limitations of
lisachenko/z-engine are also applied (x64, NTS)
To install this library, simply add it via composer
:
composer require lisachenko/native-php-matrix
Now you can test it with following example:
<?php declare(strict_types=1); use Lisachenko\NativePhpMatrix\Matrix; $first = new Matrix([[10, 20, 30]]); $second = new Matrix([[2, 4, 6]]); $value = $first * 2 + $second; // Matrix([[22, 44, 66]])
Supported features:
- Matrices addition (
$matrixA + $matrixB
) - Matrices subtraction (
$matrixA - $matrixB
) - Matrix multiplication by number (
$matrixA * 2
) - Matrices multiplication (
$matrixA * $matrixB
) - Dividing a matrix by a number (
$matrixA / 2
) - Matrices equality check (
$matrixA == $matrixB
)
For the future versions, I would like to implement native SSE/AVX assembly methods to improve the performance of calculation.