Skip to content

PHP Library that provides an implementation of userland types, powered with overloaded operators

License

Notifications You must be signed in to change notification settings

lisachenko/native-php-matrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Native matrix library

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.

About

PHP Library that provides an implementation of userland types, powered with overloaded operators

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages