Installation
Requirements
Before installing NDArray, ensure your system meets these requirements:
- PHP: Version 8.1 or higher
- FFI Extension: Must be enabled in your PHP installation
- Composer: For dependency management
Check FFI Extension
bash
php -m | grep FFIIf you don't see "FFI" in the output, you need to enable it.
Enabling FFI Extension
On Linux/macOS
Edit your php.ini file (location varies by installation):
bash
# Find your php.ini
php --ini
# Edit the file and add:
extension=ffiOn Windows (XAMPP/WAMP)
- Open
php.iniin your PHP installation directory - Find
;extension=ffi - Remove the semicolon:
extension=ffi - Restart Apache
Install via Composer
bash
composer require phpmlkit/ndarrayInstallation Verification
Create a test file to verify everything is working:
php
<?php
require_once 'vendor/autoload.php';
use PhpMlKit\NDArray\NDArray;
// Create a simple array
$vector = NDArray::array([1, 2, 3, 4, 5]);
echo "Vector: $vector\n";
echo "Sum: {$vector->sum()}\n\n";
// Create a 2D array
$matrix = NDArray::zeros([3, 3]);
echo "Zero matrix: $matrix\n\n";
echo "✓ NDArray is working correctly!\n";Run it:
bash
php test.phpExpected output:
Vector: array(5)
[1 2 3 4 5]
Sum: 15
Zero matrix: array(3, 3)
[
[0 0 0]
[0 0 0]
[0 0 0]
]
✓ NDArray is working correctly!Troubleshooting
"FFI extension not loaded"
Make sure FFI is enabled in the PHP.ini file that the CLI uses:
bash
php --iniEdit that specific file and ensure extension=ffi is present (without the semicolon).
"Platform package not found"
If you see errors about platform-specific binaries not being found:
- Check your platform is supported (Linux x86_64/ARM64, macOS x86_64/ARM64, Windows x86_64)
- Try clearing Composer cache:
composer clear-cache - Reinstall:
composer require phpmlkit/ndarray
Permission Errors
On Linux/macOS, you might need to set execute permissions:
bash
chmod +x vendor/phpmlkit/ndarray/bin/*Memory Limit Issues
For large arrays, increase PHP's memory limit:
bash
php -d memory_limit=512M your-script.phpOr in your script:
php
ini_set('memory_limit', '512M');Next Steps
Now that NDArray is installed:
- Quick Start - Create your first arrays
- NumPy Migration - If coming from Python
