Skip to content

Repository files navigation

Scrutinizer Code QualityPackagist PHP Version SupportBuild StatusCode Intelligence StatusGitHub contributorsGitHub commit activityGitHub last commitPackagist VersionGitHub code size in bytesLines of codeGitHub top language

Np

Description


Lite, Fast & Memory Efficient Mathematical PHP library for scientific computing

Np(numphp) is a library that provides objects for computing large sets of numbers in PHP.

Installation

Install Np into your project with Composer:

$ composer require ghostjat/np

##Sample Code

require__DIR__ . '/../vendor/autoload.php';
useNp\matrix;
$ta = matrix::randn(1000, 1000); $tb = matrix::randn(1000, 1000); // to generate random 2d matrix$ta->dot($tb); // do a dot operation on given matrix$ta->getMemory(); // get memory use$ta->time(); // get time/** * 7.7mb * Time-Consumed:- 0.18390893936157 */

Synopsis

WARNING:
This module is in its early stages and should be considered a Work in Progress.The interface is not final and may change in the future.

Requirements

  • PHP 8+ 64bit with ffi & #libblas, #liblapacke

Make sure you have all the necessary tools installed such as FFI, libblas, liblapacke.

Performance

System Conf:- Intel(R) Core(TM) i3-2370M CPU @ 2.40GHz 64bit Memory:- 8GB php:- 8.0.5 64bit

Current Benchmarks of this library

Benckmark

Data Size :- [500x500] Revolutions:- 5 Iterations:- 5

subjectmem_peakbestmodemeanworststdev
sum3.606mb0.014s0.014s0.015s0.015s0.000s
multiply8.589mb0.070s0.071s0.071s0.071s0.000s
lu4.648mb0.064s0.065s0.065s0.068s0.001s
eign2.801mb0.085s0.086s0.086s0.088s0.001s
cholesky1.621mb0.001s0.001s0.001s0.001s0.000s
svd3.706mb0.126s0.126s0.127s0.133s0.002s
normL21.621mb0.003s0.003s0.003s0.003s0.000s
Pinverse4.903mb0.156s0.156s0.158s0.163s0.003s
inverse1.819mb0.016s0.016s0.016s0.017s0.000s
normL11.621mb0.001s0.001s0.001s0.001s0.000s
dotMatrix3.769mb0.006s0.006s0.006s0.006s0.000s
det4.662mb0.066s0.066s0.067s0.067s0.000s
rref1.529mb9.227s9.271s9.309s9.427s0.072s
ref1.818mb0.007s0.008s0.008s0.008s0.000s
clip8.516mb0.073s0.076s0.075s0.077s0.002s
clipUpper8.516mb0.055s0.056s0.057s0.059s0.002s
clipLower8.516mb0.055s0.058s0.057s0.059s0.002s
joinBelow4.517mb0.027s0.027s0.027s0.028s0.000s
transpose8.504mb0.057s0.057s0.058s0.059s0.001s
joinLeft4.511mb0.025s0.025s0.026s0.027s0.001s
poisson1.590mb0.029s0.029s0.029s0.030s0.000s
gaussian20.203mb0.056s0.056s0.056s0.056s0.000s
randn1.528mb0.017s0.017s0.017s0.017s0.000s
uniform1.528mb0.021s0.021s0.021s0.022s0.000s
multiply4.507mb0.042s0.042s0.043s0.045s0.001s

Previous BenchMark

benchmarksubjectsetrevsitsmem_peakmoderstdev
eignBencheign0152.699mb0.309s±4.51%
svdBenchsvd0153.604mb0.148s±3.60%
poissonMatrixBenchpoisson01511.738mb0.105s±7.07%
gaussianMatrixBenchgaussian01511.738mb0.112s±17.12%
randMatrixBenchrandn0151.429mb0.048s±2.37%
uniformMatrixBenchuniform0151.429mb0.063s±8.16%
matrixTransposeBenchtranspose0158.431mb0.120s±1.32%
rrefBenchrref0151.501mb28.513s±1.90%
refBenchref0151.731mb0.023s±7.24%
sumMatrixBenchsum0152.434mb0.051s±3.59%
matrixPseudoInverseBenchinverse0154.775mb0.222s±13.76%
matrixInverseBenchinverse0151.731mb0.032s±127.50%
dotMatrixBenchdotMatrix0153.656mb0.013s±27.94%
matrixL1NormBenchnormL101101.525mb0.001s±0.80%
matrixL2NormBenchnormL201101.525mb0.003s±1.63%

License

The code is licensed MIT and the documentation is licensed CC BY-NC 4.0.

Author

Shubham Chaudhary ghost.jat@gmail.com

Releases

Packages

Used by

Contributors

Languages