rubix / tensor_ext
A PHP extension that provides objects for scientific computing in PHP.
Package info
Type:php-ext
Ext name:ext-tensor
pkg:composer/rubix/tensor_ext
Fund package maintenance!
Requires
- php: >=8.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phalcon/zephir: ^1.6.0
- phpbench/phpbench: ^1.0
- phpunit/phpunit: ^9.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- 4.1.x-dev
- 4.1.0
- 4.0.1
- 4.0.0
- 4.0.0-rc4
- 4.0.0-rc3
- 4.0.0-rc2
- 4.0.0-rc1
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.x-dev
- 3.0.11
- 3.0.10
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 3.0.0-beta
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.x-dev
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 2.0.0-beta
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-softplus
- dev-vector-factories
- dev-kernel-fusion
This package is auto-updated.
Last update: 2026-10-09 03:14:43 UTC
README
Tensor Ext is a PHP extension that brings fast Matrix and Vector computing to the PHP language. The high-level object-oriented API is written in Zephir and backed by highly-optimized native C kernels.
Features
- Object-oriented API — Friendly Matrix and Vector APIs are fluent and expressive.
- Low memory footprint — Tensor objects are backed by contiguous C buffers.
- Native BLAS and LAPACK acceleration — Highly-optimized multi-threaded linear algebra kernels.
- Universal element-wise functions — Element-wise operations are broadcasted and vectorized.
- Dynamic kernel dispatching — Optimized kernels are dispatched based on CPU architecture.
Documentation
API documentation can be found in the docs folder in the project root.
Requirements
- PHP 8.1 or above
- The PHP development package (source code and tooling)
- A C compiler such as GCC or Clang
- A Fortran compiler such as GFortran
- OpenBLAS development package
- LAPACKE C interface to LAPACK
- re2c 0.13.6 or later
- GNU make 3.81 or later
- autoconf 2.31 or later
- automake 1.14 or later
Installation
Make sure you have all the necessary build tools installed such as a C compiler and make tools. For example, on an Ubuntu linux system you can enter the following on the command line to install the necessary dependencies.
$ sudo apt-get install make gcc gfortran php-dev libopenblas-dev liblapacke-dev re2c build-essential
Install the Tensor extension via PIE:
$ pie install rubix/tensor_ext
Tips for MacOS
Install the build dependencies with Homebrew (alongside a PHP build, e.g. brew install php):
$ brew install gcc openblas lapack re2c make autoconf automake
Several of these are keg-only and not on the default build paths, so export the following before compiling:
export LDFLAGS="-L$(brew --prefix openblas)/lib -L$(brew --prefix lapack)/lib -L$(brew --prefix pcre2)/lib -L$(brew --prefix gcc)/lib/gcc/current" export CPPFLAGS="-I$(brew --prefix openblas)/include -I$(brew --prefix lapack)/include -I$(brew --prefix pcre2)/include -I$(brew --prefix gcc)/include" export PKG_CONFIG_PATH="$(brew --prefix openblas)/lib/pkgconfig:$(brew --prefix lapack)/lib/pkgconfig:$(brew --prefix pcre2)/lib/pkgconfig:$(brew --prefix gcc)/lib/pkgconfig" export PATH="$(brew --prefix gcc)/bin:$PATH" export FC=$(brew --prefix gcc)/bin/gfortran
Manually Compiling the Extension
Clone the repository locally using Git:
$ git clone https://github.com/RubixML/Tensor-Ext
Then, change into the ext directory from the project root and run the following commands from the terminal. See this guide for more information on compiling PHP extensions with PHPize.
$ cd ./ext
$ phpize
$ ./configure
$ make
$ sudo make install
Finally, add the following line to your php.ini configuration to install the extension.
extension=tensor.so
To confirm that the extension is loaded in PHP, you can run the following command.
php -m | grep tensor
Contributing
See CONTRIBUTING.md for guidelines.
License
The code is licensed MIT and the documentation is licensed CC BY-NC 4.0.