lisachenko/native-php-matrix

PHP extension that provides Matrix class powered with overloaded operators

0.2.0 2021-06-26 20:23 UTC

This package is auto-updated.

Last update: 2024-10-27 16:41:03 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.

GitHub release Minimum PHP Version License GitHub Workflow Status

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.