diff --git a/.github/workflows/build-rindow-matlib.yml b/.github/workflows/build-rindow-matlib.yml
new file mode 100644
index 0000000..c8793da
--- /dev/null
+++ b/.github/workflows/build-rindow-matlib.yml
@@ -0,0 +1,52 @@
+name: Build Rindow Matlib
+
+on:
+ workflow_dispatch:
+
+jobs:
+ build:
+ name: Build rindow-matlib (${{ matrix.arch }})
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - arch: x86_64
+ runs-on: ubuntu-24.04
+ artifact_name: linux-x86_64
+ - arch: arm64
+ runs-on: ubuntu-24.04-arm
+ artifact_name: linux-arm64
+
+ runs-on: ${{ matrix.runs-on }}
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+ with:
+ repository: rindow/rindow-matlib
+
+ - name: Install dependencies
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y build-essential cmake
+
+ - name: Build
+ run: |
+ cmake -S . -B build
+ cmake --build build --config Release
+
+ - name: Run tests
+ run: |
+ cd build
+ ctest -C Release
+
+ - name: Package
+ run: |
+ cd build
+ cpack -G TGZ -C Release
+
+ - name: Upload package artifact
+ uses: actions/upload-artifact@v4
+ with:
+ name: ${{ matrix.artifact_name }}
+ path: packages/*
\ No newline at end of file
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
deleted file mode 100644
index 7ddc965..0000000
--- a/.github/workflows/release.yml
+++ /dev/null
@@ -1,41 +0,0 @@
-name: Build and Release Libraries
-
-permissions:
- contents: write
- packages: read
-
-on:
- release:
- types:
- - published
-
- workflow_dispatch:
- inputs:
- tag:
- description: 'Release Tag'
- required: true
-
-
-jobs:
- add-libs:
- runs-on: ubuntu-latest
-
- steps:
- - name: Log in to GHCR
- uses: docker/login-action@v3
- with:
- registry: ghcr.io
- username: ${{ github.actor }}
- password: ${{ secrets.GITHUB_TOKEN }}
-
- - name: Build Libraries
- run: |
- TAG=${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.event.inputs.tag }}
- docker run --rm -v ./libs:/libs -e TAG=$TAG ghcr.io/codewithkyrian/transformers-php:latest
- ls libs
-
- - name: Add Libraries to Release
- uses: softprops/action-gh-release@v2
- with:
- files: |
- libs/*
\ No newline at end of file
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
new file mode 100644
index 0000000..ca81a72
--- /dev/null
+++ b/.github/workflows/tests.yml
@@ -0,0 +1,40 @@
+name: Tests
+
+on: ['push', 'pull_request']
+
+jobs:
+ ci:
+ runs-on: ${{ matrix.os }}
+
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [ubuntu-latest, macos-latest, windows-latest]
+ php: [8.1, 8.2, 8.3, 8.4]
+ max-parallel: 4
+
+ name: Tests PHP${{ matrix.php }} - ${{ matrix.os }}
+
+ steps:
+
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Cache dependencies
+ uses: actions/cache@v4
+ with:
+ path: ~/.composer/cache/files
+ key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
+
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php }}
+ extensions: dom, mbstring, zip, ffi
+ coverage: none
+
+ - name: Install Composer dependencies
+ run: composer update --no-interaction --prefer-dist
+
+ - name: Run Tests
+ run: composer test
diff --git a/README.md b/README.md
index 028e62e..af85eda 100644
--- a/README.md
+++ b/README.md
@@ -11,26 +11,18 @@
+
-TransformersPHP is designed to be functionally equivalent to the Python library, while still maintaining the same level
-of performance and ease of use. This library is built on top of the Hugging Face's Transformers library, which provides
-thousands of pre-trained models in 100+ languages. It is designed to be a simple and easy-to-use library for PHP
-developers using a similar API to the Python library. These models can be used for a variety of tasks, including text
-generation, summarization, translation, and more.
+TransformersPHP is designed to be functionally equivalent to the Python library, while still maintaining the same level of performance and ease of use. This library is built on top of the Hugging Face's Transformers library, which provides thousands of pre-trained models in 100+ languages. It is designed to be a simple and easy-to-use library for PHP developers using a similar API to the Python library. These models can be used for a variety of tasks, including text generation, summarization, translation, and more.
-TransformersPHP uses [ONNX Runtime](https://onnxruntime.ai/) to run the models, which is a high-performance scoring
-engine for Open Neural Network Exchange (ONNX) models. You can easily convert any PyTorch or TensorFlow model to ONNX
-and use it with TransformersPHP using [🤗 Optimum](https://github.com/huggingface/optimum#onnx--onnx-runtime).
+TransformersPHP uses [ONNX Runtime](https://onnxruntime.ai/) to run the models, which is a high-performance scoring engine for Open Neural Network Exchange (ONNX) models. You can easily convert any PyTorch or TensorFlow model to ONNX and use it with TransformersPHP using [🤗 Optimum](https://github.com/huggingface/optimum#onnx--onnx-runtime).
-TO learn more about the library and how it works, head over to
-our [extensive documentation](https://codewithkyrian.github.io/transformers-php/introduction).
+TO learn more about the library and how it works, head over to our [extensive documentation](https://codewithkyrian.github.io/transformers-php/introduction).
## Quick tour
-Because TransformersPHP is designed to be functionally equivalent to the Python library, it's super easy to learn from
-existing Python or Javascript code. We provide the `pipeline` API, which is a high-level, easy-to-use API that groups
-together a model with its necessary preprocessing and postprocessing steps.
+Because TransformersPHP is designed to be functionally equivalent to the Python library, it's super easy to learn from existing Python or Javascript code. We provide the `pipeline` API, which is a high-level, easy-to-use API that groups together a model with its necessary preprocessing and postprocessing steps.
@@ -104,15 +96,11 @@ composer require codewithkyrian/transformers
```
> [!CAUTION]
-> The ONNX library is platform-specific, so it's important to run the composer require command on the target platform
-> where the code will be executed. In most cases, this will be your development machine or a server where you deploy
-> your application, but if you're using a Docker container, run the `composer require` command inside that container.
+> The ONNX library is platform-specific, so it's important to run the composer require command on the target platform where the code will be executed. In most cases, this will be your development machine or a server where you deploy your application, but if you're using a Docker container, run the `composer require` command inside that container.
## PHP FFI Extension
-TransformersPHP uses the PHP FFI extension to interact with the ONNX runtime. The FFI extension is included by default
-in PHP 7.4 and later, but it may not be enabled by default. If the FFI extension is not enabled, you can enable it by
-uncommenting(remove the `;` from the beginning of the line) the
+TransformersPHP uses the PHP FFI extension to interact with the ONNX runtime. The FFI extension is included by default in PHP 7.4 and later, but it may not be enabled by default. If the FFI extension is not enabled, you can enable it by uncommenting(remove the `;` from the beginning of the line) the
following line in your `php.ini` file:
```ini
@@ -129,14 +117,11 @@ After making these changes, restart your web server or PHP-FPM service, and you
## Documentation
-For more detailed information on how to use the library, check out the
-documentation : [https://codewithkyrian.github.io/transformers-php](https://codewithkyrian.github.io/transformers-php)
+For more detailed information on how to use the library, check out the documentation : [https://codewithkyrian.github.io/transformers-php](https://codewithkyrian.github.io/transformers-php)
## Usage
-By default, TransformersPHP uses hosted pretrained ONNX models. For supported tasks, models that have been converted to
-work with [Xenova's Transformers.js](https://huggingface.co/models?library=transformers.js) on HuggingFace should work
-out of the box with TransformersPHP.
+By default, TransformersPHP uses hosted pretrained ONNX models. For supported tasks, models that have been converted to work with [Xenova's Transformers.js](https://huggingface.co/models?library=transformers.js) on HuggingFace should work out of the box with TransformersPHP.
## Configuration
@@ -151,27 +136,25 @@ Transformers::setup()
->setRemotePathTemplate('...') // Set the remote path template for downloading models. Defaults to `{model}/resolve/{revision}/{file}`
->setAuthToken('...') // Set the auth token for downloading models. Defaults to `null`
->setUserAgent('...') // Set the user agent for downloading models. Defaults to `transformers-php/{version}`
- ->setImageDriver('...') // Set the image driver for processing images. Defaults to `IMAGICK'
- ->setLogger('...'); // Set the logger for TransformersPHP. Defaults to `null`
+ ->setImageDriver('...') // Set the image driver for processing images. Defaults to `VIPS`
+ ->setLogger($logger) // Set a PSR-3 compatible logger. Defaults to `NullLogger` if not set
+ ->apply(); // Apply the configuration
```
-You can call the `set` methods in any order, or leave any out entirely, in which case, it uses the default values. For
-more information on the configuration options and what they mean, checkout
+You can call the `set` methods in any order, or leave any out entirely, in which case, it uses the default values. For more information on the configuration options and what they mean, checkout
the [documentation](https://codewithkyrian.github.io/transformers-php/configuration).
## Convert your models to ONNX
-TransformersPHP only works with ONNX models, therefore, you must convert your PyTorch, TensorFlow or JAX models to
-ONNX. It is recommended to use [🤗 Optimum](https://huggingface.co/docs/optimum) to perform the conversion and
-quantization of your model.
+TransformersPHP only works with ONNX models, therefore, you must convert your PyTorch, TensorFlow or JAX models to ONNX. We recommend using the [conversion script](https://github.com/huggingface/transformers.js/blob/main/scripts/convert.py) from Transformers.js, which uses the [🤗 Optimum](https://huggingface.co/docs/optimum) behind the scenes to perform the conversion and quantization of your model.
+
+```
+python -m convert --quantize --model_id
+```
## Pre-Download Models
-By default, TransformersPHP automatically retrieves model weights (ONNX format) from the Hugging Face model hub when
-you first use a pipeline or pretrained model. This can lead to a slight delay during the initial use. To improve the
-user experience, it's recommended to pre-download the models you intend to use before running them in your PHP
-application, especially for larger models. One way to do that is run the request once manually, but TransformersPHP
-also comes with a command line tool to help you do just that:
+By default, TransformersPHP automatically retrieves model weights (ONNX format) from the Hugging Face model hub when you first use a pipeline or pretrained model. This can lead to a slight delay during the initial use. To improve the user experience, it's recommended to pre-download the models you intend to use before running them in your PHP application, especially for larger models. One way to do that is run the request once manually, but TransformersPHP also comes with a command line tool to help you do just that:
```bash
./vendor/bin/transformers download [] [options]
diff --git a/VERSION b/VERSION
deleted file mode 100644
index c52db98..0000000
--- a/VERSION
+++ /dev/null
@@ -1 +0,0 @@
-0.5.3
\ No newline at end of file
diff --git a/bin/transformers b/bin/transformers
index 3056fc5..29cf8dc 100755
--- a/bin/transformers
+++ b/bin/transformers
@@ -1,5 +1,7 @@
#!/usr/bin/env php
-setName('Transformers PHP CLI');
- $application->add(new Codewithkyrian\Transformers\Commands\InstallCommand());
- $application->add(new Codewithkyrian\Transformers\Commands\DownloadModelCommand());
+ $application->addCommand(new Codewithkyrian\Transformers\Commands\DownloadModelCommand());
$application->run();
} catch (Exception $e) {
echo $e->getMessage();
exit(1);
-}
\ No newline at end of file
+}
diff --git a/composer.json b/composer.json
index 3e179e2..ca7f584 100644
--- a/composer.json
+++ b/composer.json
@@ -11,28 +11,28 @@
"php",
"codewithkyrian"
],
- "type": "library",
+ "type": "platform-package",
"require": {
"php": "^8.1",
"ext-ffi": "*",
- "psr/log": "^1.1.3|^2.0|^3.0",
- "codewithkyrian/jinja-php": "^1.0",
- "codewithkyrian/transformers-libsloader": "^2.0",
+ "codewithkyrian/jinja-php": "^2.0",
+ "codewithkyrian/platform-package-installer": "^1.0",
"imagine/imagine": "^1.3",
- "rindow/rindow-math-matrix": "^2.0",
- "rindow/rindow-matlib-ffi": "^1.0",
+ "psr/log": "^1.1 || ^2.0 || ^3.0",
+ "rindow/rindow-math-matrix": "^2.1",
+ "rindow/rindow-matlib-ffi": "^1.1",
"rindow/rindow-openblas-ffi": "^1.0",
- "symfony/console": "^6.4|^7.0",
- "rokka/imagine-vips": "^0.31.0"
+ "rokka/imagine-vips": "^0.40",
+ "symfony/console": "^6.4|^7.0"
},
"require-dev": {
- "pestphp/pest": "^2.31",
- "symfony/var-dumper": "^7.0"
+ "ffi/var-dumper": "^1.0",
+ "pestphp/pest": "^2.36.0|^3.5.0",
+ "symfony/var-dumper": "^6.4.11|^7.1.5"
},
"suggest": {
"ext-imagick": "Required to use the Imagick Driver for image processing",
- "ext-gd": "Required to use the GD Driver for image processing",
- "rokka/imagine-vips": "Required to use the VIPS Driver for image processing"
+ "ext-gd": "Required to use the GD Driver for image processing"
},
"license": "Apache-2.0",
"autoload": {
@@ -51,9 +51,10 @@
}
],
"config": {
+ "sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
- "codewithkyrian/transformers-libsloader": true
+ "codewithkyrian/platform-package-installer": true
}
},
"bin": [
@@ -61,13 +62,20 @@
],
"scripts": {
"test": "vendor/bin/pest",
- "test:coverage": "XDEBUG_MODE=coverage ./vendor/bin/pest --coverage",
- "post-install-cmd": "Codewithkyrian\\Transformers\\Utils\\LibsChecker::check",
- "post-update-cmd": "Codewithkyrian\\Transformers\\Utils\\LibsChecker::check"
+ "test:coverage": "XDEBUG_MODE=coverage ./vendor/bin/pest --coverage"
},
"archive": {
"exclude": [
"/docs"
]
+ },
+ "extra": {
+ "platform-urls": {
+ "linux-x86_64": "https://github.com/codewithkyrian/transformers-php/releases/download/{version}/dist-linux-x86_64.tar.gz",
+ "linux-arm64": "https://github.com/codewithkyrian/transformers-php/releases/download/{version}/dist-linux-arm64.tar.gz",
+ "darwin-x86_64": "https://github.com/codewithkyrian/transformers-php/releases/download/{version}/dist-darwin-x86_64.tar.gz",
+ "darwin-arm64": "https://github.com/codewithkyrian/transformers-php/releases/download/{version}/dist-darwin-arm64.tar.gz",
+ "windows-x86_64": "https://github.com/codewithkyrian/transformers-php/releases/download/{version}/dist-windows-x86_64.zip"
+ }
}
-}
+}
\ No newline at end of file
diff --git a/docs/configuration.md b/docs/configuration.md
index 2376def..cf41ddf 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -15,6 +15,7 @@ models, and the remote path template. These settings allow you to tailor how and
```php
use Codewithkyrian\Transformers\Transformers;
use Codewithkyrian\Transformers\Utils\ImageDriver;
+use Psr\Log\LoggerInterface;
Transformers::setup()
->setCacheDir('/path/to/models')
@@ -23,7 +24,7 @@ Transformers::setup()
->setAuthToken('your-token')
->setUserAgent('your-user-agent')
->setImageDriver(ImageDriver::IMAGICK)
- ->setLogger(new StreamLogger('transformers-php'));
+ ->setLogger($logger);
```
::: tip
@@ -95,8 +96,7 @@ Transformers::setup()->setUserAgent('your-user-agent');
### `setImageDriver(ImageDriver $imageDriver)`
This setting allows you to specify the image backend to use for image processing tasks. By default, the image driver is
-not set and an error will be thrown if you try to perform any image related task. You can change this to `IMAGICK`, `GD`
-or `VIPS` if you prefer, just make sure to have the required extensions installed.
+set to `VIPS`. You can change this to `IMAGICK`, `GD` or `VIPS` if you prefer, just make sure to have the required extensions installed.
```php
use Codewithkyrian\Transformers\Utils\ImageDriver;
@@ -108,11 +108,21 @@ Transformers::setup()
### `setLogger(LoggerInterface $logger)`
-This setting allows you to set a custom logger for TransformersPHP. No logger is set by default, but you can set a
-logger to debug TransformersPHP's internal behavior. The logger should implement the `Psr\Log\LoggerInterface` interface. TransformersPHP
-comes with a `StreamLogger` class, similar to Monolog's `StreamHandler`, which can be used to log to a stream (STDOUT, STDERR,
-or a file) and can be customized to log at different levels (debug, info, warning, error, critical). You can also pass in a
-logger that is already configured and ready to use e.g. a Laravel logger.
+This setting allows you to specify a PSR-3 compatible logger for TransformersPHP. The library will log various events such as model loading, generation progress, warnings, and errors. If no logger is set, a `NullLogger` will be used by default, which discards all log messages.
+
+```php
+use Psr\Log\LoggerInterface;
+use Monolog\Logger;
+use Monolog\Handler\StreamHandler;
+
+// Create a logger instance (example using Monolog)
+$logger = new Logger('transformers');
+$logger->pushHandler(new StreamHandler('logs/transformers.log', Logger::INFO));
+
+Transformers::setup()
+ ->setLogger($logger)
+ ->apply();
+```
## Standalone PHP Projects
@@ -147,6 +157,7 @@ set the cache directory to the subdirectory of the `storage` directory, as it's
```php [AppServiceProvider.php]
use Codewithkyrian\Transformers\Transformers;
+use Illuminate\Support\Facades\Log;
public function boot()
{
@@ -156,6 +167,7 @@ public function boot()
->setRemotePathTemplate('custom/path/{model}/{file}')
->setAuthToken('your-token')
->setUserAgent('your-user-agent')
+ ->setLogger(Log::getLogger())
->apply();
}
```
@@ -171,15 +183,20 @@ services, making it a good place to set up global configurations.
```php [Kernel.php]
use Codewithkyrian\Transformers\Transformers;
+use Psr\Log\LoggerInterface;
public function boot()
{
+ // Get the logger from the container
+ $logger = $this->getContainer()->get(LoggerInterface::class);
+
Transformers::setup()
->setCacheDir('/path/to/models')
->setRemoteHost('https://yourmodelshost.com')
->setRemotePathTemplate('custom/path/{model}/{file}')
->setAuthToken('your-token')
->setUserAgent('your-user-agent')
+ ->setLogger($logger)
->apply();
}
```
diff --git a/docs/getting-started.md b/docs/getting-started.md
index 07352a3..2bc7f09 100644
--- a/docs/getting-started.md
+++ b/docs/getting-started.md
@@ -30,10 +30,7 @@ can install them manually using the following command:
```
> [!CAUTION]
-> The shared libraries is platform-specific, so it's important to run the `composer require`, or `transformers install`
-> command on the target platform where the code will be executed. In most cases, this will be your development machine
-> or a server where you deploy your application, but if you're using a Docker container, run the `composer require`
-> command inside that container.
+> The shared libraries is platform-specific, so it's important to run the `composer require`, or `transformers install` command on the target platform where the code will be executed. In most cases, this will be your development machine or a server where you deploy your application, but if you're using a Docker container, run the `composer require` command inside that container.
That's it! You're now ready to use TransformersPHP in your PHP application.
@@ -89,10 +86,7 @@ Since TransformersPHP operates exclusively with ONNX models, you'll need to conv
developed or plan to use from PyTorch, TensorFlow, or JAX into the ONNX format.
For this conversion process, we recommend using
-the [conversion script](https://github.com/xenova/transformers.js/blob/main/scripts/convert.py)
-provided by the Transformers.js project. This script is designed to convert models from PyTorch, TensorFlow, and JAX to
-ONNX format, and most importantly, outputs it in a folder structure that is compatible with TransformersPHP. Behind the
-scenes, the script uses [🤗 Optimum](https://huggingface.co/docs/optimum) from Hugging Face to convert and quantize the
+the [conversion script](https://github.com/huggingface/transformers.js/blob/main/scripts/convert.py) provided by the Transformers.js project. This script is designed to convert models from PyTorch, TensorFlow, and JAX to ONNX format, and most importantly, outputs it in a folder structure that is compatible with TransformersPHP. Behind the scenes, the script uses [🤗 Optimum](https://huggingface.co/docs/optimum) from Hugging Face to convert and quantize the
models.
But let's be real, not all PHP developer are fans of Python, or even have a Python environment set up. And that's okay.
diff --git a/examples/.gitignore b/examples/.gitignore
index 487ada0..89fd117 100644
--- a/examples/.gitignore
+++ b/examples/.gitignore
@@ -1,4 +1,5 @@
vendor
.transformers-cache/*
composer.lock
-paddleocr
\ No newline at end of file
+paddleocr
+*.log
\ No newline at end of file
diff --git a/examples/bootstrap.php b/examples/bootstrap.php
index eeebf98..c48a687 100644
--- a/examples/bootstrap.php
+++ b/examples/bootstrap.php
@@ -4,11 +4,26 @@
use Codewithkyrian\Transformers\Transformers;
use Codewithkyrian\Transformers\Utils\ImageDriver;
-use Codewithkyrian\Transformers\Utils\StreamLogger;
+use Psr\Log\AbstractLogger;
require_once './vendor/autoload.php';
+$cacheDir = '/Volumes/KYRIAN SSD/Transformers';
+
+class FileLogger extends AbstractLogger
+{
+ public function __construct(protected string $filename) {}
+
+ public function log($level, $message, array $context = []): void
+ {
+ $line = sprintf("[%s][%s] %s %s\n", date('Y-m-d H:i:s'), strtoupper($level), $message, empty($context) ? '' : json_encode($context, JSON_UNESCAPED_SLASHES));
+ file_put_contents($this->filename, $line, FILE_APPEND);
+ }
+}
+
+$logger = new FileLogger(__DIR__ . '/transformers.log');
+
Transformers::setup()
- ->setCacheDir('/Users/Kyrian/.transformers')
- ->setImageDriver(ImageDriver::VIPS)
- ->setLogger(new StreamLogger(STDOUT));
+ ->setCacheDir($cacheDir)
+ ->setLogger($logger)
+ ->setImageDriver(ImageDriver::VIPS);
diff --git a/examples/composer.json b/examples/composer.json
index add8a7b..04c920e 100644
--- a/examples/composer.json
+++ b/examples/composer.json
@@ -14,10 +14,11 @@
"require": {
"php": "^8.1",
"symfony/console": "^7.0",
- "codewithkyrian/transformers": "*"
+ "codewithkyrian/transformers": "dev-model-revamp"
},
"require-dev": {
- "symfony/var-dumper": "^7.0"
+ "symfony/var-dumper": "^7.0",
+ "ffi/var-dumper": "^1.0@dev"
},
"minimum-stability": "dev",
"repositories": [
@@ -28,8 +29,8 @@
],
"config": {
"allow-plugins": {
- "codewithkyrian/transformers-libraries-downloader": true,
- "codewithkyrian/transformers-libsloader": true
+ "codewithkyrian/transformers-libsloader": true,
+ "codewithkyrian/platform-package-installer": true
}
}
}
diff --git a/examples/misc/custom-object-detection.php b/examples/misc/custom-object-detection.php
index 6bf793a..10d34a9 100644
--- a/examples/misc/custom-object-detection.php
+++ b/examples/misc/custom-object-detection.php
@@ -6,16 +6,20 @@
use Codewithkyrian\Transformers\Models\Auto\AutoModel;
use Codewithkyrian\Transformers\Processors\AutoProcessor;
+use Codewithkyrian\Transformers\Transformers;
use Codewithkyrian\Transformers\Utils\Image;
+use Codewithkyrian\Transformers\Utils\ImageDriver;
require_once './bootstrap.php';
ini_set('memory_limit', '-1');
+Transformers::setup()->setImageDriver(ImageDriver::GD);
+
$processor = AutoProcessor::fromPretrained('Xenova/yolov9-c_all');
$model = AutoModel::fromPretrained('Xenova/yolov9-c_all');
-$image = Image::read(__DIR__.'/../images/multitask.png');
+$image = Image::read(__DIR__ . '/../images/multitask.png');
$inputs = $processor($image);
@@ -42,10 +46,10 @@
$fontScalingFactor = 0.75;
$fontFile = '/Users/Kyrian/Library/Fonts/JosefinSans-Bold.ttf';
$labelBoxHeight = $fontSize * 2 * $fontScalingFactor;
-$colors = array_map(fn () => sprintf('#%06x', mt_rand(0, 0xFFFFFF)), range(0, count($boxes) - 1));
+$colors = array_map(fn() => sprintf('#%06x', mt_rand(0, 0xFFFFFF)), range(0, count($boxes) - 1));
foreach ($boxes as $box) {
- $detectionLabel = $box['label'].' '.round($box['score'], 2);
+ $detectionLabel = $box['label'] . ' ' . round($box['score'], 2);
$color = $colors[array_search($box, $boxes)];
$image = $image
@@ -69,4 +73,4 @@
);
}
-$image->save(__DIR__.'/../images/corgi-detected.jpg');
+$image->save(__DIR__ . '/../images/corgi-detected.jpg');
diff --git a/examples/misc/general-test.php b/examples/misc/general-test.php
deleted file mode 100644
index c6918e6..0000000
--- a/examples/misc/general-test.php
+++ /dev/null
@@ -1,17 +0,0 @@
-onStream(fn($text) => print($text));
+ ->onStream(fn($text) => print($text));
-
-$output = $transcriber($audioUrl,
+$output = $transcriber(
+ $audioUrl,
maxNewTokens: 256,
chunkLengthSecs: 24,
streamer: $streamer,
diff --git a/examples/pipelines/summarization.php b/examples/pipelines/summarization.php
index 2d82047..ee352ea 100644
--- a/examples/pipelines/summarization.php
+++ b/examples/pipelines/summarization.php
@@ -58,4 +58,4 @@
$summary = $summarizer($article, streamer: $streamer, maxNewTokens: 512);
-dd("Done", timeUsage(), memoryUsage());
\ No newline at end of file
+dd("Done", timeUsage(), memoryUsage());
diff --git a/examples/pipelines/text-generation.php b/examples/pipelines/text-generation.php
index cf9f166..069cfec 100644
--- a/examples/pipelines/text-generation.php
+++ b/examples/pipelines/text-generation.php
@@ -4,7 +4,6 @@
require_once './bootstrap.php';
-use Codewithkyrian\Transformers\Generation\Streamers\StdOutStreamer;
use Codewithkyrian\Transformers\Generation\Streamers\TextStreamer;
use function Codewithkyrian\Transformers\Pipelines\pipeline;
use function Codewithkyrian\Transformers\Utils\memoryUsage;
@@ -14,8 +13,9 @@
//$generator = pipeline('text-generation', 'Xenova/gpt2');
//$generator = pipeline('text-generation', 'Xenova/Qwen1.5-0.5B-Chat');
-//$generator = pipeline('text-generation', 'Xenova/TinyLlama-1.1B-Chat-v1.0');
-$generator = pipeline('text-generation', 'onnx-community/Llama-3.2-1B-Instruct', modelFilename: 'model_q4');
+// $generator = pipeline('text-generation', 'Xenova/TinyLlama-1.1B-Chat-v1.0');
+// $generator = pipeline('text-generation', 'onnx-community/Llama-3.2-1B-Instruct', modelFilename: 'model_q4');
+$generator = pipeline('text-generation', 'onnx-community/Qwen3-0.6B-ONNX');
$streamer = TextStreamer::make()->shouldSkipPrompt();
@@ -26,14 +26,15 @@
$input = $generator->tokenizer->applyChatTemplate($messages, addGenerationPrompt: true, tokenize: false);
-$output = $generator($input,
+$output = $generator(
+ $input,
streamer: $streamer,
maxNewTokens: 256,
doSample: true,
returnFullText: false,
-// temperature: 0.7,
-// repetitionPenalty: 1.3,
-// earlyStopping: true
+ // temperature: 0.7,
+ // repetitionPenalty: 1.3,
+ // earlyStopping: true
);
//$generator = pipeline('text-generation', 'Xenova/codegen-350M-mono');
@@ -47,4 +48,4 @@
// returnFullText: true,
//);
-dd($output[0]['generated_text'], timeUsage(), memoryUsage());
+dd($output[0]['generated_text'], $streamer->getTPS() . " tps", timeUsage(), memoryUsage());
diff --git a/examples/pipelines/text2text-generation.php b/examples/pipelines/text2text-generation.php
index d2e9388..df8665a 100644
--- a/examples/pipelines/text2text-generation.php
+++ b/examples/pipelines/text2text-generation.php
@@ -21,5 +21,4 @@
$output = $generator($query, streamer: $streamer, maxNewTokens: 256, doSample: true, repetitionPenalty: 1.1, temperature: 0.7);
-//dd($output);
-dd('Done', timeUsage(), memoryUsage());
+dd('Done', $streamer->getTPS()." tps", timeUsage(), memoryUsage());
diff --git a/libs/.gitignore b/libs/.gitignore
deleted file mode 100644
index f214770..0000000
--- a/libs/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/*
-!VERSIONS
\ No newline at end of file
diff --git a/platforms.yml b/platforms.yml
new file mode 100644
index 0000000..8a8824e
--- /dev/null
+++ b/platforms.yml
@@ -0,0 +1,44 @@
+linux-x86_64:
+ exclude:
+ - shared/linux-arm64
+ - shared/darwin-*
+ - shared/windows-*
+ - "*.exe"
+ - "*.dylib"
+ - "**/*.windows.*"
+
+linux-arm64:
+ exclude:
+ - shared/linux-x86_64
+ - shared/windows-*
+ - shared/darwin-*
+ - "*.exe"
+ - "*.dylib"
+ - "**/*.windows.*"
+
+darwin-x86_64:
+ exclude:
+ - shared/darwin-arm64
+ - shared/windows-*
+ - shared/linux-*
+ - "*.exe"
+ - "*.so"
+ - "**/*.linux.*"
+
+darwin-arm64:
+ exclude:
+ - shared/darwin-x86_64
+ - shared/windows-*
+ - shared/linux-*
+ - "*.exe"
+ - "*.so"
+ - "**/*.linux.*"
+
+windows-x86_64:
+ exclude:
+ - shared/linux-*
+ - shared/darwin-*
+ - "*.so"
+ - "*.dylib"
+ - "**/*.darwin.*"
+ - "**/*.linux.*"
diff --git a/shared/linux-arm64/THIRD_PARTY_NOTICES.md b/shared/linux-arm64/THIRD_PARTY_NOTICES.md
new file mode 100644
index 0000000..0cf3657
--- /dev/null
+++ b/shared/linux-arm64/THIRD_PARTY_NOTICES.md
@@ -0,0 +1,52 @@
+# Third-party notices
+
+TransformersPHP includes compiled binaries of third-party libraries as a convenience to users. These binaries are
+distributed to facilitate the functionality of TransformersPHP, but TransformersPHP does not claim ownership of the
+binaries or the underlying libraries. The original authors and contributors of these libraries retain all rights. It is
+the user's responsibility to ensure compliance with the respective licenses of these libraries when using or
+distributing the bundled binaries.
+
+Below is a list of the third-party libraries included with TransformersPHP, along with their respective licenses and
+other relevant information.
+
+| Library | Used under the terms of |
+|---------------|-----------------------------------------------------------------------------------------------------------|
+| OpenMP | MIT License |
+| OnnxRuntime | MIT License |
+| OpenBlas | BSD 3-Clause License |
+| Rindow Matlib | BSD 3-Clause License |
+| LibSamplerate | BSD 2-Clause License |
+| Libsndfile | LGPL 2.1 License |
+| aom | BSD 2-Clause + [Alliance for Open Media Patent License 1.0](https://aomedia.org/license/patent-license/) |
+| cairo | Mozilla Public License 2.0 |
+| cgif | MIT Licence |
+| expat | MIT Licence |
+| fontconfig | [fontconfig Licence](https://gitlab.freedesktop.org/fontconfig/fontconfig/blob/main/COPYING) (BSD-like) |
+| freetype | [freetype Licence](https://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/docs/FTL.TXT) (BSD-like) |
+| fribidi | LGPLv3 |
+| glib | LGPLv3 |
+| harfbuzz | MIT Licence |
+| highway | Apache-2.0 License, BSD 3-Clause |
+| lcms | MIT Licence |
+| libarchive | BSD 2-Clause |
+| libexif | LGPLv3 |
+| libffi | MIT Licence |
+| libheif | LGPLv3 |
+| libimagequant | [BSD 2-Clause](https://github.com/lovell/libimagequant/blob/main/COPYRIGHT) |
+| libnsgif | MIT Licence |
+| libpng | [libpng License](https://github.com/pnggroup/libpng/blob/master/LICENSE) |
+| librsvg | LGPLv3 |
+| libspng | [BSD 2-Clause, libpng License](https://github.com/randy408/libspng/blob/master/LICENSE) |
+| libtiff | [libtiff License](https://gitlab.com/libtiff/libtiff/blob/master/LICENSE.md) (BSD-like) |
+| libvips | LGPLv3 |
+| libwebp | New BSD License |
+| libxml2 | MIT Licence |
+| mozjpeg | [zlib License, IJG License, BSD-3-Clause](https://github.com/mozilla/mozjpeg/blob/master/LICENSE.md) |
+| pango | LGPLv3 |
+| pixman | MIT Licence |
+| proxy-libintl | LGPLv3 |
+| zlib-ng | [zlib Licence](https://github.com/zlib-ng/zlib-ng/blob/develop/LICENSE.md) |
+
+---
+
+
diff --git a/shared/linux-arm64/include/buffer.h b/shared/linux-arm64/include/buffer.h
new file mode 100644
index 0000000..e086179
--- /dev/null
+++ b/shared/linux-arm64/include/buffer.h
@@ -0,0 +1,5 @@
+#define FFI_SCOPE "Rindow\\Math\\Buffer\\FFI"
+
+typedef struct _rindow_complex_float { float real, imag; } rindow_complex_float;
+typedef struct _rindow_complex_double { double real, imag; } rindow_complex_double;
+//typedef struct { xdouble real, imag; } openblas_complex_xdouble;
diff --git a/shared/linux-arm64/include/matlib.h b/shared/linux-arm64/include/matlib.h
new file mode 100644
index 0000000..612189c
--- /dev/null
+++ b/shared/linux-arm64/include/matlib.h
@@ -0,0 +1,397 @@
+#ifndef RINDOW_MATLIB_H_
+#define RINDOW_MATLIB_H_
+
+#include
+
+enum rindow_matlib_dtype
+{
+ rindow_matlib_dtype_unknown = 0,
+ rindow_matlib_dtype_bool = 1,
+ rindow_matlib_dtype_int8 = 2,
+ rindow_matlib_dtype_int16 = 3,
+ rindow_matlib_dtype_int32 = 4,
+ rindow_matlib_dtype_int64 = 5,
+ rindow_matlib_dtype_uint8 = 6,
+ rindow_matlib_dtype_uint16 = 7,
+ rindow_matlib_dtype_uint32 = 8,
+ rindow_matlib_dtype_uint64 = 9,
+ rindow_matlib_dtype_float8 = 10,
+ rindow_matlib_dtype_float16 = 11,
+ rindow_matlib_dtype_float32 = 12,
+ rindow_matlib_dtype_float64 = 13,
+ rindow_matlib_dtype_complex16 = 14,
+ rindow_matlib_dtype_complex32 = 15,
+ rindow_matlib_dtype_complex64 = 16,
+ rindow_matlib_dtype_complex128 = 17
+};
+
+#if _MSC_VER
+#if !defined(RINDOW_FUNC)
+#if defined(RINDOW_COMPILING_DLL)
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL extern __declspec(dllexport)
+#elif defined(RINDOW_MATLIB_INCLUDING_SOURCE)
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL
+#else
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL extern __declspec(dllimport)
+#endif
+#endif
+#else // _MSC_VER
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL extern
+#endif // _MSC_VER
+
+#define RINDOW_MATLIB_SUCCESS 0
+#define RINDOW_MATLIB_E_MEM_ALLOC_FAILURE -101
+#define RINDOW_MATLIB_E_PERM_OUT_OF_RANGE -102
+#define RINDOW_MATLIB_E_DUP_AXIS -103
+#define RINDOW_MATLIB_E_UNSUPPORTED_DATA_TYPE -104
+#define RINDOW_MATLIB_E_UNMATCH_IMAGE_BUFFER_SIZE -105
+#define RINDOW_MATLIB_E_UNMATCH_COLS_BUFFER_SIZE -106
+#define RINDOW_MATLIB_E_INVALID_SHAPE_OR_PARAM -107
+#define RINDOW_MATLIB_E_IMAGES_OUT_OF_RANGE -108
+#define RINDOW_MATLIB_E_COLS_OUT_OF_RANGE -109
+
+#define RINDOW_MATLIB_NO_TRANS 111
+#define RINDOW_MATLIB_TRANS 112
+// #define RINDOW_MATLIB_CONJ_TRANS 113
+// #define RINDOW_MATLIB_CONJ_NO_TRANS 114
+
+// Matlib is compiled for sequential use
+#define RINDOW_MATLIB_SEQUENTIAL 0
+// Matlib is compiled using normal threading model
+#define RINDOW_MATLIB_THREAD 1
+// Matlib is compiled using OpenMP threading model
+#define RINDOW_MATLIB_OPENMP 2
+
+static inline int32_t rindow_matlib_common_dtype_to_valuesize(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_bool:
+ case rindow_matlib_dtype_int8:
+ case rindow_matlib_dtype_uint8:
+ case rindow_matlib_dtype_float8:
+ return 1;
+ case rindow_matlib_dtype_int16:
+ case rindow_matlib_dtype_uint16:
+ case rindow_matlib_dtype_float16:
+ case rindow_matlib_dtype_complex16:
+ return 2;
+ case rindow_matlib_dtype_int32:
+ case rindow_matlib_dtype_uint32:
+ case rindow_matlib_dtype_float32:
+ case rindow_matlib_dtype_complex32:
+ return 4;
+ case rindow_matlib_dtype_int64:
+ case rindow_matlib_dtype_uint64:
+ case rindow_matlib_dtype_float64:
+ case rindow_matlib_dtype_complex64:
+ return 8;
+ case rindow_matlib_dtype_complex128:
+ return 16;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_int(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_int8:
+ case rindow_matlib_dtype_uint8:
+ case rindow_matlib_dtype_int16:
+ case rindow_matlib_dtype_uint16:
+ case rindow_matlib_dtype_int32:
+ case rindow_matlib_dtype_uint32:
+ case rindow_matlib_dtype_int64:
+ case rindow_matlib_dtype_uint64:
+ return 1;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_float(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_float8:
+ case rindow_matlib_dtype_float16:
+ case rindow_matlib_dtype_float32:
+ case rindow_matlib_dtype_float64:
+ return 1;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_complex(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_complex16:
+ case rindow_matlib_dtype_complex32:
+ case rindow_matlib_dtype_complex64:
+ case rindow_matlib_dtype_complex128:
+ return 1;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_bool(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_bool:
+ return 1;
+ }
+ return 0;
+}
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_common_get_nprocs(void);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_common_get_num_threads(void);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_common_get_parallel(void);
+ RINDOW_FUNC_DECL char *rindow_matlib_common_get_version(void);
+
+ RINDOW_FUNC_DECL void *rindow_matlib_common_get_address(int32_t dtype, void *buffer, int32_t offset);
+
+ RINDOW_FUNC_DECL float rindow_matlib_s_sum(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL double rindow_matlib_d_sum(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL int64_t rindow_matlib_i_sum(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_imax(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_imax(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_imax(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_imin(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_imin(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_imin(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_increment(int32_t n, float *x, int32_t incX, float alpha, float beta);
+ RINDOW_FUNC_DECL void rindow_matlib_d_increment(int32_t n, double *x, int32_t incX, double alpha, double beta);
+ RINDOW_FUNC_DECL void rindow_matlib_s_reciprocal(int32_t n, float *x, int32_t incX, float alpha, float beta);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reciprocal(int32_t n, double *x, int32_t incX, double alpha, double beta);
+ RINDOW_FUNC_DECL void rindow_matlib_s_maximum(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_maximum(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_minimum(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_minimum(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_greater(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_greater(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_greater_equal(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_greater_equal(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_less(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_less(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_less_equal(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_less_equal(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_multiply(int32_t trans, int32_t m, int32_t n, float *x, int32_t incX, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_multiply(int32_t trans, int32_t m, int32_t n, double *x, int32_t incX, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_add(int32_t trans, int32_t m, int32_t n, float alpha, float *x, int32_t incX, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_add(int32_t trans, int32_t m, int32_t n, double alpha, double *x, int32_t incX, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_duplicate(int32_t trans, int32_t m, int32_t n, float *x, int32_t incX, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_duplicate(int32_t trans, int32_t m, int32_t n, double *x, int32_t incX, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_masking(int32_t m, int32_t n, int32_t k, int32_t len, float fill, int32_t mode, uint8_t *x, float *a);
+ RINDOW_FUNC_DECL void rindow_matlib_d_masking(int32_t m, int32_t n, int32_t k, int32_t len, double fill, int32_t mode, uint8_t *x, double *a);
+ RINDOW_FUNC_DECL void rindow_matlib_i_masking(int32_t dtype, int32_t m, int32_t n, int32_t k, int32_t len, void *fill, int32_t mode, uint8_t *x, void *a);
+ RINDOW_FUNC_DECL void rindow_matlib_s_square(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_square(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_sqrt(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_sqrt(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_rsqrt(int32_t n, float alpha, float *x, int32_t incX, float beta);
+ RINDOW_FUNC_DECL void rindow_matlib_d_rsqrt(int32_t n, double alpha, double *x, int32_t incX, double beta);
+ RINDOW_FUNC_DECL void rindow_matlib_s_pow(int32_t trans, int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_pow(int32_t trans, int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_exp(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_exp(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_log(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_log(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_tanh(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_tanh(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_sin(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_sin(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_cos(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_cos(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_tan(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_tan(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_zeros(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_zeros(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_i_zeros(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_onehot(int32_t dtype, int32_t m, int32_t n, void *x, int32_t incX, float alpha, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_onehot(int32_t dtype, int32_t m, int32_t n, void *x, int32_t incX, double alpha, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_softmax(int32_t m, int32_t n, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_softmax(int32_t m, int32_t n, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_equal(int32_t n, float *x, int32_t incX, float *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_equal(int32_t n, double *x, int32_t incX, double *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_i_equal(int32_t dtype, int32_t n, void *x, int32_t incX, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_notequal(int32_t n, float *x, int32_t incX, float *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_notequal(int32_t n, double *x, int32_t incX, double *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_i_notequal(int32_t dtype, int32_t n, void *x, int32_t incX, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_not(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_not(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_i_not(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_astype(int32_t n, int32_t from_dtype, void *x, int32_t incX, int32_t to_dtype, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_matrixcopy(int32_t trans, int32_t m, int32_t n, float alpha, float *a, int32_t ldA, float *b, int32_t ldB);
+ RINDOW_FUNC_DECL void rindow_matlib_d_matrixcopy(int32_t trans, int32_t m, int32_t n, double alpha, double *a, int32_t ldA, double *b, int32_t ldB);
+ RINDOW_FUNC_DECL void rindow_matlib_s_imagecopy(int32_t height, int32_t width, int32_t channels, float *a, float *b,
+ int32_t channelsFirst, int32_t heightShift, int32_t widthShift, int32_t verticalFlip, int32_t horizontalFlip, int32_t rgbFlip);
+ RINDOW_FUNC_DECL void rindow_matlib_d_imagecopy(int32_t height, int32_t width, int32_t channels, double *a, double *b,
+ int32_t channelsFirst, int32_t heightShift, int32_t widthShift, int32_t verticalFlip, int32_t horizontalFlip, int32_t rgbFlip);
+ RINDOW_FUNC_DECL void rindow_matlib_i8_imagecopy(int32_t height, int32_t width, int32_t channels, uint8_t *a, uint8_t *b,
+ int32_t channelsFirst, int32_t heightShift, int32_t widthShift, int32_t verticalFlip, int32_t horizontalFlip, int32_t rgbFlip);
+ RINDOW_FUNC_DECL void rindow_matlib_fill(int32_t dtype, int32_t n, void *value, void *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_nan2num(int32_t n, float *x, int32_t incX, float alpha);
+ RINDOW_FUNC_DECL void rindow_matlib_d_nan2num(int32_t n, double *x, int32_t incX, double alpha);
+ RINDOW_FUNC_DECL void rindow_matlib_s_isnan(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_isnan(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_searchsorted(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX,
+ int32_t right, int32_t dtype, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_searchsorted(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX,
+ int32_t right, int32_t dtype, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_cumsum(int32_t n, float *x, int32_t incX, int32_t exclusive, int32_t reverse, float *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_cumsum(int32_t n, double *x, int32_t incX, int32_t exclusive, int32_t reverse, double *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_cumsumb(int32_t m, int32_t n, int32_t k, float *a, int32_t exclusive, int32_t reverse, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_cumsumb(int32_t m, int32_t n, int32_t k, double *a, int32_t exclusive, int32_t reverse, double *b);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_transpose(int32_t ndim, int32_t *shape, int32_t *perm, float *a, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_transpose(int32_t ndim, int32_t *shape, int32_t *perm, double *a, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_transpose(int32_t dtype, int32_t ndim, int32_t *shape, int32_t *perm, void *a, void *b);
+ RINDOW_FUNC_DECL void rindow_matlib_s_bandpart(int32_t m, int32_t n, int32_t k, float *a, int32_t lower, int32_t upper);
+ RINDOW_FUNC_DECL void rindow_matlib_d_bandpart(int32_t m, int32_t n, int32_t k, double *a, int32_t lower, int32_t upper);
+ RINDOW_FUNC_DECL void rindow_matlib_i_bandpart(int32_t m, int32_t n, int32_t k, int32_t dtype, void *a, int32_t lower, int32_t upper);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_gather(int32_t reverse, int32_t addMode, int32_t n, int32_t k, int32_t numClass, int32_t dtype, void *x, float *a, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_gather(int32_t reverse, int32_t addMode, int32_t n, int32_t k, int32_t numClass, int32_t dtype, void *x, double *a, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_gather(int32_t reverse, int32_t addMode, int32_t n, int32_t k, int32_t numClass, int32_t dtype, void *x, int32_t data_dtype, void *a, void *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_reducegather(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t numClass, int32_t dtype, void *x, float *a, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_reducegather(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t numClass, int32_t dtype, void *x, double *a, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_reducegather(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t numClass, int32_t dtype, void *x, int32_t data_dtype, void *a, void *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_gatherb(int32_t reverse, int32_t addMode, int32_t batches, int32_t m, int32_t n, int32_t k, int32_t len, int32_t numClass, float *a, int32_t *x, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_gatherb(int32_t reverse, int32_t addMode, int32_t batches, int32_t m, int32_t n, int32_t k, int32_t len, int32_t numClass, double *a, int32_t *x, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_gatherb(int32_t reverse, int32_t addMode, int32_t batches, int32_t m, int32_t n, int32_t k, int32_t len, int32_t numClass, int32_t dtype, void *a, int32_t *x, void *b);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_einsum(
+ const int32_t depth,
+ const int32_t *sizeOfIndices,
+ const float *a,
+ const int32_t *ldA,
+ const float *b,
+ const int32_t *ldB,
+ float *c,
+ const int32_t ndimC);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_einsum(
+ const int32_t depth,
+ const int32_t *sizeOfIndices,
+ const double *a,
+ const int32_t *ldA,
+ const double *b,
+ const int32_t *ldB,
+ double *c,
+ const int32_t ndimC);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_einsum4p1(
+ int32_t dim0,
+ int32_t dim1,
+ int32_t dim2,
+ int32_t dim3,
+ int32_t dim4,
+ float *a,
+ int32_t ldA0,
+ int32_t ldA1,
+ int32_t ldA2,
+ int32_t ldA3,
+ int32_t ldA4,
+ float *b,
+ int32_t ldB0,
+ int32_t ldB1,
+ int32_t ldB2,
+ int32_t ldB3,
+ int32_t ldB4,
+ float *c);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_einsum4p1(
+ int32_t dim0,
+ int32_t dim1,
+ int32_t dim2,
+ int32_t dim3,
+ int32_t dim4,
+ double *a,
+ int32_t ldA0,
+ int32_t ldA1,
+ int32_t ldA2,
+ int32_t ldA3,
+ int32_t ldA4,
+ double *b,
+ int32_t ldB0,
+ int32_t ldB1,
+ int32_t ldB2,
+ int32_t ldB3,
+ int32_t ldB4,
+ double *c);
+ RINDOW_FUNC_DECL void rindow_matlib_s_slice(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t k, int32_t size, float *a, int32_t incA, float *y, int32_t incY, int32_t startAxis0, int32_t sizeAxis0, int32_t startAxis1, int32_t sizeAxis1, int32_t startAxis2, int32_t sizeAxis2);
+ RINDOW_FUNC_DECL void rindow_matlib_d_slice(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t k, int32_t size, double *a, int32_t incA, double *y, int32_t incY, int32_t startAxis0, int32_t sizeAxis0, int32_t startAxis1, int32_t sizeAxis1, int32_t startAxis2, int32_t sizeAxis2);
+ RINDOW_FUNC_DECL void rindow_matlib_i_slice(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t k, int32_t size, int32_t dtype, void *a, int32_t incA, void *y, int32_t incY, int32_t startAxis0, int32_t sizeAxis0, int32_t startAxis1, int32_t sizeAxis1, int32_t startAxis2, int32_t sizeAxis2);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_repeat(int32_t m, int32_t k, int32_t repeats, float *a, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_repeat(int32_t m, int32_t k, int32_t repeats, double *a, double *b);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_reducesum(int32_t m, int32_t n, int32_t k, float *a, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reducesum(int32_t m, int32_t n, int32_t k, double *a, double *b);
+ RINDOW_FUNC_DECL void rindow_matlib_s_reducemax(int32_t m, int32_t n, int32_t k, float *a, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reducemax(int32_t m, int32_t n, int32_t k, double *a, double *b);
+ RINDOW_FUNC_DECL void rindow_matlib_s_reduceargmax(int32_t m, int32_t n, int32_t k, float *a, int32_t dtype, void *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reduceargmax(int32_t m, int32_t n, int32_t k, double *a, int32_t dtype, void *b);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_randomuniform(int32_t n, float *x, int32_t incX, float low, float high, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_d_randomuniform(int32_t n, double *x, int32_t incX, double low, double high, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_i_randomuniform(int32_t n, int32_t dtype, void *x, int32_t incX, int32_t low, int32_t high, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_s_randomnormal(int32_t n, float *x, int32_t incX, float mean, float scale, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_d_randomnormal(int32_t n, double *x, int32_t incX, double mean, double scale, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_i_randomsequence(int32_t n, int32_t size, int32_t dtype, void *x, int32_t incX, int32_t seed);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_im2col1d(
+ int32_t dtype, int32_t reverse,
+ void *images_data,
+ int32_t images_size,
+ int32_t batches,
+ int32_t im_w,
+ int32_t channels,
+ int32_t filter_w,
+ int32_t stride_w,
+ int32_t padding, int32_t channels_first,
+ int32_t dilation_w,
+ int32_t cols_channels_first,
+ void *cols_data, int32_t cols_size);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_im2col2d(
+ int32_t dtype, int32_t reverse,
+ void *images_data, int32_t images_size,
+ int32_t batches,
+ int32_t im_h, int32_t im_w,
+ int32_t channels,
+ int32_t filter_h, int32_t filter_w,
+ int32_t stride_h, int32_t stride_w,
+ int32_t padding, int32_t channels_first,
+ int32_t dilation_h, int32_t dilation_w,
+ int32_t cols_channels_first,
+ void *cols_data, int32_t cols_size);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_im2col3d(
+ int32_t dtype, int32_t reverse,
+ void *images_data, int32_t images_size,
+ int32_t batches,
+ int32_t im_d, int32_t im_h, int32_t im_w,
+ int32_t channels,
+ int32_t filter_d, int32_t filter_h, int32_t filter_w,
+ int32_t stride_d, int32_t stride_h, int32_t stride_w,
+ int32_t padding, int32_t channels_first,
+ int32_t dilation_d, int32_t dilation_h, int32_t dilation_w,
+ int32_t cols_channels_first,
+ void *cols_data, int32_t cols_size);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+// RINDOW_MATLIB_H_
+#endif
diff --git a/shared/linux-arm64/include/onnxruntime.h b/shared/linux-arm64/include/onnxruntime.h
new file mode 100644
index 0000000..127382c
--- /dev/null
+++ b/shared/linux-arm64/include/onnxruntime.h
@@ -0,0 +1,369 @@
+#ifndef ORT_API_H
+#define ORT_API_H
+
+// https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/session/onnxruntime_c_api.h
+// keep same order
+
+typedef enum ONNXTensorElementDataType {
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16
+} ONNXTensorElementDataType;
+
+typedef enum ONNXType {
+ ONNX_TYPE_UNKNOWN,
+ ONNX_TYPE_TENSOR,
+ ONNX_TYPE_SEQUENCE,
+ ONNX_TYPE_MAP,
+ ONNX_TYPE_OPAQUE,
+ ONNX_TYPE_SPARSETENSOR,
+ ONNX_TYPE_OPTIONAL
+} ONNXType;
+
+typedef enum OrtLoggingLevel {
+ ORT_LOGGING_LEVEL_VERBOSE,
+ ORT_LOGGING_LEVEL_INFO,
+ ORT_LOGGING_LEVEL_WARNING,
+ ORT_LOGGING_LEVEL_ERROR,
+ ORT_LOGGING_LEVEL_FATAL,
+} OrtLoggingLevel;
+
+typedef enum OrtErrorCode {
+ ORT_OK,
+ ORT_FAIL,
+ ORT_INVALID_ARGUMENT,
+ ORT_NO_SUCHFILE,
+ ORT_NO_MODEL,
+ ORT_ENGINE_ERROR,
+ ORT_RUNTIME_EXCEPTION,
+ ORT_INVALID_PROTOBUF,
+ ORT_MODEL_LOADED,
+ ORT_NOT_IMPLEMENTED,
+ ORT_INVALID_GRAPH,
+ ORT_EP_FAIL,
+} OrtErrorCode;
+
+struct OrtEnv;
+typedef struct OrtEnv OrtEnv;
+
+struct OrtStatus;
+typedef struct OrtStatus OrtStatus;
+
+struct OrtMemoryInfo;
+typedef struct OrtMemoryInfo OrtMemoryInfo;
+
+struct OrtIoBinding;
+typedef struct OrtIoBinding OrtIoBinding;
+
+struct OrtSession;
+typedef struct OrtSession OrtSession;
+
+struct OrtValue;
+typedef struct OrtValue OrtValue;
+
+struct OrtRunOptions;
+typedef struct OrtRunOptions OrtRunOptions;
+
+struct OrtTypeInfo;
+typedef struct OrtTypeInfo OrtTypeInfo;
+
+struct OrtTensorTypeAndShapeInfo;
+typedef struct OrtTensorTypeAndShapeInfo OrtTensorTypeAndShapeInfo;
+
+struct OrtSessionOptions;
+typedef struct OrtSessionOptions OrtSessionOptions;
+
+struct OrtCustomOpDomain;
+typedef struct OrtCustomOpDomain OrtCustomOpDomain;
+
+struct OrtMapTypeInfo;
+typedef struct OrtMapTypeInfo OrtMapTypeInfo;
+
+struct OrtSequenceTypeInfo;
+typedef struct OrtSequenceTypeInfo OrtSequenceTypeInfo;
+
+struct OrtModelMetadata;
+typedef struct OrtModelMetadata OrtModelMetadata;
+
+struct OrtThreadPoolParams;
+typedef struct OrtThreadPoolParams OrtThreadPoolParams;
+
+struct OrtThreadingOptions;
+typedef struct OrtThreadingOptions OrtThreadingOptions;
+
+struct OrtArenaCfg;
+typedef struct OrtArenaCfg OrtArenaCfg;
+
+struct OrtPrepackedWeightsContainer;
+typedef struct OrtPrepackedWeightsContainer OrtPrepackedWeightsContainer;
+
+struct OrtTensorRTProviderOptionsV2;
+typedef struct OrtTensorRTProviderOptionsV2 OrtTensorRTProviderOptionsV2;
+
+
+
+typedef enum COREMLFlags {
+ COREML_FLAG_USE_NONE = 0x000,
+ COREML_FLAG_USE_CPU_ONLY = 0x001,
+ COREML_FLAG_ENABLE_ON_SUBGRAPH = 0x002,
+ COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE = 0x004,
+ COREML_FLAG_ONLY_ALLOW_STATIC_INPUT_SHAPES = 0x008,
+ COREML_FLAG_CREATE_MLPROGRAM = 0x010,
+ COREML_FLAG_LAST = COREML_FLAG_CREATE_MLPROGRAM
+} COREMLFlags;
+
+struct OrtOp;
+typedef struct OrtOp OrtOp;
+
+struct OrtOpAttr;
+typedef struct Ort OrtOpAttr;
+
+typedef struct OrtAllocator {
+ uint32_t version;
+ void*(* Alloc)(struct OrtAllocator* this_, size_t size);
+ void(* Free)(struct OrtAllocator* this_, void* p);
+ const struct OrtMemoryInfo*(* Info)(const struct OrtAllocator* this_);
+} OrtAllocator;
+
+typedef enum GraphOptimizationLevel {
+ ORT_DISABLE_ALL = 0,
+ ORT_ENABLE_BASIC = 1,
+ ORT_ENABLE_EXTENDED = 2,
+ ORT_ENABLE_ALL = 99
+} GraphOptimizationLevel;
+
+typedef enum ExecutionMode {
+ ORT_SEQUENTIAL = 0,
+ ORT_PARALLEL = 1,
+} ExecutionMode;
+
+struct OrtApi;
+typedef struct OrtApi OrtApi;
+
+struct OrtApiBase {
+ const OrtApi*(* GetApi)(uint32_t version);
+ const char*(* GetVersionString)(void);
+};
+typedef struct OrtApiBase OrtApiBase;
+
+const OrtApiBase* OrtGetApiBase(void);
+
+struct OrtApi {
+ OrtStatus*(* CreateStatus)(OrtErrorCode code, const char* msg);
+ OrtErrorCode(* GetErrorCode)(const OrtStatus* status);
+ const char*(* GetErrorMessage)(const OrtStatus* status);
+ OrtStatus*(* CreateEnv)(OrtLoggingLevel log_severity_level, const char* logid, OrtEnv** out);
+ OrtStatus*(* CreateEnvWithCustomLogger)();
+ OrtStatus*(* EnableTelemetryEvents)(const OrtEnv* env);
+ OrtStatus*(* DisableTelemetryEvents)(const OrtEnv* env);
+ OrtStatus*(* CreateSession)(const OrtEnv* env, const char* model_path, const OrtSessionOptions* options, OrtSession** out);
+ OrtStatus*(* CreateSessionFromArray)(const OrtEnv* env, const void* model_data, size_t model_data_length, const OrtSessionOptions* options, OrtSession** out);
+ OrtStatus*(* Run)(OrtSession* session, const OrtRunOptions* run_options, const char* const* input_names, const OrtValue* const* inputs, size_t input_len, const char* const* output_names, size_t output_names_len, OrtValue** outputs);
+ OrtStatus*(* CreateSessionOptions)(OrtSessionOptions** options);
+ OrtStatus*(* SetOptimizedModelFilePath)(OrtSessionOptions* options, const char* optimized_model_filepath);
+ OrtStatus*(* CloneSessionOptions)();
+ OrtStatus*(* SetSessionExecutionMode)(OrtSessionOptions* options, ExecutionMode execution_mode);
+ OrtStatus*(* EnableProfiling)(OrtSessionOptions* options, const char* profile_file_prefix);
+ OrtStatus*(* DisableProfiling)(OrtSessionOptions* options);
+ OrtStatus*(* EnableMemPattern)(OrtSessionOptions* options);
+ OrtStatus*(* DisableMemPattern)(OrtSessionOptions* options);
+ OrtStatus*(* EnableCpuMemArena)(OrtSessionOptions* options);
+ OrtStatus*(* DisableCpuMemArena)(OrtSessionOptions* options);
+ OrtStatus*(* SetSessionLogId)(OrtSessionOptions* options, const char* logid);
+ OrtStatus*(* SetSessionLogVerbosityLevel)(OrtSessionOptions* options, int session_log_verbosity_level);
+ OrtStatus*(* SetSessionLogSeverityLevel)(OrtSessionOptions* options, int session_log_severity_level);
+ OrtStatus*(* SetSessionGraphOptimizationLevel)(OrtSessionOptions* options, GraphOptimizationLevel graph_optimization_level);
+ OrtStatus*(* SetIntraOpNumThreads)(OrtSessionOptions* options, int intra_op_num_threads);
+ OrtStatus*(* SetInterOpNumThreads)(OrtSessionOptions* options, int inter_op_num_threads);
+ OrtStatus*(* CreateCustomOpDomain)();
+ OrtStatus*(* CustomOpDomain_Add)();
+ OrtStatus*(* AddCustomOpDomain)();
+ OrtStatus*(* RegisterCustomOpsLibrary)();
+ OrtStatus*(* SessionGetInputCount)(const OrtSession* session, size_t* out);
+ OrtStatus*(* SessionGetOutputCount)(const OrtSession* session, size_t* out);
+ OrtStatus*(* SessionGetOverridableInitializerCount)();
+ OrtStatus*(* SessionGetInputTypeInfo)(const OrtSession* session, size_t index, OrtTypeInfo** type_info);
+ OrtStatus*(* SessionGetOutputTypeInfo)(const OrtSession* session, size_t index, OrtTypeInfo** type_info);
+ OrtStatus*(* SessionGetOverridableInitializerTypeInfo)();
+ OrtStatus*(* SessionGetInputName)(const OrtSession* session, size_t index, OrtAllocator* allocator, char** value);
+ OrtStatus*(* SessionGetOutputName)(const OrtSession* session, size_t index, OrtAllocator* allocator, char** value);
+ OrtStatus*(* SessionGetOverridableInitializerName)();
+ OrtStatus*(* CreateRunOptions)(OrtRunOptions** out);
+ OrtStatus*(* RunOptionsSetRunLogVerbosityLevel)(OrtRunOptions* options, int log_verbosity_level);
+ OrtStatus*(* RunOptionsSetRunLogSeverityLevel)(OrtRunOptions* options, int log_severity_level);
+ OrtStatus*(* RunOptionsSetRunTag)(OrtRunOptions* options, const char* run_tag);
+ OrtStatus*(* RunOptionsGetRunLogVerbosityLevel)();
+ OrtStatus*(* RunOptionsGetRunLogSeverityLevel)();
+ OrtStatus*(* RunOptionsGetRunTag)();
+ OrtStatus*(* RunOptionsSetTerminate)(OrtRunOptions* options);
+ OrtStatus*(* RunOptionsUnsetTerminate)(OrtRunOptions* options);
+ OrtStatus*(* CreateTensorAsOrtValue)(OrtAllocator* allocator, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, OrtValue** out);
+ OrtStatus*(* CreateTensorWithDataAsOrtValue)(const OrtMemoryInfo* info, void* p_data, size_t p_data_len, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, OrtValue** out);
+ OrtStatus*(* IsTensor)();
+ OrtStatus*(* GetTensorMutableData)(OrtValue* value, void** out);
+ OrtStatus*(* FillStringTensor)(OrtValue* value, const char* const* s, size_t s_len);
+ OrtStatus*(* GetStringTensorDataLength)(const OrtValue* value, size_t* len);
+ OrtStatus*(* GetStringTensorContent)(const OrtValue* value, void* s, size_t s_len, size_t* offsets, size_t offsets_len);
+ OrtStatus*(* CastTypeInfoToTensorInfo)(const OrtTypeInfo* type_info, const OrtTensorTypeAndShapeInfo** out);
+ OrtStatus*(* GetOnnxTypeFromTypeInfo)(const OrtTypeInfo* type_info, enum ONNXType* out);
+ OrtStatus*(* CreateTensorTypeAndShapeInfo)();
+ OrtStatus*(* SetTensorElementType)();
+ OrtStatus*(* SetDimensions)();
+ OrtStatus*(* GetTensorElementType)(const OrtTensorTypeAndShapeInfo* info, enum ONNXTensorElementDataType* out);
+ OrtStatus*(* GetDimensionsCount)(const OrtTensorTypeAndShapeInfo* info, size_t* out);
+ OrtStatus*(* GetDimensions)(const OrtTensorTypeAndShapeInfo* info, int64_t* dim_values, size_t dim_values_length);
+ OrtStatus*(* GetSymbolicDimensions)(const OrtTensorTypeAndShapeInfo* info, const char* dim_params[], size_t dim_params_length);
+ OrtStatus*(* GetTensorShapeElementCount)(const OrtTensorTypeAndShapeInfo* info, size_t* out);
+ OrtStatus*(* GetTensorTypeAndShape)(const OrtValue* value, OrtTensorTypeAndShapeInfo** out);
+ OrtStatus*(* GetTypeInfo)();
+ OrtStatus*(* GetValueType)(const OrtValue* value, enum ONNXType* out);
+ OrtStatus*(* CreateMemoryInfo)();
+ OrtStatus*(* CreateCpuMemoryInfo)(enum OrtAllocatorType type, enum OrtMemType mem_type, OrtMemoryInfo** out);
+ OrtStatus*(* CompareMemoryInfo)();
+ OrtStatus*(* MemoryInfoGetName)();
+ OrtStatus*(* MemoryInfoGetId)();
+ OrtStatus*(* MemoryInfoGetMemType)();
+ OrtStatus*(* MemoryInfoGetType)();
+ OrtStatus*(* AllocatorAlloc)(OrtAllocator* ort_allocator, size_t size, void** out);
+ OrtStatus*(* AllocatorFree)(OrtAllocator* ort_allocator, void* p);
+ OrtStatus*(* AllocatorGetInfo)(const OrtAllocator* ort_allocator, const struct OrtMemoryInfo** out);
+ OrtStatus*(* GetAllocatorWithDefaultOptions)(OrtAllocator** out);
+ OrtStatus*(* AddFreeDimensionOverride)(OrtSessionOptions* options, const char* dim_denotation, int64_t dim_value);
+ OrtStatus*(* GetValue)(const OrtValue* value, int index, OrtAllocator* allocator, OrtValue** out);
+ OrtStatus*(* GetValueCount)(const OrtValue* value, size_t* out);
+ OrtStatus*(* CreateValue)();
+ OrtStatus*(* CreateOpaqueValue)();
+ OrtStatus*(* GetOpaqueValue)();
+ OrtStatus*(* KernelInfoGetAttribute_float)();
+ OrtStatus*(* KernelInfoGetAttribute_int64)();
+ OrtStatus*(* KernelInfoGetAttribute_string)();
+ OrtStatus*(* KernelContext_GetInputCount)();
+ OrtStatus*(* KernelContext_GetOutputCount)();
+ OrtStatus*(* KernelContext_GetInput)();
+ OrtStatus*(* KernelContext_GetOutput)();
+ void(* ReleaseEnv)(OrtEnv* input);
+ void(* ReleaseStatus)(OrtStatus* input);
+ void(* ReleaseMemoryInfo)(OrtMemoryInfo* input);
+ void(* ReleaseSession)(OrtSession* input);
+ void(* ReleaseValue)(OrtValue* input);
+ void(* ReleaseRunOptions)(OrtRunOptions* input);
+ void(* ReleaseTypeInfo)(OrtTypeInfo* input);
+ void(* ReleaseTensorTypeAndShapeInfo)(OrtTensorTypeAndShapeInfo* input);
+ void(* ReleaseSessionOptions)(OrtSessionOptions* input);
+ void(* ReleaseCustomOpDomain)();
+ OrtStatus*(* GetDenotationFromTypeInfo)();
+ OrtStatus*(* CastTypeInfoToMapTypeInfo)(const OrtTypeInfo* type_info, const OrtMapTypeInfo** out);
+ OrtStatus*(* CastTypeInfoToSequenceTypeInfo)(const OrtTypeInfo* type_info, const OrtSequenceTypeInfo** out);
+ OrtStatus*(* GetMapKeyType)(const OrtMapTypeInfo* map_type_info, enum ONNXTensorElementDataType* out);
+ OrtStatus*(* GetMapValueType)(const OrtMapTypeInfo* map_type_info, OrtTypeInfo** type_info);
+ OrtStatus*(* GetSequenceElementType)(const OrtSequenceTypeInfo* sequence_type_info, OrtTypeInfo** type_info);
+ void(* ReleaseMapTypeInfo)(OrtMapTypeInfo* input);
+ void(* ReleaseSequenceTypeInfo)(OrtSequenceTypeInfo* input);
+ OrtStatus*(* SessionEndProfiling)(OrtSession* session, OrtAllocator* allocator, char** out);
+ OrtStatus*(* SessionGetModelMetadata)(const OrtSession* session, OrtModelMetadata** out);
+ OrtStatus*(* ModelMetadataGetProducerName)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataGetGraphName)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataGetDomain)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataGetDescription)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataLookupCustomMetadataMap)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, const char* key, char** value);
+ OrtStatus*(* ModelMetadataGetVersion)(const OrtModelMetadata* model_metadata, int64_t* value);
+ void(* ReleaseModelMetadata)(OrtModelMetadata* input);
+ OrtStatus*(* CreateEnvWithGlobalThreadPools)();
+ OrtStatus*(* DisablePerSessionThreads)();
+ OrtStatus*(* CreateThreadingOptions)();
+ void(* ReleaseThreadingOptions)(OrtThreadingOptions* input);
+ OrtStatus*(* ModelMetadataGetCustomMetadataMapKeys)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char*** keys, int64_t* num_keys);
+ OrtStatus*(* AddFreeDimensionOverrideByName)(OrtSessionOptions* options, const char* dim_name, int64_t dim_value);
+ OrtStatus*(* GetAvailableProviders)(char*** out_ptr, int* provider_length);
+ OrtStatus*(* ReleaseAvailableProviders)(char** ptr, int providers_length);
+ OrtStatus*(* GetStringTensorElementLength)();
+ OrtStatus*(* GetStringTensorElement)();
+ OrtStatus*(* FillStringTensorElement)();
+ OrtStatus*(* AddSessionConfigEntry)(OrtSessionOptions* options, const char* config_key, const char* config_value);
+ OrtStatus*(* CreateAllocator)();
+ void(* ReleaseAllocator)(OrtAllocator* input);
+ OrtStatus*(* RunWithBinding)();
+ OrtStatus*(* CreateIoBinding)();
+ void(* ReleaseIoBinding)(OrtIoBinding* input);
+ OrtStatus*(* BindInput)();
+ OrtStatus*(* BindOutput)();
+ OrtStatus*(* BindOutputToDevice)();
+ OrtStatus*(* GetBoundOutputNames)();
+ OrtStatus*(* GetBoundOutputValues)();
+ void(* ClearBoundInputs)();
+ void(* ClearBoundOutputs)();
+ OrtStatus*(* TensorAt)();
+ OrtStatus*(* CreateAndRegisterAllocator)();
+ OrtStatus*(* SetLanguageProjection)();
+ OrtStatus*(* SessionGetProfilingStartTimeNs)();
+ OrtStatus*(* SetGlobalIntraOpNumThreads)();
+ OrtStatus*(* SetGlobalInterOpNumThreads)();
+ OrtStatus*(* SetGlobalSpinControl)();
+ OrtStatus*(* AddInitializer)();
+ OrtStatus*(* CreateEnvWithCustomLoggerAndGlobalThreadPools)();
+
+
+ OrtStatus*(* SetGlobalDenormalAsZero)();
+ OrtStatus*(* CreateArenaCfg)();
+ void(* ReleaseArenaCfg)(OrtArenaCfg* input);
+ OrtStatus*(* ModelMetadataGetGraphDescription)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* SessionOptionsAppendExecutionProvider_TensorRT)();
+ OrtStatus*(* SetCurrentGpuDeviceId)();
+ OrtStatus*(* GetCurrentGpuDeviceId)();
+ OrtStatus*(* KernelInfoGetAttributeArray_float)();
+ OrtStatus*(* KernelInfoGetAttributeArray_int64)();
+ OrtStatus*(* CreateArenaCfgV2)();
+ OrtStatus*(* AddRunConfigEntry)();
+ OrtStatus*(* CreatePrepackedWeightsContainer)();
+ void(* PrepackedWeightsContainer)(OrtPrepackedWeightsContainer* input);
+ OrtStatus*(* CreateSessionWithPrepackedWeightsContainer)();
+ OrtStatus*(* CreateSessionFromArrayWithPrepackedWeightsContainer)();
+ OrtStatus*(* SessionOptionsAppendExecutionProvider_TensorRT_V2)();
+ OrtStatus*(* CreateTensorRTProviderOptions)();
+ OrtStatus*(* UpdateTensorRTProviderOptions)();
+ OrtStatus*(* GetTensorRTProviderOptionsAsString)();
+ void(* ReleaseTensorRTProviderOptions)(OrtTensorRTProviderOptionsV2* input);
+ OrtStatus*(* EnableOrtCustomOps)();
+ OrtStatus*(* RegisterAllocator)();
+ OrtStatus*(* UnregisterAllocator)();
+ OrtStatus*(* IsSparseTensor)();
+ OrtStatus*(* CreateSparseTensorAsOrtValue)();
+ OrtStatus*(* FillSparseTensorCoo)();
+ OrtStatus*(* FillSparseTensorCsr)();
+ OrtStatus*(* FillSparseTensorBlockSparse)();
+ OrtStatus*(* CreateSparseTensorWithValuesAsOrtValue)();
+ OrtStatus*(* UseCooIndices)();
+ OrtStatus*(* UseCsrIndices)();
+ OrtStatus*(* UseBlockSparseIndices)();
+ OrtStatus*(* GetSparseTensorFormat)();
+ OrtStatus*(* GetSparseTensorValuesTypeAndShape)();
+ OrtStatus*(* GetSparseTensorValues)();
+ OrtStatus*(* GetSparseTensorIndicesTypeShape)();
+ OrtStatus*(* GetSparseTensorIndices)();
+ OrtStatus*(* HasValue)();
+ OrtStatus*(* KernelContext_GetGPUComputeStream)();
+ OrtStatus*(* GetTensorMemoryInfo)();
+ OrtStatus*(* GetExecutionProviderApi)();
+ OrtStatus*(* SessionOptionsSetCustomCreateThreadFn)();
+ OrtStatus*(* SessionOptionsSetCustomThreadCreationOptions)();
+ OrtStatus*(* SessionOptionsSetCustomJoinThreadFn)();
+ OrtStatus*(* SetGlobalCustomCreateThreadFn)();
+ OrtStatus*(* SetGlobalCustomThreadCreationOptions)();
+ OrtStatus*(* SetGlobalCustomJoinThreadFn)();
+ OrtStatus*(* SynchronizeBoundInputs)();
+ OrtStatus*(* SynchronizeBoundOutputs)();
+};
\ No newline at end of file
diff --git a/shared/linux-arm64/include/openblas.h b/shared/linux-arm64/include/openblas.h
new file mode 100644
index 0000000..8e902fb
--- /dev/null
+++ b/shared/linux-arm64/include/openblas.h
@@ -0,0 +1,426 @@
+#define FFI_SCOPE "Rindow\\OpenBLAS\\FFI"
+//#define FFI_LIB "libopenblas.dll"
+
+/////////////////////////////////////////////
+typedef int8_t cl_char;
+typedef uint8_t cl_uchar;
+typedef int16_t cl_short;
+typedef uint16_t cl_ushort;
+typedef int32_t cl_int;
+typedef uint32_t cl_uint;
+typedef int64_t cl_long;
+typedef uint64_t cl_ulong;
+/////////////////////////////////////////////
+typedef uint16_t bfloat16;
+typedef int32_t blasint;
+typedef int32_t lapack_int;
+/////////////////////////////////////////////
+//#define xdouble double
+typedef double xdouble;
+//#define OPENBLAS_COMPLEX_STRUCT
+typedef struct _openblas_complex_float { float real, imag; } openblas_complex_float;
+typedef struct _openblas_complex_double { double real, imag; } openblas_complex_double;
+typedef struct _openblas_complex_xdouble { xdouble real, imag; } openblas_complex_xdouble;
+//#define openblas_make_complex_float(real, imag) {(real), (imag)}
+//#define openblas_make_complex_double(real, imag) {(real), (imag)}
+//#define openblas_make_complex_xdouble(real, imag) {(real), (imag)}
+//#define openblas_complex_float_real(z) ((z).real)
+//#define openblas_complex_float_imag(z) ((z).imag)
+//#define openblas_complex_double_real(z) ((z).real)
+//#define openblas_complex_double_imag(z) ((z).imag)
+//#define openblas_complex_xdouble_real(z) ((z).real)
+//#define openblas_complex_xdouble_imag(z) ((z).imag)
+/////////////////////////////////////////////
+
+
+
+/*Set the number of threads on runtime.*/
+void openblas_set_num_threads(int num_threads);
+void goto_set_num_threads(int num_threads);
+
+/*Get the number of threads on runtime.*/
+int openblas_get_num_threads(void);
+
+/*Get the number of physical processors (cores).*/
+int openblas_get_num_procs(void);
+
+/*Get the build configure on runtime.*/
+char* openblas_get_config(void);
+
+/*Get the CPU corename on runtime.*/
+char* openblas_get_corename(void);
+
+/* Get the parallelization type which is used by OpenBLAS */
+int openblas_get_parallel(void);
+/* OpenBLAS is compiled for sequential use */
+#define OPENBLAS_SEQUENTIAL 0
+/* OpenBLAS is compiled using normal threading model */
+#define OPENBLAS_THREAD 1
+/* OpenBLAS is compiled using OpenMP threading model */
+#define OPENBLAS_OPENMP 2
+
+
+//#ifndef OPENBLAS_CONST
+//# define OPENBLAS_CONST const
+//#endif
+
+
+//#define CBLAS_INDEX size_t
+typedef size_t CBLAS_INDEX;
+
+
+typedef enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102} CBLAS_ORDER;
+typedef enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113, CblasConjNoTrans=114} CBLAS_TRANSPOSE;
+typedef enum CBLAS_UPLO {CblasUpper=121, CblasLower=122} CBLAS_UPLO;
+typedef enum CBLAS_DIAG {CblasNonUnit=131, CblasUnit=132} CBLAS_DIAG;
+typedef enum CBLAS_SIDE {CblasLeft=141, CblasRight=142} CBLAS_SIDE;
+typedef CBLAS_ORDER CBLAS_LAYOUT;
+
+float cblas_sdsdot(const blasint n, const float alpha, const float *x, const blasint incx, const float *y, const blasint incy);
+double cblas_dsdot (const blasint n, const float *x, const blasint incx, const float *y, const blasint incy);
+float cblas_sdot(const blasint n, const float *x, const blasint incx, const float *y, const blasint incy);
+double cblas_ddot(const blasint n, const double *x, const blasint incx, const double *y, const blasint incy);
+
+openblas_complex_float cblas_cdotu(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+openblas_complex_float cblas_cdotc(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+openblas_complex_double cblas_zdotu(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+openblas_complex_double cblas_zdotc(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+
+void cblas_cdotu_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+void cblas_cdotc_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+void cblas_zdotu_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+void cblas_zdotc_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+
+float cblas_sasum (const blasint n, const float *x, const blasint incx);
+double cblas_dasum (const blasint n, const double *x, const blasint incx);
+float cblas_scasum(const blasint n, const void *x, const blasint incx);
+double cblas_dzasum(const blasint n, const void *x, const blasint incx);
+
+float cblas_ssum (const blasint n, const float *x, const blasint incx);
+double cblas_dsum (const blasint n, const double *x, const blasint incx);
+float cblas_scsum(const blasint n, const void *x, const blasint incx);
+double cblas_dzsum(const blasint n, const void *x, const blasint incx);
+
+float cblas_snrm2 (const blasint N, const float *X, const blasint incX);
+double cblas_dnrm2 (const blasint N, const double *X, const blasint incX);
+float cblas_scnrm2(const blasint N, const void *X, const blasint incX);
+double cblas_dznrm2(const blasint N, const void *X, const blasint incX);
+
+CBLAS_INDEX cblas_isamax(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idamax(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icamax(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izamax(const blasint n, const void *x, const blasint incx);
+
+CBLAS_INDEX cblas_isamin(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idamin(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icamin(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izamin(const blasint n, const void *x, const blasint incx);
+
+CBLAS_INDEX cblas_ismax(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idmax(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icmax(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izmax(const blasint n, const void *x, const blasint incx);
+
+CBLAS_INDEX cblas_ismin(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idmin(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icmin(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izmin(const blasint n, const void *x, const blasint incx);
+
+void cblas_saxpy(const blasint n, const float alpha, const float *x, const blasint incx, float *y, const blasint incy);
+void cblas_daxpy(const blasint n, const double alpha, const double *x, const blasint incx, double *y, const blasint incy);
+void cblas_caxpy(const blasint n, const void *alpha, const void *x, const blasint incx, void *y, const blasint incy);
+void cblas_zaxpy(const blasint n, const void *alpha, const void *x, const blasint incx, void *y, const blasint incy);
+
+void cblas_scopy(const blasint n, const float *x, const blasint incx, float *y, const blasint incy);
+void cblas_dcopy(const blasint n, const double *x, const blasint incx, double *y, const blasint incy);
+void cblas_ccopy(const blasint n, const void *x, const blasint incx, void *y, const blasint incy);
+void cblas_zcopy(const blasint n, const void *x, const blasint incx, void *y, const blasint incy);
+
+void cblas_sswap(const blasint n, float *x, const blasint incx, float *y, const blasint incy);
+void cblas_dswap(const blasint n, double *x, const blasint incx, double *y, const blasint incy);
+void cblas_cswap(const blasint n, void *x, const blasint incx, void *y, const blasint incy);
+void cblas_zswap(const blasint n, void *x, const blasint incx, void *y, const blasint incy);
+
+void cblas_srot(const blasint N, float *X, const blasint incX, float *Y, const blasint incY, const float c, const float s);
+void cblas_drot(const blasint N, double *X, const blasint incX, double *Y, const blasint incY, const double c, const double s);
+//void cblas_csrot(const blasint n, const void *x, const blasint incx, void *y, const blasint incY, const float c, const float s);
+//void cblas_zdrot(const blasint n, const void *x, const blasint incx, void *y, const blasint incY, const double c, const double s);
+
+void cblas_srotg(float *a, float *b, float *c, float *s);
+void cblas_drotg(double *a, double *b, double *c, double *s);
+//void cblas_crotg(void *a, void *b, float *c, void *s);
+//void cblas_zrotg(void *a, void *b, double *c, void *s);
+
+
+void cblas_srotm(const blasint N, float *X, const blasint incX, float *Y, const blasint incY, const float *P);
+void cblas_drotm(const blasint N, double *X, const blasint incX, double *Y, const blasint incY, const double *P);
+
+void cblas_srotmg(float *d1, float *d2, float *b1, const float b2, float *P);
+void cblas_drotmg(double *d1, double *d2, double *b1, const double b2, double *P);
+
+void cblas_sscal(const blasint N, const float alpha, float *X, const blasint incX);
+void cblas_dscal(const blasint N, const double alpha, double *X, const blasint incX);
+void cblas_cscal(const blasint N, const void *alpha, void *X, const blasint incX);
+void cblas_zscal(const blasint N, const void *alpha, void *X, const blasint incX);
+void cblas_csscal(const blasint N, const float alpha, void *X, const blasint incX);
+void cblas_zdscal(const blasint N, const double alpha, void *X, const blasint incX);
+
+void cblas_sgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const float alpha, const float *a, const blasint lda, const float *x, const blasint incx, const float beta, float *y, const blasint incy);
+void cblas_dgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const double alpha, const double *a, const blasint lda, const double *x, const blasint incx, const double beta, double *y, const blasint incy);
+void cblas_cgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const void *alpha, const void *a, const blasint lda, const void *x, const blasint incx, const void *beta, void *y, const blasint incy);
+void cblas_zgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const void *alpha, const void *a, const blasint lda, const void *x, const blasint incx, const void *beta, void *y, const blasint incy);
+
+void cblas_sger (const enum CBLAS_ORDER order, const blasint M, const blasint N, const float alpha, const float *X, const blasint incX, const float *Y, const blasint incY, float *A, const blasint lda);
+void cblas_dger (const enum CBLAS_ORDER order, const blasint M, const blasint N, const double alpha, const double *X, const blasint incX, const double *Y, const blasint incY, double *A, const blasint lda);
+void cblas_cgeru(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_cgerc(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_zgeru(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_zgerc(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+
+void cblas_strsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_strmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_ssyr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *X, const blasint incX, float *A, const blasint lda);
+void cblas_dsyr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X, const blasint incX, double *A, const blasint lda);
+void cblas_cher(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const void *X, const blasint incX, void *A, const blasint lda);
+void cblas_zher(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const void *X, const blasint incX, void *A, const blasint lda);
+
+void cblas_ssyr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,const blasint N, const float alpha, const float *X,
+ const blasint incX, const float *Y, const blasint incY, float *A, const blasint lda);
+void cblas_dsyr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X,
+ const blasint incX, const double *Y, const blasint incY, double *A, const blasint lda);
+void cblas_cher2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX,
+ const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_zher2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX,
+ const void *Y, const blasint incY, void *A, const blasint lda);
+
+void cblas_sgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const float alpha, const float *A, const blasint lda, const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const double alpha, const double *A, const blasint lda, const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+void cblas_cgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+void cblas_ssbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K, const float alpha, const float *A,
+ const blasint lda, const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dsbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K, const double alpha, const double *A,
+ const blasint lda, const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+
+
+void cblas_stbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_stbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_stpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const float *Ap, float *X, const blasint incX);
+void cblas_dtpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const double *Ap, double *X, const blasint incX);
+void cblas_ctpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+void cblas_ztpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+
+void cblas_stpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const float *Ap, float *X, const blasint incX);
+void cblas_dtpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const double *Ap, double *X, const blasint incX);
+void cblas_ctpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+void cblas_ztpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+
+void cblas_ssymv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *A,
+ const blasint lda, const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dsymv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *A,
+ const blasint lda, const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+void cblas_chemv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *A,
+ const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zhemv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *A,
+ const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+
+void cblas_sspmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *Ap,
+ const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dspmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *Ap,
+ const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+
+void cblas_sspr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *X, const blasint incX, float *Ap);
+void cblas_dspr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X, const blasint incX, double *Ap);
+
+void cblas_chpr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const void *X, const blasint incX, void *A);
+void cblas_zhpr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const void *X,const blasint incX, void *A);
+
+void cblas_sspr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *X, const blasint incX, const float *Y, const blasint incY, float *A);
+void cblas_dspr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X, const blasint incX, const double *Y, const blasint incY, double *A);
+void cblas_chpr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *Ap);
+void cblas_zhpr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *Ap);
+
+void cblas_chbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zhbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+void cblas_chpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N,
+ const void *alpha, const void *Ap, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zhpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N,
+ const void *alpha, const void *Ap, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+void cblas_sgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const float alpha, const float *A, const blasint lda, const float *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+void cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const double alpha, const double *A, const blasint lda, const double *B, const blasint ldb, const double beta, double *C, const blasint ldc);
+void cblas_cgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+//void cblas_cgemm3m(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+// const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+//void cblas_zgemm3m(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+// const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+
+void cblas_ssymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const float alpha, const float *A, const blasint lda, const float *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+void cblas_dsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const double alpha, const double *A, const blasint lda, const double *B, const blasint ldb, const double beta, double *C, const blasint ldc);
+void cblas_csymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+void cblas_ssyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const float alpha, const float *A, const blasint lda, const float beta, float *C, const blasint ldc);
+void cblas_dsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const double alpha, const double *A, const blasint lda, const double beta, double *C, const blasint ldc);
+void cblas_csyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *beta, void *C, const blasint ldc);
+void cblas_zsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *beta, void *C, const blasint ldc);
+
+void cblas_ssyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const float alpha, const float *A, const blasint lda, const float *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+void cblas_dsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const double alpha, const double *A, const blasint lda, const double *B, const blasint ldb, const double beta, double *C, const blasint ldc);
+void cblas_csyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+
+
+void cblas_strmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const float alpha, const float *A, const blasint lda, float *B, const blasint ldb);
+void cblas_dtrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const double alpha, const double *A, const blasint lda, double *B, const blasint ldb);
+void cblas_ctrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+void cblas_ztrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+
+void cblas_strsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const float alpha, const float *A, const blasint lda, float *B, const blasint ldb);
+void cblas_dtrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const double alpha, const double *A, const blasint lda, double *B, const blasint ldb);
+void cblas_ctrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+void cblas_ztrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+
+void cblas_chemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zhemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+void cblas_cherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const float alpha, const void *A, const blasint lda, const float beta, void *C, const blasint ldc);
+void cblas_zherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const double alpha, const void *A, const blasint lda, const double beta, void *C, const blasint ldc);
+
+void cblas_cher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const float beta, void *C, const blasint ldc);
+void cblas_zher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const double beta, void *C, const blasint ldc);
+
+void cblas_xerbla(blasint p, char *rout, char *form, ...);
+
+/*** BLAS extensions ***/
+
+void cblas_saxpby(const blasint n, const float alpha, const float *x, const blasint incx,const float beta, float *y, const blasint incy);
+
+void cblas_daxpby(const blasint n, const double alpha, const double *x, const blasint incx,const double beta, double *y, const blasint incy);
+
+void cblas_caxpby(const blasint n, const void *alpha, const void *x, const blasint incx,const void *beta, void *y, const blasint incy);
+
+void cblas_zaxpby(const blasint n, const void *alpha, const void *x, const blasint incx,const void *beta, void *y, const blasint incy);
+
+void cblas_somatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const float calpha, const float *a,
+ const blasint clda, float *b, const blasint cldb);
+void cblas_domatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const double calpha, const double *a,
+ const blasint clda, double *b, const blasint cldb);
+void cblas_comatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const void* calpha, const void* a,
+ const blasint clda, void *b, const blasint cldb);
+void cblas_zomatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const void* calpha, const void* a,
+ const blasint clda, void *b, const blasint cldb);
+
+void cblas_simatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const float calpha, float *a,
+ const blasint clda, const blasint cldb);
+void cblas_dimatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const double calpha, double *a,
+ const blasint clda, const blasint cldb);
+void cblas_cimatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const float* calpha, float* a,
+ const blasint clda, const blasint cldb);
+void cblas_zimatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const double* calpha, double* a,
+ const blasint clda, const blasint cldb);
+
+void cblas_sgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const float calpha, float *a, const blasint clda, const float cbeta,
+ float *c, const blasint cldc);
+void cblas_dgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const double calpha, double *a, const blasint clda, const double cbeta,
+ double *c, const blasint cldc);
+void cblas_cgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const float *calpha, float *a, const blasint clda, const float *cbeta,
+ float *c, const blasint cldc);
+void cblas_zgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const double *calpha, double *a, const blasint clda, const double *cbeta,
+ double *c, const blasint cldc);
+
+/*** BFLOAT16 and INT8 extensions ***/
+/* convert float array to BFLOAT16 array by rounding */
+//void cblas_sbstobf16(const blasint n, const float *in, const blasint incin, bfloat16 *out, const blasint incout);
+/* convert double array to BFLOAT16 array by rounding */
+//void cblas_sbdtobf16(const blasint n, const double *in, const blasint incin, bfloat16 *out, const blasint incout);
+/* convert BFLOAT16 array to float array */
+//void cblas_sbf16tos(const blasint n, const bfloat16 *in, const blasint incin, float *out, const blasint incout);
+/* convert BFLOAT16 array to double array */
+//void cblas_dbf16tod(const blasint n, const bfloat16 *in, const blasint incin, double *out, const blasint incout);
+/* dot production of BFLOAT16 input arrays, and output as float */
+//float cblas_sbdot(const blasint n, const bfloat16 *x, const blasint incx, const bfloat16 *y, const blasint incy);
+//void cblas_sbgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n, const float alpha, const bfloat16 *a, const blasint lda, const bfloat16 *x, const blasint incx, const float beta, float *y, const blasint incy);
+
+//void cblas_sbgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+// const float alpha, const bfloat16 *A, const blasint lda, const bfloat16 *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+
+
diff --git a/shared/linux-arm64/include/samplerate.h b/shared/linux-arm64/include/samplerate.h
new file mode 100644
index 0000000..436b7ff
--- /dev/null
+++ b/shared/linux-arm64/include/samplerate.h
@@ -0,0 +1,163 @@
+#ifndef SAMPLERATE_H
+#define SAMPLERATE_H
+
+/* Opaque data type SRC_STATE. */
+typedef struct SRC_STATE_tag SRC_STATE;
+
+/* SRC_DATA is used to pass data to src_simple() and src_process(). */
+typedef struct
+{ const float *data_in ;
+ float *data_out ;
+
+ long input_frames, output_frames ;
+ long input_frames_used, output_frames_gen ;
+
+ int end_of_input ;
+
+ double src_ratio ;
+} SRC_DATA ;
+
+/*
+** User supplied callback function type for use with src_callback_new()
+** and src_callback_read(). First parameter is the same pointer that was
+** passed into src_callback_new(). Second parameter is pointer to a
+** pointer. The user supplied callback function must modify *data to
+** point to the start of the user supplied float array. The user supplied
+** function must return the number of frames that **data points to.
+*/
+
+typedef long (*src_callback_t) (void *cb_data, float **data) ;
+
+/*
+** Standard initialisation function : return an anonymous pointer to the
+** internal state of the converter. Choose a converter from the enums below.
+** Error returned in *error.
+*/
+
+SRC_STATE* src_new (int converter_type, int channels, int *error) ;
+
+/*
+** Clone a handle : return an anonymous pointer to a new converter
+** containing the same internal state as orig. Error returned in *error.
+*/
+SRC_STATE* src_clone (SRC_STATE* orig, int *error) ;
+
+/*
+** Initilisation for callback based API : return an anonymous pointer to the
+** internal state of the converter. Choose a converter from the enums below.
+** The cb_data pointer can point to any data or be set to NULL. Whatever the
+** value, when processing, user supplied function "func" gets called with
+** cb_data as first parameter.
+*/
+
+SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels,
+ int *error, void* cb_data) ;
+
+/*
+** Cleanup all internal allocations.
+** Always returns NULL.
+*/
+
+SRC_STATE* src_delete (SRC_STATE *state) ;
+
+/*
+** Standard processing function.
+** Returns non zero on error.
+*/
+
+int src_process (SRC_STATE *state, SRC_DATA *data) ;
+
+/*
+** Callback based processing function. Read up to frames worth of data from
+** the converter int *data and return frames read or -1 on error.
+*/
+long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ;
+
+/*
+** Simple interface for performing a single conversion from input buffer to
+** output buffer at a fixed conversion ratio.
+** Simple interface does not require initialisation as it can only operate on
+** a single buffer worth of audio.
+*/
+
+int src_simple (SRC_DATA *data, int converter_type, int channels) ;
+
+/*
+** This library contains a number of different sample rate converters,
+** numbered 0 through N.
+**
+** Return a string giving either a name or a more full description of each
+** sample rate converter or NULL if no sample rate converter exists for
+** the given value. The converters are sequentially numbered from 0 to N.
+*/
+
+const char *src_get_name (int converter_type) ;
+const char *src_get_description (int converter_type) ;
+const char *src_get_version (void) ;
+
+/*
+** Set a new SRC ratio. This allows step responses
+** in the conversion ratio.
+** Returns non zero on error.
+*/
+
+int src_set_ratio (SRC_STATE *state, double new_ratio) ;
+
+/*
+** Get the current channel count.
+** Returns negative on error, positive channel count otherwise
+*/
+
+int src_get_channels (SRC_STATE *state) ;
+
+/*
+** Reset the internal SRC state.
+** Does not modify the quality settings.
+** Does not free any memory allocations.
+** Returns non zero on error.
+*/
+
+int src_reset (SRC_STATE *state) ;
+
+/*
+** Return TRUE if ratio is a valid conversion ratio, FALSE
+** otherwise.
+*/
+
+int src_is_valid_ratio (double ratio) ;
+
+/*
+** Return an error number.
+*/
+
+int src_error (SRC_STATE *state) ;
+
+/*
+** Convert the error number into a string.
+*/
+const char* src_strerror (int error) ;
+
+/*
+** The following enums can be used to set the interpolator type
+** using the function src_set_converter().
+*/
+
+enum
+{
+ SRC_SINC_BEST_QUALITY = 0,
+ SRC_SINC_MEDIUM_QUALITY = 1,
+ SRC_SINC_FASTEST = 2,
+ SRC_ZERO_ORDER_HOLD = 3,
+ SRC_LINEAR = 4,
+} ;
+
+/*
+** Extra helper functions for converting from short to float and
+** back again.
+*/
+
+void src_short_to_float_array (const short *in, float *out, int len) ;
+void src_float_to_short_array (const float *in, short *out, int len) ;
+
+void src_int_to_float_array (const int *in, float *out, int len) ;
+void src_float_to_int_array (const float *in, int *out, int len) ;
\ No newline at end of file
diff --git a/shared/linux-arm64/include/sndfile.h b/shared/linux-arm64/include/sndfile.h
new file mode 100644
index 0000000..8c4df97
--- /dev/null
+++ b/shared/linux-arm64/include/sndfile.h
@@ -0,0 +1,496 @@
+#ifndef SNDFILE_H
+#define SNDFILE_H
+
+#define SNDFILE_1
+
+/** File format types. */
+enum
+{ /* Major formats. */
+ SF_FORMAT_WAV = 0x010000, /* Microsoft WAV format (little endian default). */
+ SF_FORMAT_AIFF = 0x020000, /* Apple/SGI AIFF format (big endian). */
+ SF_FORMAT_AU = 0x030000, /* Sun/NeXT AU format (big endian). */
+ SF_FORMAT_RAW = 0x040000, /* RAW PCM data. */
+ SF_FORMAT_PAF = 0x050000, /* Ensoniq PARIS file format. */
+ SF_FORMAT_SVX = 0x060000, /* Amiga IFF / SVX8 / SV16 format. */
+ SF_FORMAT_NIST = 0x070000, /* Sphere NIST format. */
+ SF_FORMAT_VOC = 0x080000, /* VOC files. */
+ SF_FORMAT_IRCAM = 0x0A0000, /* Berkeley/IRCAM/CARL */
+ SF_FORMAT_W64 = 0x0B0000, /* Sonic Foundry's 64 bit RIFF/WAV */
+ SF_FORMAT_MAT4 = 0x0C0000, /* Matlab (tm) V4.2 / GNU Octave 2.0 */
+ SF_FORMAT_MAT5 = 0x0D0000, /* Matlab (tm) V5.0 / GNU Octave 2.1 */
+ SF_FORMAT_PVF = 0x0E0000, /* Portable Voice Format */
+ SF_FORMAT_XI = 0x0F0000, /* Fasttracker 2 Extended Instrument */
+ SF_FORMAT_HTK = 0x100000, /* HMM Tool Kit format */
+ SF_FORMAT_SDS = 0x110000, /* Midi Sample Dump Standard */
+ SF_FORMAT_AVR = 0x120000, /* Audio Visual Research */
+ SF_FORMAT_WAVEX = 0x130000, /* MS WAVE with WAVEFORMATEX */
+ SF_FORMAT_SD2 = 0x160000, /* Sound Designer 2 */
+ SF_FORMAT_FLAC = 0x170000, /* FLAC lossless file format */
+ SF_FORMAT_CAF = 0x180000, /* Core Audio File format */
+ SF_FORMAT_WVE = 0x190000, /* Psion WVE format */
+ SF_FORMAT_OGG = 0x200000, /* Xiph OGG container */
+ SF_FORMAT_MPC2K = 0x210000, /* Akai MPC 2000 sampler */
+ SF_FORMAT_RF64 = 0x220000, /* RF64 WAV file */
+ SF_FORMAT_MPEG = 0x230000, /* MPEG-1/2 audio stream */
+
+ /* Subtypes from here on. */
+
+ SF_FORMAT_PCM_S8 = 0x0001, /* Signed 8 bit data */
+ SF_FORMAT_PCM_16 = 0x0002, /* Signed 16 bit data */
+ SF_FORMAT_PCM_24 = 0x0003, /* Signed 24 bit data */
+ SF_FORMAT_PCM_32 = 0x0004, /* Signed 32 bit data */
+
+ SF_FORMAT_PCM_U8 = 0x0005, /* Unsigned 8 bit data (WAV and RAW only) */
+
+ SF_FORMAT_FLOAT = 0x0006, /* 32 bit float data */
+ SF_FORMAT_DOUBLE = 0x0007, /* 64 bit float data */
+
+ SF_FORMAT_ULAW = 0x0010, /* U-Law encoded. */
+ SF_FORMAT_ALAW = 0x0011, /* A-Law encoded. */
+ SF_FORMAT_IMA_ADPCM = 0x0012, /* IMA ADPCM. */
+ SF_FORMAT_MS_ADPCM = 0x0013, /* Microsoft ADPCM. */
+
+ SF_FORMAT_GSM610 = 0x0020, /* GSM 6.10 encoding. */
+ SF_FORMAT_VOX_ADPCM = 0x0021, /* OKI / Dialogix ADPCM */
+
+ SF_FORMAT_NMS_ADPCM_16 = 0x0022, /* 16kbs NMS G721-variant encoding. */
+ SF_FORMAT_NMS_ADPCM_24 = 0x0023, /* 24kbs NMS G721-variant encoding. */
+ SF_FORMAT_NMS_ADPCM_32 = 0x0024, /* 32kbs NMS G721-variant encoding. */
+
+ SF_FORMAT_G721_32 = 0x0030, /* 32kbs G721 ADPCM encoding. */
+ SF_FORMAT_G723_24 = 0x0031, /* 24kbs G723 ADPCM encoding. */
+ SF_FORMAT_G723_40 = 0x0032, /* 40kbs G723 ADPCM encoding. */
+
+ SF_FORMAT_DWVW_12 = 0x0040, /* 12 bit Delta Width Variable Word encoding. */
+ SF_FORMAT_DWVW_16 = 0x0041, /* 16 bit Delta Width Variable Word encoding. */
+ SF_FORMAT_DWVW_24 = 0x0042, /* 24 bit Delta Width Variable Word encoding. */
+ SF_FORMAT_DWVW_N = 0x0043, /* N bit Delta Width Variable Word encoding. */
+
+ SF_FORMAT_DPCM_8 = 0x0050, /* 8 bit differential PCM (XI only) */
+ SF_FORMAT_DPCM_16 = 0x0051, /* 16 bit differential PCM (XI only) */
+
+ SF_FORMAT_VORBIS = 0x0060, /* Xiph Vorbis encoding. */
+ SF_FORMAT_OPUS = 0x0064, /* Xiph/Skype Opus encoding. */
+
+ SF_FORMAT_ALAC_16 = 0x0070, /* Apple Lossless Audio Codec (16 bit). */
+ SF_FORMAT_ALAC_20 = 0x0071, /* Apple Lossless Audio Codec (20 bit). */
+ SF_FORMAT_ALAC_24 = 0x0072, /* Apple Lossless Audio Codec (24 bit). */
+ SF_FORMAT_ALAC_32 = 0x0073, /* Apple Lossless Audio Codec (32 bit). */
+
+ SF_FORMAT_MPEG_LAYER_I = 0x0080, /* MPEG-1 Audio Layer I */
+ SF_FORMAT_MPEG_LAYER_II = 0x0081, /* MPEG-1 Audio Layer II */
+ SF_FORMAT_MPEG_LAYER_III = 0x0082, /* MPEG-2 Audio Layer III */
+
+ /* Endian-ness options. */
+
+ SF_ENDIAN_FILE = 0x00000000, /* Default file endian-ness. */
+ SF_ENDIAN_LITTLE = 0x10000000, /* Force little endian-ness. */
+ SF_ENDIAN_BIG = 0x20000000, /* Force big endian-ness. */
+ SF_ENDIAN_CPU = 0x30000000, /* Force CPU endian-ness. */
+
+ SF_FORMAT_SUBMASK = 0x0000FFFF,
+ SF_FORMAT_TYPEMASK = 0x0FFF0000,
+ SF_FORMAT_ENDMASK = 0x30000000
+};
+
+/** valid command numbers for the sf_command() interface */
+enum
+{ SFC_GET_LIB_VERSION = 0x1000,
+ SFC_GET_LOG_INFO = 0x1001,
+ SFC_GET_CURRENT_SF_INFO = 0x1002,
+
+
+ SFC_GET_NORM_DOUBLE = 0x1010,
+ SFC_GET_NORM_FLOAT = 0x1011,
+ SFC_SET_NORM_DOUBLE = 0x1012,
+ SFC_SET_NORM_FLOAT = 0x1013,
+ SFC_SET_SCALE_FLOAT_INT_READ = 0x1014,
+ SFC_SET_SCALE_INT_FLOAT_WRITE = 0x1015,
+
+ SFC_GET_SIMPLE_FORMAT_COUNT = 0x1020,
+ SFC_GET_SIMPLE_FORMAT = 0x1021,
+
+ SFC_GET_FORMAT_INFO = 0x1028,
+
+ SFC_GET_FORMAT_MAJOR_COUNT = 0x1030,
+ SFC_GET_FORMAT_MAJOR = 0x1031,
+ SFC_GET_FORMAT_SUBTYPE_COUNT = 0x1032,
+ SFC_GET_FORMAT_SUBTYPE = 0x1033,
+
+ SFC_CALC_SIGNAL_MAX = 0x1040,
+ SFC_CALC_NORM_SIGNAL_MAX = 0x1041,
+ SFC_CALC_MAX_ALL_CHANNELS = 0x1042,
+ SFC_CALC_NORM_MAX_ALL_CHANNELS = 0x1043,
+ SFC_GET_SIGNAL_MAX = 0x1044,
+ SFC_GET_MAX_ALL_CHANNELS = 0x1045,
+
+ SFC_SET_ADD_PEAK_CHUNK = 0x1050,
+
+ SFC_UPDATE_HEADER_NOW = 0x1060,
+ SFC_SET_UPDATE_HEADER_AUTO = 0x1061,
+
+ SFC_FILE_TRUNCATE = 0x1080,
+
+ SFC_SET_RAW_START_OFFSET = 0x1090,
+
+ /* Commands reserved for dithering, which is not implemented. */
+ SFC_SET_DITHER_ON_WRITE = 0x10A0,
+ SFC_SET_DITHER_ON_READ = 0x10A1,
+
+ SFC_GET_DITHER_INFO_COUNT = 0x10A2,
+ SFC_GET_DITHER_INFO = 0x10A3,
+
+ SFC_GET_EMBED_FILE_INFO = 0x10B0,
+
+ SFC_SET_CLIPPING = 0x10C0,
+ SFC_GET_CLIPPING = 0x10C1,
+
+ SFC_GET_CUE_COUNT = 0x10CD,
+ SFC_GET_CUE = 0x10CE,
+ SFC_SET_CUE = 0x10CF,
+
+ SFC_GET_INSTRUMENT = 0x10D0,
+ SFC_SET_INSTRUMENT = 0x10D1,
+
+ SFC_GET_LOOP_INFO = 0x10E0,
+
+ SFC_GET_BROADCAST_INFO = 0x10F0,
+ SFC_SET_BROADCAST_INFO = 0x10F1,
+
+ SFC_GET_CHANNEL_MAP_INFO = 0x1100,
+ SFC_SET_CHANNEL_MAP_INFO = 0x1101,
+
+ SFC_RAW_DATA_NEEDS_ENDSWAP = 0x1110,
+
+ /* Support for Wavex Ambisonics Format */
+ SFC_WAVEX_SET_AMBISONIC = 0x1200,
+ SFC_WAVEX_GET_AMBISONIC = 0x1201,
+
+ /*
+ ** RF64 files can be set so that on-close, writable files that have less
+ ** than 4GB of data in them are converted to RIFF/WAV, as per EBU
+ ** recommendations.
+ */
+ SFC_RF64_AUTO_DOWNGRADE = 0x1210,
+
+ SFC_SET_VBR_ENCODING_QUALITY = 0x1300,
+ SFC_SET_COMPRESSION_LEVEL = 0x1301,
+
+ /* Ogg format commands */
+ SFC_SET_OGG_PAGE_LATENCY_MS = 0x1302,
+ SFC_SET_OGG_PAGE_LATENCY = 0x1303,
+ SFC_GET_OGG_STREAM_SERIALNO = 0x1306,
+
+ SFC_GET_BITRATE_MODE = 0x1304,
+ SFC_SET_BITRATE_MODE = 0x1305,
+
+ /* Cart Chunk support */
+ SFC_SET_CART_INFO = 0x1400,
+ SFC_GET_CART_INFO = 0x1401,
+
+ /* Opus files original samplerate metadata */
+ SFC_SET_ORIGINAL_SAMPLERATE = 0x1500,
+ SFC_GET_ORIGINAL_SAMPLERATE = 0x1501,
+
+ /* Following commands for testing only. */
+ SFC_TEST_IEEE_FLOAT_REPLACE = 0x6001,
+
+ /*
+ ** These SFC_SET_ADD_* values are deprecated and will disappear at some
+ ** time in the future. They are guaranteed to be here up to and
+ ** including version 1.0.8 to avoid breakage of existing software.
+ ** They currently do nothing and will continue to do nothing.
+ */
+ SFC_SET_ADD_HEADER_PAD_CHUNK = 0x1051,
+
+ SFC_SET_ADD_DITHER_ON_WRITE = 0x1070,
+ SFC_SET_ADD_DITHER_ON_READ = 0x1071
+};
+
+/** String types that can be set and read from files. */
+enum
+{ SF_STR_TITLE = 0x01,
+ SF_STR_COPYRIGHT = 0x02,
+ SF_STR_SOFTWARE = 0x03,
+ SF_STR_ARTIST = 0x04,
+ SF_STR_COMMENT = 0x05,
+ SF_STR_DATE = 0x06,
+ SF_STR_ALBUM = 0x07,
+ SF_STR_LICENSE = 0x08,
+ SF_STR_TRACKNUMBER = 0x09,
+ SF_STR_GENRE = 0x10
+} ;
+
+/** Start and End index when doing metadata transcoding. */
+#define SF_STR_FIRST SF_STR_TITLE
+#define SF_STR_LAST SF_STR_GENRE
+
+enum
+{ /* True and false */
+ SF_FALSE = 0,
+ SF_TRUE = 1,
+
+ /* Modes for opening files. */
+ SFM_READ = 0x10,
+ SFM_WRITE = 0x20,
+ SFM_RDWR = 0x30,
+
+ SF_AMBISONIC_NONE = 0x40,
+ SF_AMBISONIC_B_FORMAT = 0x41
+};
+
+/** Error codes. */
+enum
+{ SF_ERR_NO_ERROR = 0,
+ SF_ERR_UNRECOGNISED_FORMAT = 1,
+ SF_ERR_SYSTEM = 2,
+ SF_ERR_MALFORMED_FILE = 3,
+ SF_ERR_UNSUPPORTED_ENCODING = 4
+};
+
+/** Channel map values (used with SFC_SET/GET_CHANNEL_MAP). */
+enum
+{ SF_CHANNEL_MAP_INVALID = 0,
+ SF_CHANNEL_MAP_MONO = 1,
+ SF_CHANNEL_MAP_LEFT, /* Apple calls this 'Left' */
+ SF_CHANNEL_MAP_RIGHT, /* Apple calls this 'Right' */
+ SF_CHANNEL_MAP_CENTER, /* Apple calls this 'Center' */
+ SF_CHANNEL_MAP_FRONT_LEFT,
+ SF_CHANNEL_MAP_FRONT_RIGHT,
+ SF_CHANNEL_MAP_FRONT_CENTER,
+ SF_CHANNEL_MAP_REAR_CENTER, /* Apple calls this 'Center Surround', Msft calls this 'Back Center' */
+ SF_CHANNEL_MAP_REAR_LEFT, /* Apple calls this 'Left Surround', Msft calls this 'Back Left' */
+ SF_CHANNEL_MAP_REAR_RIGHT, /* Apple calls this 'Right Surround', Msft calls this 'Back Right' */
+ SF_CHANNEL_MAP_LFE, /* Apple calls this 'LFEScreen', Msft calls this 'Low Frequency' */
+ SF_CHANNEL_MAP_FRONT_LEFT_OF_CENTER, /* Apple calls this 'Left Center' */
+ SF_CHANNEL_MAP_FRONT_RIGHT_OF_CENTER, /* Apple calls this 'Right Center */
+ SF_CHANNEL_MAP_SIDE_LEFT, /* Apple calls this 'Left Surround Direct' */
+ SF_CHANNEL_MAP_SIDE_RIGHT, /* Apple calls this 'Right Surround Direct' */
+ SF_CHANNEL_MAP_TOP_CENTER, /* Apple calls this 'Top Center Surround' */
+ SF_CHANNEL_MAP_TOP_FRONT_LEFT, /* Apple calls this 'Vertical Height Left' */
+ SF_CHANNEL_MAP_TOP_FRONT_RIGHT, /* Apple calls this 'Vertical Height Right' */
+ SF_CHANNEL_MAP_TOP_FRONT_CENTER, /* Apple calls this 'Vertical Height Center' */
+ SF_CHANNEL_MAP_TOP_REAR_LEFT, /* Apple and MS call this 'Top Back Left' */
+ SF_CHANNEL_MAP_TOP_REAR_RIGHT, /* Apple and MS call this 'Top Back Right' */
+ SF_CHANNEL_MAP_TOP_REAR_CENTER, /* Apple and MS call this 'Top Back Center' */
+
+ SF_CHANNEL_MAP_AMBISONIC_B_W,
+ SF_CHANNEL_MAP_AMBISONIC_B_X,
+ SF_CHANNEL_MAP_AMBISONIC_B_Y,
+ SF_CHANNEL_MAP_AMBISONIC_B_Z,
+
+ SF_CHANNEL_MAP_MAX
+};
+
+/** Bitrate mode values (for use with SFC_GET/SET_BITRATE_MODE) */
+enum
+{ SF_BITRATE_MODE_CONSTANT = 0,
+ SF_BITRATE_MODE_AVERAGE,
+ SF_BITRATE_MODE_VARIABLE
+};
+
+/* A SNDFILE* pointer can be passed around much like stdio.h's FILE* pointer. */
+typedef struct sf_private_tag SNDFILE ;
+
+/* The following typedef is system specific and is defined when libsndfile is
+** compiled. sf_count_t will be a 64 bit value when the underlying OS allows
+** 64 bit file offsets.
+** On windows, we need to allow the same header file to be compiler by both GCC
+** and the Microsoft compiler.
+*/
+
+typedef int64_t sf_count_t ;
+#ifndef SF_COUNT_MAX
+#define SF_COUNT_MAX INT64_MAX
+#endif
+
+/* A pointer to a SF_INFO structure is passed to sf_open () and filled in.
+** On write, the SF_INFO structure is filled in by the user and passed into
+** sf_open ().
+*/
+struct SF_INFO
+{ sf_count_t frames ; /* Used to be called samples. Changed to avoid confusion. */
+ int samplerate ;
+ int channels ;
+ int format ;
+ int sections ;
+ int seekable ;
+} ;
+
+typedef struct SF_INFO SF_INFO ;
+
+/* The SF_FORMAT_INFO struct is used to retrieve information about the sound
+** file formats libsndfile supports using the sf_command () interface.
+*/
+typedef struct
+{ int format ;
+ const char *name ;
+ const char *extension ;
+} SF_FORMAT_INFO;
+
+/* Open the specified file for read, write or both. On error, this will
+** return a NULL pointer. To find the error number, pass a NULL SNDFILE
+** to sf_strerror ().
+** All calls to sf_open() should be matched with a call to sf_close().
+*/
+SNDFILE* sf_open (const char *path, int mode, SF_INFO *sfinfo) ;
+
+/* Use the existing file descriptor to create a SNDFILE object. If close_desc
+** is TRUE, the file descriptor will be closed when sf_close() is called. If
+** it is FALSE, the descriptor will not be closed.
+** When passed a descriptor like this, the library will assume that the start
+** of file header is at the current file offset. This allows sound files within
+** larger container files to be read and/or written.
+** On error, this will return a NULL pointer. To find the error number, pass a
+** NULL SNDFILE to sf_strerror ().
+** All calls to sf_open_fd() should be matched with a call to sf_close().
+*/
+
+SNDFILE* sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc) ;
+
+
+/* sf_error () returns a error number which can be translated to a text
+** string using sf_error_number().
+*/
+
+int sf_error (SNDFILE *sndfile) ;
+
+
+/* sf_strerror () returns to the caller a pointer to the current error message for
+** the given SNDFILE.
+*/
+
+const char* sf_strerror (SNDFILE *sndfile) ;
+
+
+/* sf_error_number () allows the retrieval of the error string for each internal
+** error number.
+**
+*/
+
+const char* sf_error_number (int errnum) ;
+
+
+/* The following two error functions are deprecated but they will remain in the
+** library for the foreseeable future. The function sf_strerror() should be used
+** in their place.
+*/
+
+int sf_perror (SNDFILE *sndfile) ;
+int sf_error_str (SNDFILE *sndfile, char* str, size_t len) ;
+
+
+/* Allow the caller to retrieve information from or change aspects of the
+** library behaviour.
+*/
+
+int sf_command (SNDFILE *sndfile, int command, void *data, int datasize) ;
+
+
+/* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */
+
+int sf_format_check (const SF_INFO *info) ;
+
+
+
+/* Functions for retrieving and setting string data within sound files.
+** Not all file types support this features; AIFF and WAV do. For both
+** functions, the str_type parameter must be one of the SF_STR_* values
+** defined above.
+** On error, sf_set_string() returns non-zero while sf_get_string()
+** returns NULL.
+*/
+
+int sf_set_string (SNDFILE *sndfile, int str_type, const char* str) ;
+
+const char* sf_get_string (SNDFILE *sndfile, int str_type) ;
+
+/* Return the library version string. */
+const char * sf_version_string (void) ;
+
+/* Return the current byterate at this point in the file. The byte rate in this
+** case is the number of bytes per second of audio data. For instance, for a
+** stereo, 18 bit PCM encoded file with an 16kHz sample rate, the byte rate
+** would be 2 (stereo) * 2 (two bytes per sample) * 16000 => 64000 bytes/sec.
+** For some file formats the returned value will be accurate and exact, for some
+** it will be a close approximation, for some it will be the average bitrate for
+** the whole file and for some it will be a time varying value that was accurate
+** when the file was most recently read or written.
+** To get the bitrate, multiple this value by 8.
+** Returns -1 for unknown.
+*/
+int sf_current_byterate (SNDFILE *sndfile) ;
+
+/* Functions for reading/writing the waveform data of a sound file.
+*/
+
+sf_count_t sf_read_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
+sf_count_t sf_write_raw (SNDFILE *sndfile, const void *ptr, sf_count_t bytes) ;
+
+/* Functions for reading and writing the data chunk in terms of frames.
+** The number of items actually read/written = frames * number of channels.
+** sf_xxxx_raw read/writes the raw data bytes from/to the file
+** sf_xxxx_short passes data in the native short format
+** sf_xxxx_int passes data in the native int format
+** sf_xxxx_float passes data in the native float format
+** sf_xxxx_double passes data in the native double format
+** All of these read/write function return number of frames read/written.
+*/
+
+sf_count_t sf_readf_short (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_short (SNDFILE *sndfile, const short *ptr, sf_count_t frames) ;
+
+sf_count_t sf_readf_int (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_int (SNDFILE *sndfile, const int *ptr, sf_count_t frames) ;
+
+sf_count_t sf_readf_float (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_float (SNDFILE *sndfile, const float *ptr, sf_count_t frames) ;
+
+sf_count_t sf_readf_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_double (SNDFILE *sndfile, const double *ptr, sf_count_t frames) ;
+
+
+/* Functions for reading and writing the data chunk in terms of items.
+** Otherwise similar to above.
+** All of these read/write function return number of items read/written.
+*/
+
+sf_count_t sf_read_short (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
+sf_count_t sf_write_short (SNDFILE *sndfile, const short *ptr, sf_count_t items) ;
+
+sf_count_t sf_read_int (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
+sf_count_t sf_write_int (SNDFILE *sndfile, const int *ptr, sf_count_t items) ;
+
+sf_count_t sf_read_float (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
+sf_count_t sf_write_float (SNDFILE *sndfile, const float *ptr, sf_count_t items) ;
+
+sf_count_t sf_read_double (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
+sf_count_t sf_write_double (SNDFILE *sndfile, const double *ptr, sf_count_t items) ;
+
+
+/* Close the SNDFILE and clean up all memory allocations associated with this
+** file.
+** Returns 0 on success, or an error number.
+*/
+
+int sf_close (SNDFILE *sndfile) ;
+
+
+/* If the file is opened SFM_WRITE or SFM_RDWR, call fsync() on the file
+** to force the writing of data to disk. If the file is opened SFM_READ
+** no action is taken.
+*/
+
+void sf_write_sync (SNDFILE *sndfile) ;
+
+
+
+/* The function sf_wchar_open() is Windows Only!
+** Open a file passing in a Windows Unicode filename. Otherwise, this is
+** the same as sf_open().
+*/
+
+/* #ifdef _WIN32
+** SNDFILE* sf_wchar_open (const wchar_t *wpath, int mode, SF_INFO *sfinfo) ;
+** #endif
+*/
\ No newline at end of file
diff --git a/shared/linux-arm64/include/transformersphp.h b/shared/linux-arm64/include/transformersphp.h
new file mode 100644
index 0000000..7c9c4b8
--- /dev/null
+++ b/shared/linux-arm64/include/transformersphp.h
@@ -0,0 +1,19 @@
+#ifndef FAST_TRANSFORMERS_UTILS_H
+#define FAST_TRANSFORMERS_UTILS_H
+
+enum {
+ LOG_MEL_NONE = 0,
+ LOG_MEL_LOG = 1,
+ LOG_MEL_LOG10 = 2,
+ LOG_MEL_DB = 3
+};
+
+void pad_reflect(float *input, int length, float *padded, int padded_length);
+
+void spectrogram(
+ float *waveform, int waveform_length, float *spectrogram, int spectrogram_length, int hop_length, int fft_length,
+ float *window,int window_length, int d1, int d1_max, float power, int center, float preemphasis, float *mel_filters,
+ int num_mel_filters, int num_frequency_bins, float mel_floor, int log_mel, int remove_dc_offset, int do_pad, int transpose
+);
+
+#endif // FAST_TRANSFORMERS_UTILS_H
diff --git a/shared/linux-arm64/lib/libgomp.so.1 b/shared/linux-arm64/lib/libgomp.so.1
new file mode 100644
index 0000000..99aeb63
Binary files /dev/null and b/shared/linux-arm64/lib/libgomp.so.1 differ
diff --git a/shared/linux-arm64/lib/libonnxruntime.so.1.21.0 b/shared/linux-arm64/lib/libonnxruntime.so.1.21.0
new file mode 100755
index 0000000..4bdfed6
Binary files /dev/null and b/shared/linux-arm64/lib/libonnxruntime.so.1.21.0 differ
diff --git a/shared/linux-arm64/lib/libopenblas.so.0.3.28 b/shared/linux-arm64/lib/libopenblas.so.0.3.28
new file mode 100755
index 0000000..6ae9e95
Binary files /dev/null and b/shared/linux-arm64/lib/libopenblas.so.0.3.28 differ
diff --git a/shared/linux-arm64/lib/librindowmatlib.so.1.1.1 b/shared/linux-arm64/lib/librindowmatlib.so.1.1.1
new file mode 100644
index 0000000..06fc521
Binary files /dev/null and b/shared/linux-arm64/lib/librindowmatlib.so.1.1.1 differ
diff --git a/shared/linux-arm64/lib/libsamplerate.so.0.2.2 b/shared/linux-arm64/lib/libsamplerate.so.0.2.2
new file mode 100644
index 0000000..02bbc35
Binary files /dev/null and b/shared/linux-arm64/lib/libsamplerate.so.0.2.2 differ
diff --git a/shared/linux-arm64/lib/libsndfile.so.1.2.2 b/shared/linux-arm64/lib/libsndfile.so.1.2.2
new file mode 100644
index 0000000..03aad69
Binary files /dev/null and b/shared/linux-arm64/lib/libsndfile.so.1.2.2 differ
diff --git a/shared/linux-arm64/lib/libtransformersphp.so.1.0.0 b/shared/linux-arm64/lib/libtransformersphp.so.1.0.0
new file mode 100644
index 0000000..7a61d7e
Binary files /dev/null and b/shared/linux-arm64/lib/libtransformersphp.so.1.0.0 differ
diff --git a/shared/linux-arm64/lib/libvips.so.42 b/shared/linux-arm64/lib/libvips.so.42
new file mode 100644
index 0000000..78a197e
Binary files /dev/null and b/shared/linux-arm64/lib/libvips.so.42 differ
diff --git a/shared/linux-x86_64/THIRD_PARTY_NOTICES.md b/shared/linux-x86_64/THIRD_PARTY_NOTICES.md
new file mode 100644
index 0000000..0cf3657
--- /dev/null
+++ b/shared/linux-x86_64/THIRD_PARTY_NOTICES.md
@@ -0,0 +1,52 @@
+# Third-party notices
+
+TransformersPHP includes compiled binaries of third-party libraries as a convenience to users. These binaries are
+distributed to facilitate the functionality of TransformersPHP, but TransformersPHP does not claim ownership of the
+binaries or the underlying libraries. The original authors and contributors of these libraries retain all rights. It is
+the user's responsibility to ensure compliance with the respective licenses of these libraries when using or
+distributing the bundled binaries.
+
+Below is a list of the third-party libraries included with TransformersPHP, along with their respective licenses and
+other relevant information.
+
+| Library | Used under the terms of |
+|---------------|-----------------------------------------------------------------------------------------------------------|
+| OpenMP | MIT License |
+| OnnxRuntime | MIT License |
+| OpenBlas | BSD 3-Clause License |
+| Rindow Matlib | BSD 3-Clause License |
+| LibSamplerate | BSD 2-Clause License |
+| Libsndfile | LGPL 2.1 License |
+| aom | BSD 2-Clause + [Alliance for Open Media Patent License 1.0](https://aomedia.org/license/patent-license/) |
+| cairo | Mozilla Public License 2.0 |
+| cgif | MIT Licence |
+| expat | MIT Licence |
+| fontconfig | [fontconfig Licence](https://gitlab.freedesktop.org/fontconfig/fontconfig/blob/main/COPYING) (BSD-like) |
+| freetype | [freetype Licence](https://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/docs/FTL.TXT) (BSD-like) |
+| fribidi | LGPLv3 |
+| glib | LGPLv3 |
+| harfbuzz | MIT Licence |
+| highway | Apache-2.0 License, BSD 3-Clause |
+| lcms | MIT Licence |
+| libarchive | BSD 2-Clause |
+| libexif | LGPLv3 |
+| libffi | MIT Licence |
+| libheif | LGPLv3 |
+| libimagequant | [BSD 2-Clause](https://github.com/lovell/libimagequant/blob/main/COPYRIGHT) |
+| libnsgif | MIT Licence |
+| libpng | [libpng License](https://github.com/pnggroup/libpng/blob/master/LICENSE) |
+| librsvg | LGPLv3 |
+| libspng | [BSD 2-Clause, libpng License](https://github.com/randy408/libspng/blob/master/LICENSE) |
+| libtiff | [libtiff License](https://gitlab.com/libtiff/libtiff/blob/master/LICENSE.md) (BSD-like) |
+| libvips | LGPLv3 |
+| libwebp | New BSD License |
+| libxml2 | MIT Licence |
+| mozjpeg | [zlib License, IJG License, BSD-3-Clause](https://github.com/mozilla/mozjpeg/blob/master/LICENSE.md) |
+| pango | LGPLv3 |
+| pixman | MIT Licence |
+| proxy-libintl | LGPLv3 |
+| zlib-ng | [zlib Licence](https://github.com/zlib-ng/zlib-ng/blob/develop/LICENSE.md) |
+
+---
+
+
diff --git a/shared/linux-x86_64/include/buffer.h b/shared/linux-x86_64/include/buffer.h
new file mode 100644
index 0000000..e086179
--- /dev/null
+++ b/shared/linux-x86_64/include/buffer.h
@@ -0,0 +1,5 @@
+#define FFI_SCOPE "Rindow\\Math\\Buffer\\FFI"
+
+typedef struct _rindow_complex_float { float real, imag; } rindow_complex_float;
+typedef struct _rindow_complex_double { double real, imag; } rindow_complex_double;
+//typedef struct { xdouble real, imag; } openblas_complex_xdouble;
diff --git a/shared/linux-x86_64/include/matlib.h b/shared/linux-x86_64/include/matlib.h
new file mode 100644
index 0000000..612189c
--- /dev/null
+++ b/shared/linux-x86_64/include/matlib.h
@@ -0,0 +1,397 @@
+#ifndef RINDOW_MATLIB_H_
+#define RINDOW_MATLIB_H_
+
+#include
+
+enum rindow_matlib_dtype
+{
+ rindow_matlib_dtype_unknown = 0,
+ rindow_matlib_dtype_bool = 1,
+ rindow_matlib_dtype_int8 = 2,
+ rindow_matlib_dtype_int16 = 3,
+ rindow_matlib_dtype_int32 = 4,
+ rindow_matlib_dtype_int64 = 5,
+ rindow_matlib_dtype_uint8 = 6,
+ rindow_matlib_dtype_uint16 = 7,
+ rindow_matlib_dtype_uint32 = 8,
+ rindow_matlib_dtype_uint64 = 9,
+ rindow_matlib_dtype_float8 = 10,
+ rindow_matlib_dtype_float16 = 11,
+ rindow_matlib_dtype_float32 = 12,
+ rindow_matlib_dtype_float64 = 13,
+ rindow_matlib_dtype_complex16 = 14,
+ rindow_matlib_dtype_complex32 = 15,
+ rindow_matlib_dtype_complex64 = 16,
+ rindow_matlib_dtype_complex128 = 17
+};
+
+#if _MSC_VER
+#if !defined(RINDOW_FUNC)
+#if defined(RINDOW_COMPILING_DLL)
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL extern __declspec(dllexport)
+#elif defined(RINDOW_MATLIB_INCLUDING_SOURCE)
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL
+#else
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL extern __declspec(dllimport)
+#endif
+#endif
+#else // _MSC_VER
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL extern
+#endif // _MSC_VER
+
+#define RINDOW_MATLIB_SUCCESS 0
+#define RINDOW_MATLIB_E_MEM_ALLOC_FAILURE -101
+#define RINDOW_MATLIB_E_PERM_OUT_OF_RANGE -102
+#define RINDOW_MATLIB_E_DUP_AXIS -103
+#define RINDOW_MATLIB_E_UNSUPPORTED_DATA_TYPE -104
+#define RINDOW_MATLIB_E_UNMATCH_IMAGE_BUFFER_SIZE -105
+#define RINDOW_MATLIB_E_UNMATCH_COLS_BUFFER_SIZE -106
+#define RINDOW_MATLIB_E_INVALID_SHAPE_OR_PARAM -107
+#define RINDOW_MATLIB_E_IMAGES_OUT_OF_RANGE -108
+#define RINDOW_MATLIB_E_COLS_OUT_OF_RANGE -109
+
+#define RINDOW_MATLIB_NO_TRANS 111
+#define RINDOW_MATLIB_TRANS 112
+// #define RINDOW_MATLIB_CONJ_TRANS 113
+// #define RINDOW_MATLIB_CONJ_NO_TRANS 114
+
+// Matlib is compiled for sequential use
+#define RINDOW_MATLIB_SEQUENTIAL 0
+// Matlib is compiled using normal threading model
+#define RINDOW_MATLIB_THREAD 1
+// Matlib is compiled using OpenMP threading model
+#define RINDOW_MATLIB_OPENMP 2
+
+static inline int32_t rindow_matlib_common_dtype_to_valuesize(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_bool:
+ case rindow_matlib_dtype_int8:
+ case rindow_matlib_dtype_uint8:
+ case rindow_matlib_dtype_float8:
+ return 1;
+ case rindow_matlib_dtype_int16:
+ case rindow_matlib_dtype_uint16:
+ case rindow_matlib_dtype_float16:
+ case rindow_matlib_dtype_complex16:
+ return 2;
+ case rindow_matlib_dtype_int32:
+ case rindow_matlib_dtype_uint32:
+ case rindow_matlib_dtype_float32:
+ case rindow_matlib_dtype_complex32:
+ return 4;
+ case rindow_matlib_dtype_int64:
+ case rindow_matlib_dtype_uint64:
+ case rindow_matlib_dtype_float64:
+ case rindow_matlib_dtype_complex64:
+ return 8;
+ case rindow_matlib_dtype_complex128:
+ return 16;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_int(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_int8:
+ case rindow_matlib_dtype_uint8:
+ case rindow_matlib_dtype_int16:
+ case rindow_matlib_dtype_uint16:
+ case rindow_matlib_dtype_int32:
+ case rindow_matlib_dtype_uint32:
+ case rindow_matlib_dtype_int64:
+ case rindow_matlib_dtype_uint64:
+ return 1;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_float(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_float8:
+ case rindow_matlib_dtype_float16:
+ case rindow_matlib_dtype_float32:
+ case rindow_matlib_dtype_float64:
+ return 1;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_complex(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_complex16:
+ case rindow_matlib_dtype_complex32:
+ case rindow_matlib_dtype_complex64:
+ case rindow_matlib_dtype_complex128:
+ return 1;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_bool(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_bool:
+ return 1;
+ }
+ return 0;
+}
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_common_get_nprocs(void);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_common_get_num_threads(void);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_common_get_parallel(void);
+ RINDOW_FUNC_DECL char *rindow_matlib_common_get_version(void);
+
+ RINDOW_FUNC_DECL void *rindow_matlib_common_get_address(int32_t dtype, void *buffer, int32_t offset);
+
+ RINDOW_FUNC_DECL float rindow_matlib_s_sum(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL double rindow_matlib_d_sum(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL int64_t rindow_matlib_i_sum(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_imax(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_imax(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_imax(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_imin(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_imin(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_imin(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_increment(int32_t n, float *x, int32_t incX, float alpha, float beta);
+ RINDOW_FUNC_DECL void rindow_matlib_d_increment(int32_t n, double *x, int32_t incX, double alpha, double beta);
+ RINDOW_FUNC_DECL void rindow_matlib_s_reciprocal(int32_t n, float *x, int32_t incX, float alpha, float beta);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reciprocal(int32_t n, double *x, int32_t incX, double alpha, double beta);
+ RINDOW_FUNC_DECL void rindow_matlib_s_maximum(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_maximum(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_minimum(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_minimum(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_greater(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_greater(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_greater_equal(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_greater_equal(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_less(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_less(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_less_equal(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_less_equal(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_multiply(int32_t trans, int32_t m, int32_t n, float *x, int32_t incX, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_multiply(int32_t trans, int32_t m, int32_t n, double *x, int32_t incX, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_add(int32_t trans, int32_t m, int32_t n, float alpha, float *x, int32_t incX, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_add(int32_t trans, int32_t m, int32_t n, double alpha, double *x, int32_t incX, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_duplicate(int32_t trans, int32_t m, int32_t n, float *x, int32_t incX, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_duplicate(int32_t trans, int32_t m, int32_t n, double *x, int32_t incX, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_masking(int32_t m, int32_t n, int32_t k, int32_t len, float fill, int32_t mode, uint8_t *x, float *a);
+ RINDOW_FUNC_DECL void rindow_matlib_d_masking(int32_t m, int32_t n, int32_t k, int32_t len, double fill, int32_t mode, uint8_t *x, double *a);
+ RINDOW_FUNC_DECL void rindow_matlib_i_masking(int32_t dtype, int32_t m, int32_t n, int32_t k, int32_t len, void *fill, int32_t mode, uint8_t *x, void *a);
+ RINDOW_FUNC_DECL void rindow_matlib_s_square(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_square(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_sqrt(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_sqrt(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_rsqrt(int32_t n, float alpha, float *x, int32_t incX, float beta);
+ RINDOW_FUNC_DECL void rindow_matlib_d_rsqrt(int32_t n, double alpha, double *x, int32_t incX, double beta);
+ RINDOW_FUNC_DECL void rindow_matlib_s_pow(int32_t trans, int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_pow(int32_t trans, int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_exp(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_exp(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_log(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_log(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_tanh(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_tanh(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_sin(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_sin(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_cos(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_cos(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_tan(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_tan(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_zeros(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_zeros(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_i_zeros(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_onehot(int32_t dtype, int32_t m, int32_t n, void *x, int32_t incX, float alpha, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_onehot(int32_t dtype, int32_t m, int32_t n, void *x, int32_t incX, double alpha, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_softmax(int32_t m, int32_t n, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_softmax(int32_t m, int32_t n, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_equal(int32_t n, float *x, int32_t incX, float *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_equal(int32_t n, double *x, int32_t incX, double *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_i_equal(int32_t dtype, int32_t n, void *x, int32_t incX, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_notequal(int32_t n, float *x, int32_t incX, float *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_notequal(int32_t n, double *x, int32_t incX, double *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_i_notequal(int32_t dtype, int32_t n, void *x, int32_t incX, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_not(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_not(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_i_not(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_astype(int32_t n, int32_t from_dtype, void *x, int32_t incX, int32_t to_dtype, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_matrixcopy(int32_t trans, int32_t m, int32_t n, float alpha, float *a, int32_t ldA, float *b, int32_t ldB);
+ RINDOW_FUNC_DECL void rindow_matlib_d_matrixcopy(int32_t trans, int32_t m, int32_t n, double alpha, double *a, int32_t ldA, double *b, int32_t ldB);
+ RINDOW_FUNC_DECL void rindow_matlib_s_imagecopy(int32_t height, int32_t width, int32_t channels, float *a, float *b,
+ int32_t channelsFirst, int32_t heightShift, int32_t widthShift, int32_t verticalFlip, int32_t horizontalFlip, int32_t rgbFlip);
+ RINDOW_FUNC_DECL void rindow_matlib_d_imagecopy(int32_t height, int32_t width, int32_t channels, double *a, double *b,
+ int32_t channelsFirst, int32_t heightShift, int32_t widthShift, int32_t verticalFlip, int32_t horizontalFlip, int32_t rgbFlip);
+ RINDOW_FUNC_DECL void rindow_matlib_i8_imagecopy(int32_t height, int32_t width, int32_t channels, uint8_t *a, uint8_t *b,
+ int32_t channelsFirst, int32_t heightShift, int32_t widthShift, int32_t verticalFlip, int32_t horizontalFlip, int32_t rgbFlip);
+ RINDOW_FUNC_DECL void rindow_matlib_fill(int32_t dtype, int32_t n, void *value, void *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_nan2num(int32_t n, float *x, int32_t incX, float alpha);
+ RINDOW_FUNC_DECL void rindow_matlib_d_nan2num(int32_t n, double *x, int32_t incX, double alpha);
+ RINDOW_FUNC_DECL void rindow_matlib_s_isnan(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_isnan(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_searchsorted(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX,
+ int32_t right, int32_t dtype, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_searchsorted(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX,
+ int32_t right, int32_t dtype, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_cumsum(int32_t n, float *x, int32_t incX, int32_t exclusive, int32_t reverse, float *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_cumsum(int32_t n, double *x, int32_t incX, int32_t exclusive, int32_t reverse, double *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_cumsumb(int32_t m, int32_t n, int32_t k, float *a, int32_t exclusive, int32_t reverse, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_cumsumb(int32_t m, int32_t n, int32_t k, double *a, int32_t exclusive, int32_t reverse, double *b);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_transpose(int32_t ndim, int32_t *shape, int32_t *perm, float *a, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_transpose(int32_t ndim, int32_t *shape, int32_t *perm, double *a, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_transpose(int32_t dtype, int32_t ndim, int32_t *shape, int32_t *perm, void *a, void *b);
+ RINDOW_FUNC_DECL void rindow_matlib_s_bandpart(int32_t m, int32_t n, int32_t k, float *a, int32_t lower, int32_t upper);
+ RINDOW_FUNC_DECL void rindow_matlib_d_bandpart(int32_t m, int32_t n, int32_t k, double *a, int32_t lower, int32_t upper);
+ RINDOW_FUNC_DECL void rindow_matlib_i_bandpart(int32_t m, int32_t n, int32_t k, int32_t dtype, void *a, int32_t lower, int32_t upper);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_gather(int32_t reverse, int32_t addMode, int32_t n, int32_t k, int32_t numClass, int32_t dtype, void *x, float *a, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_gather(int32_t reverse, int32_t addMode, int32_t n, int32_t k, int32_t numClass, int32_t dtype, void *x, double *a, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_gather(int32_t reverse, int32_t addMode, int32_t n, int32_t k, int32_t numClass, int32_t dtype, void *x, int32_t data_dtype, void *a, void *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_reducegather(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t numClass, int32_t dtype, void *x, float *a, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_reducegather(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t numClass, int32_t dtype, void *x, double *a, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_reducegather(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t numClass, int32_t dtype, void *x, int32_t data_dtype, void *a, void *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_gatherb(int32_t reverse, int32_t addMode, int32_t batches, int32_t m, int32_t n, int32_t k, int32_t len, int32_t numClass, float *a, int32_t *x, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_gatherb(int32_t reverse, int32_t addMode, int32_t batches, int32_t m, int32_t n, int32_t k, int32_t len, int32_t numClass, double *a, int32_t *x, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_gatherb(int32_t reverse, int32_t addMode, int32_t batches, int32_t m, int32_t n, int32_t k, int32_t len, int32_t numClass, int32_t dtype, void *a, int32_t *x, void *b);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_einsum(
+ const int32_t depth,
+ const int32_t *sizeOfIndices,
+ const float *a,
+ const int32_t *ldA,
+ const float *b,
+ const int32_t *ldB,
+ float *c,
+ const int32_t ndimC);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_einsum(
+ const int32_t depth,
+ const int32_t *sizeOfIndices,
+ const double *a,
+ const int32_t *ldA,
+ const double *b,
+ const int32_t *ldB,
+ double *c,
+ const int32_t ndimC);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_einsum4p1(
+ int32_t dim0,
+ int32_t dim1,
+ int32_t dim2,
+ int32_t dim3,
+ int32_t dim4,
+ float *a,
+ int32_t ldA0,
+ int32_t ldA1,
+ int32_t ldA2,
+ int32_t ldA3,
+ int32_t ldA4,
+ float *b,
+ int32_t ldB0,
+ int32_t ldB1,
+ int32_t ldB2,
+ int32_t ldB3,
+ int32_t ldB4,
+ float *c);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_einsum4p1(
+ int32_t dim0,
+ int32_t dim1,
+ int32_t dim2,
+ int32_t dim3,
+ int32_t dim4,
+ double *a,
+ int32_t ldA0,
+ int32_t ldA1,
+ int32_t ldA2,
+ int32_t ldA3,
+ int32_t ldA4,
+ double *b,
+ int32_t ldB0,
+ int32_t ldB1,
+ int32_t ldB2,
+ int32_t ldB3,
+ int32_t ldB4,
+ double *c);
+ RINDOW_FUNC_DECL void rindow_matlib_s_slice(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t k, int32_t size, float *a, int32_t incA, float *y, int32_t incY, int32_t startAxis0, int32_t sizeAxis0, int32_t startAxis1, int32_t sizeAxis1, int32_t startAxis2, int32_t sizeAxis2);
+ RINDOW_FUNC_DECL void rindow_matlib_d_slice(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t k, int32_t size, double *a, int32_t incA, double *y, int32_t incY, int32_t startAxis0, int32_t sizeAxis0, int32_t startAxis1, int32_t sizeAxis1, int32_t startAxis2, int32_t sizeAxis2);
+ RINDOW_FUNC_DECL void rindow_matlib_i_slice(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t k, int32_t size, int32_t dtype, void *a, int32_t incA, void *y, int32_t incY, int32_t startAxis0, int32_t sizeAxis0, int32_t startAxis1, int32_t sizeAxis1, int32_t startAxis2, int32_t sizeAxis2);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_repeat(int32_t m, int32_t k, int32_t repeats, float *a, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_repeat(int32_t m, int32_t k, int32_t repeats, double *a, double *b);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_reducesum(int32_t m, int32_t n, int32_t k, float *a, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reducesum(int32_t m, int32_t n, int32_t k, double *a, double *b);
+ RINDOW_FUNC_DECL void rindow_matlib_s_reducemax(int32_t m, int32_t n, int32_t k, float *a, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reducemax(int32_t m, int32_t n, int32_t k, double *a, double *b);
+ RINDOW_FUNC_DECL void rindow_matlib_s_reduceargmax(int32_t m, int32_t n, int32_t k, float *a, int32_t dtype, void *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reduceargmax(int32_t m, int32_t n, int32_t k, double *a, int32_t dtype, void *b);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_randomuniform(int32_t n, float *x, int32_t incX, float low, float high, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_d_randomuniform(int32_t n, double *x, int32_t incX, double low, double high, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_i_randomuniform(int32_t n, int32_t dtype, void *x, int32_t incX, int32_t low, int32_t high, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_s_randomnormal(int32_t n, float *x, int32_t incX, float mean, float scale, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_d_randomnormal(int32_t n, double *x, int32_t incX, double mean, double scale, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_i_randomsequence(int32_t n, int32_t size, int32_t dtype, void *x, int32_t incX, int32_t seed);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_im2col1d(
+ int32_t dtype, int32_t reverse,
+ void *images_data,
+ int32_t images_size,
+ int32_t batches,
+ int32_t im_w,
+ int32_t channels,
+ int32_t filter_w,
+ int32_t stride_w,
+ int32_t padding, int32_t channels_first,
+ int32_t dilation_w,
+ int32_t cols_channels_first,
+ void *cols_data, int32_t cols_size);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_im2col2d(
+ int32_t dtype, int32_t reverse,
+ void *images_data, int32_t images_size,
+ int32_t batches,
+ int32_t im_h, int32_t im_w,
+ int32_t channels,
+ int32_t filter_h, int32_t filter_w,
+ int32_t stride_h, int32_t stride_w,
+ int32_t padding, int32_t channels_first,
+ int32_t dilation_h, int32_t dilation_w,
+ int32_t cols_channels_first,
+ void *cols_data, int32_t cols_size);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_im2col3d(
+ int32_t dtype, int32_t reverse,
+ void *images_data, int32_t images_size,
+ int32_t batches,
+ int32_t im_d, int32_t im_h, int32_t im_w,
+ int32_t channels,
+ int32_t filter_d, int32_t filter_h, int32_t filter_w,
+ int32_t stride_d, int32_t stride_h, int32_t stride_w,
+ int32_t padding, int32_t channels_first,
+ int32_t dilation_d, int32_t dilation_h, int32_t dilation_w,
+ int32_t cols_channels_first,
+ void *cols_data, int32_t cols_size);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+// RINDOW_MATLIB_H_
+#endif
diff --git a/shared/linux-x86_64/include/onnxruntime.h b/shared/linux-x86_64/include/onnxruntime.h
new file mode 100644
index 0000000..127382c
--- /dev/null
+++ b/shared/linux-x86_64/include/onnxruntime.h
@@ -0,0 +1,369 @@
+#ifndef ORT_API_H
+#define ORT_API_H
+
+// https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/session/onnxruntime_c_api.h
+// keep same order
+
+typedef enum ONNXTensorElementDataType {
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16
+} ONNXTensorElementDataType;
+
+typedef enum ONNXType {
+ ONNX_TYPE_UNKNOWN,
+ ONNX_TYPE_TENSOR,
+ ONNX_TYPE_SEQUENCE,
+ ONNX_TYPE_MAP,
+ ONNX_TYPE_OPAQUE,
+ ONNX_TYPE_SPARSETENSOR,
+ ONNX_TYPE_OPTIONAL
+} ONNXType;
+
+typedef enum OrtLoggingLevel {
+ ORT_LOGGING_LEVEL_VERBOSE,
+ ORT_LOGGING_LEVEL_INFO,
+ ORT_LOGGING_LEVEL_WARNING,
+ ORT_LOGGING_LEVEL_ERROR,
+ ORT_LOGGING_LEVEL_FATAL,
+} OrtLoggingLevel;
+
+typedef enum OrtErrorCode {
+ ORT_OK,
+ ORT_FAIL,
+ ORT_INVALID_ARGUMENT,
+ ORT_NO_SUCHFILE,
+ ORT_NO_MODEL,
+ ORT_ENGINE_ERROR,
+ ORT_RUNTIME_EXCEPTION,
+ ORT_INVALID_PROTOBUF,
+ ORT_MODEL_LOADED,
+ ORT_NOT_IMPLEMENTED,
+ ORT_INVALID_GRAPH,
+ ORT_EP_FAIL,
+} OrtErrorCode;
+
+struct OrtEnv;
+typedef struct OrtEnv OrtEnv;
+
+struct OrtStatus;
+typedef struct OrtStatus OrtStatus;
+
+struct OrtMemoryInfo;
+typedef struct OrtMemoryInfo OrtMemoryInfo;
+
+struct OrtIoBinding;
+typedef struct OrtIoBinding OrtIoBinding;
+
+struct OrtSession;
+typedef struct OrtSession OrtSession;
+
+struct OrtValue;
+typedef struct OrtValue OrtValue;
+
+struct OrtRunOptions;
+typedef struct OrtRunOptions OrtRunOptions;
+
+struct OrtTypeInfo;
+typedef struct OrtTypeInfo OrtTypeInfo;
+
+struct OrtTensorTypeAndShapeInfo;
+typedef struct OrtTensorTypeAndShapeInfo OrtTensorTypeAndShapeInfo;
+
+struct OrtSessionOptions;
+typedef struct OrtSessionOptions OrtSessionOptions;
+
+struct OrtCustomOpDomain;
+typedef struct OrtCustomOpDomain OrtCustomOpDomain;
+
+struct OrtMapTypeInfo;
+typedef struct OrtMapTypeInfo OrtMapTypeInfo;
+
+struct OrtSequenceTypeInfo;
+typedef struct OrtSequenceTypeInfo OrtSequenceTypeInfo;
+
+struct OrtModelMetadata;
+typedef struct OrtModelMetadata OrtModelMetadata;
+
+struct OrtThreadPoolParams;
+typedef struct OrtThreadPoolParams OrtThreadPoolParams;
+
+struct OrtThreadingOptions;
+typedef struct OrtThreadingOptions OrtThreadingOptions;
+
+struct OrtArenaCfg;
+typedef struct OrtArenaCfg OrtArenaCfg;
+
+struct OrtPrepackedWeightsContainer;
+typedef struct OrtPrepackedWeightsContainer OrtPrepackedWeightsContainer;
+
+struct OrtTensorRTProviderOptionsV2;
+typedef struct OrtTensorRTProviderOptionsV2 OrtTensorRTProviderOptionsV2;
+
+
+
+typedef enum COREMLFlags {
+ COREML_FLAG_USE_NONE = 0x000,
+ COREML_FLAG_USE_CPU_ONLY = 0x001,
+ COREML_FLAG_ENABLE_ON_SUBGRAPH = 0x002,
+ COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE = 0x004,
+ COREML_FLAG_ONLY_ALLOW_STATIC_INPUT_SHAPES = 0x008,
+ COREML_FLAG_CREATE_MLPROGRAM = 0x010,
+ COREML_FLAG_LAST = COREML_FLAG_CREATE_MLPROGRAM
+} COREMLFlags;
+
+struct OrtOp;
+typedef struct OrtOp OrtOp;
+
+struct OrtOpAttr;
+typedef struct Ort OrtOpAttr;
+
+typedef struct OrtAllocator {
+ uint32_t version;
+ void*(* Alloc)(struct OrtAllocator* this_, size_t size);
+ void(* Free)(struct OrtAllocator* this_, void* p);
+ const struct OrtMemoryInfo*(* Info)(const struct OrtAllocator* this_);
+} OrtAllocator;
+
+typedef enum GraphOptimizationLevel {
+ ORT_DISABLE_ALL = 0,
+ ORT_ENABLE_BASIC = 1,
+ ORT_ENABLE_EXTENDED = 2,
+ ORT_ENABLE_ALL = 99
+} GraphOptimizationLevel;
+
+typedef enum ExecutionMode {
+ ORT_SEQUENTIAL = 0,
+ ORT_PARALLEL = 1,
+} ExecutionMode;
+
+struct OrtApi;
+typedef struct OrtApi OrtApi;
+
+struct OrtApiBase {
+ const OrtApi*(* GetApi)(uint32_t version);
+ const char*(* GetVersionString)(void);
+};
+typedef struct OrtApiBase OrtApiBase;
+
+const OrtApiBase* OrtGetApiBase(void);
+
+struct OrtApi {
+ OrtStatus*(* CreateStatus)(OrtErrorCode code, const char* msg);
+ OrtErrorCode(* GetErrorCode)(const OrtStatus* status);
+ const char*(* GetErrorMessage)(const OrtStatus* status);
+ OrtStatus*(* CreateEnv)(OrtLoggingLevel log_severity_level, const char* logid, OrtEnv** out);
+ OrtStatus*(* CreateEnvWithCustomLogger)();
+ OrtStatus*(* EnableTelemetryEvents)(const OrtEnv* env);
+ OrtStatus*(* DisableTelemetryEvents)(const OrtEnv* env);
+ OrtStatus*(* CreateSession)(const OrtEnv* env, const char* model_path, const OrtSessionOptions* options, OrtSession** out);
+ OrtStatus*(* CreateSessionFromArray)(const OrtEnv* env, const void* model_data, size_t model_data_length, const OrtSessionOptions* options, OrtSession** out);
+ OrtStatus*(* Run)(OrtSession* session, const OrtRunOptions* run_options, const char* const* input_names, const OrtValue* const* inputs, size_t input_len, const char* const* output_names, size_t output_names_len, OrtValue** outputs);
+ OrtStatus*(* CreateSessionOptions)(OrtSessionOptions** options);
+ OrtStatus*(* SetOptimizedModelFilePath)(OrtSessionOptions* options, const char* optimized_model_filepath);
+ OrtStatus*(* CloneSessionOptions)();
+ OrtStatus*(* SetSessionExecutionMode)(OrtSessionOptions* options, ExecutionMode execution_mode);
+ OrtStatus*(* EnableProfiling)(OrtSessionOptions* options, const char* profile_file_prefix);
+ OrtStatus*(* DisableProfiling)(OrtSessionOptions* options);
+ OrtStatus*(* EnableMemPattern)(OrtSessionOptions* options);
+ OrtStatus*(* DisableMemPattern)(OrtSessionOptions* options);
+ OrtStatus*(* EnableCpuMemArena)(OrtSessionOptions* options);
+ OrtStatus*(* DisableCpuMemArena)(OrtSessionOptions* options);
+ OrtStatus*(* SetSessionLogId)(OrtSessionOptions* options, const char* logid);
+ OrtStatus*(* SetSessionLogVerbosityLevel)(OrtSessionOptions* options, int session_log_verbosity_level);
+ OrtStatus*(* SetSessionLogSeverityLevel)(OrtSessionOptions* options, int session_log_severity_level);
+ OrtStatus*(* SetSessionGraphOptimizationLevel)(OrtSessionOptions* options, GraphOptimizationLevel graph_optimization_level);
+ OrtStatus*(* SetIntraOpNumThreads)(OrtSessionOptions* options, int intra_op_num_threads);
+ OrtStatus*(* SetInterOpNumThreads)(OrtSessionOptions* options, int inter_op_num_threads);
+ OrtStatus*(* CreateCustomOpDomain)();
+ OrtStatus*(* CustomOpDomain_Add)();
+ OrtStatus*(* AddCustomOpDomain)();
+ OrtStatus*(* RegisterCustomOpsLibrary)();
+ OrtStatus*(* SessionGetInputCount)(const OrtSession* session, size_t* out);
+ OrtStatus*(* SessionGetOutputCount)(const OrtSession* session, size_t* out);
+ OrtStatus*(* SessionGetOverridableInitializerCount)();
+ OrtStatus*(* SessionGetInputTypeInfo)(const OrtSession* session, size_t index, OrtTypeInfo** type_info);
+ OrtStatus*(* SessionGetOutputTypeInfo)(const OrtSession* session, size_t index, OrtTypeInfo** type_info);
+ OrtStatus*(* SessionGetOverridableInitializerTypeInfo)();
+ OrtStatus*(* SessionGetInputName)(const OrtSession* session, size_t index, OrtAllocator* allocator, char** value);
+ OrtStatus*(* SessionGetOutputName)(const OrtSession* session, size_t index, OrtAllocator* allocator, char** value);
+ OrtStatus*(* SessionGetOverridableInitializerName)();
+ OrtStatus*(* CreateRunOptions)(OrtRunOptions** out);
+ OrtStatus*(* RunOptionsSetRunLogVerbosityLevel)(OrtRunOptions* options, int log_verbosity_level);
+ OrtStatus*(* RunOptionsSetRunLogSeverityLevel)(OrtRunOptions* options, int log_severity_level);
+ OrtStatus*(* RunOptionsSetRunTag)(OrtRunOptions* options, const char* run_tag);
+ OrtStatus*(* RunOptionsGetRunLogVerbosityLevel)();
+ OrtStatus*(* RunOptionsGetRunLogSeverityLevel)();
+ OrtStatus*(* RunOptionsGetRunTag)();
+ OrtStatus*(* RunOptionsSetTerminate)(OrtRunOptions* options);
+ OrtStatus*(* RunOptionsUnsetTerminate)(OrtRunOptions* options);
+ OrtStatus*(* CreateTensorAsOrtValue)(OrtAllocator* allocator, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, OrtValue** out);
+ OrtStatus*(* CreateTensorWithDataAsOrtValue)(const OrtMemoryInfo* info, void* p_data, size_t p_data_len, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, OrtValue** out);
+ OrtStatus*(* IsTensor)();
+ OrtStatus*(* GetTensorMutableData)(OrtValue* value, void** out);
+ OrtStatus*(* FillStringTensor)(OrtValue* value, const char* const* s, size_t s_len);
+ OrtStatus*(* GetStringTensorDataLength)(const OrtValue* value, size_t* len);
+ OrtStatus*(* GetStringTensorContent)(const OrtValue* value, void* s, size_t s_len, size_t* offsets, size_t offsets_len);
+ OrtStatus*(* CastTypeInfoToTensorInfo)(const OrtTypeInfo* type_info, const OrtTensorTypeAndShapeInfo** out);
+ OrtStatus*(* GetOnnxTypeFromTypeInfo)(const OrtTypeInfo* type_info, enum ONNXType* out);
+ OrtStatus*(* CreateTensorTypeAndShapeInfo)();
+ OrtStatus*(* SetTensorElementType)();
+ OrtStatus*(* SetDimensions)();
+ OrtStatus*(* GetTensorElementType)(const OrtTensorTypeAndShapeInfo* info, enum ONNXTensorElementDataType* out);
+ OrtStatus*(* GetDimensionsCount)(const OrtTensorTypeAndShapeInfo* info, size_t* out);
+ OrtStatus*(* GetDimensions)(const OrtTensorTypeAndShapeInfo* info, int64_t* dim_values, size_t dim_values_length);
+ OrtStatus*(* GetSymbolicDimensions)(const OrtTensorTypeAndShapeInfo* info, const char* dim_params[], size_t dim_params_length);
+ OrtStatus*(* GetTensorShapeElementCount)(const OrtTensorTypeAndShapeInfo* info, size_t* out);
+ OrtStatus*(* GetTensorTypeAndShape)(const OrtValue* value, OrtTensorTypeAndShapeInfo** out);
+ OrtStatus*(* GetTypeInfo)();
+ OrtStatus*(* GetValueType)(const OrtValue* value, enum ONNXType* out);
+ OrtStatus*(* CreateMemoryInfo)();
+ OrtStatus*(* CreateCpuMemoryInfo)(enum OrtAllocatorType type, enum OrtMemType mem_type, OrtMemoryInfo** out);
+ OrtStatus*(* CompareMemoryInfo)();
+ OrtStatus*(* MemoryInfoGetName)();
+ OrtStatus*(* MemoryInfoGetId)();
+ OrtStatus*(* MemoryInfoGetMemType)();
+ OrtStatus*(* MemoryInfoGetType)();
+ OrtStatus*(* AllocatorAlloc)(OrtAllocator* ort_allocator, size_t size, void** out);
+ OrtStatus*(* AllocatorFree)(OrtAllocator* ort_allocator, void* p);
+ OrtStatus*(* AllocatorGetInfo)(const OrtAllocator* ort_allocator, const struct OrtMemoryInfo** out);
+ OrtStatus*(* GetAllocatorWithDefaultOptions)(OrtAllocator** out);
+ OrtStatus*(* AddFreeDimensionOverride)(OrtSessionOptions* options, const char* dim_denotation, int64_t dim_value);
+ OrtStatus*(* GetValue)(const OrtValue* value, int index, OrtAllocator* allocator, OrtValue** out);
+ OrtStatus*(* GetValueCount)(const OrtValue* value, size_t* out);
+ OrtStatus*(* CreateValue)();
+ OrtStatus*(* CreateOpaqueValue)();
+ OrtStatus*(* GetOpaqueValue)();
+ OrtStatus*(* KernelInfoGetAttribute_float)();
+ OrtStatus*(* KernelInfoGetAttribute_int64)();
+ OrtStatus*(* KernelInfoGetAttribute_string)();
+ OrtStatus*(* KernelContext_GetInputCount)();
+ OrtStatus*(* KernelContext_GetOutputCount)();
+ OrtStatus*(* KernelContext_GetInput)();
+ OrtStatus*(* KernelContext_GetOutput)();
+ void(* ReleaseEnv)(OrtEnv* input);
+ void(* ReleaseStatus)(OrtStatus* input);
+ void(* ReleaseMemoryInfo)(OrtMemoryInfo* input);
+ void(* ReleaseSession)(OrtSession* input);
+ void(* ReleaseValue)(OrtValue* input);
+ void(* ReleaseRunOptions)(OrtRunOptions* input);
+ void(* ReleaseTypeInfo)(OrtTypeInfo* input);
+ void(* ReleaseTensorTypeAndShapeInfo)(OrtTensorTypeAndShapeInfo* input);
+ void(* ReleaseSessionOptions)(OrtSessionOptions* input);
+ void(* ReleaseCustomOpDomain)();
+ OrtStatus*(* GetDenotationFromTypeInfo)();
+ OrtStatus*(* CastTypeInfoToMapTypeInfo)(const OrtTypeInfo* type_info, const OrtMapTypeInfo** out);
+ OrtStatus*(* CastTypeInfoToSequenceTypeInfo)(const OrtTypeInfo* type_info, const OrtSequenceTypeInfo** out);
+ OrtStatus*(* GetMapKeyType)(const OrtMapTypeInfo* map_type_info, enum ONNXTensorElementDataType* out);
+ OrtStatus*(* GetMapValueType)(const OrtMapTypeInfo* map_type_info, OrtTypeInfo** type_info);
+ OrtStatus*(* GetSequenceElementType)(const OrtSequenceTypeInfo* sequence_type_info, OrtTypeInfo** type_info);
+ void(* ReleaseMapTypeInfo)(OrtMapTypeInfo* input);
+ void(* ReleaseSequenceTypeInfo)(OrtSequenceTypeInfo* input);
+ OrtStatus*(* SessionEndProfiling)(OrtSession* session, OrtAllocator* allocator, char** out);
+ OrtStatus*(* SessionGetModelMetadata)(const OrtSession* session, OrtModelMetadata** out);
+ OrtStatus*(* ModelMetadataGetProducerName)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataGetGraphName)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataGetDomain)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataGetDescription)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataLookupCustomMetadataMap)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, const char* key, char** value);
+ OrtStatus*(* ModelMetadataGetVersion)(const OrtModelMetadata* model_metadata, int64_t* value);
+ void(* ReleaseModelMetadata)(OrtModelMetadata* input);
+ OrtStatus*(* CreateEnvWithGlobalThreadPools)();
+ OrtStatus*(* DisablePerSessionThreads)();
+ OrtStatus*(* CreateThreadingOptions)();
+ void(* ReleaseThreadingOptions)(OrtThreadingOptions* input);
+ OrtStatus*(* ModelMetadataGetCustomMetadataMapKeys)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char*** keys, int64_t* num_keys);
+ OrtStatus*(* AddFreeDimensionOverrideByName)(OrtSessionOptions* options, const char* dim_name, int64_t dim_value);
+ OrtStatus*(* GetAvailableProviders)(char*** out_ptr, int* provider_length);
+ OrtStatus*(* ReleaseAvailableProviders)(char** ptr, int providers_length);
+ OrtStatus*(* GetStringTensorElementLength)();
+ OrtStatus*(* GetStringTensorElement)();
+ OrtStatus*(* FillStringTensorElement)();
+ OrtStatus*(* AddSessionConfigEntry)(OrtSessionOptions* options, const char* config_key, const char* config_value);
+ OrtStatus*(* CreateAllocator)();
+ void(* ReleaseAllocator)(OrtAllocator* input);
+ OrtStatus*(* RunWithBinding)();
+ OrtStatus*(* CreateIoBinding)();
+ void(* ReleaseIoBinding)(OrtIoBinding* input);
+ OrtStatus*(* BindInput)();
+ OrtStatus*(* BindOutput)();
+ OrtStatus*(* BindOutputToDevice)();
+ OrtStatus*(* GetBoundOutputNames)();
+ OrtStatus*(* GetBoundOutputValues)();
+ void(* ClearBoundInputs)();
+ void(* ClearBoundOutputs)();
+ OrtStatus*(* TensorAt)();
+ OrtStatus*(* CreateAndRegisterAllocator)();
+ OrtStatus*(* SetLanguageProjection)();
+ OrtStatus*(* SessionGetProfilingStartTimeNs)();
+ OrtStatus*(* SetGlobalIntraOpNumThreads)();
+ OrtStatus*(* SetGlobalInterOpNumThreads)();
+ OrtStatus*(* SetGlobalSpinControl)();
+ OrtStatus*(* AddInitializer)();
+ OrtStatus*(* CreateEnvWithCustomLoggerAndGlobalThreadPools)();
+
+
+ OrtStatus*(* SetGlobalDenormalAsZero)();
+ OrtStatus*(* CreateArenaCfg)();
+ void(* ReleaseArenaCfg)(OrtArenaCfg* input);
+ OrtStatus*(* ModelMetadataGetGraphDescription)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* SessionOptionsAppendExecutionProvider_TensorRT)();
+ OrtStatus*(* SetCurrentGpuDeviceId)();
+ OrtStatus*(* GetCurrentGpuDeviceId)();
+ OrtStatus*(* KernelInfoGetAttributeArray_float)();
+ OrtStatus*(* KernelInfoGetAttributeArray_int64)();
+ OrtStatus*(* CreateArenaCfgV2)();
+ OrtStatus*(* AddRunConfigEntry)();
+ OrtStatus*(* CreatePrepackedWeightsContainer)();
+ void(* PrepackedWeightsContainer)(OrtPrepackedWeightsContainer* input);
+ OrtStatus*(* CreateSessionWithPrepackedWeightsContainer)();
+ OrtStatus*(* CreateSessionFromArrayWithPrepackedWeightsContainer)();
+ OrtStatus*(* SessionOptionsAppendExecutionProvider_TensorRT_V2)();
+ OrtStatus*(* CreateTensorRTProviderOptions)();
+ OrtStatus*(* UpdateTensorRTProviderOptions)();
+ OrtStatus*(* GetTensorRTProviderOptionsAsString)();
+ void(* ReleaseTensorRTProviderOptions)(OrtTensorRTProviderOptionsV2* input);
+ OrtStatus*(* EnableOrtCustomOps)();
+ OrtStatus*(* RegisterAllocator)();
+ OrtStatus*(* UnregisterAllocator)();
+ OrtStatus*(* IsSparseTensor)();
+ OrtStatus*(* CreateSparseTensorAsOrtValue)();
+ OrtStatus*(* FillSparseTensorCoo)();
+ OrtStatus*(* FillSparseTensorCsr)();
+ OrtStatus*(* FillSparseTensorBlockSparse)();
+ OrtStatus*(* CreateSparseTensorWithValuesAsOrtValue)();
+ OrtStatus*(* UseCooIndices)();
+ OrtStatus*(* UseCsrIndices)();
+ OrtStatus*(* UseBlockSparseIndices)();
+ OrtStatus*(* GetSparseTensorFormat)();
+ OrtStatus*(* GetSparseTensorValuesTypeAndShape)();
+ OrtStatus*(* GetSparseTensorValues)();
+ OrtStatus*(* GetSparseTensorIndicesTypeShape)();
+ OrtStatus*(* GetSparseTensorIndices)();
+ OrtStatus*(* HasValue)();
+ OrtStatus*(* KernelContext_GetGPUComputeStream)();
+ OrtStatus*(* GetTensorMemoryInfo)();
+ OrtStatus*(* GetExecutionProviderApi)();
+ OrtStatus*(* SessionOptionsSetCustomCreateThreadFn)();
+ OrtStatus*(* SessionOptionsSetCustomThreadCreationOptions)();
+ OrtStatus*(* SessionOptionsSetCustomJoinThreadFn)();
+ OrtStatus*(* SetGlobalCustomCreateThreadFn)();
+ OrtStatus*(* SetGlobalCustomThreadCreationOptions)();
+ OrtStatus*(* SetGlobalCustomJoinThreadFn)();
+ OrtStatus*(* SynchronizeBoundInputs)();
+ OrtStatus*(* SynchronizeBoundOutputs)();
+};
\ No newline at end of file
diff --git a/shared/linux-x86_64/include/openblas.h b/shared/linux-x86_64/include/openblas.h
new file mode 100644
index 0000000..8e902fb
--- /dev/null
+++ b/shared/linux-x86_64/include/openblas.h
@@ -0,0 +1,426 @@
+#define FFI_SCOPE "Rindow\\OpenBLAS\\FFI"
+//#define FFI_LIB "libopenblas.dll"
+
+/////////////////////////////////////////////
+typedef int8_t cl_char;
+typedef uint8_t cl_uchar;
+typedef int16_t cl_short;
+typedef uint16_t cl_ushort;
+typedef int32_t cl_int;
+typedef uint32_t cl_uint;
+typedef int64_t cl_long;
+typedef uint64_t cl_ulong;
+/////////////////////////////////////////////
+typedef uint16_t bfloat16;
+typedef int32_t blasint;
+typedef int32_t lapack_int;
+/////////////////////////////////////////////
+//#define xdouble double
+typedef double xdouble;
+//#define OPENBLAS_COMPLEX_STRUCT
+typedef struct _openblas_complex_float { float real, imag; } openblas_complex_float;
+typedef struct _openblas_complex_double { double real, imag; } openblas_complex_double;
+typedef struct _openblas_complex_xdouble { xdouble real, imag; } openblas_complex_xdouble;
+//#define openblas_make_complex_float(real, imag) {(real), (imag)}
+//#define openblas_make_complex_double(real, imag) {(real), (imag)}
+//#define openblas_make_complex_xdouble(real, imag) {(real), (imag)}
+//#define openblas_complex_float_real(z) ((z).real)
+//#define openblas_complex_float_imag(z) ((z).imag)
+//#define openblas_complex_double_real(z) ((z).real)
+//#define openblas_complex_double_imag(z) ((z).imag)
+//#define openblas_complex_xdouble_real(z) ((z).real)
+//#define openblas_complex_xdouble_imag(z) ((z).imag)
+/////////////////////////////////////////////
+
+
+
+/*Set the number of threads on runtime.*/
+void openblas_set_num_threads(int num_threads);
+void goto_set_num_threads(int num_threads);
+
+/*Get the number of threads on runtime.*/
+int openblas_get_num_threads(void);
+
+/*Get the number of physical processors (cores).*/
+int openblas_get_num_procs(void);
+
+/*Get the build configure on runtime.*/
+char* openblas_get_config(void);
+
+/*Get the CPU corename on runtime.*/
+char* openblas_get_corename(void);
+
+/* Get the parallelization type which is used by OpenBLAS */
+int openblas_get_parallel(void);
+/* OpenBLAS is compiled for sequential use */
+#define OPENBLAS_SEQUENTIAL 0
+/* OpenBLAS is compiled using normal threading model */
+#define OPENBLAS_THREAD 1
+/* OpenBLAS is compiled using OpenMP threading model */
+#define OPENBLAS_OPENMP 2
+
+
+//#ifndef OPENBLAS_CONST
+//# define OPENBLAS_CONST const
+//#endif
+
+
+//#define CBLAS_INDEX size_t
+typedef size_t CBLAS_INDEX;
+
+
+typedef enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102} CBLAS_ORDER;
+typedef enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113, CblasConjNoTrans=114} CBLAS_TRANSPOSE;
+typedef enum CBLAS_UPLO {CblasUpper=121, CblasLower=122} CBLAS_UPLO;
+typedef enum CBLAS_DIAG {CblasNonUnit=131, CblasUnit=132} CBLAS_DIAG;
+typedef enum CBLAS_SIDE {CblasLeft=141, CblasRight=142} CBLAS_SIDE;
+typedef CBLAS_ORDER CBLAS_LAYOUT;
+
+float cblas_sdsdot(const blasint n, const float alpha, const float *x, const blasint incx, const float *y, const blasint incy);
+double cblas_dsdot (const blasint n, const float *x, const blasint incx, const float *y, const blasint incy);
+float cblas_sdot(const blasint n, const float *x, const blasint incx, const float *y, const blasint incy);
+double cblas_ddot(const blasint n, const double *x, const blasint incx, const double *y, const blasint incy);
+
+openblas_complex_float cblas_cdotu(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+openblas_complex_float cblas_cdotc(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+openblas_complex_double cblas_zdotu(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+openblas_complex_double cblas_zdotc(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+
+void cblas_cdotu_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+void cblas_cdotc_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+void cblas_zdotu_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+void cblas_zdotc_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+
+float cblas_sasum (const blasint n, const float *x, const blasint incx);
+double cblas_dasum (const blasint n, const double *x, const blasint incx);
+float cblas_scasum(const blasint n, const void *x, const blasint incx);
+double cblas_dzasum(const blasint n, const void *x, const blasint incx);
+
+float cblas_ssum (const blasint n, const float *x, const blasint incx);
+double cblas_dsum (const blasint n, const double *x, const blasint incx);
+float cblas_scsum(const blasint n, const void *x, const blasint incx);
+double cblas_dzsum(const blasint n, const void *x, const blasint incx);
+
+float cblas_snrm2 (const blasint N, const float *X, const blasint incX);
+double cblas_dnrm2 (const blasint N, const double *X, const blasint incX);
+float cblas_scnrm2(const blasint N, const void *X, const blasint incX);
+double cblas_dznrm2(const blasint N, const void *X, const blasint incX);
+
+CBLAS_INDEX cblas_isamax(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idamax(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icamax(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izamax(const blasint n, const void *x, const blasint incx);
+
+CBLAS_INDEX cblas_isamin(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idamin(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icamin(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izamin(const blasint n, const void *x, const blasint incx);
+
+CBLAS_INDEX cblas_ismax(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idmax(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icmax(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izmax(const blasint n, const void *x, const blasint incx);
+
+CBLAS_INDEX cblas_ismin(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idmin(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icmin(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izmin(const blasint n, const void *x, const blasint incx);
+
+void cblas_saxpy(const blasint n, const float alpha, const float *x, const blasint incx, float *y, const blasint incy);
+void cblas_daxpy(const blasint n, const double alpha, const double *x, const blasint incx, double *y, const blasint incy);
+void cblas_caxpy(const blasint n, const void *alpha, const void *x, const blasint incx, void *y, const blasint incy);
+void cblas_zaxpy(const blasint n, const void *alpha, const void *x, const blasint incx, void *y, const blasint incy);
+
+void cblas_scopy(const blasint n, const float *x, const blasint incx, float *y, const blasint incy);
+void cblas_dcopy(const blasint n, const double *x, const blasint incx, double *y, const blasint incy);
+void cblas_ccopy(const blasint n, const void *x, const blasint incx, void *y, const blasint incy);
+void cblas_zcopy(const blasint n, const void *x, const blasint incx, void *y, const blasint incy);
+
+void cblas_sswap(const blasint n, float *x, const blasint incx, float *y, const blasint incy);
+void cblas_dswap(const blasint n, double *x, const blasint incx, double *y, const blasint incy);
+void cblas_cswap(const blasint n, void *x, const blasint incx, void *y, const blasint incy);
+void cblas_zswap(const blasint n, void *x, const blasint incx, void *y, const blasint incy);
+
+void cblas_srot(const blasint N, float *X, const blasint incX, float *Y, const blasint incY, const float c, const float s);
+void cblas_drot(const blasint N, double *X, const blasint incX, double *Y, const blasint incY, const double c, const double s);
+//void cblas_csrot(const blasint n, const void *x, const blasint incx, void *y, const blasint incY, const float c, const float s);
+//void cblas_zdrot(const blasint n, const void *x, const blasint incx, void *y, const blasint incY, const double c, const double s);
+
+void cblas_srotg(float *a, float *b, float *c, float *s);
+void cblas_drotg(double *a, double *b, double *c, double *s);
+//void cblas_crotg(void *a, void *b, float *c, void *s);
+//void cblas_zrotg(void *a, void *b, double *c, void *s);
+
+
+void cblas_srotm(const blasint N, float *X, const blasint incX, float *Y, const blasint incY, const float *P);
+void cblas_drotm(const blasint N, double *X, const blasint incX, double *Y, const blasint incY, const double *P);
+
+void cblas_srotmg(float *d1, float *d2, float *b1, const float b2, float *P);
+void cblas_drotmg(double *d1, double *d2, double *b1, const double b2, double *P);
+
+void cblas_sscal(const blasint N, const float alpha, float *X, const blasint incX);
+void cblas_dscal(const blasint N, const double alpha, double *X, const blasint incX);
+void cblas_cscal(const blasint N, const void *alpha, void *X, const blasint incX);
+void cblas_zscal(const blasint N, const void *alpha, void *X, const blasint incX);
+void cblas_csscal(const blasint N, const float alpha, void *X, const blasint incX);
+void cblas_zdscal(const blasint N, const double alpha, void *X, const blasint incX);
+
+void cblas_sgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const float alpha, const float *a, const blasint lda, const float *x, const blasint incx, const float beta, float *y, const blasint incy);
+void cblas_dgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const double alpha, const double *a, const blasint lda, const double *x, const blasint incx, const double beta, double *y, const blasint incy);
+void cblas_cgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const void *alpha, const void *a, const blasint lda, const void *x, const blasint incx, const void *beta, void *y, const blasint incy);
+void cblas_zgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const void *alpha, const void *a, const blasint lda, const void *x, const blasint incx, const void *beta, void *y, const blasint incy);
+
+void cblas_sger (const enum CBLAS_ORDER order, const blasint M, const blasint N, const float alpha, const float *X, const blasint incX, const float *Y, const blasint incY, float *A, const blasint lda);
+void cblas_dger (const enum CBLAS_ORDER order, const blasint M, const blasint N, const double alpha, const double *X, const blasint incX, const double *Y, const blasint incY, double *A, const blasint lda);
+void cblas_cgeru(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_cgerc(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_zgeru(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_zgerc(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+
+void cblas_strsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_strmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_ssyr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *X, const blasint incX, float *A, const blasint lda);
+void cblas_dsyr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X, const blasint incX, double *A, const blasint lda);
+void cblas_cher(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const void *X, const blasint incX, void *A, const blasint lda);
+void cblas_zher(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const void *X, const blasint incX, void *A, const blasint lda);
+
+void cblas_ssyr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,const blasint N, const float alpha, const float *X,
+ const blasint incX, const float *Y, const blasint incY, float *A, const blasint lda);
+void cblas_dsyr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X,
+ const blasint incX, const double *Y, const blasint incY, double *A, const blasint lda);
+void cblas_cher2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX,
+ const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_zher2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX,
+ const void *Y, const blasint incY, void *A, const blasint lda);
+
+void cblas_sgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const float alpha, const float *A, const blasint lda, const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const double alpha, const double *A, const blasint lda, const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+void cblas_cgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+void cblas_ssbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K, const float alpha, const float *A,
+ const blasint lda, const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dsbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K, const double alpha, const double *A,
+ const blasint lda, const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+
+
+void cblas_stbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_stbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_stpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const float *Ap, float *X, const blasint incX);
+void cblas_dtpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const double *Ap, double *X, const blasint incX);
+void cblas_ctpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+void cblas_ztpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+
+void cblas_stpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const float *Ap, float *X, const blasint incX);
+void cblas_dtpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const double *Ap, double *X, const blasint incX);
+void cblas_ctpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+void cblas_ztpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+
+void cblas_ssymv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *A,
+ const blasint lda, const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dsymv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *A,
+ const blasint lda, const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+void cblas_chemv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *A,
+ const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zhemv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *A,
+ const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+
+void cblas_sspmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *Ap,
+ const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dspmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *Ap,
+ const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+
+void cblas_sspr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *X, const blasint incX, float *Ap);
+void cblas_dspr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X, const blasint incX, double *Ap);
+
+void cblas_chpr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const void *X, const blasint incX, void *A);
+void cblas_zhpr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const void *X,const blasint incX, void *A);
+
+void cblas_sspr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *X, const blasint incX, const float *Y, const blasint incY, float *A);
+void cblas_dspr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X, const blasint incX, const double *Y, const blasint incY, double *A);
+void cblas_chpr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *Ap);
+void cblas_zhpr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *Ap);
+
+void cblas_chbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zhbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+void cblas_chpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N,
+ const void *alpha, const void *Ap, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zhpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N,
+ const void *alpha, const void *Ap, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+void cblas_sgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const float alpha, const float *A, const blasint lda, const float *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+void cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const double alpha, const double *A, const blasint lda, const double *B, const blasint ldb, const double beta, double *C, const blasint ldc);
+void cblas_cgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+//void cblas_cgemm3m(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+// const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+//void cblas_zgemm3m(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+// const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+
+void cblas_ssymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const float alpha, const float *A, const blasint lda, const float *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+void cblas_dsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const double alpha, const double *A, const blasint lda, const double *B, const blasint ldb, const double beta, double *C, const blasint ldc);
+void cblas_csymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+void cblas_ssyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const float alpha, const float *A, const blasint lda, const float beta, float *C, const blasint ldc);
+void cblas_dsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const double alpha, const double *A, const blasint lda, const double beta, double *C, const blasint ldc);
+void cblas_csyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *beta, void *C, const blasint ldc);
+void cblas_zsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *beta, void *C, const blasint ldc);
+
+void cblas_ssyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const float alpha, const float *A, const blasint lda, const float *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+void cblas_dsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const double alpha, const double *A, const blasint lda, const double *B, const blasint ldb, const double beta, double *C, const blasint ldc);
+void cblas_csyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+
+
+void cblas_strmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const float alpha, const float *A, const blasint lda, float *B, const blasint ldb);
+void cblas_dtrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const double alpha, const double *A, const blasint lda, double *B, const blasint ldb);
+void cblas_ctrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+void cblas_ztrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+
+void cblas_strsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const float alpha, const float *A, const blasint lda, float *B, const blasint ldb);
+void cblas_dtrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const double alpha, const double *A, const blasint lda, double *B, const blasint ldb);
+void cblas_ctrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+void cblas_ztrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+
+void cblas_chemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zhemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+void cblas_cherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const float alpha, const void *A, const blasint lda, const float beta, void *C, const blasint ldc);
+void cblas_zherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const double alpha, const void *A, const blasint lda, const double beta, void *C, const blasint ldc);
+
+void cblas_cher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const float beta, void *C, const blasint ldc);
+void cblas_zher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const double beta, void *C, const blasint ldc);
+
+void cblas_xerbla(blasint p, char *rout, char *form, ...);
+
+/*** BLAS extensions ***/
+
+void cblas_saxpby(const blasint n, const float alpha, const float *x, const blasint incx,const float beta, float *y, const blasint incy);
+
+void cblas_daxpby(const blasint n, const double alpha, const double *x, const blasint incx,const double beta, double *y, const blasint incy);
+
+void cblas_caxpby(const blasint n, const void *alpha, const void *x, const blasint incx,const void *beta, void *y, const blasint incy);
+
+void cblas_zaxpby(const blasint n, const void *alpha, const void *x, const blasint incx,const void *beta, void *y, const blasint incy);
+
+void cblas_somatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const float calpha, const float *a,
+ const blasint clda, float *b, const blasint cldb);
+void cblas_domatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const double calpha, const double *a,
+ const blasint clda, double *b, const blasint cldb);
+void cblas_comatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const void* calpha, const void* a,
+ const blasint clda, void *b, const blasint cldb);
+void cblas_zomatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const void* calpha, const void* a,
+ const blasint clda, void *b, const blasint cldb);
+
+void cblas_simatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const float calpha, float *a,
+ const blasint clda, const blasint cldb);
+void cblas_dimatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const double calpha, double *a,
+ const blasint clda, const blasint cldb);
+void cblas_cimatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const float* calpha, float* a,
+ const blasint clda, const blasint cldb);
+void cblas_zimatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const double* calpha, double* a,
+ const blasint clda, const blasint cldb);
+
+void cblas_sgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const float calpha, float *a, const blasint clda, const float cbeta,
+ float *c, const blasint cldc);
+void cblas_dgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const double calpha, double *a, const blasint clda, const double cbeta,
+ double *c, const blasint cldc);
+void cblas_cgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const float *calpha, float *a, const blasint clda, const float *cbeta,
+ float *c, const blasint cldc);
+void cblas_zgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const double *calpha, double *a, const blasint clda, const double *cbeta,
+ double *c, const blasint cldc);
+
+/*** BFLOAT16 and INT8 extensions ***/
+/* convert float array to BFLOAT16 array by rounding */
+//void cblas_sbstobf16(const blasint n, const float *in, const blasint incin, bfloat16 *out, const blasint incout);
+/* convert double array to BFLOAT16 array by rounding */
+//void cblas_sbdtobf16(const blasint n, const double *in, const blasint incin, bfloat16 *out, const blasint incout);
+/* convert BFLOAT16 array to float array */
+//void cblas_sbf16tos(const blasint n, const bfloat16 *in, const blasint incin, float *out, const blasint incout);
+/* convert BFLOAT16 array to double array */
+//void cblas_dbf16tod(const blasint n, const bfloat16 *in, const blasint incin, double *out, const blasint incout);
+/* dot production of BFLOAT16 input arrays, and output as float */
+//float cblas_sbdot(const blasint n, const bfloat16 *x, const blasint incx, const bfloat16 *y, const blasint incy);
+//void cblas_sbgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n, const float alpha, const bfloat16 *a, const blasint lda, const bfloat16 *x, const blasint incx, const float beta, float *y, const blasint incy);
+
+//void cblas_sbgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+// const float alpha, const bfloat16 *A, const blasint lda, const bfloat16 *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+
+
diff --git a/shared/linux-x86_64/include/samplerate.h b/shared/linux-x86_64/include/samplerate.h
new file mode 100644
index 0000000..436b7ff
--- /dev/null
+++ b/shared/linux-x86_64/include/samplerate.h
@@ -0,0 +1,163 @@
+#ifndef SAMPLERATE_H
+#define SAMPLERATE_H
+
+/* Opaque data type SRC_STATE. */
+typedef struct SRC_STATE_tag SRC_STATE;
+
+/* SRC_DATA is used to pass data to src_simple() and src_process(). */
+typedef struct
+{ const float *data_in ;
+ float *data_out ;
+
+ long input_frames, output_frames ;
+ long input_frames_used, output_frames_gen ;
+
+ int end_of_input ;
+
+ double src_ratio ;
+} SRC_DATA ;
+
+/*
+** User supplied callback function type for use with src_callback_new()
+** and src_callback_read(). First parameter is the same pointer that was
+** passed into src_callback_new(). Second parameter is pointer to a
+** pointer. The user supplied callback function must modify *data to
+** point to the start of the user supplied float array. The user supplied
+** function must return the number of frames that **data points to.
+*/
+
+typedef long (*src_callback_t) (void *cb_data, float **data) ;
+
+/*
+** Standard initialisation function : return an anonymous pointer to the
+** internal state of the converter. Choose a converter from the enums below.
+** Error returned in *error.
+*/
+
+SRC_STATE* src_new (int converter_type, int channels, int *error) ;
+
+/*
+** Clone a handle : return an anonymous pointer to a new converter
+** containing the same internal state as orig. Error returned in *error.
+*/
+SRC_STATE* src_clone (SRC_STATE* orig, int *error) ;
+
+/*
+** Initilisation for callback based API : return an anonymous pointer to the
+** internal state of the converter. Choose a converter from the enums below.
+** The cb_data pointer can point to any data or be set to NULL. Whatever the
+** value, when processing, user supplied function "func" gets called with
+** cb_data as first parameter.
+*/
+
+SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels,
+ int *error, void* cb_data) ;
+
+/*
+** Cleanup all internal allocations.
+** Always returns NULL.
+*/
+
+SRC_STATE* src_delete (SRC_STATE *state) ;
+
+/*
+** Standard processing function.
+** Returns non zero on error.
+*/
+
+int src_process (SRC_STATE *state, SRC_DATA *data) ;
+
+/*
+** Callback based processing function. Read up to frames worth of data from
+** the converter int *data and return frames read or -1 on error.
+*/
+long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ;
+
+/*
+** Simple interface for performing a single conversion from input buffer to
+** output buffer at a fixed conversion ratio.
+** Simple interface does not require initialisation as it can only operate on
+** a single buffer worth of audio.
+*/
+
+int src_simple (SRC_DATA *data, int converter_type, int channels) ;
+
+/*
+** This library contains a number of different sample rate converters,
+** numbered 0 through N.
+**
+** Return a string giving either a name or a more full description of each
+** sample rate converter or NULL if no sample rate converter exists for
+** the given value. The converters are sequentially numbered from 0 to N.
+*/
+
+const char *src_get_name (int converter_type) ;
+const char *src_get_description (int converter_type) ;
+const char *src_get_version (void) ;
+
+/*
+** Set a new SRC ratio. This allows step responses
+** in the conversion ratio.
+** Returns non zero on error.
+*/
+
+int src_set_ratio (SRC_STATE *state, double new_ratio) ;
+
+/*
+** Get the current channel count.
+** Returns negative on error, positive channel count otherwise
+*/
+
+int src_get_channels (SRC_STATE *state) ;
+
+/*
+** Reset the internal SRC state.
+** Does not modify the quality settings.
+** Does not free any memory allocations.
+** Returns non zero on error.
+*/
+
+int src_reset (SRC_STATE *state) ;
+
+/*
+** Return TRUE if ratio is a valid conversion ratio, FALSE
+** otherwise.
+*/
+
+int src_is_valid_ratio (double ratio) ;
+
+/*
+** Return an error number.
+*/
+
+int src_error (SRC_STATE *state) ;
+
+/*
+** Convert the error number into a string.
+*/
+const char* src_strerror (int error) ;
+
+/*
+** The following enums can be used to set the interpolator type
+** using the function src_set_converter().
+*/
+
+enum
+{
+ SRC_SINC_BEST_QUALITY = 0,
+ SRC_SINC_MEDIUM_QUALITY = 1,
+ SRC_SINC_FASTEST = 2,
+ SRC_ZERO_ORDER_HOLD = 3,
+ SRC_LINEAR = 4,
+} ;
+
+/*
+** Extra helper functions for converting from short to float and
+** back again.
+*/
+
+void src_short_to_float_array (const short *in, float *out, int len) ;
+void src_float_to_short_array (const float *in, short *out, int len) ;
+
+void src_int_to_float_array (const int *in, float *out, int len) ;
+void src_float_to_int_array (const float *in, int *out, int len) ;
\ No newline at end of file
diff --git a/shared/linux-x86_64/include/sndfile.h b/shared/linux-x86_64/include/sndfile.h
new file mode 100644
index 0000000..8c4df97
--- /dev/null
+++ b/shared/linux-x86_64/include/sndfile.h
@@ -0,0 +1,496 @@
+#ifndef SNDFILE_H
+#define SNDFILE_H
+
+#define SNDFILE_1
+
+/** File format types. */
+enum
+{ /* Major formats. */
+ SF_FORMAT_WAV = 0x010000, /* Microsoft WAV format (little endian default). */
+ SF_FORMAT_AIFF = 0x020000, /* Apple/SGI AIFF format (big endian). */
+ SF_FORMAT_AU = 0x030000, /* Sun/NeXT AU format (big endian). */
+ SF_FORMAT_RAW = 0x040000, /* RAW PCM data. */
+ SF_FORMAT_PAF = 0x050000, /* Ensoniq PARIS file format. */
+ SF_FORMAT_SVX = 0x060000, /* Amiga IFF / SVX8 / SV16 format. */
+ SF_FORMAT_NIST = 0x070000, /* Sphere NIST format. */
+ SF_FORMAT_VOC = 0x080000, /* VOC files. */
+ SF_FORMAT_IRCAM = 0x0A0000, /* Berkeley/IRCAM/CARL */
+ SF_FORMAT_W64 = 0x0B0000, /* Sonic Foundry's 64 bit RIFF/WAV */
+ SF_FORMAT_MAT4 = 0x0C0000, /* Matlab (tm) V4.2 / GNU Octave 2.0 */
+ SF_FORMAT_MAT5 = 0x0D0000, /* Matlab (tm) V5.0 / GNU Octave 2.1 */
+ SF_FORMAT_PVF = 0x0E0000, /* Portable Voice Format */
+ SF_FORMAT_XI = 0x0F0000, /* Fasttracker 2 Extended Instrument */
+ SF_FORMAT_HTK = 0x100000, /* HMM Tool Kit format */
+ SF_FORMAT_SDS = 0x110000, /* Midi Sample Dump Standard */
+ SF_FORMAT_AVR = 0x120000, /* Audio Visual Research */
+ SF_FORMAT_WAVEX = 0x130000, /* MS WAVE with WAVEFORMATEX */
+ SF_FORMAT_SD2 = 0x160000, /* Sound Designer 2 */
+ SF_FORMAT_FLAC = 0x170000, /* FLAC lossless file format */
+ SF_FORMAT_CAF = 0x180000, /* Core Audio File format */
+ SF_FORMAT_WVE = 0x190000, /* Psion WVE format */
+ SF_FORMAT_OGG = 0x200000, /* Xiph OGG container */
+ SF_FORMAT_MPC2K = 0x210000, /* Akai MPC 2000 sampler */
+ SF_FORMAT_RF64 = 0x220000, /* RF64 WAV file */
+ SF_FORMAT_MPEG = 0x230000, /* MPEG-1/2 audio stream */
+
+ /* Subtypes from here on. */
+
+ SF_FORMAT_PCM_S8 = 0x0001, /* Signed 8 bit data */
+ SF_FORMAT_PCM_16 = 0x0002, /* Signed 16 bit data */
+ SF_FORMAT_PCM_24 = 0x0003, /* Signed 24 bit data */
+ SF_FORMAT_PCM_32 = 0x0004, /* Signed 32 bit data */
+
+ SF_FORMAT_PCM_U8 = 0x0005, /* Unsigned 8 bit data (WAV and RAW only) */
+
+ SF_FORMAT_FLOAT = 0x0006, /* 32 bit float data */
+ SF_FORMAT_DOUBLE = 0x0007, /* 64 bit float data */
+
+ SF_FORMAT_ULAW = 0x0010, /* U-Law encoded. */
+ SF_FORMAT_ALAW = 0x0011, /* A-Law encoded. */
+ SF_FORMAT_IMA_ADPCM = 0x0012, /* IMA ADPCM. */
+ SF_FORMAT_MS_ADPCM = 0x0013, /* Microsoft ADPCM. */
+
+ SF_FORMAT_GSM610 = 0x0020, /* GSM 6.10 encoding. */
+ SF_FORMAT_VOX_ADPCM = 0x0021, /* OKI / Dialogix ADPCM */
+
+ SF_FORMAT_NMS_ADPCM_16 = 0x0022, /* 16kbs NMS G721-variant encoding. */
+ SF_FORMAT_NMS_ADPCM_24 = 0x0023, /* 24kbs NMS G721-variant encoding. */
+ SF_FORMAT_NMS_ADPCM_32 = 0x0024, /* 32kbs NMS G721-variant encoding. */
+
+ SF_FORMAT_G721_32 = 0x0030, /* 32kbs G721 ADPCM encoding. */
+ SF_FORMAT_G723_24 = 0x0031, /* 24kbs G723 ADPCM encoding. */
+ SF_FORMAT_G723_40 = 0x0032, /* 40kbs G723 ADPCM encoding. */
+
+ SF_FORMAT_DWVW_12 = 0x0040, /* 12 bit Delta Width Variable Word encoding. */
+ SF_FORMAT_DWVW_16 = 0x0041, /* 16 bit Delta Width Variable Word encoding. */
+ SF_FORMAT_DWVW_24 = 0x0042, /* 24 bit Delta Width Variable Word encoding. */
+ SF_FORMAT_DWVW_N = 0x0043, /* N bit Delta Width Variable Word encoding. */
+
+ SF_FORMAT_DPCM_8 = 0x0050, /* 8 bit differential PCM (XI only) */
+ SF_FORMAT_DPCM_16 = 0x0051, /* 16 bit differential PCM (XI only) */
+
+ SF_FORMAT_VORBIS = 0x0060, /* Xiph Vorbis encoding. */
+ SF_FORMAT_OPUS = 0x0064, /* Xiph/Skype Opus encoding. */
+
+ SF_FORMAT_ALAC_16 = 0x0070, /* Apple Lossless Audio Codec (16 bit). */
+ SF_FORMAT_ALAC_20 = 0x0071, /* Apple Lossless Audio Codec (20 bit). */
+ SF_FORMAT_ALAC_24 = 0x0072, /* Apple Lossless Audio Codec (24 bit). */
+ SF_FORMAT_ALAC_32 = 0x0073, /* Apple Lossless Audio Codec (32 bit). */
+
+ SF_FORMAT_MPEG_LAYER_I = 0x0080, /* MPEG-1 Audio Layer I */
+ SF_FORMAT_MPEG_LAYER_II = 0x0081, /* MPEG-1 Audio Layer II */
+ SF_FORMAT_MPEG_LAYER_III = 0x0082, /* MPEG-2 Audio Layer III */
+
+ /* Endian-ness options. */
+
+ SF_ENDIAN_FILE = 0x00000000, /* Default file endian-ness. */
+ SF_ENDIAN_LITTLE = 0x10000000, /* Force little endian-ness. */
+ SF_ENDIAN_BIG = 0x20000000, /* Force big endian-ness. */
+ SF_ENDIAN_CPU = 0x30000000, /* Force CPU endian-ness. */
+
+ SF_FORMAT_SUBMASK = 0x0000FFFF,
+ SF_FORMAT_TYPEMASK = 0x0FFF0000,
+ SF_FORMAT_ENDMASK = 0x30000000
+};
+
+/** valid command numbers for the sf_command() interface */
+enum
+{ SFC_GET_LIB_VERSION = 0x1000,
+ SFC_GET_LOG_INFO = 0x1001,
+ SFC_GET_CURRENT_SF_INFO = 0x1002,
+
+
+ SFC_GET_NORM_DOUBLE = 0x1010,
+ SFC_GET_NORM_FLOAT = 0x1011,
+ SFC_SET_NORM_DOUBLE = 0x1012,
+ SFC_SET_NORM_FLOAT = 0x1013,
+ SFC_SET_SCALE_FLOAT_INT_READ = 0x1014,
+ SFC_SET_SCALE_INT_FLOAT_WRITE = 0x1015,
+
+ SFC_GET_SIMPLE_FORMAT_COUNT = 0x1020,
+ SFC_GET_SIMPLE_FORMAT = 0x1021,
+
+ SFC_GET_FORMAT_INFO = 0x1028,
+
+ SFC_GET_FORMAT_MAJOR_COUNT = 0x1030,
+ SFC_GET_FORMAT_MAJOR = 0x1031,
+ SFC_GET_FORMAT_SUBTYPE_COUNT = 0x1032,
+ SFC_GET_FORMAT_SUBTYPE = 0x1033,
+
+ SFC_CALC_SIGNAL_MAX = 0x1040,
+ SFC_CALC_NORM_SIGNAL_MAX = 0x1041,
+ SFC_CALC_MAX_ALL_CHANNELS = 0x1042,
+ SFC_CALC_NORM_MAX_ALL_CHANNELS = 0x1043,
+ SFC_GET_SIGNAL_MAX = 0x1044,
+ SFC_GET_MAX_ALL_CHANNELS = 0x1045,
+
+ SFC_SET_ADD_PEAK_CHUNK = 0x1050,
+
+ SFC_UPDATE_HEADER_NOW = 0x1060,
+ SFC_SET_UPDATE_HEADER_AUTO = 0x1061,
+
+ SFC_FILE_TRUNCATE = 0x1080,
+
+ SFC_SET_RAW_START_OFFSET = 0x1090,
+
+ /* Commands reserved for dithering, which is not implemented. */
+ SFC_SET_DITHER_ON_WRITE = 0x10A0,
+ SFC_SET_DITHER_ON_READ = 0x10A1,
+
+ SFC_GET_DITHER_INFO_COUNT = 0x10A2,
+ SFC_GET_DITHER_INFO = 0x10A3,
+
+ SFC_GET_EMBED_FILE_INFO = 0x10B0,
+
+ SFC_SET_CLIPPING = 0x10C0,
+ SFC_GET_CLIPPING = 0x10C1,
+
+ SFC_GET_CUE_COUNT = 0x10CD,
+ SFC_GET_CUE = 0x10CE,
+ SFC_SET_CUE = 0x10CF,
+
+ SFC_GET_INSTRUMENT = 0x10D0,
+ SFC_SET_INSTRUMENT = 0x10D1,
+
+ SFC_GET_LOOP_INFO = 0x10E0,
+
+ SFC_GET_BROADCAST_INFO = 0x10F0,
+ SFC_SET_BROADCAST_INFO = 0x10F1,
+
+ SFC_GET_CHANNEL_MAP_INFO = 0x1100,
+ SFC_SET_CHANNEL_MAP_INFO = 0x1101,
+
+ SFC_RAW_DATA_NEEDS_ENDSWAP = 0x1110,
+
+ /* Support for Wavex Ambisonics Format */
+ SFC_WAVEX_SET_AMBISONIC = 0x1200,
+ SFC_WAVEX_GET_AMBISONIC = 0x1201,
+
+ /*
+ ** RF64 files can be set so that on-close, writable files that have less
+ ** than 4GB of data in them are converted to RIFF/WAV, as per EBU
+ ** recommendations.
+ */
+ SFC_RF64_AUTO_DOWNGRADE = 0x1210,
+
+ SFC_SET_VBR_ENCODING_QUALITY = 0x1300,
+ SFC_SET_COMPRESSION_LEVEL = 0x1301,
+
+ /* Ogg format commands */
+ SFC_SET_OGG_PAGE_LATENCY_MS = 0x1302,
+ SFC_SET_OGG_PAGE_LATENCY = 0x1303,
+ SFC_GET_OGG_STREAM_SERIALNO = 0x1306,
+
+ SFC_GET_BITRATE_MODE = 0x1304,
+ SFC_SET_BITRATE_MODE = 0x1305,
+
+ /* Cart Chunk support */
+ SFC_SET_CART_INFO = 0x1400,
+ SFC_GET_CART_INFO = 0x1401,
+
+ /* Opus files original samplerate metadata */
+ SFC_SET_ORIGINAL_SAMPLERATE = 0x1500,
+ SFC_GET_ORIGINAL_SAMPLERATE = 0x1501,
+
+ /* Following commands for testing only. */
+ SFC_TEST_IEEE_FLOAT_REPLACE = 0x6001,
+
+ /*
+ ** These SFC_SET_ADD_* values are deprecated and will disappear at some
+ ** time in the future. They are guaranteed to be here up to and
+ ** including version 1.0.8 to avoid breakage of existing software.
+ ** They currently do nothing and will continue to do nothing.
+ */
+ SFC_SET_ADD_HEADER_PAD_CHUNK = 0x1051,
+
+ SFC_SET_ADD_DITHER_ON_WRITE = 0x1070,
+ SFC_SET_ADD_DITHER_ON_READ = 0x1071
+};
+
+/** String types that can be set and read from files. */
+enum
+{ SF_STR_TITLE = 0x01,
+ SF_STR_COPYRIGHT = 0x02,
+ SF_STR_SOFTWARE = 0x03,
+ SF_STR_ARTIST = 0x04,
+ SF_STR_COMMENT = 0x05,
+ SF_STR_DATE = 0x06,
+ SF_STR_ALBUM = 0x07,
+ SF_STR_LICENSE = 0x08,
+ SF_STR_TRACKNUMBER = 0x09,
+ SF_STR_GENRE = 0x10
+} ;
+
+/** Start and End index when doing metadata transcoding. */
+#define SF_STR_FIRST SF_STR_TITLE
+#define SF_STR_LAST SF_STR_GENRE
+
+enum
+{ /* True and false */
+ SF_FALSE = 0,
+ SF_TRUE = 1,
+
+ /* Modes for opening files. */
+ SFM_READ = 0x10,
+ SFM_WRITE = 0x20,
+ SFM_RDWR = 0x30,
+
+ SF_AMBISONIC_NONE = 0x40,
+ SF_AMBISONIC_B_FORMAT = 0x41
+};
+
+/** Error codes. */
+enum
+{ SF_ERR_NO_ERROR = 0,
+ SF_ERR_UNRECOGNISED_FORMAT = 1,
+ SF_ERR_SYSTEM = 2,
+ SF_ERR_MALFORMED_FILE = 3,
+ SF_ERR_UNSUPPORTED_ENCODING = 4
+};
+
+/** Channel map values (used with SFC_SET/GET_CHANNEL_MAP). */
+enum
+{ SF_CHANNEL_MAP_INVALID = 0,
+ SF_CHANNEL_MAP_MONO = 1,
+ SF_CHANNEL_MAP_LEFT, /* Apple calls this 'Left' */
+ SF_CHANNEL_MAP_RIGHT, /* Apple calls this 'Right' */
+ SF_CHANNEL_MAP_CENTER, /* Apple calls this 'Center' */
+ SF_CHANNEL_MAP_FRONT_LEFT,
+ SF_CHANNEL_MAP_FRONT_RIGHT,
+ SF_CHANNEL_MAP_FRONT_CENTER,
+ SF_CHANNEL_MAP_REAR_CENTER, /* Apple calls this 'Center Surround', Msft calls this 'Back Center' */
+ SF_CHANNEL_MAP_REAR_LEFT, /* Apple calls this 'Left Surround', Msft calls this 'Back Left' */
+ SF_CHANNEL_MAP_REAR_RIGHT, /* Apple calls this 'Right Surround', Msft calls this 'Back Right' */
+ SF_CHANNEL_MAP_LFE, /* Apple calls this 'LFEScreen', Msft calls this 'Low Frequency' */
+ SF_CHANNEL_MAP_FRONT_LEFT_OF_CENTER, /* Apple calls this 'Left Center' */
+ SF_CHANNEL_MAP_FRONT_RIGHT_OF_CENTER, /* Apple calls this 'Right Center */
+ SF_CHANNEL_MAP_SIDE_LEFT, /* Apple calls this 'Left Surround Direct' */
+ SF_CHANNEL_MAP_SIDE_RIGHT, /* Apple calls this 'Right Surround Direct' */
+ SF_CHANNEL_MAP_TOP_CENTER, /* Apple calls this 'Top Center Surround' */
+ SF_CHANNEL_MAP_TOP_FRONT_LEFT, /* Apple calls this 'Vertical Height Left' */
+ SF_CHANNEL_MAP_TOP_FRONT_RIGHT, /* Apple calls this 'Vertical Height Right' */
+ SF_CHANNEL_MAP_TOP_FRONT_CENTER, /* Apple calls this 'Vertical Height Center' */
+ SF_CHANNEL_MAP_TOP_REAR_LEFT, /* Apple and MS call this 'Top Back Left' */
+ SF_CHANNEL_MAP_TOP_REAR_RIGHT, /* Apple and MS call this 'Top Back Right' */
+ SF_CHANNEL_MAP_TOP_REAR_CENTER, /* Apple and MS call this 'Top Back Center' */
+
+ SF_CHANNEL_MAP_AMBISONIC_B_W,
+ SF_CHANNEL_MAP_AMBISONIC_B_X,
+ SF_CHANNEL_MAP_AMBISONIC_B_Y,
+ SF_CHANNEL_MAP_AMBISONIC_B_Z,
+
+ SF_CHANNEL_MAP_MAX
+};
+
+/** Bitrate mode values (for use with SFC_GET/SET_BITRATE_MODE) */
+enum
+{ SF_BITRATE_MODE_CONSTANT = 0,
+ SF_BITRATE_MODE_AVERAGE,
+ SF_BITRATE_MODE_VARIABLE
+};
+
+/* A SNDFILE* pointer can be passed around much like stdio.h's FILE* pointer. */
+typedef struct sf_private_tag SNDFILE ;
+
+/* The following typedef is system specific and is defined when libsndfile is
+** compiled. sf_count_t will be a 64 bit value when the underlying OS allows
+** 64 bit file offsets.
+** On windows, we need to allow the same header file to be compiler by both GCC
+** and the Microsoft compiler.
+*/
+
+typedef int64_t sf_count_t ;
+#ifndef SF_COUNT_MAX
+#define SF_COUNT_MAX INT64_MAX
+#endif
+
+/* A pointer to a SF_INFO structure is passed to sf_open () and filled in.
+** On write, the SF_INFO structure is filled in by the user and passed into
+** sf_open ().
+*/
+struct SF_INFO
+{ sf_count_t frames ; /* Used to be called samples. Changed to avoid confusion. */
+ int samplerate ;
+ int channels ;
+ int format ;
+ int sections ;
+ int seekable ;
+} ;
+
+typedef struct SF_INFO SF_INFO ;
+
+/* The SF_FORMAT_INFO struct is used to retrieve information about the sound
+** file formats libsndfile supports using the sf_command () interface.
+*/
+typedef struct
+{ int format ;
+ const char *name ;
+ const char *extension ;
+} SF_FORMAT_INFO;
+
+/* Open the specified file for read, write or both. On error, this will
+** return a NULL pointer. To find the error number, pass a NULL SNDFILE
+** to sf_strerror ().
+** All calls to sf_open() should be matched with a call to sf_close().
+*/
+SNDFILE* sf_open (const char *path, int mode, SF_INFO *sfinfo) ;
+
+/* Use the existing file descriptor to create a SNDFILE object. If close_desc
+** is TRUE, the file descriptor will be closed when sf_close() is called. If
+** it is FALSE, the descriptor will not be closed.
+** When passed a descriptor like this, the library will assume that the start
+** of file header is at the current file offset. This allows sound files within
+** larger container files to be read and/or written.
+** On error, this will return a NULL pointer. To find the error number, pass a
+** NULL SNDFILE to sf_strerror ().
+** All calls to sf_open_fd() should be matched with a call to sf_close().
+*/
+
+SNDFILE* sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc) ;
+
+
+/* sf_error () returns a error number which can be translated to a text
+** string using sf_error_number().
+*/
+
+int sf_error (SNDFILE *sndfile) ;
+
+
+/* sf_strerror () returns to the caller a pointer to the current error message for
+** the given SNDFILE.
+*/
+
+const char* sf_strerror (SNDFILE *sndfile) ;
+
+
+/* sf_error_number () allows the retrieval of the error string for each internal
+** error number.
+**
+*/
+
+const char* sf_error_number (int errnum) ;
+
+
+/* The following two error functions are deprecated but they will remain in the
+** library for the foreseeable future. The function sf_strerror() should be used
+** in their place.
+*/
+
+int sf_perror (SNDFILE *sndfile) ;
+int sf_error_str (SNDFILE *sndfile, char* str, size_t len) ;
+
+
+/* Allow the caller to retrieve information from or change aspects of the
+** library behaviour.
+*/
+
+int sf_command (SNDFILE *sndfile, int command, void *data, int datasize) ;
+
+
+/* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */
+
+int sf_format_check (const SF_INFO *info) ;
+
+
+
+/* Functions for retrieving and setting string data within sound files.
+** Not all file types support this features; AIFF and WAV do. For both
+** functions, the str_type parameter must be one of the SF_STR_* values
+** defined above.
+** On error, sf_set_string() returns non-zero while sf_get_string()
+** returns NULL.
+*/
+
+int sf_set_string (SNDFILE *sndfile, int str_type, const char* str) ;
+
+const char* sf_get_string (SNDFILE *sndfile, int str_type) ;
+
+/* Return the library version string. */
+const char * sf_version_string (void) ;
+
+/* Return the current byterate at this point in the file. The byte rate in this
+** case is the number of bytes per second of audio data. For instance, for a
+** stereo, 18 bit PCM encoded file with an 16kHz sample rate, the byte rate
+** would be 2 (stereo) * 2 (two bytes per sample) * 16000 => 64000 bytes/sec.
+** For some file formats the returned value will be accurate and exact, for some
+** it will be a close approximation, for some it will be the average bitrate for
+** the whole file and for some it will be a time varying value that was accurate
+** when the file was most recently read or written.
+** To get the bitrate, multiple this value by 8.
+** Returns -1 for unknown.
+*/
+int sf_current_byterate (SNDFILE *sndfile) ;
+
+/* Functions for reading/writing the waveform data of a sound file.
+*/
+
+sf_count_t sf_read_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
+sf_count_t sf_write_raw (SNDFILE *sndfile, const void *ptr, sf_count_t bytes) ;
+
+/* Functions for reading and writing the data chunk in terms of frames.
+** The number of items actually read/written = frames * number of channels.
+** sf_xxxx_raw read/writes the raw data bytes from/to the file
+** sf_xxxx_short passes data in the native short format
+** sf_xxxx_int passes data in the native int format
+** sf_xxxx_float passes data in the native float format
+** sf_xxxx_double passes data in the native double format
+** All of these read/write function return number of frames read/written.
+*/
+
+sf_count_t sf_readf_short (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_short (SNDFILE *sndfile, const short *ptr, sf_count_t frames) ;
+
+sf_count_t sf_readf_int (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_int (SNDFILE *sndfile, const int *ptr, sf_count_t frames) ;
+
+sf_count_t sf_readf_float (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_float (SNDFILE *sndfile, const float *ptr, sf_count_t frames) ;
+
+sf_count_t sf_readf_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_double (SNDFILE *sndfile, const double *ptr, sf_count_t frames) ;
+
+
+/* Functions for reading and writing the data chunk in terms of items.
+** Otherwise similar to above.
+** All of these read/write function return number of items read/written.
+*/
+
+sf_count_t sf_read_short (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
+sf_count_t sf_write_short (SNDFILE *sndfile, const short *ptr, sf_count_t items) ;
+
+sf_count_t sf_read_int (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
+sf_count_t sf_write_int (SNDFILE *sndfile, const int *ptr, sf_count_t items) ;
+
+sf_count_t sf_read_float (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
+sf_count_t sf_write_float (SNDFILE *sndfile, const float *ptr, sf_count_t items) ;
+
+sf_count_t sf_read_double (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
+sf_count_t sf_write_double (SNDFILE *sndfile, const double *ptr, sf_count_t items) ;
+
+
+/* Close the SNDFILE and clean up all memory allocations associated with this
+** file.
+** Returns 0 on success, or an error number.
+*/
+
+int sf_close (SNDFILE *sndfile) ;
+
+
+/* If the file is opened SFM_WRITE or SFM_RDWR, call fsync() on the file
+** to force the writing of data to disk. If the file is opened SFM_READ
+** no action is taken.
+*/
+
+void sf_write_sync (SNDFILE *sndfile) ;
+
+
+
+/* The function sf_wchar_open() is Windows Only!
+** Open a file passing in a Windows Unicode filename. Otherwise, this is
+** the same as sf_open().
+*/
+
+/* #ifdef _WIN32
+** SNDFILE* sf_wchar_open (const wchar_t *wpath, int mode, SF_INFO *sfinfo) ;
+** #endif
+*/
\ No newline at end of file
diff --git a/shared/linux-x86_64/include/transformersphp.h b/shared/linux-x86_64/include/transformersphp.h
new file mode 100644
index 0000000..7c9c4b8
--- /dev/null
+++ b/shared/linux-x86_64/include/transformersphp.h
@@ -0,0 +1,19 @@
+#ifndef FAST_TRANSFORMERS_UTILS_H
+#define FAST_TRANSFORMERS_UTILS_H
+
+enum {
+ LOG_MEL_NONE = 0,
+ LOG_MEL_LOG = 1,
+ LOG_MEL_LOG10 = 2,
+ LOG_MEL_DB = 3
+};
+
+void pad_reflect(float *input, int length, float *padded, int padded_length);
+
+void spectrogram(
+ float *waveform, int waveform_length, float *spectrogram, int spectrogram_length, int hop_length, int fft_length,
+ float *window,int window_length, int d1, int d1_max, float power, int center, float preemphasis, float *mel_filters,
+ int num_mel_filters, int num_frequency_bins, float mel_floor, int log_mel, int remove_dc_offset, int do_pad, int transpose
+);
+
+#endif // FAST_TRANSFORMERS_UTILS_H
diff --git a/shared/linux-x86_64/lib/libgomp.so b/shared/linux-x86_64/lib/libgomp.so
new file mode 100644
index 0000000..cabef57
Binary files /dev/null and b/shared/linux-x86_64/lib/libgomp.so differ
diff --git a/shared/linux-x86_64/lib/libonnxruntime.so.1.21.0 b/shared/linux-x86_64/lib/libonnxruntime.so.1.21.0
new file mode 100755
index 0000000..a643bd6
Binary files /dev/null and b/shared/linux-x86_64/lib/libonnxruntime.so.1.21.0 differ
diff --git a/shared/linux-x86_64/lib/libopenblas.so.0.3.28 b/shared/linux-x86_64/lib/libopenblas.so.0.3.28
new file mode 100755
index 0000000..af6a45d
Binary files /dev/null and b/shared/linux-x86_64/lib/libopenblas.so.0.3.28 differ
diff --git a/shared/linux-x86_64/lib/librindowmatlib.so.1.1.1 b/shared/linux-x86_64/lib/librindowmatlib.so.1.1.1
new file mode 100644
index 0000000..9cbe13a
Binary files /dev/null and b/shared/linux-x86_64/lib/librindowmatlib.so.1.1.1 differ
diff --git a/shared/linux-x86_64/lib/libsamplerate.so.0.2.2 b/shared/linux-x86_64/lib/libsamplerate.so.0.2.2
new file mode 100644
index 0000000..4ceb149
Binary files /dev/null and b/shared/linux-x86_64/lib/libsamplerate.so.0.2.2 differ
diff --git a/shared/linux-x86_64/lib/libsndfile.so.1.2.2 b/shared/linux-x86_64/lib/libsndfile.so.1.2.2
new file mode 100644
index 0000000..01b3afa
Binary files /dev/null and b/shared/linux-x86_64/lib/libsndfile.so.1.2.2 differ
diff --git a/shared/linux-x86_64/lib/libtransformersphp.so.1.0.0 b/shared/linux-x86_64/lib/libtransformersphp.so.1.0.0
new file mode 100644
index 0000000..824307d
Binary files /dev/null and b/shared/linux-x86_64/lib/libtransformersphp.so.1.0.0 differ
diff --git a/shared/linux-x86_64/lib/libvips.so.42 b/shared/linux-x86_64/lib/libvips.so.42
new file mode 100644
index 0000000..23abdc8
Binary files /dev/null and b/shared/linux-x86_64/lib/libvips.so.42 differ
diff --git a/shared/macosx-arm64/THIRD_PARTY_NOTICES.md b/shared/macosx-arm64/THIRD_PARTY_NOTICES.md
new file mode 100644
index 0000000..0cf3657
--- /dev/null
+++ b/shared/macosx-arm64/THIRD_PARTY_NOTICES.md
@@ -0,0 +1,52 @@
+# Third-party notices
+
+TransformersPHP includes compiled binaries of third-party libraries as a convenience to users. These binaries are
+distributed to facilitate the functionality of TransformersPHP, but TransformersPHP does not claim ownership of the
+binaries or the underlying libraries. The original authors and contributors of these libraries retain all rights. It is
+the user's responsibility to ensure compliance with the respective licenses of these libraries when using or
+distributing the bundled binaries.
+
+Below is a list of the third-party libraries included with TransformersPHP, along with their respective licenses and
+other relevant information.
+
+| Library | Used under the terms of |
+|---------------|-----------------------------------------------------------------------------------------------------------|
+| OpenMP | MIT License |
+| OnnxRuntime | MIT License |
+| OpenBlas | BSD 3-Clause License |
+| Rindow Matlib | BSD 3-Clause License |
+| LibSamplerate | BSD 2-Clause License |
+| Libsndfile | LGPL 2.1 License |
+| aom | BSD 2-Clause + [Alliance for Open Media Patent License 1.0](https://aomedia.org/license/patent-license/) |
+| cairo | Mozilla Public License 2.0 |
+| cgif | MIT Licence |
+| expat | MIT Licence |
+| fontconfig | [fontconfig Licence](https://gitlab.freedesktop.org/fontconfig/fontconfig/blob/main/COPYING) (BSD-like) |
+| freetype | [freetype Licence](https://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/docs/FTL.TXT) (BSD-like) |
+| fribidi | LGPLv3 |
+| glib | LGPLv3 |
+| harfbuzz | MIT Licence |
+| highway | Apache-2.0 License, BSD 3-Clause |
+| lcms | MIT Licence |
+| libarchive | BSD 2-Clause |
+| libexif | LGPLv3 |
+| libffi | MIT Licence |
+| libheif | LGPLv3 |
+| libimagequant | [BSD 2-Clause](https://github.com/lovell/libimagequant/blob/main/COPYRIGHT) |
+| libnsgif | MIT Licence |
+| libpng | [libpng License](https://github.com/pnggroup/libpng/blob/master/LICENSE) |
+| librsvg | LGPLv3 |
+| libspng | [BSD 2-Clause, libpng License](https://github.com/randy408/libspng/blob/master/LICENSE) |
+| libtiff | [libtiff License](https://gitlab.com/libtiff/libtiff/blob/master/LICENSE.md) (BSD-like) |
+| libvips | LGPLv3 |
+| libwebp | New BSD License |
+| libxml2 | MIT Licence |
+| mozjpeg | [zlib License, IJG License, BSD-3-Clause](https://github.com/mozilla/mozjpeg/blob/master/LICENSE.md) |
+| pango | LGPLv3 |
+| pixman | MIT Licence |
+| proxy-libintl | LGPLv3 |
+| zlib-ng | [zlib Licence](https://github.com/zlib-ng/zlib-ng/blob/develop/LICENSE.md) |
+
+---
+
+
diff --git a/shared/macosx-arm64/include/buffer.h b/shared/macosx-arm64/include/buffer.h
new file mode 100644
index 0000000..e086179
--- /dev/null
+++ b/shared/macosx-arm64/include/buffer.h
@@ -0,0 +1,5 @@
+#define FFI_SCOPE "Rindow\\Math\\Buffer\\FFI"
+
+typedef struct _rindow_complex_float { float real, imag; } rindow_complex_float;
+typedef struct _rindow_complex_double { double real, imag; } rindow_complex_double;
+//typedef struct { xdouble real, imag; } openblas_complex_xdouble;
diff --git a/shared/macosx-arm64/include/matlib.h b/shared/macosx-arm64/include/matlib.h
new file mode 100644
index 0000000..612189c
--- /dev/null
+++ b/shared/macosx-arm64/include/matlib.h
@@ -0,0 +1,397 @@
+#ifndef RINDOW_MATLIB_H_
+#define RINDOW_MATLIB_H_
+
+#include
+
+enum rindow_matlib_dtype
+{
+ rindow_matlib_dtype_unknown = 0,
+ rindow_matlib_dtype_bool = 1,
+ rindow_matlib_dtype_int8 = 2,
+ rindow_matlib_dtype_int16 = 3,
+ rindow_matlib_dtype_int32 = 4,
+ rindow_matlib_dtype_int64 = 5,
+ rindow_matlib_dtype_uint8 = 6,
+ rindow_matlib_dtype_uint16 = 7,
+ rindow_matlib_dtype_uint32 = 8,
+ rindow_matlib_dtype_uint64 = 9,
+ rindow_matlib_dtype_float8 = 10,
+ rindow_matlib_dtype_float16 = 11,
+ rindow_matlib_dtype_float32 = 12,
+ rindow_matlib_dtype_float64 = 13,
+ rindow_matlib_dtype_complex16 = 14,
+ rindow_matlib_dtype_complex32 = 15,
+ rindow_matlib_dtype_complex64 = 16,
+ rindow_matlib_dtype_complex128 = 17
+};
+
+#if _MSC_VER
+#if !defined(RINDOW_FUNC)
+#if defined(RINDOW_COMPILING_DLL)
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL extern __declspec(dllexport)
+#elif defined(RINDOW_MATLIB_INCLUDING_SOURCE)
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL
+#else
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL extern __declspec(dllimport)
+#endif
+#endif
+#else // _MSC_VER
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL extern
+#endif // _MSC_VER
+
+#define RINDOW_MATLIB_SUCCESS 0
+#define RINDOW_MATLIB_E_MEM_ALLOC_FAILURE -101
+#define RINDOW_MATLIB_E_PERM_OUT_OF_RANGE -102
+#define RINDOW_MATLIB_E_DUP_AXIS -103
+#define RINDOW_MATLIB_E_UNSUPPORTED_DATA_TYPE -104
+#define RINDOW_MATLIB_E_UNMATCH_IMAGE_BUFFER_SIZE -105
+#define RINDOW_MATLIB_E_UNMATCH_COLS_BUFFER_SIZE -106
+#define RINDOW_MATLIB_E_INVALID_SHAPE_OR_PARAM -107
+#define RINDOW_MATLIB_E_IMAGES_OUT_OF_RANGE -108
+#define RINDOW_MATLIB_E_COLS_OUT_OF_RANGE -109
+
+#define RINDOW_MATLIB_NO_TRANS 111
+#define RINDOW_MATLIB_TRANS 112
+// #define RINDOW_MATLIB_CONJ_TRANS 113
+// #define RINDOW_MATLIB_CONJ_NO_TRANS 114
+
+// Matlib is compiled for sequential use
+#define RINDOW_MATLIB_SEQUENTIAL 0
+// Matlib is compiled using normal threading model
+#define RINDOW_MATLIB_THREAD 1
+// Matlib is compiled using OpenMP threading model
+#define RINDOW_MATLIB_OPENMP 2
+
+static inline int32_t rindow_matlib_common_dtype_to_valuesize(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_bool:
+ case rindow_matlib_dtype_int8:
+ case rindow_matlib_dtype_uint8:
+ case rindow_matlib_dtype_float8:
+ return 1;
+ case rindow_matlib_dtype_int16:
+ case rindow_matlib_dtype_uint16:
+ case rindow_matlib_dtype_float16:
+ case rindow_matlib_dtype_complex16:
+ return 2;
+ case rindow_matlib_dtype_int32:
+ case rindow_matlib_dtype_uint32:
+ case rindow_matlib_dtype_float32:
+ case rindow_matlib_dtype_complex32:
+ return 4;
+ case rindow_matlib_dtype_int64:
+ case rindow_matlib_dtype_uint64:
+ case rindow_matlib_dtype_float64:
+ case rindow_matlib_dtype_complex64:
+ return 8;
+ case rindow_matlib_dtype_complex128:
+ return 16;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_int(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_int8:
+ case rindow_matlib_dtype_uint8:
+ case rindow_matlib_dtype_int16:
+ case rindow_matlib_dtype_uint16:
+ case rindow_matlib_dtype_int32:
+ case rindow_matlib_dtype_uint32:
+ case rindow_matlib_dtype_int64:
+ case rindow_matlib_dtype_uint64:
+ return 1;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_float(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_float8:
+ case rindow_matlib_dtype_float16:
+ case rindow_matlib_dtype_float32:
+ case rindow_matlib_dtype_float64:
+ return 1;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_complex(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_complex16:
+ case rindow_matlib_dtype_complex32:
+ case rindow_matlib_dtype_complex64:
+ case rindow_matlib_dtype_complex128:
+ return 1;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_bool(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_bool:
+ return 1;
+ }
+ return 0;
+}
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_common_get_nprocs(void);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_common_get_num_threads(void);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_common_get_parallel(void);
+ RINDOW_FUNC_DECL char *rindow_matlib_common_get_version(void);
+
+ RINDOW_FUNC_DECL void *rindow_matlib_common_get_address(int32_t dtype, void *buffer, int32_t offset);
+
+ RINDOW_FUNC_DECL float rindow_matlib_s_sum(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL double rindow_matlib_d_sum(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL int64_t rindow_matlib_i_sum(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_imax(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_imax(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_imax(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_imin(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_imin(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_imin(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_increment(int32_t n, float *x, int32_t incX, float alpha, float beta);
+ RINDOW_FUNC_DECL void rindow_matlib_d_increment(int32_t n, double *x, int32_t incX, double alpha, double beta);
+ RINDOW_FUNC_DECL void rindow_matlib_s_reciprocal(int32_t n, float *x, int32_t incX, float alpha, float beta);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reciprocal(int32_t n, double *x, int32_t incX, double alpha, double beta);
+ RINDOW_FUNC_DECL void rindow_matlib_s_maximum(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_maximum(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_minimum(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_minimum(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_greater(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_greater(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_greater_equal(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_greater_equal(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_less(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_less(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_less_equal(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_less_equal(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_multiply(int32_t trans, int32_t m, int32_t n, float *x, int32_t incX, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_multiply(int32_t trans, int32_t m, int32_t n, double *x, int32_t incX, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_add(int32_t trans, int32_t m, int32_t n, float alpha, float *x, int32_t incX, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_add(int32_t trans, int32_t m, int32_t n, double alpha, double *x, int32_t incX, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_duplicate(int32_t trans, int32_t m, int32_t n, float *x, int32_t incX, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_duplicate(int32_t trans, int32_t m, int32_t n, double *x, int32_t incX, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_masking(int32_t m, int32_t n, int32_t k, int32_t len, float fill, int32_t mode, uint8_t *x, float *a);
+ RINDOW_FUNC_DECL void rindow_matlib_d_masking(int32_t m, int32_t n, int32_t k, int32_t len, double fill, int32_t mode, uint8_t *x, double *a);
+ RINDOW_FUNC_DECL void rindow_matlib_i_masking(int32_t dtype, int32_t m, int32_t n, int32_t k, int32_t len, void *fill, int32_t mode, uint8_t *x, void *a);
+ RINDOW_FUNC_DECL void rindow_matlib_s_square(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_square(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_sqrt(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_sqrt(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_rsqrt(int32_t n, float alpha, float *x, int32_t incX, float beta);
+ RINDOW_FUNC_DECL void rindow_matlib_d_rsqrt(int32_t n, double alpha, double *x, int32_t incX, double beta);
+ RINDOW_FUNC_DECL void rindow_matlib_s_pow(int32_t trans, int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_pow(int32_t trans, int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_exp(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_exp(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_log(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_log(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_tanh(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_tanh(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_sin(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_sin(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_cos(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_cos(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_tan(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_tan(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_zeros(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_zeros(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_i_zeros(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_onehot(int32_t dtype, int32_t m, int32_t n, void *x, int32_t incX, float alpha, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_onehot(int32_t dtype, int32_t m, int32_t n, void *x, int32_t incX, double alpha, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_softmax(int32_t m, int32_t n, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_softmax(int32_t m, int32_t n, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_equal(int32_t n, float *x, int32_t incX, float *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_equal(int32_t n, double *x, int32_t incX, double *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_i_equal(int32_t dtype, int32_t n, void *x, int32_t incX, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_notequal(int32_t n, float *x, int32_t incX, float *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_notequal(int32_t n, double *x, int32_t incX, double *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_i_notequal(int32_t dtype, int32_t n, void *x, int32_t incX, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_not(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_not(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_i_not(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_astype(int32_t n, int32_t from_dtype, void *x, int32_t incX, int32_t to_dtype, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_matrixcopy(int32_t trans, int32_t m, int32_t n, float alpha, float *a, int32_t ldA, float *b, int32_t ldB);
+ RINDOW_FUNC_DECL void rindow_matlib_d_matrixcopy(int32_t trans, int32_t m, int32_t n, double alpha, double *a, int32_t ldA, double *b, int32_t ldB);
+ RINDOW_FUNC_DECL void rindow_matlib_s_imagecopy(int32_t height, int32_t width, int32_t channels, float *a, float *b,
+ int32_t channelsFirst, int32_t heightShift, int32_t widthShift, int32_t verticalFlip, int32_t horizontalFlip, int32_t rgbFlip);
+ RINDOW_FUNC_DECL void rindow_matlib_d_imagecopy(int32_t height, int32_t width, int32_t channels, double *a, double *b,
+ int32_t channelsFirst, int32_t heightShift, int32_t widthShift, int32_t verticalFlip, int32_t horizontalFlip, int32_t rgbFlip);
+ RINDOW_FUNC_DECL void rindow_matlib_i8_imagecopy(int32_t height, int32_t width, int32_t channels, uint8_t *a, uint8_t *b,
+ int32_t channelsFirst, int32_t heightShift, int32_t widthShift, int32_t verticalFlip, int32_t horizontalFlip, int32_t rgbFlip);
+ RINDOW_FUNC_DECL void rindow_matlib_fill(int32_t dtype, int32_t n, void *value, void *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_nan2num(int32_t n, float *x, int32_t incX, float alpha);
+ RINDOW_FUNC_DECL void rindow_matlib_d_nan2num(int32_t n, double *x, int32_t incX, double alpha);
+ RINDOW_FUNC_DECL void rindow_matlib_s_isnan(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_isnan(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_searchsorted(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX,
+ int32_t right, int32_t dtype, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_searchsorted(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX,
+ int32_t right, int32_t dtype, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_cumsum(int32_t n, float *x, int32_t incX, int32_t exclusive, int32_t reverse, float *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_cumsum(int32_t n, double *x, int32_t incX, int32_t exclusive, int32_t reverse, double *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_cumsumb(int32_t m, int32_t n, int32_t k, float *a, int32_t exclusive, int32_t reverse, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_cumsumb(int32_t m, int32_t n, int32_t k, double *a, int32_t exclusive, int32_t reverse, double *b);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_transpose(int32_t ndim, int32_t *shape, int32_t *perm, float *a, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_transpose(int32_t ndim, int32_t *shape, int32_t *perm, double *a, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_transpose(int32_t dtype, int32_t ndim, int32_t *shape, int32_t *perm, void *a, void *b);
+ RINDOW_FUNC_DECL void rindow_matlib_s_bandpart(int32_t m, int32_t n, int32_t k, float *a, int32_t lower, int32_t upper);
+ RINDOW_FUNC_DECL void rindow_matlib_d_bandpart(int32_t m, int32_t n, int32_t k, double *a, int32_t lower, int32_t upper);
+ RINDOW_FUNC_DECL void rindow_matlib_i_bandpart(int32_t m, int32_t n, int32_t k, int32_t dtype, void *a, int32_t lower, int32_t upper);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_gather(int32_t reverse, int32_t addMode, int32_t n, int32_t k, int32_t numClass, int32_t dtype, void *x, float *a, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_gather(int32_t reverse, int32_t addMode, int32_t n, int32_t k, int32_t numClass, int32_t dtype, void *x, double *a, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_gather(int32_t reverse, int32_t addMode, int32_t n, int32_t k, int32_t numClass, int32_t dtype, void *x, int32_t data_dtype, void *a, void *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_reducegather(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t numClass, int32_t dtype, void *x, float *a, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_reducegather(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t numClass, int32_t dtype, void *x, double *a, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_reducegather(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t numClass, int32_t dtype, void *x, int32_t data_dtype, void *a, void *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_gatherb(int32_t reverse, int32_t addMode, int32_t batches, int32_t m, int32_t n, int32_t k, int32_t len, int32_t numClass, float *a, int32_t *x, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_gatherb(int32_t reverse, int32_t addMode, int32_t batches, int32_t m, int32_t n, int32_t k, int32_t len, int32_t numClass, double *a, int32_t *x, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_gatherb(int32_t reverse, int32_t addMode, int32_t batches, int32_t m, int32_t n, int32_t k, int32_t len, int32_t numClass, int32_t dtype, void *a, int32_t *x, void *b);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_einsum(
+ const int32_t depth,
+ const int32_t *sizeOfIndices,
+ const float *a,
+ const int32_t *ldA,
+ const float *b,
+ const int32_t *ldB,
+ float *c,
+ const int32_t ndimC);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_einsum(
+ const int32_t depth,
+ const int32_t *sizeOfIndices,
+ const double *a,
+ const int32_t *ldA,
+ const double *b,
+ const int32_t *ldB,
+ double *c,
+ const int32_t ndimC);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_einsum4p1(
+ int32_t dim0,
+ int32_t dim1,
+ int32_t dim2,
+ int32_t dim3,
+ int32_t dim4,
+ float *a,
+ int32_t ldA0,
+ int32_t ldA1,
+ int32_t ldA2,
+ int32_t ldA3,
+ int32_t ldA4,
+ float *b,
+ int32_t ldB0,
+ int32_t ldB1,
+ int32_t ldB2,
+ int32_t ldB3,
+ int32_t ldB4,
+ float *c);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_einsum4p1(
+ int32_t dim0,
+ int32_t dim1,
+ int32_t dim2,
+ int32_t dim3,
+ int32_t dim4,
+ double *a,
+ int32_t ldA0,
+ int32_t ldA1,
+ int32_t ldA2,
+ int32_t ldA3,
+ int32_t ldA4,
+ double *b,
+ int32_t ldB0,
+ int32_t ldB1,
+ int32_t ldB2,
+ int32_t ldB3,
+ int32_t ldB4,
+ double *c);
+ RINDOW_FUNC_DECL void rindow_matlib_s_slice(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t k, int32_t size, float *a, int32_t incA, float *y, int32_t incY, int32_t startAxis0, int32_t sizeAxis0, int32_t startAxis1, int32_t sizeAxis1, int32_t startAxis2, int32_t sizeAxis2);
+ RINDOW_FUNC_DECL void rindow_matlib_d_slice(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t k, int32_t size, double *a, int32_t incA, double *y, int32_t incY, int32_t startAxis0, int32_t sizeAxis0, int32_t startAxis1, int32_t sizeAxis1, int32_t startAxis2, int32_t sizeAxis2);
+ RINDOW_FUNC_DECL void rindow_matlib_i_slice(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t k, int32_t size, int32_t dtype, void *a, int32_t incA, void *y, int32_t incY, int32_t startAxis0, int32_t sizeAxis0, int32_t startAxis1, int32_t sizeAxis1, int32_t startAxis2, int32_t sizeAxis2);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_repeat(int32_t m, int32_t k, int32_t repeats, float *a, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_repeat(int32_t m, int32_t k, int32_t repeats, double *a, double *b);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_reducesum(int32_t m, int32_t n, int32_t k, float *a, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reducesum(int32_t m, int32_t n, int32_t k, double *a, double *b);
+ RINDOW_FUNC_DECL void rindow_matlib_s_reducemax(int32_t m, int32_t n, int32_t k, float *a, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reducemax(int32_t m, int32_t n, int32_t k, double *a, double *b);
+ RINDOW_FUNC_DECL void rindow_matlib_s_reduceargmax(int32_t m, int32_t n, int32_t k, float *a, int32_t dtype, void *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reduceargmax(int32_t m, int32_t n, int32_t k, double *a, int32_t dtype, void *b);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_randomuniform(int32_t n, float *x, int32_t incX, float low, float high, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_d_randomuniform(int32_t n, double *x, int32_t incX, double low, double high, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_i_randomuniform(int32_t n, int32_t dtype, void *x, int32_t incX, int32_t low, int32_t high, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_s_randomnormal(int32_t n, float *x, int32_t incX, float mean, float scale, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_d_randomnormal(int32_t n, double *x, int32_t incX, double mean, double scale, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_i_randomsequence(int32_t n, int32_t size, int32_t dtype, void *x, int32_t incX, int32_t seed);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_im2col1d(
+ int32_t dtype, int32_t reverse,
+ void *images_data,
+ int32_t images_size,
+ int32_t batches,
+ int32_t im_w,
+ int32_t channels,
+ int32_t filter_w,
+ int32_t stride_w,
+ int32_t padding, int32_t channels_first,
+ int32_t dilation_w,
+ int32_t cols_channels_first,
+ void *cols_data, int32_t cols_size);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_im2col2d(
+ int32_t dtype, int32_t reverse,
+ void *images_data, int32_t images_size,
+ int32_t batches,
+ int32_t im_h, int32_t im_w,
+ int32_t channels,
+ int32_t filter_h, int32_t filter_w,
+ int32_t stride_h, int32_t stride_w,
+ int32_t padding, int32_t channels_first,
+ int32_t dilation_h, int32_t dilation_w,
+ int32_t cols_channels_first,
+ void *cols_data, int32_t cols_size);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_im2col3d(
+ int32_t dtype, int32_t reverse,
+ void *images_data, int32_t images_size,
+ int32_t batches,
+ int32_t im_d, int32_t im_h, int32_t im_w,
+ int32_t channels,
+ int32_t filter_d, int32_t filter_h, int32_t filter_w,
+ int32_t stride_d, int32_t stride_h, int32_t stride_w,
+ int32_t padding, int32_t channels_first,
+ int32_t dilation_d, int32_t dilation_h, int32_t dilation_w,
+ int32_t cols_channels_first,
+ void *cols_data, int32_t cols_size);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+// RINDOW_MATLIB_H_
+#endif
diff --git a/shared/macosx-arm64/include/onnxruntime.h b/shared/macosx-arm64/include/onnxruntime.h
new file mode 100644
index 0000000..127382c
--- /dev/null
+++ b/shared/macosx-arm64/include/onnxruntime.h
@@ -0,0 +1,369 @@
+#ifndef ORT_API_H
+#define ORT_API_H
+
+// https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/session/onnxruntime_c_api.h
+// keep same order
+
+typedef enum ONNXTensorElementDataType {
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16
+} ONNXTensorElementDataType;
+
+typedef enum ONNXType {
+ ONNX_TYPE_UNKNOWN,
+ ONNX_TYPE_TENSOR,
+ ONNX_TYPE_SEQUENCE,
+ ONNX_TYPE_MAP,
+ ONNX_TYPE_OPAQUE,
+ ONNX_TYPE_SPARSETENSOR,
+ ONNX_TYPE_OPTIONAL
+} ONNXType;
+
+typedef enum OrtLoggingLevel {
+ ORT_LOGGING_LEVEL_VERBOSE,
+ ORT_LOGGING_LEVEL_INFO,
+ ORT_LOGGING_LEVEL_WARNING,
+ ORT_LOGGING_LEVEL_ERROR,
+ ORT_LOGGING_LEVEL_FATAL,
+} OrtLoggingLevel;
+
+typedef enum OrtErrorCode {
+ ORT_OK,
+ ORT_FAIL,
+ ORT_INVALID_ARGUMENT,
+ ORT_NO_SUCHFILE,
+ ORT_NO_MODEL,
+ ORT_ENGINE_ERROR,
+ ORT_RUNTIME_EXCEPTION,
+ ORT_INVALID_PROTOBUF,
+ ORT_MODEL_LOADED,
+ ORT_NOT_IMPLEMENTED,
+ ORT_INVALID_GRAPH,
+ ORT_EP_FAIL,
+} OrtErrorCode;
+
+struct OrtEnv;
+typedef struct OrtEnv OrtEnv;
+
+struct OrtStatus;
+typedef struct OrtStatus OrtStatus;
+
+struct OrtMemoryInfo;
+typedef struct OrtMemoryInfo OrtMemoryInfo;
+
+struct OrtIoBinding;
+typedef struct OrtIoBinding OrtIoBinding;
+
+struct OrtSession;
+typedef struct OrtSession OrtSession;
+
+struct OrtValue;
+typedef struct OrtValue OrtValue;
+
+struct OrtRunOptions;
+typedef struct OrtRunOptions OrtRunOptions;
+
+struct OrtTypeInfo;
+typedef struct OrtTypeInfo OrtTypeInfo;
+
+struct OrtTensorTypeAndShapeInfo;
+typedef struct OrtTensorTypeAndShapeInfo OrtTensorTypeAndShapeInfo;
+
+struct OrtSessionOptions;
+typedef struct OrtSessionOptions OrtSessionOptions;
+
+struct OrtCustomOpDomain;
+typedef struct OrtCustomOpDomain OrtCustomOpDomain;
+
+struct OrtMapTypeInfo;
+typedef struct OrtMapTypeInfo OrtMapTypeInfo;
+
+struct OrtSequenceTypeInfo;
+typedef struct OrtSequenceTypeInfo OrtSequenceTypeInfo;
+
+struct OrtModelMetadata;
+typedef struct OrtModelMetadata OrtModelMetadata;
+
+struct OrtThreadPoolParams;
+typedef struct OrtThreadPoolParams OrtThreadPoolParams;
+
+struct OrtThreadingOptions;
+typedef struct OrtThreadingOptions OrtThreadingOptions;
+
+struct OrtArenaCfg;
+typedef struct OrtArenaCfg OrtArenaCfg;
+
+struct OrtPrepackedWeightsContainer;
+typedef struct OrtPrepackedWeightsContainer OrtPrepackedWeightsContainer;
+
+struct OrtTensorRTProviderOptionsV2;
+typedef struct OrtTensorRTProviderOptionsV2 OrtTensorRTProviderOptionsV2;
+
+
+
+typedef enum COREMLFlags {
+ COREML_FLAG_USE_NONE = 0x000,
+ COREML_FLAG_USE_CPU_ONLY = 0x001,
+ COREML_FLAG_ENABLE_ON_SUBGRAPH = 0x002,
+ COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE = 0x004,
+ COREML_FLAG_ONLY_ALLOW_STATIC_INPUT_SHAPES = 0x008,
+ COREML_FLAG_CREATE_MLPROGRAM = 0x010,
+ COREML_FLAG_LAST = COREML_FLAG_CREATE_MLPROGRAM
+} COREMLFlags;
+
+struct OrtOp;
+typedef struct OrtOp OrtOp;
+
+struct OrtOpAttr;
+typedef struct Ort OrtOpAttr;
+
+typedef struct OrtAllocator {
+ uint32_t version;
+ void*(* Alloc)(struct OrtAllocator* this_, size_t size);
+ void(* Free)(struct OrtAllocator* this_, void* p);
+ const struct OrtMemoryInfo*(* Info)(const struct OrtAllocator* this_);
+} OrtAllocator;
+
+typedef enum GraphOptimizationLevel {
+ ORT_DISABLE_ALL = 0,
+ ORT_ENABLE_BASIC = 1,
+ ORT_ENABLE_EXTENDED = 2,
+ ORT_ENABLE_ALL = 99
+} GraphOptimizationLevel;
+
+typedef enum ExecutionMode {
+ ORT_SEQUENTIAL = 0,
+ ORT_PARALLEL = 1,
+} ExecutionMode;
+
+struct OrtApi;
+typedef struct OrtApi OrtApi;
+
+struct OrtApiBase {
+ const OrtApi*(* GetApi)(uint32_t version);
+ const char*(* GetVersionString)(void);
+};
+typedef struct OrtApiBase OrtApiBase;
+
+const OrtApiBase* OrtGetApiBase(void);
+
+struct OrtApi {
+ OrtStatus*(* CreateStatus)(OrtErrorCode code, const char* msg);
+ OrtErrorCode(* GetErrorCode)(const OrtStatus* status);
+ const char*(* GetErrorMessage)(const OrtStatus* status);
+ OrtStatus*(* CreateEnv)(OrtLoggingLevel log_severity_level, const char* logid, OrtEnv** out);
+ OrtStatus*(* CreateEnvWithCustomLogger)();
+ OrtStatus*(* EnableTelemetryEvents)(const OrtEnv* env);
+ OrtStatus*(* DisableTelemetryEvents)(const OrtEnv* env);
+ OrtStatus*(* CreateSession)(const OrtEnv* env, const char* model_path, const OrtSessionOptions* options, OrtSession** out);
+ OrtStatus*(* CreateSessionFromArray)(const OrtEnv* env, const void* model_data, size_t model_data_length, const OrtSessionOptions* options, OrtSession** out);
+ OrtStatus*(* Run)(OrtSession* session, const OrtRunOptions* run_options, const char* const* input_names, const OrtValue* const* inputs, size_t input_len, const char* const* output_names, size_t output_names_len, OrtValue** outputs);
+ OrtStatus*(* CreateSessionOptions)(OrtSessionOptions** options);
+ OrtStatus*(* SetOptimizedModelFilePath)(OrtSessionOptions* options, const char* optimized_model_filepath);
+ OrtStatus*(* CloneSessionOptions)();
+ OrtStatus*(* SetSessionExecutionMode)(OrtSessionOptions* options, ExecutionMode execution_mode);
+ OrtStatus*(* EnableProfiling)(OrtSessionOptions* options, const char* profile_file_prefix);
+ OrtStatus*(* DisableProfiling)(OrtSessionOptions* options);
+ OrtStatus*(* EnableMemPattern)(OrtSessionOptions* options);
+ OrtStatus*(* DisableMemPattern)(OrtSessionOptions* options);
+ OrtStatus*(* EnableCpuMemArena)(OrtSessionOptions* options);
+ OrtStatus*(* DisableCpuMemArena)(OrtSessionOptions* options);
+ OrtStatus*(* SetSessionLogId)(OrtSessionOptions* options, const char* logid);
+ OrtStatus*(* SetSessionLogVerbosityLevel)(OrtSessionOptions* options, int session_log_verbosity_level);
+ OrtStatus*(* SetSessionLogSeverityLevel)(OrtSessionOptions* options, int session_log_severity_level);
+ OrtStatus*(* SetSessionGraphOptimizationLevel)(OrtSessionOptions* options, GraphOptimizationLevel graph_optimization_level);
+ OrtStatus*(* SetIntraOpNumThreads)(OrtSessionOptions* options, int intra_op_num_threads);
+ OrtStatus*(* SetInterOpNumThreads)(OrtSessionOptions* options, int inter_op_num_threads);
+ OrtStatus*(* CreateCustomOpDomain)();
+ OrtStatus*(* CustomOpDomain_Add)();
+ OrtStatus*(* AddCustomOpDomain)();
+ OrtStatus*(* RegisterCustomOpsLibrary)();
+ OrtStatus*(* SessionGetInputCount)(const OrtSession* session, size_t* out);
+ OrtStatus*(* SessionGetOutputCount)(const OrtSession* session, size_t* out);
+ OrtStatus*(* SessionGetOverridableInitializerCount)();
+ OrtStatus*(* SessionGetInputTypeInfo)(const OrtSession* session, size_t index, OrtTypeInfo** type_info);
+ OrtStatus*(* SessionGetOutputTypeInfo)(const OrtSession* session, size_t index, OrtTypeInfo** type_info);
+ OrtStatus*(* SessionGetOverridableInitializerTypeInfo)();
+ OrtStatus*(* SessionGetInputName)(const OrtSession* session, size_t index, OrtAllocator* allocator, char** value);
+ OrtStatus*(* SessionGetOutputName)(const OrtSession* session, size_t index, OrtAllocator* allocator, char** value);
+ OrtStatus*(* SessionGetOverridableInitializerName)();
+ OrtStatus*(* CreateRunOptions)(OrtRunOptions** out);
+ OrtStatus*(* RunOptionsSetRunLogVerbosityLevel)(OrtRunOptions* options, int log_verbosity_level);
+ OrtStatus*(* RunOptionsSetRunLogSeverityLevel)(OrtRunOptions* options, int log_severity_level);
+ OrtStatus*(* RunOptionsSetRunTag)(OrtRunOptions* options, const char* run_tag);
+ OrtStatus*(* RunOptionsGetRunLogVerbosityLevel)();
+ OrtStatus*(* RunOptionsGetRunLogSeverityLevel)();
+ OrtStatus*(* RunOptionsGetRunTag)();
+ OrtStatus*(* RunOptionsSetTerminate)(OrtRunOptions* options);
+ OrtStatus*(* RunOptionsUnsetTerminate)(OrtRunOptions* options);
+ OrtStatus*(* CreateTensorAsOrtValue)(OrtAllocator* allocator, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, OrtValue** out);
+ OrtStatus*(* CreateTensorWithDataAsOrtValue)(const OrtMemoryInfo* info, void* p_data, size_t p_data_len, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, OrtValue** out);
+ OrtStatus*(* IsTensor)();
+ OrtStatus*(* GetTensorMutableData)(OrtValue* value, void** out);
+ OrtStatus*(* FillStringTensor)(OrtValue* value, const char* const* s, size_t s_len);
+ OrtStatus*(* GetStringTensorDataLength)(const OrtValue* value, size_t* len);
+ OrtStatus*(* GetStringTensorContent)(const OrtValue* value, void* s, size_t s_len, size_t* offsets, size_t offsets_len);
+ OrtStatus*(* CastTypeInfoToTensorInfo)(const OrtTypeInfo* type_info, const OrtTensorTypeAndShapeInfo** out);
+ OrtStatus*(* GetOnnxTypeFromTypeInfo)(const OrtTypeInfo* type_info, enum ONNXType* out);
+ OrtStatus*(* CreateTensorTypeAndShapeInfo)();
+ OrtStatus*(* SetTensorElementType)();
+ OrtStatus*(* SetDimensions)();
+ OrtStatus*(* GetTensorElementType)(const OrtTensorTypeAndShapeInfo* info, enum ONNXTensorElementDataType* out);
+ OrtStatus*(* GetDimensionsCount)(const OrtTensorTypeAndShapeInfo* info, size_t* out);
+ OrtStatus*(* GetDimensions)(const OrtTensorTypeAndShapeInfo* info, int64_t* dim_values, size_t dim_values_length);
+ OrtStatus*(* GetSymbolicDimensions)(const OrtTensorTypeAndShapeInfo* info, const char* dim_params[], size_t dim_params_length);
+ OrtStatus*(* GetTensorShapeElementCount)(const OrtTensorTypeAndShapeInfo* info, size_t* out);
+ OrtStatus*(* GetTensorTypeAndShape)(const OrtValue* value, OrtTensorTypeAndShapeInfo** out);
+ OrtStatus*(* GetTypeInfo)();
+ OrtStatus*(* GetValueType)(const OrtValue* value, enum ONNXType* out);
+ OrtStatus*(* CreateMemoryInfo)();
+ OrtStatus*(* CreateCpuMemoryInfo)(enum OrtAllocatorType type, enum OrtMemType mem_type, OrtMemoryInfo** out);
+ OrtStatus*(* CompareMemoryInfo)();
+ OrtStatus*(* MemoryInfoGetName)();
+ OrtStatus*(* MemoryInfoGetId)();
+ OrtStatus*(* MemoryInfoGetMemType)();
+ OrtStatus*(* MemoryInfoGetType)();
+ OrtStatus*(* AllocatorAlloc)(OrtAllocator* ort_allocator, size_t size, void** out);
+ OrtStatus*(* AllocatorFree)(OrtAllocator* ort_allocator, void* p);
+ OrtStatus*(* AllocatorGetInfo)(const OrtAllocator* ort_allocator, const struct OrtMemoryInfo** out);
+ OrtStatus*(* GetAllocatorWithDefaultOptions)(OrtAllocator** out);
+ OrtStatus*(* AddFreeDimensionOverride)(OrtSessionOptions* options, const char* dim_denotation, int64_t dim_value);
+ OrtStatus*(* GetValue)(const OrtValue* value, int index, OrtAllocator* allocator, OrtValue** out);
+ OrtStatus*(* GetValueCount)(const OrtValue* value, size_t* out);
+ OrtStatus*(* CreateValue)();
+ OrtStatus*(* CreateOpaqueValue)();
+ OrtStatus*(* GetOpaqueValue)();
+ OrtStatus*(* KernelInfoGetAttribute_float)();
+ OrtStatus*(* KernelInfoGetAttribute_int64)();
+ OrtStatus*(* KernelInfoGetAttribute_string)();
+ OrtStatus*(* KernelContext_GetInputCount)();
+ OrtStatus*(* KernelContext_GetOutputCount)();
+ OrtStatus*(* KernelContext_GetInput)();
+ OrtStatus*(* KernelContext_GetOutput)();
+ void(* ReleaseEnv)(OrtEnv* input);
+ void(* ReleaseStatus)(OrtStatus* input);
+ void(* ReleaseMemoryInfo)(OrtMemoryInfo* input);
+ void(* ReleaseSession)(OrtSession* input);
+ void(* ReleaseValue)(OrtValue* input);
+ void(* ReleaseRunOptions)(OrtRunOptions* input);
+ void(* ReleaseTypeInfo)(OrtTypeInfo* input);
+ void(* ReleaseTensorTypeAndShapeInfo)(OrtTensorTypeAndShapeInfo* input);
+ void(* ReleaseSessionOptions)(OrtSessionOptions* input);
+ void(* ReleaseCustomOpDomain)();
+ OrtStatus*(* GetDenotationFromTypeInfo)();
+ OrtStatus*(* CastTypeInfoToMapTypeInfo)(const OrtTypeInfo* type_info, const OrtMapTypeInfo** out);
+ OrtStatus*(* CastTypeInfoToSequenceTypeInfo)(const OrtTypeInfo* type_info, const OrtSequenceTypeInfo** out);
+ OrtStatus*(* GetMapKeyType)(const OrtMapTypeInfo* map_type_info, enum ONNXTensorElementDataType* out);
+ OrtStatus*(* GetMapValueType)(const OrtMapTypeInfo* map_type_info, OrtTypeInfo** type_info);
+ OrtStatus*(* GetSequenceElementType)(const OrtSequenceTypeInfo* sequence_type_info, OrtTypeInfo** type_info);
+ void(* ReleaseMapTypeInfo)(OrtMapTypeInfo* input);
+ void(* ReleaseSequenceTypeInfo)(OrtSequenceTypeInfo* input);
+ OrtStatus*(* SessionEndProfiling)(OrtSession* session, OrtAllocator* allocator, char** out);
+ OrtStatus*(* SessionGetModelMetadata)(const OrtSession* session, OrtModelMetadata** out);
+ OrtStatus*(* ModelMetadataGetProducerName)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataGetGraphName)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataGetDomain)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataGetDescription)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataLookupCustomMetadataMap)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, const char* key, char** value);
+ OrtStatus*(* ModelMetadataGetVersion)(const OrtModelMetadata* model_metadata, int64_t* value);
+ void(* ReleaseModelMetadata)(OrtModelMetadata* input);
+ OrtStatus*(* CreateEnvWithGlobalThreadPools)();
+ OrtStatus*(* DisablePerSessionThreads)();
+ OrtStatus*(* CreateThreadingOptions)();
+ void(* ReleaseThreadingOptions)(OrtThreadingOptions* input);
+ OrtStatus*(* ModelMetadataGetCustomMetadataMapKeys)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char*** keys, int64_t* num_keys);
+ OrtStatus*(* AddFreeDimensionOverrideByName)(OrtSessionOptions* options, const char* dim_name, int64_t dim_value);
+ OrtStatus*(* GetAvailableProviders)(char*** out_ptr, int* provider_length);
+ OrtStatus*(* ReleaseAvailableProviders)(char** ptr, int providers_length);
+ OrtStatus*(* GetStringTensorElementLength)();
+ OrtStatus*(* GetStringTensorElement)();
+ OrtStatus*(* FillStringTensorElement)();
+ OrtStatus*(* AddSessionConfigEntry)(OrtSessionOptions* options, const char* config_key, const char* config_value);
+ OrtStatus*(* CreateAllocator)();
+ void(* ReleaseAllocator)(OrtAllocator* input);
+ OrtStatus*(* RunWithBinding)();
+ OrtStatus*(* CreateIoBinding)();
+ void(* ReleaseIoBinding)(OrtIoBinding* input);
+ OrtStatus*(* BindInput)();
+ OrtStatus*(* BindOutput)();
+ OrtStatus*(* BindOutputToDevice)();
+ OrtStatus*(* GetBoundOutputNames)();
+ OrtStatus*(* GetBoundOutputValues)();
+ void(* ClearBoundInputs)();
+ void(* ClearBoundOutputs)();
+ OrtStatus*(* TensorAt)();
+ OrtStatus*(* CreateAndRegisterAllocator)();
+ OrtStatus*(* SetLanguageProjection)();
+ OrtStatus*(* SessionGetProfilingStartTimeNs)();
+ OrtStatus*(* SetGlobalIntraOpNumThreads)();
+ OrtStatus*(* SetGlobalInterOpNumThreads)();
+ OrtStatus*(* SetGlobalSpinControl)();
+ OrtStatus*(* AddInitializer)();
+ OrtStatus*(* CreateEnvWithCustomLoggerAndGlobalThreadPools)();
+
+
+ OrtStatus*(* SetGlobalDenormalAsZero)();
+ OrtStatus*(* CreateArenaCfg)();
+ void(* ReleaseArenaCfg)(OrtArenaCfg* input);
+ OrtStatus*(* ModelMetadataGetGraphDescription)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* SessionOptionsAppendExecutionProvider_TensorRT)();
+ OrtStatus*(* SetCurrentGpuDeviceId)();
+ OrtStatus*(* GetCurrentGpuDeviceId)();
+ OrtStatus*(* KernelInfoGetAttributeArray_float)();
+ OrtStatus*(* KernelInfoGetAttributeArray_int64)();
+ OrtStatus*(* CreateArenaCfgV2)();
+ OrtStatus*(* AddRunConfigEntry)();
+ OrtStatus*(* CreatePrepackedWeightsContainer)();
+ void(* PrepackedWeightsContainer)(OrtPrepackedWeightsContainer* input);
+ OrtStatus*(* CreateSessionWithPrepackedWeightsContainer)();
+ OrtStatus*(* CreateSessionFromArrayWithPrepackedWeightsContainer)();
+ OrtStatus*(* SessionOptionsAppendExecutionProvider_TensorRT_V2)();
+ OrtStatus*(* CreateTensorRTProviderOptions)();
+ OrtStatus*(* UpdateTensorRTProviderOptions)();
+ OrtStatus*(* GetTensorRTProviderOptionsAsString)();
+ void(* ReleaseTensorRTProviderOptions)(OrtTensorRTProviderOptionsV2* input);
+ OrtStatus*(* EnableOrtCustomOps)();
+ OrtStatus*(* RegisterAllocator)();
+ OrtStatus*(* UnregisterAllocator)();
+ OrtStatus*(* IsSparseTensor)();
+ OrtStatus*(* CreateSparseTensorAsOrtValue)();
+ OrtStatus*(* FillSparseTensorCoo)();
+ OrtStatus*(* FillSparseTensorCsr)();
+ OrtStatus*(* FillSparseTensorBlockSparse)();
+ OrtStatus*(* CreateSparseTensorWithValuesAsOrtValue)();
+ OrtStatus*(* UseCooIndices)();
+ OrtStatus*(* UseCsrIndices)();
+ OrtStatus*(* UseBlockSparseIndices)();
+ OrtStatus*(* GetSparseTensorFormat)();
+ OrtStatus*(* GetSparseTensorValuesTypeAndShape)();
+ OrtStatus*(* GetSparseTensorValues)();
+ OrtStatus*(* GetSparseTensorIndicesTypeShape)();
+ OrtStatus*(* GetSparseTensorIndices)();
+ OrtStatus*(* HasValue)();
+ OrtStatus*(* KernelContext_GetGPUComputeStream)();
+ OrtStatus*(* GetTensorMemoryInfo)();
+ OrtStatus*(* GetExecutionProviderApi)();
+ OrtStatus*(* SessionOptionsSetCustomCreateThreadFn)();
+ OrtStatus*(* SessionOptionsSetCustomThreadCreationOptions)();
+ OrtStatus*(* SessionOptionsSetCustomJoinThreadFn)();
+ OrtStatus*(* SetGlobalCustomCreateThreadFn)();
+ OrtStatus*(* SetGlobalCustomThreadCreationOptions)();
+ OrtStatus*(* SetGlobalCustomJoinThreadFn)();
+ OrtStatus*(* SynchronizeBoundInputs)();
+ OrtStatus*(* SynchronizeBoundOutputs)();
+};
\ No newline at end of file
diff --git a/shared/macosx-arm64/include/openblas.h b/shared/macosx-arm64/include/openblas.h
new file mode 100644
index 0000000..8e902fb
--- /dev/null
+++ b/shared/macosx-arm64/include/openblas.h
@@ -0,0 +1,426 @@
+#define FFI_SCOPE "Rindow\\OpenBLAS\\FFI"
+//#define FFI_LIB "libopenblas.dll"
+
+/////////////////////////////////////////////
+typedef int8_t cl_char;
+typedef uint8_t cl_uchar;
+typedef int16_t cl_short;
+typedef uint16_t cl_ushort;
+typedef int32_t cl_int;
+typedef uint32_t cl_uint;
+typedef int64_t cl_long;
+typedef uint64_t cl_ulong;
+/////////////////////////////////////////////
+typedef uint16_t bfloat16;
+typedef int32_t blasint;
+typedef int32_t lapack_int;
+/////////////////////////////////////////////
+//#define xdouble double
+typedef double xdouble;
+//#define OPENBLAS_COMPLEX_STRUCT
+typedef struct _openblas_complex_float { float real, imag; } openblas_complex_float;
+typedef struct _openblas_complex_double { double real, imag; } openblas_complex_double;
+typedef struct _openblas_complex_xdouble { xdouble real, imag; } openblas_complex_xdouble;
+//#define openblas_make_complex_float(real, imag) {(real), (imag)}
+//#define openblas_make_complex_double(real, imag) {(real), (imag)}
+//#define openblas_make_complex_xdouble(real, imag) {(real), (imag)}
+//#define openblas_complex_float_real(z) ((z).real)
+//#define openblas_complex_float_imag(z) ((z).imag)
+//#define openblas_complex_double_real(z) ((z).real)
+//#define openblas_complex_double_imag(z) ((z).imag)
+//#define openblas_complex_xdouble_real(z) ((z).real)
+//#define openblas_complex_xdouble_imag(z) ((z).imag)
+/////////////////////////////////////////////
+
+
+
+/*Set the number of threads on runtime.*/
+void openblas_set_num_threads(int num_threads);
+void goto_set_num_threads(int num_threads);
+
+/*Get the number of threads on runtime.*/
+int openblas_get_num_threads(void);
+
+/*Get the number of physical processors (cores).*/
+int openblas_get_num_procs(void);
+
+/*Get the build configure on runtime.*/
+char* openblas_get_config(void);
+
+/*Get the CPU corename on runtime.*/
+char* openblas_get_corename(void);
+
+/* Get the parallelization type which is used by OpenBLAS */
+int openblas_get_parallel(void);
+/* OpenBLAS is compiled for sequential use */
+#define OPENBLAS_SEQUENTIAL 0
+/* OpenBLAS is compiled using normal threading model */
+#define OPENBLAS_THREAD 1
+/* OpenBLAS is compiled using OpenMP threading model */
+#define OPENBLAS_OPENMP 2
+
+
+//#ifndef OPENBLAS_CONST
+//# define OPENBLAS_CONST const
+//#endif
+
+
+//#define CBLAS_INDEX size_t
+typedef size_t CBLAS_INDEX;
+
+
+typedef enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102} CBLAS_ORDER;
+typedef enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113, CblasConjNoTrans=114} CBLAS_TRANSPOSE;
+typedef enum CBLAS_UPLO {CblasUpper=121, CblasLower=122} CBLAS_UPLO;
+typedef enum CBLAS_DIAG {CblasNonUnit=131, CblasUnit=132} CBLAS_DIAG;
+typedef enum CBLAS_SIDE {CblasLeft=141, CblasRight=142} CBLAS_SIDE;
+typedef CBLAS_ORDER CBLAS_LAYOUT;
+
+float cblas_sdsdot(const blasint n, const float alpha, const float *x, const blasint incx, const float *y, const blasint incy);
+double cblas_dsdot (const blasint n, const float *x, const blasint incx, const float *y, const blasint incy);
+float cblas_sdot(const blasint n, const float *x, const blasint incx, const float *y, const blasint incy);
+double cblas_ddot(const blasint n, const double *x, const blasint incx, const double *y, const blasint incy);
+
+openblas_complex_float cblas_cdotu(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+openblas_complex_float cblas_cdotc(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+openblas_complex_double cblas_zdotu(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+openblas_complex_double cblas_zdotc(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+
+void cblas_cdotu_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+void cblas_cdotc_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+void cblas_zdotu_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+void cblas_zdotc_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+
+float cblas_sasum (const blasint n, const float *x, const blasint incx);
+double cblas_dasum (const blasint n, const double *x, const blasint incx);
+float cblas_scasum(const blasint n, const void *x, const blasint incx);
+double cblas_dzasum(const blasint n, const void *x, const blasint incx);
+
+float cblas_ssum (const blasint n, const float *x, const blasint incx);
+double cblas_dsum (const blasint n, const double *x, const blasint incx);
+float cblas_scsum(const blasint n, const void *x, const blasint incx);
+double cblas_dzsum(const blasint n, const void *x, const blasint incx);
+
+float cblas_snrm2 (const blasint N, const float *X, const blasint incX);
+double cblas_dnrm2 (const blasint N, const double *X, const blasint incX);
+float cblas_scnrm2(const blasint N, const void *X, const blasint incX);
+double cblas_dznrm2(const blasint N, const void *X, const blasint incX);
+
+CBLAS_INDEX cblas_isamax(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idamax(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icamax(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izamax(const blasint n, const void *x, const blasint incx);
+
+CBLAS_INDEX cblas_isamin(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idamin(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icamin(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izamin(const blasint n, const void *x, const blasint incx);
+
+CBLAS_INDEX cblas_ismax(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idmax(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icmax(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izmax(const blasint n, const void *x, const blasint incx);
+
+CBLAS_INDEX cblas_ismin(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idmin(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icmin(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izmin(const blasint n, const void *x, const blasint incx);
+
+void cblas_saxpy(const blasint n, const float alpha, const float *x, const blasint incx, float *y, const blasint incy);
+void cblas_daxpy(const blasint n, const double alpha, const double *x, const blasint incx, double *y, const blasint incy);
+void cblas_caxpy(const blasint n, const void *alpha, const void *x, const blasint incx, void *y, const blasint incy);
+void cblas_zaxpy(const blasint n, const void *alpha, const void *x, const blasint incx, void *y, const blasint incy);
+
+void cblas_scopy(const blasint n, const float *x, const blasint incx, float *y, const blasint incy);
+void cblas_dcopy(const blasint n, const double *x, const blasint incx, double *y, const blasint incy);
+void cblas_ccopy(const blasint n, const void *x, const blasint incx, void *y, const blasint incy);
+void cblas_zcopy(const blasint n, const void *x, const blasint incx, void *y, const blasint incy);
+
+void cblas_sswap(const blasint n, float *x, const blasint incx, float *y, const blasint incy);
+void cblas_dswap(const blasint n, double *x, const blasint incx, double *y, const blasint incy);
+void cblas_cswap(const blasint n, void *x, const blasint incx, void *y, const blasint incy);
+void cblas_zswap(const blasint n, void *x, const blasint incx, void *y, const blasint incy);
+
+void cblas_srot(const blasint N, float *X, const blasint incX, float *Y, const blasint incY, const float c, const float s);
+void cblas_drot(const blasint N, double *X, const blasint incX, double *Y, const blasint incY, const double c, const double s);
+//void cblas_csrot(const blasint n, const void *x, const blasint incx, void *y, const blasint incY, const float c, const float s);
+//void cblas_zdrot(const blasint n, const void *x, const blasint incx, void *y, const blasint incY, const double c, const double s);
+
+void cblas_srotg(float *a, float *b, float *c, float *s);
+void cblas_drotg(double *a, double *b, double *c, double *s);
+//void cblas_crotg(void *a, void *b, float *c, void *s);
+//void cblas_zrotg(void *a, void *b, double *c, void *s);
+
+
+void cblas_srotm(const blasint N, float *X, const blasint incX, float *Y, const blasint incY, const float *P);
+void cblas_drotm(const blasint N, double *X, const blasint incX, double *Y, const blasint incY, const double *P);
+
+void cblas_srotmg(float *d1, float *d2, float *b1, const float b2, float *P);
+void cblas_drotmg(double *d1, double *d2, double *b1, const double b2, double *P);
+
+void cblas_sscal(const blasint N, const float alpha, float *X, const blasint incX);
+void cblas_dscal(const blasint N, const double alpha, double *X, const blasint incX);
+void cblas_cscal(const blasint N, const void *alpha, void *X, const blasint incX);
+void cblas_zscal(const blasint N, const void *alpha, void *X, const blasint incX);
+void cblas_csscal(const blasint N, const float alpha, void *X, const blasint incX);
+void cblas_zdscal(const blasint N, const double alpha, void *X, const blasint incX);
+
+void cblas_sgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const float alpha, const float *a, const blasint lda, const float *x, const blasint incx, const float beta, float *y, const blasint incy);
+void cblas_dgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const double alpha, const double *a, const blasint lda, const double *x, const blasint incx, const double beta, double *y, const blasint incy);
+void cblas_cgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const void *alpha, const void *a, const blasint lda, const void *x, const blasint incx, const void *beta, void *y, const blasint incy);
+void cblas_zgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const void *alpha, const void *a, const blasint lda, const void *x, const blasint incx, const void *beta, void *y, const blasint incy);
+
+void cblas_sger (const enum CBLAS_ORDER order, const blasint M, const blasint N, const float alpha, const float *X, const blasint incX, const float *Y, const blasint incY, float *A, const blasint lda);
+void cblas_dger (const enum CBLAS_ORDER order, const blasint M, const blasint N, const double alpha, const double *X, const blasint incX, const double *Y, const blasint incY, double *A, const blasint lda);
+void cblas_cgeru(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_cgerc(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_zgeru(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_zgerc(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+
+void cblas_strsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_strmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_ssyr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *X, const blasint incX, float *A, const blasint lda);
+void cblas_dsyr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X, const blasint incX, double *A, const blasint lda);
+void cblas_cher(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const void *X, const blasint incX, void *A, const blasint lda);
+void cblas_zher(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const void *X, const blasint incX, void *A, const blasint lda);
+
+void cblas_ssyr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,const blasint N, const float alpha, const float *X,
+ const blasint incX, const float *Y, const blasint incY, float *A, const blasint lda);
+void cblas_dsyr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X,
+ const blasint incX, const double *Y, const blasint incY, double *A, const blasint lda);
+void cblas_cher2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX,
+ const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_zher2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX,
+ const void *Y, const blasint incY, void *A, const blasint lda);
+
+void cblas_sgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const float alpha, const float *A, const blasint lda, const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const double alpha, const double *A, const blasint lda, const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+void cblas_cgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+void cblas_ssbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K, const float alpha, const float *A,
+ const blasint lda, const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dsbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K, const double alpha, const double *A,
+ const blasint lda, const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+
+
+void cblas_stbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_stbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_stpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const float *Ap, float *X, const blasint incX);
+void cblas_dtpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const double *Ap, double *X, const blasint incX);
+void cblas_ctpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+void cblas_ztpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+
+void cblas_stpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const float *Ap, float *X, const blasint incX);
+void cblas_dtpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const double *Ap, double *X, const blasint incX);
+void cblas_ctpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+void cblas_ztpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+
+void cblas_ssymv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *A,
+ const blasint lda, const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dsymv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *A,
+ const blasint lda, const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+void cblas_chemv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *A,
+ const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zhemv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *A,
+ const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+
+void cblas_sspmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *Ap,
+ const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dspmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *Ap,
+ const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+
+void cblas_sspr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *X, const blasint incX, float *Ap);
+void cblas_dspr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X, const blasint incX, double *Ap);
+
+void cblas_chpr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const void *X, const blasint incX, void *A);
+void cblas_zhpr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const void *X,const blasint incX, void *A);
+
+void cblas_sspr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *X, const blasint incX, const float *Y, const blasint incY, float *A);
+void cblas_dspr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X, const blasint incX, const double *Y, const blasint incY, double *A);
+void cblas_chpr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *Ap);
+void cblas_zhpr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *Ap);
+
+void cblas_chbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zhbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+void cblas_chpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N,
+ const void *alpha, const void *Ap, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zhpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N,
+ const void *alpha, const void *Ap, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+void cblas_sgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const float alpha, const float *A, const blasint lda, const float *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+void cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const double alpha, const double *A, const blasint lda, const double *B, const blasint ldb, const double beta, double *C, const blasint ldc);
+void cblas_cgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+//void cblas_cgemm3m(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+// const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+//void cblas_zgemm3m(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+// const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+
+void cblas_ssymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const float alpha, const float *A, const blasint lda, const float *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+void cblas_dsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const double alpha, const double *A, const blasint lda, const double *B, const blasint ldb, const double beta, double *C, const blasint ldc);
+void cblas_csymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+void cblas_ssyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const float alpha, const float *A, const blasint lda, const float beta, float *C, const blasint ldc);
+void cblas_dsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const double alpha, const double *A, const blasint lda, const double beta, double *C, const blasint ldc);
+void cblas_csyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *beta, void *C, const blasint ldc);
+void cblas_zsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *beta, void *C, const blasint ldc);
+
+void cblas_ssyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const float alpha, const float *A, const blasint lda, const float *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+void cblas_dsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const double alpha, const double *A, const blasint lda, const double *B, const blasint ldb, const double beta, double *C, const blasint ldc);
+void cblas_csyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+
+
+void cblas_strmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const float alpha, const float *A, const blasint lda, float *B, const blasint ldb);
+void cblas_dtrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const double alpha, const double *A, const blasint lda, double *B, const blasint ldb);
+void cblas_ctrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+void cblas_ztrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+
+void cblas_strsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const float alpha, const float *A, const blasint lda, float *B, const blasint ldb);
+void cblas_dtrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const double alpha, const double *A, const blasint lda, double *B, const blasint ldb);
+void cblas_ctrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+void cblas_ztrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+
+void cblas_chemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zhemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+void cblas_cherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const float alpha, const void *A, const blasint lda, const float beta, void *C, const blasint ldc);
+void cblas_zherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const double alpha, const void *A, const blasint lda, const double beta, void *C, const blasint ldc);
+
+void cblas_cher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const float beta, void *C, const blasint ldc);
+void cblas_zher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const double beta, void *C, const blasint ldc);
+
+void cblas_xerbla(blasint p, char *rout, char *form, ...);
+
+/*** BLAS extensions ***/
+
+void cblas_saxpby(const blasint n, const float alpha, const float *x, const blasint incx,const float beta, float *y, const blasint incy);
+
+void cblas_daxpby(const blasint n, const double alpha, const double *x, const blasint incx,const double beta, double *y, const blasint incy);
+
+void cblas_caxpby(const blasint n, const void *alpha, const void *x, const blasint incx,const void *beta, void *y, const blasint incy);
+
+void cblas_zaxpby(const blasint n, const void *alpha, const void *x, const blasint incx,const void *beta, void *y, const blasint incy);
+
+void cblas_somatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const float calpha, const float *a,
+ const blasint clda, float *b, const blasint cldb);
+void cblas_domatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const double calpha, const double *a,
+ const blasint clda, double *b, const blasint cldb);
+void cblas_comatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const void* calpha, const void* a,
+ const blasint clda, void *b, const blasint cldb);
+void cblas_zomatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const void* calpha, const void* a,
+ const blasint clda, void *b, const blasint cldb);
+
+void cblas_simatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const float calpha, float *a,
+ const blasint clda, const blasint cldb);
+void cblas_dimatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const double calpha, double *a,
+ const blasint clda, const blasint cldb);
+void cblas_cimatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const float* calpha, float* a,
+ const blasint clda, const blasint cldb);
+void cblas_zimatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const double* calpha, double* a,
+ const blasint clda, const blasint cldb);
+
+void cblas_sgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const float calpha, float *a, const blasint clda, const float cbeta,
+ float *c, const blasint cldc);
+void cblas_dgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const double calpha, double *a, const blasint clda, const double cbeta,
+ double *c, const blasint cldc);
+void cblas_cgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const float *calpha, float *a, const blasint clda, const float *cbeta,
+ float *c, const blasint cldc);
+void cblas_zgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const double *calpha, double *a, const blasint clda, const double *cbeta,
+ double *c, const blasint cldc);
+
+/*** BFLOAT16 and INT8 extensions ***/
+/* convert float array to BFLOAT16 array by rounding */
+//void cblas_sbstobf16(const blasint n, const float *in, const blasint incin, bfloat16 *out, const blasint incout);
+/* convert double array to BFLOAT16 array by rounding */
+//void cblas_sbdtobf16(const blasint n, const double *in, const blasint incin, bfloat16 *out, const blasint incout);
+/* convert BFLOAT16 array to float array */
+//void cblas_sbf16tos(const blasint n, const bfloat16 *in, const blasint incin, float *out, const blasint incout);
+/* convert BFLOAT16 array to double array */
+//void cblas_dbf16tod(const blasint n, const bfloat16 *in, const blasint incin, double *out, const blasint incout);
+/* dot production of BFLOAT16 input arrays, and output as float */
+//float cblas_sbdot(const blasint n, const bfloat16 *x, const blasint incx, const bfloat16 *y, const blasint incy);
+//void cblas_sbgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n, const float alpha, const bfloat16 *a, const blasint lda, const bfloat16 *x, const blasint incx, const float beta, float *y, const blasint incy);
+
+//void cblas_sbgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+// const float alpha, const bfloat16 *A, const blasint lda, const bfloat16 *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+
+
diff --git a/shared/macosx-arm64/include/samplerate.h b/shared/macosx-arm64/include/samplerate.h
new file mode 100644
index 0000000..436b7ff
--- /dev/null
+++ b/shared/macosx-arm64/include/samplerate.h
@@ -0,0 +1,163 @@
+#ifndef SAMPLERATE_H
+#define SAMPLERATE_H
+
+/* Opaque data type SRC_STATE. */
+typedef struct SRC_STATE_tag SRC_STATE;
+
+/* SRC_DATA is used to pass data to src_simple() and src_process(). */
+typedef struct
+{ const float *data_in ;
+ float *data_out ;
+
+ long input_frames, output_frames ;
+ long input_frames_used, output_frames_gen ;
+
+ int end_of_input ;
+
+ double src_ratio ;
+} SRC_DATA ;
+
+/*
+** User supplied callback function type for use with src_callback_new()
+** and src_callback_read(). First parameter is the same pointer that was
+** passed into src_callback_new(). Second parameter is pointer to a
+** pointer. The user supplied callback function must modify *data to
+** point to the start of the user supplied float array. The user supplied
+** function must return the number of frames that **data points to.
+*/
+
+typedef long (*src_callback_t) (void *cb_data, float **data) ;
+
+/*
+** Standard initialisation function : return an anonymous pointer to the
+** internal state of the converter. Choose a converter from the enums below.
+** Error returned in *error.
+*/
+
+SRC_STATE* src_new (int converter_type, int channels, int *error) ;
+
+/*
+** Clone a handle : return an anonymous pointer to a new converter
+** containing the same internal state as orig. Error returned in *error.
+*/
+SRC_STATE* src_clone (SRC_STATE* orig, int *error) ;
+
+/*
+** Initilisation for callback based API : return an anonymous pointer to the
+** internal state of the converter. Choose a converter from the enums below.
+** The cb_data pointer can point to any data or be set to NULL. Whatever the
+** value, when processing, user supplied function "func" gets called with
+** cb_data as first parameter.
+*/
+
+SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels,
+ int *error, void* cb_data) ;
+
+/*
+** Cleanup all internal allocations.
+** Always returns NULL.
+*/
+
+SRC_STATE* src_delete (SRC_STATE *state) ;
+
+/*
+** Standard processing function.
+** Returns non zero on error.
+*/
+
+int src_process (SRC_STATE *state, SRC_DATA *data) ;
+
+/*
+** Callback based processing function. Read up to frames worth of data from
+** the converter int *data and return frames read or -1 on error.
+*/
+long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ;
+
+/*
+** Simple interface for performing a single conversion from input buffer to
+** output buffer at a fixed conversion ratio.
+** Simple interface does not require initialisation as it can only operate on
+** a single buffer worth of audio.
+*/
+
+int src_simple (SRC_DATA *data, int converter_type, int channels) ;
+
+/*
+** This library contains a number of different sample rate converters,
+** numbered 0 through N.
+**
+** Return a string giving either a name or a more full description of each
+** sample rate converter or NULL if no sample rate converter exists for
+** the given value. The converters are sequentially numbered from 0 to N.
+*/
+
+const char *src_get_name (int converter_type) ;
+const char *src_get_description (int converter_type) ;
+const char *src_get_version (void) ;
+
+/*
+** Set a new SRC ratio. This allows step responses
+** in the conversion ratio.
+** Returns non zero on error.
+*/
+
+int src_set_ratio (SRC_STATE *state, double new_ratio) ;
+
+/*
+** Get the current channel count.
+** Returns negative on error, positive channel count otherwise
+*/
+
+int src_get_channels (SRC_STATE *state) ;
+
+/*
+** Reset the internal SRC state.
+** Does not modify the quality settings.
+** Does not free any memory allocations.
+** Returns non zero on error.
+*/
+
+int src_reset (SRC_STATE *state) ;
+
+/*
+** Return TRUE if ratio is a valid conversion ratio, FALSE
+** otherwise.
+*/
+
+int src_is_valid_ratio (double ratio) ;
+
+/*
+** Return an error number.
+*/
+
+int src_error (SRC_STATE *state) ;
+
+/*
+** Convert the error number into a string.
+*/
+const char* src_strerror (int error) ;
+
+/*
+** The following enums can be used to set the interpolator type
+** using the function src_set_converter().
+*/
+
+enum
+{
+ SRC_SINC_BEST_QUALITY = 0,
+ SRC_SINC_MEDIUM_QUALITY = 1,
+ SRC_SINC_FASTEST = 2,
+ SRC_ZERO_ORDER_HOLD = 3,
+ SRC_LINEAR = 4,
+} ;
+
+/*
+** Extra helper functions for converting from short to float and
+** back again.
+*/
+
+void src_short_to_float_array (const short *in, float *out, int len) ;
+void src_float_to_short_array (const float *in, short *out, int len) ;
+
+void src_int_to_float_array (const int *in, float *out, int len) ;
+void src_float_to_int_array (const float *in, int *out, int len) ;
\ No newline at end of file
diff --git a/shared/macosx-arm64/include/sndfile.h b/shared/macosx-arm64/include/sndfile.h
new file mode 100644
index 0000000..8c4df97
--- /dev/null
+++ b/shared/macosx-arm64/include/sndfile.h
@@ -0,0 +1,496 @@
+#ifndef SNDFILE_H
+#define SNDFILE_H
+
+#define SNDFILE_1
+
+/** File format types. */
+enum
+{ /* Major formats. */
+ SF_FORMAT_WAV = 0x010000, /* Microsoft WAV format (little endian default). */
+ SF_FORMAT_AIFF = 0x020000, /* Apple/SGI AIFF format (big endian). */
+ SF_FORMAT_AU = 0x030000, /* Sun/NeXT AU format (big endian). */
+ SF_FORMAT_RAW = 0x040000, /* RAW PCM data. */
+ SF_FORMAT_PAF = 0x050000, /* Ensoniq PARIS file format. */
+ SF_FORMAT_SVX = 0x060000, /* Amiga IFF / SVX8 / SV16 format. */
+ SF_FORMAT_NIST = 0x070000, /* Sphere NIST format. */
+ SF_FORMAT_VOC = 0x080000, /* VOC files. */
+ SF_FORMAT_IRCAM = 0x0A0000, /* Berkeley/IRCAM/CARL */
+ SF_FORMAT_W64 = 0x0B0000, /* Sonic Foundry's 64 bit RIFF/WAV */
+ SF_FORMAT_MAT4 = 0x0C0000, /* Matlab (tm) V4.2 / GNU Octave 2.0 */
+ SF_FORMAT_MAT5 = 0x0D0000, /* Matlab (tm) V5.0 / GNU Octave 2.1 */
+ SF_FORMAT_PVF = 0x0E0000, /* Portable Voice Format */
+ SF_FORMAT_XI = 0x0F0000, /* Fasttracker 2 Extended Instrument */
+ SF_FORMAT_HTK = 0x100000, /* HMM Tool Kit format */
+ SF_FORMAT_SDS = 0x110000, /* Midi Sample Dump Standard */
+ SF_FORMAT_AVR = 0x120000, /* Audio Visual Research */
+ SF_FORMAT_WAVEX = 0x130000, /* MS WAVE with WAVEFORMATEX */
+ SF_FORMAT_SD2 = 0x160000, /* Sound Designer 2 */
+ SF_FORMAT_FLAC = 0x170000, /* FLAC lossless file format */
+ SF_FORMAT_CAF = 0x180000, /* Core Audio File format */
+ SF_FORMAT_WVE = 0x190000, /* Psion WVE format */
+ SF_FORMAT_OGG = 0x200000, /* Xiph OGG container */
+ SF_FORMAT_MPC2K = 0x210000, /* Akai MPC 2000 sampler */
+ SF_FORMAT_RF64 = 0x220000, /* RF64 WAV file */
+ SF_FORMAT_MPEG = 0x230000, /* MPEG-1/2 audio stream */
+
+ /* Subtypes from here on. */
+
+ SF_FORMAT_PCM_S8 = 0x0001, /* Signed 8 bit data */
+ SF_FORMAT_PCM_16 = 0x0002, /* Signed 16 bit data */
+ SF_FORMAT_PCM_24 = 0x0003, /* Signed 24 bit data */
+ SF_FORMAT_PCM_32 = 0x0004, /* Signed 32 bit data */
+
+ SF_FORMAT_PCM_U8 = 0x0005, /* Unsigned 8 bit data (WAV and RAW only) */
+
+ SF_FORMAT_FLOAT = 0x0006, /* 32 bit float data */
+ SF_FORMAT_DOUBLE = 0x0007, /* 64 bit float data */
+
+ SF_FORMAT_ULAW = 0x0010, /* U-Law encoded. */
+ SF_FORMAT_ALAW = 0x0011, /* A-Law encoded. */
+ SF_FORMAT_IMA_ADPCM = 0x0012, /* IMA ADPCM. */
+ SF_FORMAT_MS_ADPCM = 0x0013, /* Microsoft ADPCM. */
+
+ SF_FORMAT_GSM610 = 0x0020, /* GSM 6.10 encoding. */
+ SF_FORMAT_VOX_ADPCM = 0x0021, /* OKI / Dialogix ADPCM */
+
+ SF_FORMAT_NMS_ADPCM_16 = 0x0022, /* 16kbs NMS G721-variant encoding. */
+ SF_FORMAT_NMS_ADPCM_24 = 0x0023, /* 24kbs NMS G721-variant encoding. */
+ SF_FORMAT_NMS_ADPCM_32 = 0x0024, /* 32kbs NMS G721-variant encoding. */
+
+ SF_FORMAT_G721_32 = 0x0030, /* 32kbs G721 ADPCM encoding. */
+ SF_FORMAT_G723_24 = 0x0031, /* 24kbs G723 ADPCM encoding. */
+ SF_FORMAT_G723_40 = 0x0032, /* 40kbs G723 ADPCM encoding. */
+
+ SF_FORMAT_DWVW_12 = 0x0040, /* 12 bit Delta Width Variable Word encoding. */
+ SF_FORMAT_DWVW_16 = 0x0041, /* 16 bit Delta Width Variable Word encoding. */
+ SF_FORMAT_DWVW_24 = 0x0042, /* 24 bit Delta Width Variable Word encoding. */
+ SF_FORMAT_DWVW_N = 0x0043, /* N bit Delta Width Variable Word encoding. */
+
+ SF_FORMAT_DPCM_8 = 0x0050, /* 8 bit differential PCM (XI only) */
+ SF_FORMAT_DPCM_16 = 0x0051, /* 16 bit differential PCM (XI only) */
+
+ SF_FORMAT_VORBIS = 0x0060, /* Xiph Vorbis encoding. */
+ SF_FORMAT_OPUS = 0x0064, /* Xiph/Skype Opus encoding. */
+
+ SF_FORMAT_ALAC_16 = 0x0070, /* Apple Lossless Audio Codec (16 bit). */
+ SF_FORMAT_ALAC_20 = 0x0071, /* Apple Lossless Audio Codec (20 bit). */
+ SF_FORMAT_ALAC_24 = 0x0072, /* Apple Lossless Audio Codec (24 bit). */
+ SF_FORMAT_ALAC_32 = 0x0073, /* Apple Lossless Audio Codec (32 bit). */
+
+ SF_FORMAT_MPEG_LAYER_I = 0x0080, /* MPEG-1 Audio Layer I */
+ SF_FORMAT_MPEG_LAYER_II = 0x0081, /* MPEG-1 Audio Layer II */
+ SF_FORMAT_MPEG_LAYER_III = 0x0082, /* MPEG-2 Audio Layer III */
+
+ /* Endian-ness options. */
+
+ SF_ENDIAN_FILE = 0x00000000, /* Default file endian-ness. */
+ SF_ENDIAN_LITTLE = 0x10000000, /* Force little endian-ness. */
+ SF_ENDIAN_BIG = 0x20000000, /* Force big endian-ness. */
+ SF_ENDIAN_CPU = 0x30000000, /* Force CPU endian-ness. */
+
+ SF_FORMAT_SUBMASK = 0x0000FFFF,
+ SF_FORMAT_TYPEMASK = 0x0FFF0000,
+ SF_FORMAT_ENDMASK = 0x30000000
+};
+
+/** valid command numbers for the sf_command() interface */
+enum
+{ SFC_GET_LIB_VERSION = 0x1000,
+ SFC_GET_LOG_INFO = 0x1001,
+ SFC_GET_CURRENT_SF_INFO = 0x1002,
+
+
+ SFC_GET_NORM_DOUBLE = 0x1010,
+ SFC_GET_NORM_FLOAT = 0x1011,
+ SFC_SET_NORM_DOUBLE = 0x1012,
+ SFC_SET_NORM_FLOAT = 0x1013,
+ SFC_SET_SCALE_FLOAT_INT_READ = 0x1014,
+ SFC_SET_SCALE_INT_FLOAT_WRITE = 0x1015,
+
+ SFC_GET_SIMPLE_FORMAT_COUNT = 0x1020,
+ SFC_GET_SIMPLE_FORMAT = 0x1021,
+
+ SFC_GET_FORMAT_INFO = 0x1028,
+
+ SFC_GET_FORMAT_MAJOR_COUNT = 0x1030,
+ SFC_GET_FORMAT_MAJOR = 0x1031,
+ SFC_GET_FORMAT_SUBTYPE_COUNT = 0x1032,
+ SFC_GET_FORMAT_SUBTYPE = 0x1033,
+
+ SFC_CALC_SIGNAL_MAX = 0x1040,
+ SFC_CALC_NORM_SIGNAL_MAX = 0x1041,
+ SFC_CALC_MAX_ALL_CHANNELS = 0x1042,
+ SFC_CALC_NORM_MAX_ALL_CHANNELS = 0x1043,
+ SFC_GET_SIGNAL_MAX = 0x1044,
+ SFC_GET_MAX_ALL_CHANNELS = 0x1045,
+
+ SFC_SET_ADD_PEAK_CHUNK = 0x1050,
+
+ SFC_UPDATE_HEADER_NOW = 0x1060,
+ SFC_SET_UPDATE_HEADER_AUTO = 0x1061,
+
+ SFC_FILE_TRUNCATE = 0x1080,
+
+ SFC_SET_RAW_START_OFFSET = 0x1090,
+
+ /* Commands reserved for dithering, which is not implemented. */
+ SFC_SET_DITHER_ON_WRITE = 0x10A0,
+ SFC_SET_DITHER_ON_READ = 0x10A1,
+
+ SFC_GET_DITHER_INFO_COUNT = 0x10A2,
+ SFC_GET_DITHER_INFO = 0x10A3,
+
+ SFC_GET_EMBED_FILE_INFO = 0x10B0,
+
+ SFC_SET_CLIPPING = 0x10C0,
+ SFC_GET_CLIPPING = 0x10C1,
+
+ SFC_GET_CUE_COUNT = 0x10CD,
+ SFC_GET_CUE = 0x10CE,
+ SFC_SET_CUE = 0x10CF,
+
+ SFC_GET_INSTRUMENT = 0x10D0,
+ SFC_SET_INSTRUMENT = 0x10D1,
+
+ SFC_GET_LOOP_INFO = 0x10E0,
+
+ SFC_GET_BROADCAST_INFO = 0x10F0,
+ SFC_SET_BROADCAST_INFO = 0x10F1,
+
+ SFC_GET_CHANNEL_MAP_INFO = 0x1100,
+ SFC_SET_CHANNEL_MAP_INFO = 0x1101,
+
+ SFC_RAW_DATA_NEEDS_ENDSWAP = 0x1110,
+
+ /* Support for Wavex Ambisonics Format */
+ SFC_WAVEX_SET_AMBISONIC = 0x1200,
+ SFC_WAVEX_GET_AMBISONIC = 0x1201,
+
+ /*
+ ** RF64 files can be set so that on-close, writable files that have less
+ ** than 4GB of data in them are converted to RIFF/WAV, as per EBU
+ ** recommendations.
+ */
+ SFC_RF64_AUTO_DOWNGRADE = 0x1210,
+
+ SFC_SET_VBR_ENCODING_QUALITY = 0x1300,
+ SFC_SET_COMPRESSION_LEVEL = 0x1301,
+
+ /* Ogg format commands */
+ SFC_SET_OGG_PAGE_LATENCY_MS = 0x1302,
+ SFC_SET_OGG_PAGE_LATENCY = 0x1303,
+ SFC_GET_OGG_STREAM_SERIALNO = 0x1306,
+
+ SFC_GET_BITRATE_MODE = 0x1304,
+ SFC_SET_BITRATE_MODE = 0x1305,
+
+ /* Cart Chunk support */
+ SFC_SET_CART_INFO = 0x1400,
+ SFC_GET_CART_INFO = 0x1401,
+
+ /* Opus files original samplerate metadata */
+ SFC_SET_ORIGINAL_SAMPLERATE = 0x1500,
+ SFC_GET_ORIGINAL_SAMPLERATE = 0x1501,
+
+ /* Following commands for testing only. */
+ SFC_TEST_IEEE_FLOAT_REPLACE = 0x6001,
+
+ /*
+ ** These SFC_SET_ADD_* values are deprecated and will disappear at some
+ ** time in the future. They are guaranteed to be here up to and
+ ** including version 1.0.8 to avoid breakage of existing software.
+ ** They currently do nothing and will continue to do nothing.
+ */
+ SFC_SET_ADD_HEADER_PAD_CHUNK = 0x1051,
+
+ SFC_SET_ADD_DITHER_ON_WRITE = 0x1070,
+ SFC_SET_ADD_DITHER_ON_READ = 0x1071
+};
+
+/** String types that can be set and read from files. */
+enum
+{ SF_STR_TITLE = 0x01,
+ SF_STR_COPYRIGHT = 0x02,
+ SF_STR_SOFTWARE = 0x03,
+ SF_STR_ARTIST = 0x04,
+ SF_STR_COMMENT = 0x05,
+ SF_STR_DATE = 0x06,
+ SF_STR_ALBUM = 0x07,
+ SF_STR_LICENSE = 0x08,
+ SF_STR_TRACKNUMBER = 0x09,
+ SF_STR_GENRE = 0x10
+} ;
+
+/** Start and End index when doing metadata transcoding. */
+#define SF_STR_FIRST SF_STR_TITLE
+#define SF_STR_LAST SF_STR_GENRE
+
+enum
+{ /* True and false */
+ SF_FALSE = 0,
+ SF_TRUE = 1,
+
+ /* Modes for opening files. */
+ SFM_READ = 0x10,
+ SFM_WRITE = 0x20,
+ SFM_RDWR = 0x30,
+
+ SF_AMBISONIC_NONE = 0x40,
+ SF_AMBISONIC_B_FORMAT = 0x41
+};
+
+/** Error codes. */
+enum
+{ SF_ERR_NO_ERROR = 0,
+ SF_ERR_UNRECOGNISED_FORMAT = 1,
+ SF_ERR_SYSTEM = 2,
+ SF_ERR_MALFORMED_FILE = 3,
+ SF_ERR_UNSUPPORTED_ENCODING = 4
+};
+
+/** Channel map values (used with SFC_SET/GET_CHANNEL_MAP). */
+enum
+{ SF_CHANNEL_MAP_INVALID = 0,
+ SF_CHANNEL_MAP_MONO = 1,
+ SF_CHANNEL_MAP_LEFT, /* Apple calls this 'Left' */
+ SF_CHANNEL_MAP_RIGHT, /* Apple calls this 'Right' */
+ SF_CHANNEL_MAP_CENTER, /* Apple calls this 'Center' */
+ SF_CHANNEL_MAP_FRONT_LEFT,
+ SF_CHANNEL_MAP_FRONT_RIGHT,
+ SF_CHANNEL_MAP_FRONT_CENTER,
+ SF_CHANNEL_MAP_REAR_CENTER, /* Apple calls this 'Center Surround', Msft calls this 'Back Center' */
+ SF_CHANNEL_MAP_REAR_LEFT, /* Apple calls this 'Left Surround', Msft calls this 'Back Left' */
+ SF_CHANNEL_MAP_REAR_RIGHT, /* Apple calls this 'Right Surround', Msft calls this 'Back Right' */
+ SF_CHANNEL_MAP_LFE, /* Apple calls this 'LFEScreen', Msft calls this 'Low Frequency' */
+ SF_CHANNEL_MAP_FRONT_LEFT_OF_CENTER, /* Apple calls this 'Left Center' */
+ SF_CHANNEL_MAP_FRONT_RIGHT_OF_CENTER, /* Apple calls this 'Right Center */
+ SF_CHANNEL_MAP_SIDE_LEFT, /* Apple calls this 'Left Surround Direct' */
+ SF_CHANNEL_MAP_SIDE_RIGHT, /* Apple calls this 'Right Surround Direct' */
+ SF_CHANNEL_MAP_TOP_CENTER, /* Apple calls this 'Top Center Surround' */
+ SF_CHANNEL_MAP_TOP_FRONT_LEFT, /* Apple calls this 'Vertical Height Left' */
+ SF_CHANNEL_MAP_TOP_FRONT_RIGHT, /* Apple calls this 'Vertical Height Right' */
+ SF_CHANNEL_MAP_TOP_FRONT_CENTER, /* Apple calls this 'Vertical Height Center' */
+ SF_CHANNEL_MAP_TOP_REAR_LEFT, /* Apple and MS call this 'Top Back Left' */
+ SF_CHANNEL_MAP_TOP_REAR_RIGHT, /* Apple and MS call this 'Top Back Right' */
+ SF_CHANNEL_MAP_TOP_REAR_CENTER, /* Apple and MS call this 'Top Back Center' */
+
+ SF_CHANNEL_MAP_AMBISONIC_B_W,
+ SF_CHANNEL_MAP_AMBISONIC_B_X,
+ SF_CHANNEL_MAP_AMBISONIC_B_Y,
+ SF_CHANNEL_MAP_AMBISONIC_B_Z,
+
+ SF_CHANNEL_MAP_MAX
+};
+
+/** Bitrate mode values (for use with SFC_GET/SET_BITRATE_MODE) */
+enum
+{ SF_BITRATE_MODE_CONSTANT = 0,
+ SF_BITRATE_MODE_AVERAGE,
+ SF_BITRATE_MODE_VARIABLE
+};
+
+/* A SNDFILE* pointer can be passed around much like stdio.h's FILE* pointer. */
+typedef struct sf_private_tag SNDFILE ;
+
+/* The following typedef is system specific and is defined when libsndfile is
+** compiled. sf_count_t will be a 64 bit value when the underlying OS allows
+** 64 bit file offsets.
+** On windows, we need to allow the same header file to be compiler by both GCC
+** and the Microsoft compiler.
+*/
+
+typedef int64_t sf_count_t ;
+#ifndef SF_COUNT_MAX
+#define SF_COUNT_MAX INT64_MAX
+#endif
+
+/* A pointer to a SF_INFO structure is passed to sf_open () and filled in.
+** On write, the SF_INFO structure is filled in by the user and passed into
+** sf_open ().
+*/
+struct SF_INFO
+{ sf_count_t frames ; /* Used to be called samples. Changed to avoid confusion. */
+ int samplerate ;
+ int channels ;
+ int format ;
+ int sections ;
+ int seekable ;
+} ;
+
+typedef struct SF_INFO SF_INFO ;
+
+/* The SF_FORMAT_INFO struct is used to retrieve information about the sound
+** file formats libsndfile supports using the sf_command () interface.
+*/
+typedef struct
+{ int format ;
+ const char *name ;
+ const char *extension ;
+} SF_FORMAT_INFO;
+
+/* Open the specified file for read, write or both. On error, this will
+** return a NULL pointer. To find the error number, pass a NULL SNDFILE
+** to sf_strerror ().
+** All calls to sf_open() should be matched with a call to sf_close().
+*/
+SNDFILE* sf_open (const char *path, int mode, SF_INFO *sfinfo) ;
+
+/* Use the existing file descriptor to create a SNDFILE object. If close_desc
+** is TRUE, the file descriptor will be closed when sf_close() is called. If
+** it is FALSE, the descriptor will not be closed.
+** When passed a descriptor like this, the library will assume that the start
+** of file header is at the current file offset. This allows sound files within
+** larger container files to be read and/or written.
+** On error, this will return a NULL pointer. To find the error number, pass a
+** NULL SNDFILE to sf_strerror ().
+** All calls to sf_open_fd() should be matched with a call to sf_close().
+*/
+
+SNDFILE* sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc) ;
+
+
+/* sf_error () returns a error number which can be translated to a text
+** string using sf_error_number().
+*/
+
+int sf_error (SNDFILE *sndfile) ;
+
+
+/* sf_strerror () returns to the caller a pointer to the current error message for
+** the given SNDFILE.
+*/
+
+const char* sf_strerror (SNDFILE *sndfile) ;
+
+
+/* sf_error_number () allows the retrieval of the error string for each internal
+** error number.
+**
+*/
+
+const char* sf_error_number (int errnum) ;
+
+
+/* The following two error functions are deprecated but they will remain in the
+** library for the foreseeable future. The function sf_strerror() should be used
+** in their place.
+*/
+
+int sf_perror (SNDFILE *sndfile) ;
+int sf_error_str (SNDFILE *sndfile, char* str, size_t len) ;
+
+
+/* Allow the caller to retrieve information from or change aspects of the
+** library behaviour.
+*/
+
+int sf_command (SNDFILE *sndfile, int command, void *data, int datasize) ;
+
+
+/* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */
+
+int sf_format_check (const SF_INFO *info) ;
+
+
+
+/* Functions for retrieving and setting string data within sound files.
+** Not all file types support this features; AIFF and WAV do. For both
+** functions, the str_type parameter must be one of the SF_STR_* values
+** defined above.
+** On error, sf_set_string() returns non-zero while sf_get_string()
+** returns NULL.
+*/
+
+int sf_set_string (SNDFILE *sndfile, int str_type, const char* str) ;
+
+const char* sf_get_string (SNDFILE *sndfile, int str_type) ;
+
+/* Return the library version string. */
+const char * sf_version_string (void) ;
+
+/* Return the current byterate at this point in the file. The byte rate in this
+** case is the number of bytes per second of audio data. For instance, for a
+** stereo, 18 bit PCM encoded file with an 16kHz sample rate, the byte rate
+** would be 2 (stereo) * 2 (two bytes per sample) * 16000 => 64000 bytes/sec.
+** For some file formats the returned value will be accurate and exact, for some
+** it will be a close approximation, for some it will be the average bitrate for
+** the whole file and for some it will be a time varying value that was accurate
+** when the file was most recently read or written.
+** To get the bitrate, multiple this value by 8.
+** Returns -1 for unknown.
+*/
+int sf_current_byterate (SNDFILE *sndfile) ;
+
+/* Functions for reading/writing the waveform data of a sound file.
+*/
+
+sf_count_t sf_read_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
+sf_count_t sf_write_raw (SNDFILE *sndfile, const void *ptr, sf_count_t bytes) ;
+
+/* Functions for reading and writing the data chunk in terms of frames.
+** The number of items actually read/written = frames * number of channels.
+** sf_xxxx_raw read/writes the raw data bytes from/to the file
+** sf_xxxx_short passes data in the native short format
+** sf_xxxx_int passes data in the native int format
+** sf_xxxx_float passes data in the native float format
+** sf_xxxx_double passes data in the native double format
+** All of these read/write function return number of frames read/written.
+*/
+
+sf_count_t sf_readf_short (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_short (SNDFILE *sndfile, const short *ptr, sf_count_t frames) ;
+
+sf_count_t sf_readf_int (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_int (SNDFILE *sndfile, const int *ptr, sf_count_t frames) ;
+
+sf_count_t sf_readf_float (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_float (SNDFILE *sndfile, const float *ptr, sf_count_t frames) ;
+
+sf_count_t sf_readf_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_double (SNDFILE *sndfile, const double *ptr, sf_count_t frames) ;
+
+
+/* Functions for reading and writing the data chunk in terms of items.
+** Otherwise similar to above.
+** All of these read/write function return number of items read/written.
+*/
+
+sf_count_t sf_read_short (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
+sf_count_t sf_write_short (SNDFILE *sndfile, const short *ptr, sf_count_t items) ;
+
+sf_count_t sf_read_int (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
+sf_count_t sf_write_int (SNDFILE *sndfile, const int *ptr, sf_count_t items) ;
+
+sf_count_t sf_read_float (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
+sf_count_t sf_write_float (SNDFILE *sndfile, const float *ptr, sf_count_t items) ;
+
+sf_count_t sf_read_double (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
+sf_count_t sf_write_double (SNDFILE *sndfile, const double *ptr, sf_count_t items) ;
+
+
+/* Close the SNDFILE and clean up all memory allocations associated with this
+** file.
+** Returns 0 on success, or an error number.
+*/
+
+int sf_close (SNDFILE *sndfile) ;
+
+
+/* If the file is opened SFM_WRITE or SFM_RDWR, call fsync() on the file
+** to force the writing of data to disk. If the file is opened SFM_READ
+** no action is taken.
+*/
+
+void sf_write_sync (SNDFILE *sndfile) ;
+
+
+
+/* The function sf_wchar_open() is Windows Only!
+** Open a file passing in a Windows Unicode filename. Otherwise, this is
+** the same as sf_open().
+*/
+
+/* #ifdef _WIN32
+** SNDFILE* sf_wchar_open (const wchar_t *wpath, int mode, SF_INFO *sfinfo) ;
+** #endif
+*/
\ No newline at end of file
diff --git a/shared/macosx-arm64/include/transformersphp.h b/shared/macosx-arm64/include/transformersphp.h
new file mode 100644
index 0000000..7c9c4b8
--- /dev/null
+++ b/shared/macosx-arm64/include/transformersphp.h
@@ -0,0 +1,19 @@
+#ifndef FAST_TRANSFORMERS_UTILS_H
+#define FAST_TRANSFORMERS_UTILS_H
+
+enum {
+ LOG_MEL_NONE = 0,
+ LOG_MEL_LOG = 1,
+ LOG_MEL_LOG10 = 2,
+ LOG_MEL_DB = 3
+};
+
+void pad_reflect(float *input, int length, float *padded, int padded_length);
+
+void spectrogram(
+ float *waveform, int waveform_length, float *spectrogram, int spectrogram_length, int hop_length, int fft_length,
+ float *window,int window_length, int d1, int d1_max, float power, int center, float preemphasis, float *mel_filters,
+ int num_mel_filters, int num_frequency_bins, float mel_floor, int log_mel, int remove_dc_offset, int do_pad, int transpose
+);
+
+#endif // FAST_TRANSFORMERS_UTILS_H
diff --git a/shared/macosx-arm64/lib/libomp.dylib b/shared/macosx-arm64/lib/libomp.dylib
new file mode 100644
index 0000000..daa35e6
Binary files /dev/null and b/shared/macosx-arm64/lib/libomp.dylib differ
diff --git a/shared/macosx-arm64/lib/libonnxruntime.1.21.0.dylib b/shared/macosx-arm64/lib/libonnxruntime.1.21.0.dylib
new file mode 100755
index 0000000..e8f233d
Binary files /dev/null and b/shared/macosx-arm64/lib/libonnxruntime.1.21.0.dylib differ
diff --git a/shared/macosx-arm64/lib/libopenblas.0.3.28.dylib b/shared/macosx-arm64/lib/libopenblas.0.3.28.dylib
new file mode 100755
index 0000000..77df571
Binary files /dev/null and b/shared/macosx-arm64/lib/libopenblas.0.3.28.dylib differ
diff --git a/shared/macosx-arm64/lib/librindowmatlib.1.1.1.dylib b/shared/macosx-arm64/lib/librindowmatlib.1.1.1.dylib
new file mode 100755
index 0000000..15b3e17
Binary files /dev/null and b/shared/macosx-arm64/lib/librindowmatlib.1.1.1.dylib differ
diff --git a/shared/macosx-arm64/lib/libsamplerate.0.2.2.dylib b/shared/macosx-arm64/lib/libsamplerate.0.2.2.dylib
new file mode 100644
index 0000000..d68e8d7
Binary files /dev/null and b/shared/macosx-arm64/lib/libsamplerate.0.2.2.dylib differ
diff --git a/shared/macosx-arm64/lib/libsndfile.1.2.2.dylib b/shared/macosx-arm64/lib/libsndfile.1.2.2.dylib
new file mode 100644
index 0000000..144af7c
Binary files /dev/null and b/shared/macosx-arm64/lib/libsndfile.1.2.2.dylib differ
diff --git a/shared/macosx-arm64/lib/libtransformersphp.1.0.0.dylib b/shared/macosx-arm64/lib/libtransformersphp.1.0.0.dylib
new file mode 100755
index 0000000..a9cf5a3
Binary files /dev/null and b/shared/macosx-arm64/lib/libtransformersphp.1.0.0.dylib differ
diff --git a/shared/macosx-arm64/lib/libvips.42.dylib b/shared/macosx-arm64/lib/libvips.42.dylib
new file mode 100644
index 0000000..941c7d6
Binary files /dev/null and b/shared/macosx-arm64/lib/libvips.42.dylib differ
diff --git a/shared/macosx-x86_64/THIRD_PARTY_NOTICES.md b/shared/macosx-x86_64/THIRD_PARTY_NOTICES.md
new file mode 100644
index 0000000..0cf3657
--- /dev/null
+++ b/shared/macosx-x86_64/THIRD_PARTY_NOTICES.md
@@ -0,0 +1,52 @@
+# Third-party notices
+
+TransformersPHP includes compiled binaries of third-party libraries as a convenience to users. These binaries are
+distributed to facilitate the functionality of TransformersPHP, but TransformersPHP does not claim ownership of the
+binaries or the underlying libraries. The original authors and contributors of these libraries retain all rights. It is
+the user's responsibility to ensure compliance with the respective licenses of these libraries when using or
+distributing the bundled binaries.
+
+Below is a list of the third-party libraries included with TransformersPHP, along with their respective licenses and
+other relevant information.
+
+| Library | Used under the terms of |
+|---------------|-----------------------------------------------------------------------------------------------------------|
+| OpenMP | MIT License |
+| OnnxRuntime | MIT License |
+| OpenBlas | BSD 3-Clause License |
+| Rindow Matlib | BSD 3-Clause License |
+| LibSamplerate | BSD 2-Clause License |
+| Libsndfile | LGPL 2.1 License |
+| aom | BSD 2-Clause + [Alliance for Open Media Patent License 1.0](https://aomedia.org/license/patent-license/) |
+| cairo | Mozilla Public License 2.0 |
+| cgif | MIT Licence |
+| expat | MIT Licence |
+| fontconfig | [fontconfig Licence](https://gitlab.freedesktop.org/fontconfig/fontconfig/blob/main/COPYING) (BSD-like) |
+| freetype | [freetype Licence](https://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/docs/FTL.TXT) (BSD-like) |
+| fribidi | LGPLv3 |
+| glib | LGPLv3 |
+| harfbuzz | MIT Licence |
+| highway | Apache-2.0 License, BSD 3-Clause |
+| lcms | MIT Licence |
+| libarchive | BSD 2-Clause |
+| libexif | LGPLv3 |
+| libffi | MIT Licence |
+| libheif | LGPLv3 |
+| libimagequant | [BSD 2-Clause](https://github.com/lovell/libimagequant/blob/main/COPYRIGHT) |
+| libnsgif | MIT Licence |
+| libpng | [libpng License](https://github.com/pnggroup/libpng/blob/master/LICENSE) |
+| librsvg | LGPLv3 |
+| libspng | [BSD 2-Clause, libpng License](https://github.com/randy408/libspng/blob/master/LICENSE) |
+| libtiff | [libtiff License](https://gitlab.com/libtiff/libtiff/blob/master/LICENSE.md) (BSD-like) |
+| libvips | LGPLv3 |
+| libwebp | New BSD License |
+| libxml2 | MIT Licence |
+| mozjpeg | [zlib License, IJG License, BSD-3-Clause](https://github.com/mozilla/mozjpeg/blob/master/LICENSE.md) |
+| pango | LGPLv3 |
+| pixman | MIT Licence |
+| proxy-libintl | LGPLv3 |
+| zlib-ng | [zlib Licence](https://github.com/zlib-ng/zlib-ng/blob/develop/LICENSE.md) |
+
+---
+
+
diff --git a/shared/macosx-x86_64/include/buffer.h b/shared/macosx-x86_64/include/buffer.h
new file mode 100644
index 0000000..e086179
--- /dev/null
+++ b/shared/macosx-x86_64/include/buffer.h
@@ -0,0 +1,5 @@
+#define FFI_SCOPE "Rindow\\Math\\Buffer\\FFI"
+
+typedef struct _rindow_complex_float { float real, imag; } rindow_complex_float;
+typedef struct _rindow_complex_double { double real, imag; } rindow_complex_double;
+//typedef struct { xdouble real, imag; } openblas_complex_xdouble;
diff --git a/shared/macosx-x86_64/include/matlib.h b/shared/macosx-x86_64/include/matlib.h
new file mode 100644
index 0000000..612189c
--- /dev/null
+++ b/shared/macosx-x86_64/include/matlib.h
@@ -0,0 +1,397 @@
+#ifndef RINDOW_MATLIB_H_
+#define RINDOW_MATLIB_H_
+
+#include
+
+enum rindow_matlib_dtype
+{
+ rindow_matlib_dtype_unknown = 0,
+ rindow_matlib_dtype_bool = 1,
+ rindow_matlib_dtype_int8 = 2,
+ rindow_matlib_dtype_int16 = 3,
+ rindow_matlib_dtype_int32 = 4,
+ rindow_matlib_dtype_int64 = 5,
+ rindow_matlib_dtype_uint8 = 6,
+ rindow_matlib_dtype_uint16 = 7,
+ rindow_matlib_dtype_uint32 = 8,
+ rindow_matlib_dtype_uint64 = 9,
+ rindow_matlib_dtype_float8 = 10,
+ rindow_matlib_dtype_float16 = 11,
+ rindow_matlib_dtype_float32 = 12,
+ rindow_matlib_dtype_float64 = 13,
+ rindow_matlib_dtype_complex16 = 14,
+ rindow_matlib_dtype_complex32 = 15,
+ rindow_matlib_dtype_complex64 = 16,
+ rindow_matlib_dtype_complex128 = 17
+};
+
+#if _MSC_VER
+#if !defined(RINDOW_FUNC)
+#if defined(RINDOW_COMPILING_DLL)
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL extern __declspec(dllexport)
+#elif defined(RINDOW_MATLIB_INCLUDING_SOURCE)
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL
+#else
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL extern __declspec(dllimport)
+#endif
+#endif
+#else // _MSC_VER
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL extern
+#endif // _MSC_VER
+
+#define RINDOW_MATLIB_SUCCESS 0
+#define RINDOW_MATLIB_E_MEM_ALLOC_FAILURE -101
+#define RINDOW_MATLIB_E_PERM_OUT_OF_RANGE -102
+#define RINDOW_MATLIB_E_DUP_AXIS -103
+#define RINDOW_MATLIB_E_UNSUPPORTED_DATA_TYPE -104
+#define RINDOW_MATLIB_E_UNMATCH_IMAGE_BUFFER_SIZE -105
+#define RINDOW_MATLIB_E_UNMATCH_COLS_BUFFER_SIZE -106
+#define RINDOW_MATLIB_E_INVALID_SHAPE_OR_PARAM -107
+#define RINDOW_MATLIB_E_IMAGES_OUT_OF_RANGE -108
+#define RINDOW_MATLIB_E_COLS_OUT_OF_RANGE -109
+
+#define RINDOW_MATLIB_NO_TRANS 111
+#define RINDOW_MATLIB_TRANS 112
+// #define RINDOW_MATLIB_CONJ_TRANS 113
+// #define RINDOW_MATLIB_CONJ_NO_TRANS 114
+
+// Matlib is compiled for sequential use
+#define RINDOW_MATLIB_SEQUENTIAL 0
+// Matlib is compiled using normal threading model
+#define RINDOW_MATLIB_THREAD 1
+// Matlib is compiled using OpenMP threading model
+#define RINDOW_MATLIB_OPENMP 2
+
+static inline int32_t rindow_matlib_common_dtype_to_valuesize(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_bool:
+ case rindow_matlib_dtype_int8:
+ case rindow_matlib_dtype_uint8:
+ case rindow_matlib_dtype_float8:
+ return 1;
+ case rindow_matlib_dtype_int16:
+ case rindow_matlib_dtype_uint16:
+ case rindow_matlib_dtype_float16:
+ case rindow_matlib_dtype_complex16:
+ return 2;
+ case rindow_matlib_dtype_int32:
+ case rindow_matlib_dtype_uint32:
+ case rindow_matlib_dtype_float32:
+ case rindow_matlib_dtype_complex32:
+ return 4;
+ case rindow_matlib_dtype_int64:
+ case rindow_matlib_dtype_uint64:
+ case rindow_matlib_dtype_float64:
+ case rindow_matlib_dtype_complex64:
+ return 8;
+ case rindow_matlib_dtype_complex128:
+ return 16;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_int(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_int8:
+ case rindow_matlib_dtype_uint8:
+ case rindow_matlib_dtype_int16:
+ case rindow_matlib_dtype_uint16:
+ case rindow_matlib_dtype_int32:
+ case rindow_matlib_dtype_uint32:
+ case rindow_matlib_dtype_int64:
+ case rindow_matlib_dtype_uint64:
+ return 1;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_float(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_float8:
+ case rindow_matlib_dtype_float16:
+ case rindow_matlib_dtype_float32:
+ case rindow_matlib_dtype_float64:
+ return 1;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_complex(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_complex16:
+ case rindow_matlib_dtype_complex32:
+ case rindow_matlib_dtype_complex64:
+ case rindow_matlib_dtype_complex128:
+ return 1;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_bool(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_bool:
+ return 1;
+ }
+ return 0;
+}
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_common_get_nprocs(void);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_common_get_num_threads(void);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_common_get_parallel(void);
+ RINDOW_FUNC_DECL char *rindow_matlib_common_get_version(void);
+
+ RINDOW_FUNC_DECL void *rindow_matlib_common_get_address(int32_t dtype, void *buffer, int32_t offset);
+
+ RINDOW_FUNC_DECL float rindow_matlib_s_sum(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL double rindow_matlib_d_sum(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL int64_t rindow_matlib_i_sum(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_imax(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_imax(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_imax(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_imin(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_imin(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_imin(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_increment(int32_t n, float *x, int32_t incX, float alpha, float beta);
+ RINDOW_FUNC_DECL void rindow_matlib_d_increment(int32_t n, double *x, int32_t incX, double alpha, double beta);
+ RINDOW_FUNC_DECL void rindow_matlib_s_reciprocal(int32_t n, float *x, int32_t incX, float alpha, float beta);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reciprocal(int32_t n, double *x, int32_t incX, double alpha, double beta);
+ RINDOW_FUNC_DECL void rindow_matlib_s_maximum(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_maximum(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_minimum(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_minimum(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_greater(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_greater(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_greater_equal(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_greater_equal(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_less(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_less(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_less_equal(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_less_equal(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_multiply(int32_t trans, int32_t m, int32_t n, float *x, int32_t incX, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_multiply(int32_t trans, int32_t m, int32_t n, double *x, int32_t incX, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_add(int32_t trans, int32_t m, int32_t n, float alpha, float *x, int32_t incX, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_add(int32_t trans, int32_t m, int32_t n, double alpha, double *x, int32_t incX, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_duplicate(int32_t trans, int32_t m, int32_t n, float *x, int32_t incX, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_duplicate(int32_t trans, int32_t m, int32_t n, double *x, int32_t incX, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_masking(int32_t m, int32_t n, int32_t k, int32_t len, float fill, int32_t mode, uint8_t *x, float *a);
+ RINDOW_FUNC_DECL void rindow_matlib_d_masking(int32_t m, int32_t n, int32_t k, int32_t len, double fill, int32_t mode, uint8_t *x, double *a);
+ RINDOW_FUNC_DECL void rindow_matlib_i_masking(int32_t dtype, int32_t m, int32_t n, int32_t k, int32_t len, void *fill, int32_t mode, uint8_t *x, void *a);
+ RINDOW_FUNC_DECL void rindow_matlib_s_square(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_square(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_sqrt(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_sqrt(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_rsqrt(int32_t n, float alpha, float *x, int32_t incX, float beta);
+ RINDOW_FUNC_DECL void rindow_matlib_d_rsqrt(int32_t n, double alpha, double *x, int32_t incX, double beta);
+ RINDOW_FUNC_DECL void rindow_matlib_s_pow(int32_t trans, int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_pow(int32_t trans, int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_exp(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_exp(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_log(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_log(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_tanh(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_tanh(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_sin(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_sin(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_cos(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_cos(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_tan(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_tan(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_zeros(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_zeros(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_i_zeros(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_onehot(int32_t dtype, int32_t m, int32_t n, void *x, int32_t incX, float alpha, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_onehot(int32_t dtype, int32_t m, int32_t n, void *x, int32_t incX, double alpha, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_softmax(int32_t m, int32_t n, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_softmax(int32_t m, int32_t n, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_equal(int32_t n, float *x, int32_t incX, float *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_equal(int32_t n, double *x, int32_t incX, double *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_i_equal(int32_t dtype, int32_t n, void *x, int32_t incX, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_notequal(int32_t n, float *x, int32_t incX, float *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_notequal(int32_t n, double *x, int32_t incX, double *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_i_notequal(int32_t dtype, int32_t n, void *x, int32_t incX, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_not(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_not(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_i_not(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_astype(int32_t n, int32_t from_dtype, void *x, int32_t incX, int32_t to_dtype, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_matrixcopy(int32_t trans, int32_t m, int32_t n, float alpha, float *a, int32_t ldA, float *b, int32_t ldB);
+ RINDOW_FUNC_DECL void rindow_matlib_d_matrixcopy(int32_t trans, int32_t m, int32_t n, double alpha, double *a, int32_t ldA, double *b, int32_t ldB);
+ RINDOW_FUNC_DECL void rindow_matlib_s_imagecopy(int32_t height, int32_t width, int32_t channels, float *a, float *b,
+ int32_t channelsFirst, int32_t heightShift, int32_t widthShift, int32_t verticalFlip, int32_t horizontalFlip, int32_t rgbFlip);
+ RINDOW_FUNC_DECL void rindow_matlib_d_imagecopy(int32_t height, int32_t width, int32_t channels, double *a, double *b,
+ int32_t channelsFirst, int32_t heightShift, int32_t widthShift, int32_t verticalFlip, int32_t horizontalFlip, int32_t rgbFlip);
+ RINDOW_FUNC_DECL void rindow_matlib_i8_imagecopy(int32_t height, int32_t width, int32_t channels, uint8_t *a, uint8_t *b,
+ int32_t channelsFirst, int32_t heightShift, int32_t widthShift, int32_t verticalFlip, int32_t horizontalFlip, int32_t rgbFlip);
+ RINDOW_FUNC_DECL void rindow_matlib_fill(int32_t dtype, int32_t n, void *value, void *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_nan2num(int32_t n, float *x, int32_t incX, float alpha);
+ RINDOW_FUNC_DECL void rindow_matlib_d_nan2num(int32_t n, double *x, int32_t incX, double alpha);
+ RINDOW_FUNC_DECL void rindow_matlib_s_isnan(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_isnan(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_searchsorted(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX,
+ int32_t right, int32_t dtype, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_searchsorted(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX,
+ int32_t right, int32_t dtype, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_cumsum(int32_t n, float *x, int32_t incX, int32_t exclusive, int32_t reverse, float *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_cumsum(int32_t n, double *x, int32_t incX, int32_t exclusive, int32_t reverse, double *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_cumsumb(int32_t m, int32_t n, int32_t k, float *a, int32_t exclusive, int32_t reverse, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_cumsumb(int32_t m, int32_t n, int32_t k, double *a, int32_t exclusive, int32_t reverse, double *b);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_transpose(int32_t ndim, int32_t *shape, int32_t *perm, float *a, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_transpose(int32_t ndim, int32_t *shape, int32_t *perm, double *a, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_transpose(int32_t dtype, int32_t ndim, int32_t *shape, int32_t *perm, void *a, void *b);
+ RINDOW_FUNC_DECL void rindow_matlib_s_bandpart(int32_t m, int32_t n, int32_t k, float *a, int32_t lower, int32_t upper);
+ RINDOW_FUNC_DECL void rindow_matlib_d_bandpart(int32_t m, int32_t n, int32_t k, double *a, int32_t lower, int32_t upper);
+ RINDOW_FUNC_DECL void rindow_matlib_i_bandpart(int32_t m, int32_t n, int32_t k, int32_t dtype, void *a, int32_t lower, int32_t upper);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_gather(int32_t reverse, int32_t addMode, int32_t n, int32_t k, int32_t numClass, int32_t dtype, void *x, float *a, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_gather(int32_t reverse, int32_t addMode, int32_t n, int32_t k, int32_t numClass, int32_t dtype, void *x, double *a, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_gather(int32_t reverse, int32_t addMode, int32_t n, int32_t k, int32_t numClass, int32_t dtype, void *x, int32_t data_dtype, void *a, void *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_reducegather(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t numClass, int32_t dtype, void *x, float *a, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_reducegather(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t numClass, int32_t dtype, void *x, double *a, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_reducegather(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t numClass, int32_t dtype, void *x, int32_t data_dtype, void *a, void *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_gatherb(int32_t reverse, int32_t addMode, int32_t batches, int32_t m, int32_t n, int32_t k, int32_t len, int32_t numClass, float *a, int32_t *x, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_gatherb(int32_t reverse, int32_t addMode, int32_t batches, int32_t m, int32_t n, int32_t k, int32_t len, int32_t numClass, double *a, int32_t *x, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_gatherb(int32_t reverse, int32_t addMode, int32_t batches, int32_t m, int32_t n, int32_t k, int32_t len, int32_t numClass, int32_t dtype, void *a, int32_t *x, void *b);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_einsum(
+ const int32_t depth,
+ const int32_t *sizeOfIndices,
+ const float *a,
+ const int32_t *ldA,
+ const float *b,
+ const int32_t *ldB,
+ float *c,
+ const int32_t ndimC);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_einsum(
+ const int32_t depth,
+ const int32_t *sizeOfIndices,
+ const double *a,
+ const int32_t *ldA,
+ const double *b,
+ const int32_t *ldB,
+ double *c,
+ const int32_t ndimC);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_einsum4p1(
+ int32_t dim0,
+ int32_t dim1,
+ int32_t dim2,
+ int32_t dim3,
+ int32_t dim4,
+ float *a,
+ int32_t ldA0,
+ int32_t ldA1,
+ int32_t ldA2,
+ int32_t ldA3,
+ int32_t ldA4,
+ float *b,
+ int32_t ldB0,
+ int32_t ldB1,
+ int32_t ldB2,
+ int32_t ldB3,
+ int32_t ldB4,
+ float *c);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_einsum4p1(
+ int32_t dim0,
+ int32_t dim1,
+ int32_t dim2,
+ int32_t dim3,
+ int32_t dim4,
+ double *a,
+ int32_t ldA0,
+ int32_t ldA1,
+ int32_t ldA2,
+ int32_t ldA3,
+ int32_t ldA4,
+ double *b,
+ int32_t ldB0,
+ int32_t ldB1,
+ int32_t ldB2,
+ int32_t ldB3,
+ int32_t ldB4,
+ double *c);
+ RINDOW_FUNC_DECL void rindow_matlib_s_slice(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t k, int32_t size, float *a, int32_t incA, float *y, int32_t incY, int32_t startAxis0, int32_t sizeAxis0, int32_t startAxis1, int32_t sizeAxis1, int32_t startAxis2, int32_t sizeAxis2);
+ RINDOW_FUNC_DECL void rindow_matlib_d_slice(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t k, int32_t size, double *a, int32_t incA, double *y, int32_t incY, int32_t startAxis0, int32_t sizeAxis0, int32_t startAxis1, int32_t sizeAxis1, int32_t startAxis2, int32_t sizeAxis2);
+ RINDOW_FUNC_DECL void rindow_matlib_i_slice(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t k, int32_t size, int32_t dtype, void *a, int32_t incA, void *y, int32_t incY, int32_t startAxis0, int32_t sizeAxis0, int32_t startAxis1, int32_t sizeAxis1, int32_t startAxis2, int32_t sizeAxis2);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_repeat(int32_t m, int32_t k, int32_t repeats, float *a, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_repeat(int32_t m, int32_t k, int32_t repeats, double *a, double *b);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_reducesum(int32_t m, int32_t n, int32_t k, float *a, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reducesum(int32_t m, int32_t n, int32_t k, double *a, double *b);
+ RINDOW_FUNC_DECL void rindow_matlib_s_reducemax(int32_t m, int32_t n, int32_t k, float *a, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reducemax(int32_t m, int32_t n, int32_t k, double *a, double *b);
+ RINDOW_FUNC_DECL void rindow_matlib_s_reduceargmax(int32_t m, int32_t n, int32_t k, float *a, int32_t dtype, void *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reduceargmax(int32_t m, int32_t n, int32_t k, double *a, int32_t dtype, void *b);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_randomuniform(int32_t n, float *x, int32_t incX, float low, float high, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_d_randomuniform(int32_t n, double *x, int32_t incX, double low, double high, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_i_randomuniform(int32_t n, int32_t dtype, void *x, int32_t incX, int32_t low, int32_t high, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_s_randomnormal(int32_t n, float *x, int32_t incX, float mean, float scale, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_d_randomnormal(int32_t n, double *x, int32_t incX, double mean, double scale, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_i_randomsequence(int32_t n, int32_t size, int32_t dtype, void *x, int32_t incX, int32_t seed);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_im2col1d(
+ int32_t dtype, int32_t reverse,
+ void *images_data,
+ int32_t images_size,
+ int32_t batches,
+ int32_t im_w,
+ int32_t channels,
+ int32_t filter_w,
+ int32_t stride_w,
+ int32_t padding, int32_t channels_first,
+ int32_t dilation_w,
+ int32_t cols_channels_first,
+ void *cols_data, int32_t cols_size);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_im2col2d(
+ int32_t dtype, int32_t reverse,
+ void *images_data, int32_t images_size,
+ int32_t batches,
+ int32_t im_h, int32_t im_w,
+ int32_t channels,
+ int32_t filter_h, int32_t filter_w,
+ int32_t stride_h, int32_t stride_w,
+ int32_t padding, int32_t channels_first,
+ int32_t dilation_h, int32_t dilation_w,
+ int32_t cols_channels_first,
+ void *cols_data, int32_t cols_size);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_im2col3d(
+ int32_t dtype, int32_t reverse,
+ void *images_data, int32_t images_size,
+ int32_t batches,
+ int32_t im_d, int32_t im_h, int32_t im_w,
+ int32_t channels,
+ int32_t filter_d, int32_t filter_h, int32_t filter_w,
+ int32_t stride_d, int32_t stride_h, int32_t stride_w,
+ int32_t padding, int32_t channels_first,
+ int32_t dilation_d, int32_t dilation_h, int32_t dilation_w,
+ int32_t cols_channels_first,
+ void *cols_data, int32_t cols_size);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+// RINDOW_MATLIB_H_
+#endif
diff --git a/shared/macosx-x86_64/include/onnxruntime.h b/shared/macosx-x86_64/include/onnxruntime.h
new file mode 100644
index 0000000..127382c
--- /dev/null
+++ b/shared/macosx-x86_64/include/onnxruntime.h
@@ -0,0 +1,369 @@
+#ifndef ORT_API_H
+#define ORT_API_H
+
+// https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/session/onnxruntime_c_api.h
+// keep same order
+
+typedef enum ONNXTensorElementDataType {
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16
+} ONNXTensorElementDataType;
+
+typedef enum ONNXType {
+ ONNX_TYPE_UNKNOWN,
+ ONNX_TYPE_TENSOR,
+ ONNX_TYPE_SEQUENCE,
+ ONNX_TYPE_MAP,
+ ONNX_TYPE_OPAQUE,
+ ONNX_TYPE_SPARSETENSOR,
+ ONNX_TYPE_OPTIONAL
+} ONNXType;
+
+typedef enum OrtLoggingLevel {
+ ORT_LOGGING_LEVEL_VERBOSE,
+ ORT_LOGGING_LEVEL_INFO,
+ ORT_LOGGING_LEVEL_WARNING,
+ ORT_LOGGING_LEVEL_ERROR,
+ ORT_LOGGING_LEVEL_FATAL,
+} OrtLoggingLevel;
+
+typedef enum OrtErrorCode {
+ ORT_OK,
+ ORT_FAIL,
+ ORT_INVALID_ARGUMENT,
+ ORT_NO_SUCHFILE,
+ ORT_NO_MODEL,
+ ORT_ENGINE_ERROR,
+ ORT_RUNTIME_EXCEPTION,
+ ORT_INVALID_PROTOBUF,
+ ORT_MODEL_LOADED,
+ ORT_NOT_IMPLEMENTED,
+ ORT_INVALID_GRAPH,
+ ORT_EP_FAIL,
+} OrtErrorCode;
+
+struct OrtEnv;
+typedef struct OrtEnv OrtEnv;
+
+struct OrtStatus;
+typedef struct OrtStatus OrtStatus;
+
+struct OrtMemoryInfo;
+typedef struct OrtMemoryInfo OrtMemoryInfo;
+
+struct OrtIoBinding;
+typedef struct OrtIoBinding OrtIoBinding;
+
+struct OrtSession;
+typedef struct OrtSession OrtSession;
+
+struct OrtValue;
+typedef struct OrtValue OrtValue;
+
+struct OrtRunOptions;
+typedef struct OrtRunOptions OrtRunOptions;
+
+struct OrtTypeInfo;
+typedef struct OrtTypeInfo OrtTypeInfo;
+
+struct OrtTensorTypeAndShapeInfo;
+typedef struct OrtTensorTypeAndShapeInfo OrtTensorTypeAndShapeInfo;
+
+struct OrtSessionOptions;
+typedef struct OrtSessionOptions OrtSessionOptions;
+
+struct OrtCustomOpDomain;
+typedef struct OrtCustomOpDomain OrtCustomOpDomain;
+
+struct OrtMapTypeInfo;
+typedef struct OrtMapTypeInfo OrtMapTypeInfo;
+
+struct OrtSequenceTypeInfo;
+typedef struct OrtSequenceTypeInfo OrtSequenceTypeInfo;
+
+struct OrtModelMetadata;
+typedef struct OrtModelMetadata OrtModelMetadata;
+
+struct OrtThreadPoolParams;
+typedef struct OrtThreadPoolParams OrtThreadPoolParams;
+
+struct OrtThreadingOptions;
+typedef struct OrtThreadingOptions OrtThreadingOptions;
+
+struct OrtArenaCfg;
+typedef struct OrtArenaCfg OrtArenaCfg;
+
+struct OrtPrepackedWeightsContainer;
+typedef struct OrtPrepackedWeightsContainer OrtPrepackedWeightsContainer;
+
+struct OrtTensorRTProviderOptionsV2;
+typedef struct OrtTensorRTProviderOptionsV2 OrtTensorRTProviderOptionsV2;
+
+
+
+typedef enum COREMLFlags {
+ COREML_FLAG_USE_NONE = 0x000,
+ COREML_FLAG_USE_CPU_ONLY = 0x001,
+ COREML_FLAG_ENABLE_ON_SUBGRAPH = 0x002,
+ COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE = 0x004,
+ COREML_FLAG_ONLY_ALLOW_STATIC_INPUT_SHAPES = 0x008,
+ COREML_FLAG_CREATE_MLPROGRAM = 0x010,
+ COREML_FLAG_LAST = COREML_FLAG_CREATE_MLPROGRAM
+} COREMLFlags;
+
+struct OrtOp;
+typedef struct OrtOp OrtOp;
+
+struct OrtOpAttr;
+typedef struct Ort OrtOpAttr;
+
+typedef struct OrtAllocator {
+ uint32_t version;
+ void*(* Alloc)(struct OrtAllocator* this_, size_t size);
+ void(* Free)(struct OrtAllocator* this_, void* p);
+ const struct OrtMemoryInfo*(* Info)(const struct OrtAllocator* this_);
+} OrtAllocator;
+
+typedef enum GraphOptimizationLevel {
+ ORT_DISABLE_ALL = 0,
+ ORT_ENABLE_BASIC = 1,
+ ORT_ENABLE_EXTENDED = 2,
+ ORT_ENABLE_ALL = 99
+} GraphOptimizationLevel;
+
+typedef enum ExecutionMode {
+ ORT_SEQUENTIAL = 0,
+ ORT_PARALLEL = 1,
+} ExecutionMode;
+
+struct OrtApi;
+typedef struct OrtApi OrtApi;
+
+struct OrtApiBase {
+ const OrtApi*(* GetApi)(uint32_t version);
+ const char*(* GetVersionString)(void);
+};
+typedef struct OrtApiBase OrtApiBase;
+
+const OrtApiBase* OrtGetApiBase(void);
+
+struct OrtApi {
+ OrtStatus*(* CreateStatus)(OrtErrorCode code, const char* msg);
+ OrtErrorCode(* GetErrorCode)(const OrtStatus* status);
+ const char*(* GetErrorMessage)(const OrtStatus* status);
+ OrtStatus*(* CreateEnv)(OrtLoggingLevel log_severity_level, const char* logid, OrtEnv** out);
+ OrtStatus*(* CreateEnvWithCustomLogger)();
+ OrtStatus*(* EnableTelemetryEvents)(const OrtEnv* env);
+ OrtStatus*(* DisableTelemetryEvents)(const OrtEnv* env);
+ OrtStatus*(* CreateSession)(const OrtEnv* env, const char* model_path, const OrtSessionOptions* options, OrtSession** out);
+ OrtStatus*(* CreateSessionFromArray)(const OrtEnv* env, const void* model_data, size_t model_data_length, const OrtSessionOptions* options, OrtSession** out);
+ OrtStatus*(* Run)(OrtSession* session, const OrtRunOptions* run_options, const char* const* input_names, const OrtValue* const* inputs, size_t input_len, const char* const* output_names, size_t output_names_len, OrtValue** outputs);
+ OrtStatus*(* CreateSessionOptions)(OrtSessionOptions** options);
+ OrtStatus*(* SetOptimizedModelFilePath)(OrtSessionOptions* options, const char* optimized_model_filepath);
+ OrtStatus*(* CloneSessionOptions)();
+ OrtStatus*(* SetSessionExecutionMode)(OrtSessionOptions* options, ExecutionMode execution_mode);
+ OrtStatus*(* EnableProfiling)(OrtSessionOptions* options, const char* profile_file_prefix);
+ OrtStatus*(* DisableProfiling)(OrtSessionOptions* options);
+ OrtStatus*(* EnableMemPattern)(OrtSessionOptions* options);
+ OrtStatus*(* DisableMemPattern)(OrtSessionOptions* options);
+ OrtStatus*(* EnableCpuMemArena)(OrtSessionOptions* options);
+ OrtStatus*(* DisableCpuMemArena)(OrtSessionOptions* options);
+ OrtStatus*(* SetSessionLogId)(OrtSessionOptions* options, const char* logid);
+ OrtStatus*(* SetSessionLogVerbosityLevel)(OrtSessionOptions* options, int session_log_verbosity_level);
+ OrtStatus*(* SetSessionLogSeverityLevel)(OrtSessionOptions* options, int session_log_severity_level);
+ OrtStatus*(* SetSessionGraphOptimizationLevel)(OrtSessionOptions* options, GraphOptimizationLevel graph_optimization_level);
+ OrtStatus*(* SetIntraOpNumThreads)(OrtSessionOptions* options, int intra_op_num_threads);
+ OrtStatus*(* SetInterOpNumThreads)(OrtSessionOptions* options, int inter_op_num_threads);
+ OrtStatus*(* CreateCustomOpDomain)();
+ OrtStatus*(* CustomOpDomain_Add)();
+ OrtStatus*(* AddCustomOpDomain)();
+ OrtStatus*(* RegisterCustomOpsLibrary)();
+ OrtStatus*(* SessionGetInputCount)(const OrtSession* session, size_t* out);
+ OrtStatus*(* SessionGetOutputCount)(const OrtSession* session, size_t* out);
+ OrtStatus*(* SessionGetOverridableInitializerCount)();
+ OrtStatus*(* SessionGetInputTypeInfo)(const OrtSession* session, size_t index, OrtTypeInfo** type_info);
+ OrtStatus*(* SessionGetOutputTypeInfo)(const OrtSession* session, size_t index, OrtTypeInfo** type_info);
+ OrtStatus*(* SessionGetOverridableInitializerTypeInfo)();
+ OrtStatus*(* SessionGetInputName)(const OrtSession* session, size_t index, OrtAllocator* allocator, char** value);
+ OrtStatus*(* SessionGetOutputName)(const OrtSession* session, size_t index, OrtAllocator* allocator, char** value);
+ OrtStatus*(* SessionGetOverridableInitializerName)();
+ OrtStatus*(* CreateRunOptions)(OrtRunOptions** out);
+ OrtStatus*(* RunOptionsSetRunLogVerbosityLevel)(OrtRunOptions* options, int log_verbosity_level);
+ OrtStatus*(* RunOptionsSetRunLogSeverityLevel)(OrtRunOptions* options, int log_severity_level);
+ OrtStatus*(* RunOptionsSetRunTag)(OrtRunOptions* options, const char* run_tag);
+ OrtStatus*(* RunOptionsGetRunLogVerbosityLevel)();
+ OrtStatus*(* RunOptionsGetRunLogSeverityLevel)();
+ OrtStatus*(* RunOptionsGetRunTag)();
+ OrtStatus*(* RunOptionsSetTerminate)(OrtRunOptions* options);
+ OrtStatus*(* RunOptionsUnsetTerminate)(OrtRunOptions* options);
+ OrtStatus*(* CreateTensorAsOrtValue)(OrtAllocator* allocator, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, OrtValue** out);
+ OrtStatus*(* CreateTensorWithDataAsOrtValue)(const OrtMemoryInfo* info, void* p_data, size_t p_data_len, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, OrtValue** out);
+ OrtStatus*(* IsTensor)();
+ OrtStatus*(* GetTensorMutableData)(OrtValue* value, void** out);
+ OrtStatus*(* FillStringTensor)(OrtValue* value, const char* const* s, size_t s_len);
+ OrtStatus*(* GetStringTensorDataLength)(const OrtValue* value, size_t* len);
+ OrtStatus*(* GetStringTensorContent)(const OrtValue* value, void* s, size_t s_len, size_t* offsets, size_t offsets_len);
+ OrtStatus*(* CastTypeInfoToTensorInfo)(const OrtTypeInfo* type_info, const OrtTensorTypeAndShapeInfo** out);
+ OrtStatus*(* GetOnnxTypeFromTypeInfo)(const OrtTypeInfo* type_info, enum ONNXType* out);
+ OrtStatus*(* CreateTensorTypeAndShapeInfo)();
+ OrtStatus*(* SetTensorElementType)();
+ OrtStatus*(* SetDimensions)();
+ OrtStatus*(* GetTensorElementType)(const OrtTensorTypeAndShapeInfo* info, enum ONNXTensorElementDataType* out);
+ OrtStatus*(* GetDimensionsCount)(const OrtTensorTypeAndShapeInfo* info, size_t* out);
+ OrtStatus*(* GetDimensions)(const OrtTensorTypeAndShapeInfo* info, int64_t* dim_values, size_t dim_values_length);
+ OrtStatus*(* GetSymbolicDimensions)(const OrtTensorTypeAndShapeInfo* info, const char* dim_params[], size_t dim_params_length);
+ OrtStatus*(* GetTensorShapeElementCount)(const OrtTensorTypeAndShapeInfo* info, size_t* out);
+ OrtStatus*(* GetTensorTypeAndShape)(const OrtValue* value, OrtTensorTypeAndShapeInfo** out);
+ OrtStatus*(* GetTypeInfo)();
+ OrtStatus*(* GetValueType)(const OrtValue* value, enum ONNXType* out);
+ OrtStatus*(* CreateMemoryInfo)();
+ OrtStatus*(* CreateCpuMemoryInfo)(enum OrtAllocatorType type, enum OrtMemType mem_type, OrtMemoryInfo** out);
+ OrtStatus*(* CompareMemoryInfo)();
+ OrtStatus*(* MemoryInfoGetName)();
+ OrtStatus*(* MemoryInfoGetId)();
+ OrtStatus*(* MemoryInfoGetMemType)();
+ OrtStatus*(* MemoryInfoGetType)();
+ OrtStatus*(* AllocatorAlloc)(OrtAllocator* ort_allocator, size_t size, void** out);
+ OrtStatus*(* AllocatorFree)(OrtAllocator* ort_allocator, void* p);
+ OrtStatus*(* AllocatorGetInfo)(const OrtAllocator* ort_allocator, const struct OrtMemoryInfo** out);
+ OrtStatus*(* GetAllocatorWithDefaultOptions)(OrtAllocator** out);
+ OrtStatus*(* AddFreeDimensionOverride)(OrtSessionOptions* options, const char* dim_denotation, int64_t dim_value);
+ OrtStatus*(* GetValue)(const OrtValue* value, int index, OrtAllocator* allocator, OrtValue** out);
+ OrtStatus*(* GetValueCount)(const OrtValue* value, size_t* out);
+ OrtStatus*(* CreateValue)();
+ OrtStatus*(* CreateOpaqueValue)();
+ OrtStatus*(* GetOpaqueValue)();
+ OrtStatus*(* KernelInfoGetAttribute_float)();
+ OrtStatus*(* KernelInfoGetAttribute_int64)();
+ OrtStatus*(* KernelInfoGetAttribute_string)();
+ OrtStatus*(* KernelContext_GetInputCount)();
+ OrtStatus*(* KernelContext_GetOutputCount)();
+ OrtStatus*(* KernelContext_GetInput)();
+ OrtStatus*(* KernelContext_GetOutput)();
+ void(* ReleaseEnv)(OrtEnv* input);
+ void(* ReleaseStatus)(OrtStatus* input);
+ void(* ReleaseMemoryInfo)(OrtMemoryInfo* input);
+ void(* ReleaseSession)(OrtSession* input);
+ void(* ReleaseValue)(OrtValue* input);
+ void(* ReleaseRunOptions)(OrtRunOptions* input);
+ void(* ReleaseTypeInfo)(OrtTypeInfo* input);
+ void(* ReleaseTensorTypeAndShapeInfo)(OrtTensorTypeAndShapeInfo* input);
+ void(* ReleaseSessionOptions)(OrtSessionOptions* input);
+ void(* ReleaseCustomOpDomain)();
+ OrtStatus*(* GetDenotationFromTypeInfo)();
+ OrtStatus*(* CastTypeInfoToMapTypeInfo)(const OrtTypeInfo* type_info, const OrtMapTypeInfo** out);
+ OrtStatus*(* CastTypeInfoToSequenceTypeInfo)(const OrtTypeInfo* type_info, const OrtSequenceTypeInfo** out);
+ OrtStatus*(* GetMapKeyType)(const OrtMapTypeInfo* map_type_info, enum ONNXTensorElementDataType* out);
+ OrtStatus*(* GetMapValueType)(const OrtMapTypeInfo* map_type_info, OrtTypeInfo** type_info);
+ OrtStatus*(* GetSequenceElementType)(const OrtSequenceTypeInfo* sequence_type_info, OrtTypeInfo** type_info);
+ void(* ReleaseMapTypeInfo)(OrtMapTypeInfo* input);
+ void(* ReleaseSequenceTypeInfo)(OrtSequenceTypeInfo* input);
+ OrtStatus*(* SessionEndProfiling)(OrtSession* session, OrtAllocator* allocator, char** out);
+ OrtStatus*(* SessionGetModelMetadata)(const OrtSession* session, OrtModelMetadata** out);
+ OrtStatus*(* ModelMetadataGetProducerName)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataGetGraphName)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataGetDomain)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataGetDescription)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataLookupCustomMetadataMap)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, const char* key, char** value);
+ OrtStatus*(* ModelMetadataGetVersion)(const OrtModelMetadata* model_metadata, int64_t* value);
+ void(* ReleaseModelMetadata)(OrtModelMetadata* input);
+ OrtStatus*(* CreateEnvWithGlobalThreadPools)();
+ OrtStatus*(* DisablePerSessionThreads)();
+ OrtStatus*(* CreateThreadingOptions)();
+ void(* ReleaseThreadingOptions)(OrtThreadingOptions* input);
+ OrtStatus*(* ModelMetadataGetCustomMetadataMapKeys)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char*** keys, int64_t* num_keys);
+ OrtStatus*(* AddFreeDimensionOverrideByName)(OrtSessionOptions* options, const char* dim_name, int64_t dim_value);
+ OrtStatus*(* GetAvailableProviders)(char*** out_ptr, int* provider_length);
+ OrtStatus*(* ReleaseAvailableProviders)(char** ptr, int providers_length);
+ OrtStatus*(* GetStringTensorElementLength)();
+ OrtStatus*(* GetStringTensorElement)();
+ OrtStatus*(* FillStringTensorElement)();
+ OrtStatus*(* AddSessionConfigEntry)(OrtSessionOptions* options, const char* config_key, const char* config_value);
+ OrtStatus*(* CreateAllocator)();
+ void(* ReleaseAllocator)(OrtAllocator* input);
+ OrtStatus*(* RunWithBinding)();
+ OrtStatus*(* CreateIoBinding)();
+ void(* ReleaseIoBinding)(OrtIoBinding* input);
+ OrtStatus*(* BindInput)();
+ OrtStatus*(* BindOutput)();
+ OrtStatus*(* BindOutputToDevice)();
+ OrtStatus*(* GetBoundOutputNames)();
+ OrtStatus*(* GetBoundOutputValues)();
+ void(* ClearBoundInputs)();
+ void(* ClearBoundOutputs)();
+ OrtStatus*(* TensorAt)();
+ OrtStatus*(* CreateAndRegisterAllocator)();
+ OrtStatus*(* SetLanguageProjection)();
+ OrtStatus*(* SessionGetProfilingStartTimeNs)();
+ OrtStatus*(* SetGlobalIntraOpNumThreads)();
+ OrtStatus*(* SetGlobalInterOpNumThreads)();
+ OrtStatus*(* SetGlobalSpinControl)();
+ OrtStatus*(* AddInitializer)();
+ OrtStatus*(* CreateEnvWithCustomLoggerAndGlobalThreadPools)();
+
+
+ OrtStatus*(* SetGlobalDenormalAsZero)();
+ OrtStatus*(* CreateArenaCfg)();
+ void(* ReleaseArenaCfg)(OrtArenaCfg* input);
+ OrtStatus*(* ModelMetadataGetGraphDescription)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* SessionOptionsAppendExecutionProvider_TensorRT)();
+ OrtStatus*(* SetCurrentGpuDeviceId)();
+ OrtStatus*(* GetCurrentGpuDeviceId)();
+ OrtStatus*(* KernelInfoGetAttributeArray_float)();
+ OrtStatus*(* KernelInfoGetAttributeArray_int64)();
+ OrtStatus*(* CreateArenaCfgV2)();
+ OrtStatus*(* AddRunConfigEntry)();
+ OrtStatus*(* CreatePrepackedWeightsContainer)();
+ void(* PrepackedWeightsContainer)(OrtPrepackedWeightsContainer* input);
+ OrtStatus*(* CreateSessionWithPrepackedWeightsContainer)();
+ OrtStatus*(* CreateSessionFromArrayWithPrepackedWeightsContainer)();
+ OrtStatus*(* SessionOptionsAppendExecutionProvider_TensorRT_V2)();
+ OrtStatus*(* CreateTensorRTProviderOptions)();
+ OrtStatus*(* UpdateTensorRTProviderOptions)();
+ OrtStatus*(* GetTensorRTProviderOptionsAsString)();
+ void(* ReleaseTensorRTProviderOptions)(OrtTensorRTProviderOptionsV2* input);
+ OrtStatus*(* EnableOrtCustomOps)();
+ OrtStatus*(* RegisterAllocator)();
+ OrtStatus*(* UnregisterAllocator)();
+ OrtStatus*(* IsSparseTensor)();
+ OrtStatus*(* CreateSparseTensorAsOrtValue)();
+ OrtStatus*(* FillSparseTensorCoo)();
+ OrtStatus*(* FillSparseTensorCsr)();
+ OrtStatus*(* FillSparseTensorBlockSparse)();
+ OrtStatus*(* CreateSparseTensorWithValuesAsOrtValue)();
+ OrtStatus*(* UseCooIndices)();
+ OrtStatus*(* UseCsrIndices)();
+ OrtStatus*(* UseBlockSparseIndices)();
+ OrtStatus*(* GetSparseTensorFormat)();
+ OrtStatus*(* GetSparseTensorValuesTypeAndShape)();
+ OrtStatus*(* GetSparseTensorValues)();
+ OrtStatus*(* GetSparseTensorIndicesTypeShape)();
+ OrtStatus*(* GetSparseTensorIndices)();
+ OrtStatus*(* HasValue)();
+ OrtStatus*(* KernelContext_GetGPUComputeStream)();
+ OrtStatus*(* GetTensorMemoryInfo)();
+ OrtStatus*(* GetExecutionProviderApi)();
+ OrtStatus*(* SessionOptionsSetCustomCreateThreadFn)();
+ OrtStatus*(* SessionOptionsSetCustomThreadCreationOptions)();
+ OrtStatus*(* SessionOptionsSetCustomJoinThreadFn)();
+ OrtStatus*(* SetGlobalCustomCreateThreadFn)();
+ OrtStatus*(* SetGlobalCustomThreadCreationOptions)();
+ OrtStatus*(* SetGlobalCustomJoinThreadFn)();
+ OrtStatus*(* SynchronizeBoundInputs)();
+ OrtStatus*(* SynchronizeBoundOutputs)();
+};
\ No newline at end of file
diff --git a/shared/macosx-x86_64/include/openblas.h b/shared/macosx-x86_64/include/openblas.h
new file mode 100644
index 0000000..8e902fb
--- /dev/null
+++ b/shared/macosx-x86_64/include/openblas.h
@@ -0,0 +1,426 @@
+#define FFI_SCOPE "Rindow\\OpenBLAS\\FFI"
+//#define FFI_LIB "libopenblas.dll"
+
+/////////////////////////////////////////////
+typedef int8_t cl_char;
+typedef uint8_t cl_uchar;
+typedef int16_t cl_short;
+typedef uint16_t cl_ushort;
+typedef int32_t cl_int;
+typedef uint32_t cl_uint;
+typedef int64_t cl_long;
+typedef uint64_t cl_ulong;
+/////////////////////////////////////////////
+typedef uint16_t bfloat16;
+typedef int32_t blasint;
+typedef int32_t lapack_int;
+/////////////////////////////////////////////
+//#define xdouble double
+typedef double xdouble;
+//#define OPENBLAS_COMPLEX_STRUCT
+typedef struct _openblas_complex_float { float real, imag; } openblas_complex_float;
+typedef struct _openblas_complex_double { double real, imag; } openblas_complex_double;
+typedef struct _openblas_complex_xdouble { xdouble real, imag; } openblas_complex_xdouble;
+//#define openblas_make_complex_float(real, imag) {(real), (imag)}
+//#define openblas_make_complex_double(real, imag) {(real), (imag)}
+//#define openblas_make_complex_xdouble(real, imag) {(real), (imag)}
+//#define openblas_complex_float_real(z) ((z).real)
+//#define openblas_complex_float_imag(z) ((z).imag)
+//#define openblas_complex_double_real(z) ((z).real)
+//#define openblas_complex_double_imag(z) ((z).imag)
+//#define openblas_complex_xdouble_real(z) ((z).real)
+//#define openblas_complex_xdouble_imag(z) ((z).imag)
+/////////////////////////////////////////////
+
+
+
+/*Set the number of threads on runtime.*/
+void openblas_set_num_threads(int num_threads);
+void goto_set_num_threads(int num_threads);
+
+/*Get the number of threads on runtime.*/
+int openblas_get_num_threads(void);
+
+/*Get the number of physical processors (cores).*/
+int openblas_get_num_procs(void);
+
+/*Get the build configure on runtime.*/
+char* openblas_get_config(void);
+
+/*Get the CPU corename on runtime.*/
+char* openblas_get_corename(void);
+
+/* Get the parallelization type which is used by OpenBLAS */
+int openblas_get_parallel(void);
+/* OpenBLAS is compiled for sequential use */
+#define OPENBLAS_SEQUENTIAL 0
+/* OpenBLAS is compiled using normal threading model */
+#define OPENBLAS_THREAD 1
+/* OpenBLAS is compiled using OpenMP threading model */
+#define OPENBLAS_OPENMP 2
+
+
+//#ifndef OPENBLAS_CONST
+//# define OPENBLAS_CONST const
+//#endif
+
+
+//#define CBLAS_INDEX size_t
+typedef size_t CBLAS_INDEX;
+
+
+typedef enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102} CBLAS_ORDER;
+typedef enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113, CblasConjNoTrans=114} CBLAS_TRANSPOSE;
+typedef enum CBLAS_UPLO {CblasUpper=121, CblasLower=122} CBLAS_UPLO;
+typedef enum CBLAS_DIAG {CblasNonUnit=131, CblasUnit=132} CBLAS_DIAG;
+typedef enum CBLAS_SIDE {CblasLeft=141, CblasRight=142} CBLAS_SIDE;
+typedef CBLAS_ORDER CBLAS_LAYOUT;
+
+float cblas_sdsdot(const blasint n, const float alpha, const float *x, const blasint incx, const float *y, const blasint incy);
+double cblas_dsdot (const blasint n, const float *x, const blasint incx, const float *y, const blasint incy);
+float cblas_sdot(const blasint n, const float *x, const blasint incx, const float *y, const blasint incy);
+double cblas_ddot(const blasint n, const double *x, const blasint incx, const double *y, const blasint incy);
+
+openblas_complex_float cblas_cdotu(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+openblas_complex_float cblas_cdotc(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+openblas_complex_double cblas_zdotu(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+openblas_complex_double cblas_zdotc(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+
+void cblas_cdotu_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+void cblas_cdotc_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+void cblas_zdotu_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+void cblas_zdotc_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+
+float cblas_sasum (const blasint n, const float *x, const blasint incx);
+double cblas_dasum (const blasint n, const double *x, const blasint incx);
+float cblas_scasum(const blasint n, const void *x, const blasint incx);
+double cblas_dzasum(const blasint n, const void *x, const blasint incx);
+
+float cblas_ssum (const blasint n, const float *x, const blasint incx);
+double cblas_dsum (const blasint n, const double *x, const blasint incx);
+float cblas_scsum(const blasint n, const void *x, const blasint incx);
+double cblas_dzsum(const blasint n, const void *x, const blasint incx);
+
+float cblas_snrm2 (const blasint N, const float *X, const blasint incX);
+double cblas_dnrm2 (const blasint N, const double *X, const blasint incX);
+float cblas_scnrm2(const blasint N, const void *X, const blasint incX);
+double cblas_dznrm2(const blasint N, const void *X, const blasint incX);
+
+CBLAS_INDEX cblas_isamax(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idamax(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icamax(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izamax(const blasint n, const void *x, const blasint incx);
+
+CBLAS_INDEX cblas_isamin(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idamin(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icamin(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izamin(const blasint n, const void *x, const blasint incx);
+
+CBLAS_INDEX cblas_ismax(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idmax(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icmax(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izmax(const blasint n, const void *x, const blasint incx);
+
+CBLAS_INDEX cblas_ismin(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idmin(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icmin(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izmin(const blasint n, const void *x, const blasint incx);
+
+void cblas_saxpy(const blasint n, const float alpha, const float *x, const blasint incx, float *y, const blasint incy);
+void cblas_daxpy(const blasint n, const double alpha, const double *x, const blasint incx, double *y, const blasint incy);
+void cblas_caxpy(const blasint n, const void *alpha, const void *x, const blasint incx, void *y, const blasint incy);
+void cblas_zaxpy(const blasint n, const void *alpha, const void *x, const blasint incx, void *y, const blasint incy);
+
+void cblas_scopy(const blasint n, const float *x, const blasint incx, float *y, const blasint incy);
+void cblas_dcopy(const blasint n, const double *x, const blasint incx, double *y, const blasint incy);
+void cblas_ccopy(const blasint n, const void *x, const blasint incx, void *y, const blasint incy);
+void cblas_zcopy(const blasint n, const void *x, const blasint incx, void *y, const blasint incy);
+
+void cblas_sswap(const blasint n, float *x, const blasint incx, float *y, const blasint incy);
+void cblas_dswap(const blasint n, double *x, const blasint incx, double *y, const blasint incy);
+void cblas_cswap(const blasint n, void *x, const blasint incx, void *y, const blasint incy);
+void cblas_zswap(const blasint n, void *x, const blasint incx, void *y, const blasint incy);
+
+void cblas_srot(const blasint N, float *X, const blasint incX, float *Y, const blasint incY, const float c, const float s);
+void cblas_drot(const blasint N, double *X, const blasint incX, double *Y, const blasint incY, const double c, const double s);
+//void cblas_csrot(const blasint n, const void *x, const blasint incx, void *y, const blasint incY, const float c, const float s);
+//void cblas_zdrot(const blasint n, const void *x, const blasint incx, void *y, const blasint incY, const double c, const double s);
+
+void cblas_srotg(float *a, float *b, float *c, float *s);
+void cblas_drotg(double *a, double *b, double *c, double *s);
+//void cblas_crotg(void *a, void *b, float *c, void *s);
+//void cblas_zrotg(void *a, void *b, double *c, void *s);
+
+
+void cblas_srotm(const blasint N, float *X, const blasint incX, float *Y, const blasint incY, const float *P);
+void cblas_drotm(const blasint N, double *X, const blasint incX, double *Y, const blasint incY, const double *P);
+
+void cblas_srotmg(float *d1, float *d2, float *b1, const float b2, float *P);
+void cblas_drotmg(double *d1, double *d2, double *b1, const double b2, double *P);
+
+void cblas_sscal(const blasint N, const float alpha, float *X, const blasint incX);
+void cblas_dscal(const blasint N, const double alpha, double *X, const blasint incX);
+void cblas_cscal(const blasint N, const void *alpha, void *X, const blasint incX);
+void cblas_zscal(const blasint N, const void *alpha, void *X, const blasint incX);
+void cblas_csscal(const blasint N, const float alpha, void *X, const blasint incX);
+void cblas_zdscal(const blasint N, const double alpha, void *X, const blasint incX);
+
+void cblas_sgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const float alpha, const float *a, const blasint lda, const float *x, const blasint incx, const float beta, float *y, const blasint incy);
+void cblas_dgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const double alpha, const double *a, const blasint lda, const double *x, const blasint incx, const double beta, double *y, const blasint incy);
+void cblas_cgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const void *alpha, const void *a, const blasint lda, const void *x, const blasint incx, const void *beta, void *y, const blasint incy);
+void cblas_zgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const void *alpha, const void *a, const blasint lda, const void *x, const blasint incx, const void *beta, void *y, const blasint incy);
+
+void cblas_sger (const enum CBLAS_ORDER order, const blasint M, const blasint N, const float alpha, const float *X, const blasint incX, const float *Y, const blasint incY, float *A, const blasint lda);
+void cblas_dger (const enum CBLAS_ORDER order, const blasint M, const blasint N, const double alpha, const double *X, const blasint incX, const double *Y, const blasint incY, double *A, const blasint lda);
+void cblas_cgeru(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_cgerc(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_zgeru(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_zgerc(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+
+void cblas_strsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_strmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_ssyr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *X, const blasint incX, float *A, const blasint lda);
+void cblas_dsyr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X, const blasint incX, double *A, const blasint lda);
+void cblas_cher(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const void *X, const blasint incX, void *A, const blasint lda);
+void cblas_zher(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const void *X, const blasint incX, void *A, const blasint lda);
+
+void cblas_ssyr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,const blasint N, const float alpha, const float *X,
+ const blasint incX, const float *Y, const blasint incY, float *A, const blasint lda);
+void cblas_dsyr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X,
+ const blasint incX, const double *Y, const blasint incY, double *A, const blasint lda);
+void cblas_cher2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX,
+ const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_zher2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX,
+ const void *Y, const blasint incY, void *A, const blasint lda);
+
+void cblas_sgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const float alpha, const float *A, const blasint lda, const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const double alpha, const double *A, const blasint lda, const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+void cblas_cgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+void cblas_ssbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K, const float alpha, const float *A,
+ const blasint lda, const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dsbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K, const double alpha, const double *A,
+ const blasint lda, const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+
+
+void cblas_stbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_stbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_stpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const float *Ap, float *X, const blasint incX);
+void cblas_dtpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const double *Ap, double *X, const blasint incX);
+void cblas_ctpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+void cblas_ztpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+
+void cblas_stpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const float *Ap, float *X, const blasint incX);
+void cblas_dtpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const double *Ap, double *X, const blasint incX);
+void cblas_ctpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+void cblas_ztpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+
+void cblas_ssymv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *A,
+ const blasint lda, const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dsymv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *A,
+ const blasint lda, const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+void cblas_chemv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *A,
+ const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zhemv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *A,
+ const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+
+void cblas_sspmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *Ap,
+ const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dspmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *Ap,
+ const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+
+void cblas_sspr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *X, const blasint incX, float *Ap);
+void cblas_dspr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X, const blasint incX, double *Ap);
+
+void cblas_chpr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const void *X, const blasint incX, void *A);
+void cblas_zhpr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const void *X,const blasint incX, void *A);
+
+void cblas_sspr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *X, const blasint incX, const float *Y, const blasint incY, float *A);
+void cblas_dspr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X, const blasint incX, const double *Y, const blasint incY, double *A);
+void cblas_chpr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *Ap);
+void cblas_zhpr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *Ap);
+
+void cblas_chbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zhbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+void cblas_chpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N,
+ const void *alpha, const void *Ap, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zhpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N,
+ const void *alpha, const void *Ap, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+void cblas_sgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const float alpha, const float *A, const blasint lda, const float *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+void cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const double alpha, const double *A, const blasint lda, const double *B, const blasint ldb, const double beta, double *C, const blasint ldc);
+void cblas_cgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+//void cblas_cgemm3m(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+// const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+//void cblas_zgemm3m(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+// const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+
+void cblas_ssymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const float alpha, const float *A, const blasint lda, const float *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+void cblas_dsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const double alpha, const double *A, const blasint lda, const double *B, const blasint ldb, const double beta, double *C, const blasint ldc);
+void cblas_csymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+void cblas_ssyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const float alpha, const float *A, const blasint lda, const float beta, float *C, const blasint ldc);
+void cblas_dsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const double alpha, const double *A, const blasint lda, const double beta, double *C, const blasint ldc);
+void cblas_csyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *beta, void *C, const blasint ldc);
+void cblas_zsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *beta, void *C, const blasint ldc);
+
+void cblas_ssyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const float alpha, const float *A, const blasint lda, const float *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+void cblas_dsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const double alpha, const double *A, const blasint lda, const double *B, const blasint ldb, const double beta, double *C, const blasint ldc);
+void cblas_csyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+
+
+void cblas_strmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const float alpha, const float *A, const blasint lda, float *B, const blasint ldb);
+void cblas_dtrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const double alpha, const double *A, const blasint lda, double *B, const blasint ldb);
+void cblas_ctrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+void cblas_ztrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+
+void cblas_strsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const float alpha, const float *A, const blasint lda, float *B, const blasint ldb);
+void cblas_dtrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const double alpha, const double *A, const blasint lda, double *B, const blasint ldb);
+void cblas_ctrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+void cblas_ztrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+
+void cblas_chemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zhemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+void cblas_cherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const float alpha, const void *A, const blasint lda, const float beta, void *C, const blasint ldc);
+void cblas_zherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const double alpha, const void *A, const blasint lda, const double beta, void *C, const blasint ldc);
+
+void cblas_cher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const float beta, void *C, const blasint ldc);
+void cblas_zher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const double beta, void *C, const blasint ldc);
+
+void cblas_xerbla(blasint p, char *rout, char *form, ...);
+
+/*** BLAS extensions ***/
+
+void cblas_saxpby(const blasint n, const float alpha, const float *x, const blasint incx,const float beta, float *y, const blasint incy);
+
+void cblas_daxpby(const blasint n, const double alpha, const double *x, const blasint incx,const double beta, double *y, const blasint incy);
+
+void cblas_caxpby(const blasint n, const void *alpha, const void *x, const blasint incx,const void *beta, void *y, const blasint incy);
+
+void cblas_zaxpby(const blasint n, const void *alpha, const void *x, const blasint incx,const void *beta, void *y, const blasint incy);
+
+void cblas_somatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const float calpha, const float *a,
+ const blasint clda, float *b, const blasint cldb);
+void cblas_domatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const double calpha, const double *a,
+ const blasint clda, double *b, const blasint cldb);
+void cblas_comatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const void* calpha, const void* a,
+ const blasint clda, void *b, const blasint cldb);
+void cblas_zomatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const void* calpha, const void* a,
+ const blasint clda, void *b, const blasint cldb);
+
+void cblas_simatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const float calpha, float *a,
+ const blasint clda, const blasint cldb);
+void cblas_dimatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const double calpha, double *a,
+ const blasint clda, const blasint cldb);
+void cblas_cimatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const float* calpha, float* a,
+ const blasint clda, const blasint cldb);
+void cblas_zimatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const double* calpha, double* a,
+ const blasint clda, const blasint cldb);
+
+void cblas_sgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const float calpha, float *a, const blasint clda, const float cbeta,
+ float *c, const blasint cldc);
+void cblas_dgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const double calpha, double *a, const blasint clda, const double cbeta,
+ double *c, const blasint cldc);
+void cblas_cgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const float *calpha, float *a, const blasint clda, const float *cbeta,
+ float *c, const blasint cldc);
+void cblas_zgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const double *calpha, double *a, const blasint clda, const double *cbeta,
+ double *c, const blasint cldc);
+
+/*** BFLOAT16 and INT8 extensions ***/
+/* convert float array to BFLOAT16 array by rounding */
+//void cblas_sbstobf16(const blasint n, const float *in, const blasint incin, bfloat16 *out, const blasint incout);
+/* convert double array to BFLOAT16 array by rounding */
+//void cblas_sbdtobf16(const blasint n, const double *in, const blasint incin, bfloat16 *out, const blasint incout);
+/* convert BFLOAT16 array to float array */
+//void cblas_sbf16tos(const blasint n, const bfloat16 *in, const blasint incin, float *out, const blasint incout);
+/* convert BFLOAT16 array to double array */
+//void cblas_dbf16tod(const blasint n, const bfloat16 *in, const blasint incin, double *out, const blasint incout);
+/* dot production of BFLOAT16 input arrays, and output as float */
+//float cblas_sbdot(const blasint n, const bfloat16 *x, const blasint incx, const bfloat16 *y, const blasint incy);
+//void cblas_sbgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n, const float alpha, const bfloat16 *a, const blasint lda, const bfloat16 *x, const blasint incx, const float beta, float *y, const blasint incy);
+
+//void cblas_sbgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+// const float alpha, const bfloat16 *A, const blasint lda, const bfloat16 *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+
+
diff --git a/shared/macosx-x86_64/include/samplerate.h b/shared/macosx-x86_64/include/samplerate.h
new file mode 100644
index 0000000..436b7ff
--- /dev/null
+++ b/shared/macosx-x86_64/include/samplerate.h
@@ -0,0 +1,163 @@
+#ifndef SAMPLERATE_H
+#define SAMPLERATE_H
+
+/* Opaque data type SRC_STATE. */
+typedef struct SRC_STATE_tag SRC_STATE;
+
+/* SRC_DATA is used to pass data to src_simple() and src_process(). */
+typedef struct
+{ const float *data_in ;
+ float *data_out ;
+
+ long input_frames, output_frames ;
+ long input_frames_used, output_frames_gen ;
+
+ int end_of_input ;
+
+ double src_ratio ;
+} SRC_DATA ;
+
+/*
+** User supplied callback function type for use with src_callback_new()
+** and src_callback_read(). First parameter is the same pointer that was
+** passed into src_callback_new(). Second parameter is pointer to a
+** pointer. The user supplied callback function must modify *data to
+** point to the start of the user supplied float array. The user supplied
+** function must return the number of frames that **data points to.
+*/
+
+typedef long (*src_callback_t) (void *cb_data, float **data) ;
+
+/*
+** Standard initialisation function : return an anonymous pointer to the
+** internal state of the converter. Choose a converter from the enums below.
+** Error returned in *error.
+*/
+
+SRC_STATE* src_new (int converter_type, int channels, int *error) ;
+
+/*
+** Clone a handle : return an anonymous pointer to a new converter
+** containing the same internal state as orig. Error returned in *error.
+*/
+SRC_STATE* src_clone (SRC_STATE* orig, int *error) ;
+
+/*
+** Initilisation for callback based API : return an anonymous pointer to the
+** internal state of the converter. Choose a converter from the enums below.
+** The cb_data pointer can point to any data or be set to NULL. Whatever the
+** value, when processing, user supplied function "func" gets called with
+** cb_data as first parameter.
+*/
+
+SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels,
+ int *error, void* cb_data) ;
+
+/*
+** Cleanup all internal allocations.
+** Always returns NULL.
+*/
+
+SRC_STATE* src_delete (SRC_STATE *state) ;
+
+/*
+** Standard processing function.
+** Returns non zero on error.
+*/
+
+int src_process (SRC_STATE *state, SRC_DATA *data) ;
+
+/*
+** Callback based processing function. Read up to frames worth of data from
+** the converter int *data and return frames read or -1 on error.
+*/
+long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ;
+
+/*
+** Simple interface for performing a single conversion from input buffer to
+** output buffer at a fixed conversion ratio.
+** Simple interface does not require initialisation as it can only operate on
+** a single buffer worth of audio.
+*/
+
+int src_simple (SRC_DATA *data, int converter_type, int channels) ;
+
+/*
+** This library contains a number of different sample rate converters,
+** numbered 0 through N.
+**
+** Return a string giving either a name or a more full description of each
+** sample rate converter or NULL if no sample rate converter exists for
+** the given value. The converters are sequentially numbered from 0 to N.
+*/
+
+const char *src_get_name (int converter_type) ;
+const char *src_get_description (int converter_type) ;
+const char *src_get_version (void) ;
+
+/*
+** Set a new SRC ratio. This allows step responses
+** in the conversion ratio.
+** Returns non zero on error.
+*/
+
+int src_set_ratio (SRC_STATE *state, double new_ratio) ;
+
+/*
+** Get the current channel count.
+** Returns negative on error, positive channel count otherwise
+*/
+
+int src_get_channels (SRC_STATE *state) ;
+
+/*
+** Reset the internal SRC state.
+** Does not modify the quality settings.
+** Does not free any memory allocations.
+** Returns non zero on error.
+*/
+
+int src_reset (SRC_STATE *state) ;
+
+/*
+** Return TRUE if ratio is a valid conversion ratio, FALSE
+** otherwise.
+*/
+
+int src_is_valid_ratio (double ratio) ;
+
+/*
+** Return an error number.
+*/
+
+int src_error (SRC_STATE *state) ;
+
+/*
+** Convert the error number into a string.
+*/
+const char* src_strerror (int error) ;
+
+/*
+** The following enums can be used to set the interpolator type
+** using the function src_set_converter().
+*/
+
+enum
+{
+ SRC_SINC_BEST_QUALITY = 0,
+ SRC_SINC_MEDIUM_QUALITY = 1,
+ SRC_SINC_FASTEST = 2,
+ SRC_ZERO_ORDER_HOLD = 3,
+ SRC_LINEAR = 4,
+} ;
+
+/*
+** Extra helper functions for converting from short to float and
+** back again.
+*/
+
+void src_short_to_float_array (const short *in, float *out, int len) ;
+void src_float_to_short_array (const float *in, short *out, int len) ;
+
+void src_int_to_float_array (const int *in, float *out, int len) ;
+void src_float_to_int_array (const float *in, int *out, int len) ;
\ No newline at end of file
diff --git a/shared/macosx-x86_64/include/sndfile.h b/shared/macosx-x86_64/include/sndfile.h
new file mode 100644
index 0000000..8c4df97
--- /dev/null
+++ b/shared/macosx-x86_64/include/sndfile.h
@@ -0,0 +1,496 @@
+#ifndef SNDFILE_H
+#define SNDFILE_H
+
+#define SNDFILE_1
+
+/** File format types. */
+enum
+{ /* Major formats. */
+ SF_FORMAT_WAV = 0x010000, /* Microsoft WAV format (little endian default). */
+ SF_FORMAT_AIFF = 0x020000, /* Apple/SGI AIFF format (big endian). */
+ SF_FORMAT_AU = 0x030000, /* Sun/NeXT AU format (big endian). */
+ SF_FORMAT_RAW = 0x040000, /* RAW PCM data. */
+ SF_FORMAT_PAF = 0x050000, /* Ensoniq PARIS file format. */
+ SF_FORMAT_SVX = 0x060000, /* Amiga IFF / SVX8 / SV16 format. */
+ SF_FORMAT_NIST = 0x070000, /* Sphere NIST format. */
+ SF_FORMAT_VOC = 0x080000, /* VOC files. */
+ SF_FORMAT_IRCAM = 0x0A0000, /* Berkeley/IRCAM/CARL */
+ SF_FORMAT_W64 = 0x0B0000, /* Sonic Foundry's 64 bit RIFF/WAV */
+ SF_FORMAT_MAT4 = 0x0C0000, /* Matlab (tm) V4.2 / GNU Octave 2.0 */
+ SF_FORMAT_MAT5 = 0x0D0000, /* Matlab (tm) V5.0 / GNU Octave 2.1 */
+ SF_FORMAT_PVF = 0x0E0000, /* Portable Voice Format */
+ SF_FORMAT_XI = 0x0F0000, /* Fasttracker 2 Extended Instrument */
+ SF_FORMAT_HTK = 0x100000, /* HMM Tool Kit format */
+ SF_FORMAT_SDS = 0x110000, /* Midi Sample Dump Standard */
+ SF_FORMAT_AVR = 0x120000, /* Audio Visual Research */
+ SF_FORMAT_WAVEX = 0x130000, /* MS WAVE with WAVEFORMATEX */
+ SF_FORMAT_SD2 = 0x160000, /* Sound Designer 2 */
+ SF_FORMAT_FLAC = 0x170000, /* FLAC lossless file format */
+ SF_FORMAT_CAF = 0x180000, /* Core Audio File format */
+ SF_FORMAT_WVE = 0x190000, /* Psion WVE format */
+ SF_FORMAT_OGG = 0x200000, /* Xiph OGG container */
+ SF_FORMAT_MPC2K = 0x210000, /* Akai MPC 2000 sampler */
+ SF_FORMAT_RF64 = 0x220000, /* RF64 WAV file */
+ SF_FORMAT_MPEG = 0x230000, /* MPEG-1/2 audio stream */
+
+ /* Subtypes from here on. */
+
+ SF_FORMAT_PCM_S8 = 0x0001, /* Signed 8 bit data */
+ SF_FORMAT_PCM_16 = 0x0002, /* Signed 16 bit data */
+ SF_FORMAT_PCM_24 = 0x0003, /* Signed 24 bit data */
+ SF_FORMAT_PCM_32 = 0x0004, /* Signed 32 bit data */
+
+ SF_FORMAT_PCM_U8 = 0x0005, /* Unsigned 8 bit data (WAV and RAW only) */
+
+ SF_FORMAT_FLOAT = 0x0006, /* 32 bit float data */
+ SF_FORMAT_DOUBLE = 0x0007, /* 64 bit float data */
+
+ SF_FORMAT_ULAW = 0x0010, /* U-Law encoded. */
+ SF_FORMAT_ALAW = 0x0011, /* A-Law encoded. */
+ SF_FORMAT_IMA_ADPCM = 0x0012, /* IMA ADPCM. */
+ SF_FORMAT_MS_ADPCM = 0x0013, /* Microsoft ADPCM. */
+
+ SF_FORMAT_GSM610 = 0x0020, /* GSM 6.10 encoding. */
+ SF_FORMAT_VOX_ADPCM = 0x0021, /* OKI / Dialogix ADPCM */
+
+ SF_FORMAT_NMS_ADPCM_16 = 0x0022, /* 16kbs NMS G721-variant encoding. */
+ SF_FORMAT_NMS_ADPCM_24 = 0x0023, /* 24kbs NMS G721-variant encoding. */
+ SF_FORMAT_NMS_ADPCM_32 = 0x0024, /* 32kbs NMS G721-variant encoding. */
+
+ SF_FORMAT_G721_32 = 0x0030, /* 32kbs G721 ADPCM encoding. */
+ SF_FORMAT_G723_24 = 0x0031, /* 24kbs G723 ADPCM encoding. */
+ SF_FORMAT_G723_40 = 0x0032, /* 40kbs G723 ADPCM encoding. */
+
+ SF_FORMAT_DWVW_12 = 0x0040, /* 12 bit Delta Width Variable Word encoding. */
+ SF_FORMAT_DWVW_16 = 0x0041, /* 16 bit Delta Width Variable Word encoding. */
+ SF_FORMAT_DWVW_24 = 0x0042, /* 24 bit Delta Width Variable Word encoding. */
+ SF_FORMAT_DWVW_N = 0x0043, /* N bit Delta Width Variable Word encoding. */
+
+ SF_FORMAT_DPCM_8 = 0x0050, /* 8 bit differential PCM (XI only) */
+ SF_FORMAT_DPCM_16 = 0x0051, /* 16 bit differential PCM (XI only) */
+
+ SF_FORMAT_VORBIS = 0x0060, /* Xiph Vorbis encoding. */
+ SF_FORMAT_OPUS = 0x0064, /* Xiph/Skype Opus encoding. */
+
+ SF_FORMAT_ALAC_16 = 0x0070, /* Apple Lossless Audio Codec (16 bit). */
+ SF_FORMAT_ALAC_20 = 0x0071, /* Apple Lossless Audio Codec (20 bit). */
+ SF_FORMAT_ALAC_24 = 0x0072, /* Apple Lossless Audio Codec (24 bit). */
+ SF_FORMAT_ALAC_32 = 0x0073, /* Apple Lossless Audio Codec (32 bit). */
+
+ SF_FORMAT_MPEG_LAYER_I = 0x0080, /* MPEG-1 Audio Layer I */
+ SF_FORMAT_MPEG_LAYER_II = 0x0081, /* MPEG-1 Audio Layer II */
+ SF_FORMAT_MPEG_LAYER_III = 0x0082, /* MPEG-2 Audio Layer III */
+
+ /* Endian-ness options. */
+
+ SF_ENDIAN_FILE = 0x00000000, /* Default file endian-ness. */
+ SF_ENDIAN_LITTLE = 0x10000000, /* Force little endian-ness. */
+ SF_ENDIAN_BIG = 0x20000000, /* Force big endian-ness. */
+ SF_ENDIAN_CPU = 0x30000000, /* Force CPU endian-ness. */
+
+ SF_FORMAT_SUBMASK = 0x0000FFFF,
+ SF_FORMAT_TYPEMASK = 0x0FFF0000,
+ SF_FORMAT_ENDMASK = 0x30000000
+};
+
+/** valid command numbers for the sf_command() interface */
+enum
+{ SFC_GET_LIB_VERSION = 0x1000,
+ SFC_GET_LOG_INFO = 0x1001,
+ SFC_GET_CURRENT_SF_INFO = 0x1002,
+
+
+ SFC_GET_NORM_DOUBLE = 0x1010,
+ SFC_GET_NORM_FLOAT = 0x1011,
+ SFC_SET_NORM_DOUBLE = 0x1012,
+ SFC_SET_NORM_FLOAT = 0x1013,
+ SFC_SET_SCALE_FLOAT_INT_READ = 0x1014,
+ SFC_SET_SCALE_INT_FLOAT_WRITE = 0x1015,
+
+ SFC_GET_SIMPLE_FORMAT_COUNT = 0x1020,
+ SFC_GET_SIMPLE_FORMAT = 0x1021,
+
+ SFC_GET_FORMAT_INFO = 0x1028,
+
+ SFC_GET_FORMAT_MAJOR_COUNT = 0x1030,
+ SFC_GET_FORMAT_MAJOR = 0x1031,
+ SFC_GET_FORMAT_SUBTYPE_COUNT = 0x1032,
+ SFC_GET_FORMAT_SUBTYPE = 0x1033,
+
+ SFC_CALC_SIGNAL_MAX = 0x1040,
+ SFC_CALC_NORM_SIGNAL_MAX = 0x1041,
+ SFC_CALC_MAX_ALL_CHANNELS = 0x1042,
+ SFC_CALC_NORM_MAX_ALL_CHANNELS = 0x1043,
+ SFC_GET_SIGNAL_MAX = 0x1044,
+ SFC_GET_MAX_ALL_CHANNELS = 0x1045,
+
+ SFC_SET_ADD_PEAK_CHUNK = 0x1050,
+
+ SFC_UPDATE_HEADER_NOW = 0x1060,
+ SFC_SET_UPDATE_HEADER_AUTO = 0x1061,
+
+ SFC_FILE_TRUNCATE = 0x1080,
+
+ SFC_SET_RAW_START_OFFSET = 0x1090,
+
+ /* Commands reserved for dithering, which is not implemented. */
+ SFC_SET_DITHER_ON_WRITE = 0x10A0,
+ SFC_SET_DITHER_ON_READ = 0x10A1,
+
+ SFC_GET_DITHER_INFO_COUNT = 0x10A2,
+ SFC_GET_DITHER_INFO = 0x10A3,
+
+ SFC_GET_EMBED_FILE_INFO = 0x10B0,
+
+ SFC_SET_CLIPPING = 0x10C0,
+ SFC_GET_CLIPPING = 0x10C1,
+
+ SFC_GET_CUE_COUNT = 0x10CD,
+ SFC_GET_CUE = 0x10CE,
+ SFC_SET_CUE = 0x10CF,
+
+ SFC_GET_INSTRUMENT = 0x10D0,
+ SFC_SET_INSTRUMENT = 0x10D1,
+
+ SFC_GET_LOOP_INFO = 0x10E0,
+
+ SFC_GET_BROADCAST_INFO = 0x10F0,
+ SFC_SET_BROADCAST_INFO = 0x10F1,
+
+ SFC_GET_CHANNEL_MAP_INFO = 0x1100,
+ SFC_SET_CHANNEL_MAP_INFO = 0x1101,
+
+ SFC_RAW_DATA_NEEDS_ENDSWAP = 0x1110,
+
+ /* Support for Wavex Ambisonics Format */
+ SFC_WAVEX_SET_AMBISONIC = 0x1200,
+ SFC_WAVEX_GET_AMBISONIC = 0x1201,
+
+ /*
+ ** RF64 files can be set so that on-close, writable files that have less
+ ** than 4GB of data in them are converted to RIFF/WAV, as per EBU
+ ** recommendations.
+ */
+ SFC_RF64_AUTO_DOWNGRADE = 0x1210,
+
+ SFC_SET_VBR_ENCODING_QUALITY = 0x1300,
+ SFC_SET_COMPRESSION_LEVEL = 0x1301,
+
+ /* Ogg format commands */
+ SFC_SET_OGG_PAGE_LATENCY_MS = 0x1302,
+ SFC_SET_OGG_PAGE_LATENCY = 0x1303,
+ SFC_GET_OGG_STREAM_SERIALNO = 0x1306,
+
+ SFC_GET_BITRATE_MODE = 0x1304,
+ SFC_SET_BITRATE_MODE = 0x1305,
+
+ /* Cart Chunk support */
+ SFC_SET_CART_INFO = 0x1400,
+ SFC_GET_CART_INFO = 0x1401,
+
+ /* Opus files original samplerate metadata */
+ SFC_SET_ORIGINAL_SAMPLERATE = 0x1500,
+ SFC_GET_ORIGINAL_SAMPLERATE = 0x1501,
+
+ /* Following commands for testing only. */
+ SFC_TEST_IEEE_FLOAT_REPLACE = 0x6001,
+
+ /*
+ ** These SFC_SET_ADD_* values are deprecated and will disappear at some
+ ** time in the future. They are guaranteed to be here up to and
+ ** including version 1.0.8 to avoid breakage of existing software.
+ ** They currently do nothing and will continue to do nothing.
+ */
+ SFC_SET_ADD_HEADER_PAD_CHUNK = 0x1051,
+
+ SFC_SET_ADD_DITHER_ON_WRITE = 0x1070,
+ SFC_SET_ADD_DITHER_ON_READ = 0x1071
+};
+
+/** String types that can be set and read from files. */
+enum
+{ SF_STR_TITLE = 0x01,
+ SF_STR_COPYRIGHT = 0x02,
+ SF_STR_SOFTWARE = 0x03,
+ SF_STR_ARTIST = 0x04,
+ SF_STR_COMMENT = 0x05,
+ SF_STR_DATE = 0x06,
+ SF_STR_ALBUM = 0x07,
+ SF_STR_LICENSE = 0x08,
+ SF_STR_TRACKNUMBER = 0x09,
+ SF_STR_GENRE = 0x10
+} ;
+
+/** Start and End index when doing metadata transcoding. */
+#define SF_STR_FIRST SF_STR_TITLE
+#define SF_STR_LAST SF_STR_GENRE
+
+enum
+{ /* True and false */
+ SF_FALSE = 0,
+ SF_TRUE = 1,
+
+ /* Modes for opening files. */
+ SFM_READ = 0x10,
+ SFM_WRITE = 0x20,
+ SFM_RDWR = 0x30,
+
+ SF_AMBISONIC_NONE = 0x40,
+ SF_AMBISONIC_B_FORMAT = 0x41
+};
+
+/** Error codes. */
+enum
+{ SF_ERR_NO_ERROR = 0,
+ SF_ERR_UNRECOGNISED_FORMAT = 1,
+ SF_ERR_SYSTEM = 2,
+ SF_ERR_MALFORMED_FILE = 3,
+ SF_ERR_UNSUPPORTED_ENCODING = 4
+};
+
+/** Channel map values (used with SFC_SET/GET_CHANNEL_MAP). */
+enum
+{ SF_CHANNEL_MAP_INVALID = 0,
+ SF_CHANNEL_MAP_MONO = 1,
+ SF_CHANNEL_MAP_LEFT, /* Apple calls this 'Left' */
+ SF_CHANNEL_MAP_RIGHT, /* Apple calls this 'Right' */
+ SF_CHANNEL_MAP_CENTER, /* Apple calls this 'Center' */
+ SF_CHANNEL_MAP_FRONT_LEFT,
+ SF_CHANNEL_MAP_FRONT_RIGHT,
+ SF_CHANNEL_MAP_FRONT_CENTER,
+ SF_CHANNEL_MAP_REAR_CENTER, /* Apple calls this 'Center Surround', Msft calls this 'Back Center' */
+ SF_CHANNEL_MAP_REAR_LEFT, /* Apple calls this 'Left Surround', Msft calls this 'Back Left' */
+ SF_CHANNEL_MAP_REAR_RIGHT, /* Apple calls this 'Right Surround', Msft calls this 'Back Right' */
+ SF_CHANNEL_MAP_LFE, /* Apple calls this 'LFEScreen', Msft calls this 'Low Frequency' */
+ SF_CHANNEL_MAP_FRONT_LEFT_OF_CENTER, /* Apple calls this 'Left Center' */
+ SF_CHANNEL_MAP_FRONT_RIGHT_OF_CENTER, /* Apple calls this 'Right Center */
+ SF_CHANNEL_MAP_SIDE_LEFT, /* Apple calls this 'Left Surround Direct' */
+ SF_CHANNEL_MAP_SIDE_RIGHT, /* Apple calls this 'Right Surround Direct' */
+ SF_CHANNEL_MAP_TOP_CENTER, /* Apple calls this 'Top Center Surround' */
+ SF_CHANNEL_MAP_TOP_FRONT_LEFT, /* Apple calls this 'Vertical Height Left' */
+ SF_CHANNEL_MAP_TOP_FRONT_RIGHT, /* Apple calls this 'Vertical Height Right' */
+ SF_CHANNEL_MAP_TOP_FRONT_CENTER, /* Apple calls this 'Vertical Height Center' */
+ SF_CHANNEL_MAP_TOP_REAR_LEFT, /* Apple and MS call this 'Top Back Left' */
+ SF_CHANNEL_MAP_TOP_REAR_RIGHT, /* Apple and MS call this 'Top Back Right' */
+ SF_CHANNEL_MAP_TOP_REAR_CENTER, /* Apple and MS call this 'Top Back Center' */
+
+ SF_CHANNEL_MAP_AMBISONIC_B_W,
+ SF_CHANNEL_MAP_AMBISONIC_B_X,
+ SF_CHANNEL_MAP_AMBISONIC_B_Y,
+ SF_CHANNEL_MAP_AMBISONIC_B_Z,
+
+ SF_CHANNEL_MAP_MAX
+};
+
+/** Bitrate mode values (for use with SFC_GET/SET_BITRATE_MODE) */
+enum
+{ SF_BITRATE_MODE_CONSTANT = 0,
+ SF_BITRATE_MODE_AVERAGE,
+ SF_BITRATE_MODE_VARIABLE
+};
+
+/* A SNDFILE* pointer can be passed around much like stdio.h's FILE* pointer. */
+typedef struct sf_private_tag SNDFILE ;
+
+/* The following typedef is system specific and is defined when libsndfile is
+** compiled. sf_count_t will be a 64 bit value when the underlying OS allows
+** 64 bit file offsets.
+** On windows, we need to allow the same header file to be compiler by both GCC
+** and the Microsoft compiler.
+*/
+
+typedef int64_t sf_count_t ;
+#ifndef SF_COUNT_MAX
+#define SF_COUNT_MAX INT64_MAX
+#endif
+
+/* A pointer to a SF_INFO structure is passed to sf_open () and filled in.
+** On write, the SF_INFO structure is filled in by the user and passed into
+** sf_open ().
+*/
+struct SF_INFO
+{ sf_count_t frames ; /* Used to be called samples. Changed to avoid confusion. */
+ int samplerate ;
+ int channels ;
+ int format ;
+ int sections ;
+ int seekable ;
+} ;
+
+typedef struct SF_INFO SF_INFO ;
+
+/* The SF_FORMAT_INFO struct is used to retrieve information about the sound
+** file formats libsndfile supports using the sf_command () interface.
+*/
+typedef struct
+{ int format ;
+ const char *name ;
+ const char *extension ;
+} SF_FORMAT_INFO;
+
+/* Open the specified file for read, write or both. On error, this will
+** return a NULL pointer. To find the error number, pass a NULL SNDFILE
+** to sf_strerror ().
+** All calls to sf_open() should be matched with a call to sf_close().
+*/
+SNDFILE* sf_open (const char *path, int mode, SF_INFO *sfinfo) ;
+
+/* Use the existing file descriptor to create a SNDFILE object. If close_desc
+** is TRUE, the file descriptor will be closed when sf_close() is called. If
+** it is FALSE, the descriptor will not be closed.
+** When passed a descriptor like this, the library will assume that the start
+** of file header is at the current file offset. This allows sound files within
+** larger container files to be read and/or written.
+** On error, this will return a NULL pointer. To find the error number, pass a
+** NULL SNDFILE to sf_strerror ().
+** All calls to sf_open_fd() should be matched with a call to sf_close().
+*/
+
+SNDFILE* sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc) ;
+
+
+/* sf_error () returns a error number which can be translated to a text
+** string using sf_error_number().
+*/
+
+int sf_error (SNDFILE *sndfile) ;
+
+
+/* sf_strerror () returns to the caller a pointer to the current error message for
+** the given SNDFILE.
+*/
+
+const char* sf_strerror (SNDFILE *sndfile) ;
+
+
+/* sf_error_number () allows the retrieval of the error string for each internal
+** error number.
+**
+*/
+
+const char* sf_error_number (int errnum) ;
+
+
+/* The following two error functions are deprecated but they will remain in the
+** library for the foreseeable future. The function sf_strerror() should be used
+** in their place.
+*/
+
+int sf_perror (SNDFILE *sndfile) ;
+int sf_error_str (SNDFILE *sndfile, char* str, size_t len) ;
+
+
+/* Allow the caller to retrieve information from or change aspects of the
+** library behaviour.
+*/
+
+int sf_command (SNDFILE *sndfile, int command, void *data, int datasize) ;
+
+
+/* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */
+
+int sf_format_check (const SF_INFO *info) ;
+
+
+
+/* Functions for retrieving and setting string data within sound files.
+** Not all file types support this features; AIFF and WAV do. For both
+** functions, the str_type parameter must be one of the SF_STR_* values
+** defined above.
+** On error, sf_set_string() returns non-zero while sf_get_string()
+** returns NULL.
+*/
+
+int sf_set_string (SNDFILE *sndfile, int str_type, const char* str) ;
+
+const char* sf_get_string (SNDFILE *sndfile, int str_type) ;
+
+/* Return the library version string. */
+const char * sf_version_string (void) ;
+
+/* Return the current byterate at this point in the file. The byte rate in this
+** case is the number of bytes per second of audio data. For instance, for a
+** stereo, 18 bit PCM encoded file with an 16kHz sample rate, the byte rate
+** would be 2 (stereo) * 2 (two bytes per sample) * 16000 => 64000 bytes/sec.
+** For some file formats the returned value will be accurate and exact, for some
+** it will be a close approximation, for some it will be the average bitrate for
+** the whole file and for some it will be a time varying value that was accurate
+** when the file was most recently read or written.
+** To get the bitrate, multiple this value by 8.
+** Returns -1 for unknown.
+*/
+int sf_current_byterate (SNDFILE *sndfile) ;
+
+/* Functions for reading/writing the waveform data of a sound file.
+*/
+
+sf_count_t sf_read_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
+sf_count_t sf_write_raw (SNDFILE *sndfile, const void *ptr, sf_count_t bytes) ;
+
+/* Functions for reading and writing the data chunk in terms of frames.
+** The number of items actually read/written = frames * number of channels.
+** sf_xxxx_raw read/writes the raw data bytes from/to the file
+** sf_xxxx_short passes data in the native short format
+** sf_xxxx_int passes data in the native int format
+** sf_xxxx_float passes data in the native float format
+** sf_xxxx_double passes data in the native double format
+** All of these read/write function return number of frames read/written.
+*/
+
+sf_count_t sf_readf_short (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_short (SNDFILE *sndfile, const short *ptr, sf_count_t frames) ;
+
+sf_count_t sf_readf_int (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_int (SNDFILE *sndfile, const int *ptr, sf_count_t frames) ;
+
+sf_count_t sf_readf_float (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_float (SNDFILE *sndfile, const float *ptr, sf_count_t frames) ;
+
+sf_count_t sf_readf_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_double (SNDFILE *sndfile, const double *ptr, sf_count_t frames) ;
+
+
+/* Functions for reading and writing the data chunk in terms of items.
+** Otherwise similar to above.
+** All of these read/write function return number of items read/written.
+*/
+
+sf_count_t sf_read_short (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
+sf_count_t sf_write_short (SNDFILE *sndfile, const short *ptr, sf_count_t items) ;
+
+sf_count_t sf_read_int (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
+sf_count_t sf_write_int (SNDFILE *sndfile, const int *ptr, sf_count_t items) ;
+
+sf_count_t sf_read_float (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
+sf_count_t sf_write_float (SNDFILE *sndfile, const float *ptr, sf_count_t items) ;
+
+sf_count_t sf_read_double (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
+sf_count_t sf_write_double (SNDFILE *sndfile, const double *ptr, sf_count_t items) ;
+
+
+/* Close the SNDFILE and clean up all memory allocations associated with this
+** file.
+** Returns 0 on success, or an error number.
+*/
+
+int sf_close (SNDFILE *sndfile) ;
+
+
+/* If the file is opened SFM_WRITE or SFM_RDWR, call fsync() on the file
+** to force the writing of data to disk. If the file is opened SFM_READ
+** no action is taken.
+*/
+
+void sf_write_sync (SNDFILE *sndfile) ;
+
+
+
+/* The function sf_wchar_open() is Windows Only!
+** Open a file passing in a Windows Unicode filename. Otherwise, this is
+** the same as sf_open().
+*/
+
+/* #ifdef _WIN32
+** SNDFILE* sf_wchar_open (const wchar_t *wpath, int mode, SF_INFO *sfinfo) ;
+** #endif
+*/
\ No newline at end of file
diff --git a/shared/macosx-x86_64/include/transformersphp.h b/shared/macosx-x86_64/include/transformersphp.h
new file mode 100644
index 0000000..7c9c4b8
--- /dev/null
+++ b/shared/macosx-x86_64/include/transformersphp.h
@@ -0,0 +1,19 @@
+#ifndef FAST_TRANSFORMERS_UTILS_H
+#define FAST_TRANSFORMERS_UTILS_H
+
+enum {
+ LOG_MEL_NONE = 0,
+ LOG_MEL_LOG = 1,
+ LOG_MEL_LOG10 = 2,
+ LOG_MEL_DB = 3
+};
+
+void pad_reflect(float *input, int length, float *padded, int padded_length);
+
+void spectrogram(
+ float *waveform, int waveform_length, float *spectrogram, int spectrogram_length, int hop_length, int fft_length,
+ float *window,int window_length, int d1, int d1_max, float power, int center, float preemphasis, float *mel_filters,
+ int num_mel_filters, int num_frequency_bins, float mel_floor, int log_mel, int remove_dc_offset, int do_pad, int transpose
+);
+
+#endif // FAST_TRANSFORMERS_UTILS_H
diff --git a/shared/macosx-x86_64/lib/libomp.dylib b/shared/macosx-x86_64/lib/libomp.dylib
new file mode 100644
index 0000000..8fe1601
Binary files /dev/null and b/shared/macosx-x86_64/lib/libomp.dylib differ
diff --git a/shared/macosx-x86_64/lib/libonnxruntime.1.21.0.dylib b/shared/macosx-x86_64/lib/libonnxruntime.1.21.0.dylib
new file mode 100755
index 0000000..ac25cc7
Binary files /dev/null and b/shared/macosx-x86_64/lib/libonnxruntime.1.21.0.dylib differ
diff --git a/shared/macosx-x86_64/lib/libopenblas.0.3.28.dylib b/shared/macosx-x86_64/lib/libopenblas.0.3.28.dylib
new file mode 100755
index 0000000..a69f560
Binary files /dev/null and b/shared/macosx-x86_64/lib/libopenblas.0.3.28.dylib differ
diff --git a/shared/macosx-x86_64/lib/librindowmatlib.1.1.1.dylib b/shared/macosx-x86_64/lib/librindowmatlib.1.1.1.dylib
new file mode 100755
index 0000000..dc04892
Binary files /dev/null and b/shared/macosx-x86_64/lib/librindowmatlib.1.1.1.dylib differ
diff --git a/shared/macosx-x86_64/lib/libsamplerate.0.2.2.dylib b/shared/macosx-x86_64/lib/libsamplerate.0.2.2.dylib
new file mode 100644
index 0000000..d68e8d7
Binary files /dev/null and b/shared/macosx-x86_64/lib/libsamplerate.0.2.2.dylib differ
diff --git a/shared/macosx-x86_64/lib/libsndfile.1.2.2.dylib b/shared/macosx-x86_64/lib/libsndfile.1.2.2.dylib
new file mode 100644
index 0000000..18e9334
Binary files /dev/null and b/shared/macosx-x86_64/lib/libsndfile.1.2.2.dylib differ
diff --git a/shared/macosx-x86_64/lib/libtransformersphp.1.0.0.dylib b/shared/macosx-x86_64/lib/libtransformersphp.1.0.0.dylib
new file mode 100755
index 0000000..26872cb
Binary files /dev/null and b/shared/macosx-x86_64/lib/libtransformersphp.1.0.0.dylib differ
diff --git a/shared/macosx-x86_64/lib/libvips.42.dylib b/shared/macosx-x86_64/lib/libvips.42.dylib
new file mode 100644
index 0000000..70cab10
Binary files /dev/null and b/shared/macosx-x86_64/lib/libvips.42.dylib differ
diff --git a/shared/windows-x86_64/THIRD_PARTY_NOTICES.md b/shared/windows-x86_64/THIRD_PARTY_NOTICES.md
new file mode 100644
index 0000000..0cf3657
--- /dev/null
+++ b/shared/windows-x86_64/THIRD_PARTY_NOTICES.md
@@ -0,0 +1,52 @@
+# Third-party notices
+
+TransformersPHP includes compiled binaries of third-party libraries as a convenience to users. These binaries are
+distributed to facilitate the functionality of TransformersPHP, but TransformersPHP does not claim ownership of the
+binaries or the underlying libraries. The original authors and contributors of these libraries retain all rights. It is
+the user's responsibility to ensure compliance with the respective licenses of these libraries when using or
+distributing the bundled binaries.
+
+Below is a list of the third-party libraries included with TransformersPHP, along with their respective licenses and
+other relevant information.
+
+| Library | Used under the terms of |
+|---------------|-----------------------------------------------------------------------------------------------------------|
+| OpenMP | MIT License |
+| OnnxRuntime | MIT License |
+| OpenBlas | BSD 3-Clause License |
+| Rindow Matlib | BSD 3-Clause License |
+| LibSamplerate | BSD 2-Clause License |
+| Libsndfile | LGPL 2.1 License |
+| aom | BSD 2-Clause + [Alliance for Open Media Patent License 1.0](https://aomedia.org/license/patent-license/) |
+| cairo | Mozilla Public License 2.0 |
+| cgif | MIT Licence |
+| expat | MIT Licence |
+| fontconfig | [fontconfig Licence](https://gitlab.freedesktop.org/fontconfig/fontconfig/blob/main/COPYING) (BSD-like) |
+| freetype | [freetype Licence](https://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/docs/FTL.TXT) (BSD-like) |
+| fribidi | LGPLv3 |
+| glib | LGPLv3 |
+| harfbuzz | MIT Licence |
+| highway | Apache-2.0 License, BSD 3-Clause |
+| lcms | MIT Licence |
+| libarchive | BSD 2-Clause |
+| libexif | LGPLv3 |
+| libffi | MIT Licence |
+| libheif | LGPLv3 |
+| libimagequant | [BSD 2-Clause](https://github.com/lovell/libimagequant/blob/main/COPYRIGHT) |
+| libnsgif | MIT Licence |
+| libpng | [libpng License](https://github.com/pnggroup/libpng/blob/master/LICENSE) |
+| librsvg | LGPLv3 |
+| libspng | [BSD 2-Clause, libpng License](https://github.com/randy408/libspng/blob/master/LICENSE) |
+| libtiff | [libtiff License](https://gitlab.com/libtiff/libtiff/blob/master/LICENSE.md) (BSD-like) |
+| libvips | LGPLv3 |
+| libwebp | New BSD License |
+| libxml2 | MIT Licence |
+| mozjpeg | [zlib License, IJG License, BSD-3-Clause](https://github.com/mozilla/mozjpeg/blob/master/LICENSE.md) |
+| pango | LGPLv3 |
+| pixman | MIT Licence |
+| proxy-libintl | LGPLv3 |
+| zlib-ng | [zlib Licence](https://github.com/zlib-ng/zlib-ng/blob/develop/LICENSE.md) |
+
+---
+
+
diff --git a/shared/windows-x86_64/include/buffer.h b/shared/windows-x86_64/include/buffer.h
new file mode 100644
index 0000000..e086179
--- /dev/null
+++ b/shared/windows-x86_64/include/buffer.h
@@ -0,0 +1,5 @@
+#define FFI_SCOPE "Rindow\\Math\\Buffer\\FFI"
+
+typedef struct _rindow_complex_float { float real, imag; } rindow_complex_float;
+typedef struct _rindow_complex_double { double real, imag; } rindow_complex_double;
+//typedef struct { xdouble real, imag; } openblas_complex_xdouble;
diff --git a/shared/windows-x86_64/include/matlib.h b/shared/windows-x86_64/include/matlib.h
new file mode 100644
index 0000000..612189c
--- /dev/null
+++ b/shared/windows-x86_64/include/matlib.h
@@ -0,0 +1,397 @@
+#ifndef RINDOW_MATLIB_H_
+#define RINDOW_MATLIB_H_
+
+#include
+
+enum rindow_matlib_dtype
+{
+ rindow_matlib_dtype_unknown = 0,
+ rindow_matlib_dtype_bool = 1,
+ rindow_matlib_dtype_int8 = 2,
+ rindow_matlib_dtype_int16 = 3,
+ rindow_matlib_dtype_int32 = 4,
+ rindow_matlib_dtype_int64 = 5,
+ rindow_matlib_dtype_uint8 = 6,
+ rindow_matlib_dtype_uint16 = 7,
+ rindow_matlib_dtype_uint32 = 8,
+ rindow_matlib_dtype_uint64 = 9,
+ rindow_matlib_dtype_float8 = 10,
+ rindow_matlib_dtype_float16 = 11,
+ rindow_matlib_dtype_float32 = 12,
+ rindow_matlib_dtype_float64 = 13,
+ rindow_matlib_dtype_complex16 = 14,
+ rindow_matlib_dtype_complex32 = 15,
+ rindow_matlib_dtype_complex64 = 16,
+ rindow_matlib_dtype_complex128 = 17
+};
+
+#if _MSC_VER
+#if !defined(RINDOW_FUNC)
+#if defined(RINDOW_COMPILING_DLL)
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL extern __declspec(dllexport)
+#elif defined(RINDOW_MATLIB_INCLUDING_SOURCE)
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL
+#else
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL extern __declspec(dllimport)
+#endif
+#endif
+#else // _MSC_VER
+#define RINDOW_FUNC
+#define RINDOW_FUNC_DECL extern
+#endif // _MSC_VER
+
+#define RINDOW_MATLIB_SUCCESS 0
+#define RINDOW_MATLIB_E_MEM_ALLOC_FAILURE -101
+#define RINDOW_MATLIB_E_PERM_OUT_OF_RANGE -102
+#define RINDOW_MATLIB_E_DUP_AXIS -103
+#define RINDOW_MATLIB_E_UNSUPPORTED_DATA_TYPE -104
+#define RINDOW_MATLIB_E_UNMATCH_IMAGE_BUFFER_SIZE -105
+#define RINDOW_MATLIB_E_UNMATCH_COLS_BUFFER_SIZE -106
+#define RINDOW_MATLIB_E_INVALID_SHAPE_OR_PARAM -107
+#define RINDOW_MATLIB_E_IMAGES_OUT_OF_RANGE -108
+#define RINDOW_MATLIB_E_COLS_OUT_OF_RANGE -109
+
+#define RINDOW_MATLIB_NO_TRANS 111
+#define RINDOW_MATLIB_TRANS 112
+// #define RINDOW_MATLIB_CONJ_TRANS 113
+// #define RINDOW_MATLIB_CONJ_NO_TRANS 114
+
+// Matlib is compiled for sequential use
+#define RINDOW_MATLIB_SEQUENTIAL 0
+// Matlib is compiled using normal threading model
+#define RINDOW_MATLIB_THREAD 1
+// Matlib is compiled using OpenMP threading model
+#define RINDOW_MATLIB_OPENMP 2
+
+static inline int32_t rindow_matlib_common_dtype_to_valuesize(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_bool:
+ case rindow_matlib_dtype_int8:
+ case rindow_matlib_dtype_uint8:
+ case rindow_matlib_dtype_float8:
+ return 1;
+ case rindow_matlib_dtype_int16:
+ case rindow_matlib_dtype_uint16:
+ case rindow_matlib_dtype_float16:
+ case rindow_matlib_dtype_complex16:
+ return 2;
+ case rindow_matlib_dtype_int32:
+ case rindow_matlib_dtype_uint32:
+ case rindow_matlib_dtype_float32:
+ case rindow_matlib_dtype_complex32:
+ return 4;
+ case rindow_matlib_dtype_int64:
+ case rindow_matlib_dtype_uint64:
+ case rindow_matlib_dtype_float64:
+ case rindow_matlib_dtype_complex64:
+ return 8;
+ case rindow_matlib_dtype_complex128:
+ return 16;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_int(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_int8:
+ case rindow_matlib_dtype_uint8:
+ case rindow_matlib_dtype_int16:
+ case rindow_matlib_dtype_uint16:
+ case rindow_matlib_dtype_int32:
+ case rindow_matlib_dtype_uint32:
+ case rindow_matlib_dtype_int64:
+ case rindow_matlib_dtype_uint64:
+ return 1;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_float(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_float8:
+ case rindow_matlib_dtype_float16:
+ case rindow_matlib_dtype_float32:
+ case rindow_matlib_dtype_float64:
+ return 1;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_complex(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_complex16:
+ case rindow_matlib_dtype_complex32:
+ case rindow_matlib_dtype_complex64:
+ case rindow_matlib_dtype_complex128:
+ return 1;
+ }
+ return 0;
+}
+
+static inline int32_t rindow_matlib_common_dtype_is_bool(int32_t dtype)
+{
+ switch (dtype)
+ {
+ case rindow_matlib_dtype_bool:
+ return 1;
+ }
+ return 0;
+}
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_common_get_nprocs(void);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_common_get_num_threads(void);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_common_get_parallel(void);
+ RINDOW_FUNC_DECL char *rindow_matlib_common_get_version(void);
+
+ RINDOW_FUNC_DECL void *rindow_matlib_common_get_address(int32_t dtype, void *buffer, int32_t offset);
+
+ RINDOW_FUNC_DECL float rindow_matlib_s_sum(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL double rindow_matlib_d_sum(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL int64_t rindow_matlib_i_sum(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_imax(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_imax(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_imax(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_imin(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_imin(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_imin(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_increment(int32_t n, float *x, int32_t incX, float alpha, float beta);
+ RINDOW_FUNC_DECL void rindow_matlib_d_increment(int32_t n, double *x, int32_t incX, double alpha, double beta);
+ RINDOW_FUNC_DECL void rindow_matlib_s_reciprocal(int32_t n, float *x, int32_t incX, float alpha, float beta);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reciprocal(int32_t n, double *x, int32_t incX, double alpha, double beta);
+ RINDOW_FUNC_DECL void rindow_matlib_s_maximum(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_maximum(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_minimum(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_minimum(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_greater(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_greater(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_greater_equal(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_greater_equal(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_less(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_less(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_less_equal(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_less_equal(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_multiply(int32_t trans, int32_t m, int32_t n, float *x, int32_t incX, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_multiply(int32_t trans, int32_t m, int32_t n, double *x, int32_t incX, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_add(int32_t trans, int32_t m, int32_t n, float alpha, float *x, int32_t incX, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_add(int32_t trans, int32_t m, int32_t n, double alpha, double *x, int32_t incX, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_duplicate(int32_t trans, int32_t m, int32_t n, float *x, int32_t incX, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_duplicate(int32_t trans, int32_t m, int32_t n, double *x, int32_t incX, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_masking(int32_t m, int32_t n, int32_t k, int32_t len, float fill, int32_t mode, uint8_t *x, float *a);
+ RINDOW_FUNC_DECL void rindow_matlib_d_masking(int32_t m, int32_t n, int32_t k, int32_t len, double fill, int32_t mode, uint8_t *x, double *a);
+ RINDOW_FUNC_DECL void rindow_matlib_i_masking(int32_t dtype, int32_t m, int32_t n, int32_t k, int32_t len, void *fill, int32_t mode, uint8_t *x, void *a);
+ RINDOW_FUNC_DECL void rindow_matlib_s_square(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_square(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_sqrt(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_sqrt(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_rsqrt(int32_t n, float alpha, float *x, int32_t incX, float beta);
+ RINDOW_FUNC_DECL void rindow_matlib_d_rsqrt(int32_t n, double alpha, double *x, int32_t incX, double beta);
+ RINDOW_FUNC_DECL void rindow_matlib_s_pow(int32_t trans, int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_pow(int32_t trans, int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_exp(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_exp(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_log(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_log(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_tanh(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_tanh(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_sin(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_sin(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_cos(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_cos(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_tan(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_tan(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_zeros(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_zeros(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_i_zeros(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_onehot(int32_t dtype, int32_t m, int32_t n, void *x, int32_t incX, float alpha, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_onehot(int32_t dtype, int32_t m, int32_t n, void *x, int32_t incX, double alpha, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_softmax(int32_t m, int32_t n, float *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_d_softmax(int32_t m, int32_t n, double *a, int32_t ldA);
+ RINDOW_FUNC_DECL void rindow_matlib_s_equal(int32_t n, float *x, int32_t incX, float *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_equal(int32_t n, double *x, int32_t incX, double *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_i_equal(int32_t dtype, int32_t n, void *x, int32_t incX, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_notequal(int32_t n, float *x, int32_t incX, float *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_notequal(int32_t n, double *x, int32_t incX, double *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_i_notequal(int32_t dtype, int32_t n, void *x, int32_t incX, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_not(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_not(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_i_not(int32_t dtype, int32_t n, void *x, int32_t incX);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_astype(int32_t n, int32_t from_dtype, void *x, int32_t incX, int32_t to_dtype, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_matrixcopy(int32_t trans, int32_t m, int32_t n, float alpha, float *a, int32_t ldA, float *b, int32_t ldB);
+ RINDOW_FUNC_DECL void rindow_matlib_d_matrixcopy(int32_t trans, int32_t m, int32_t n, double alpha, double *a, int32_t ldA, double *b, int32_t ldB);
+ RINDOW_FUNC_DECL void rindow_matlib_s_imagecopy(int32_t height, int32_t width, int32_t channels, float *a, float *b,
+ int32_t channelsFirst, int32_t heightShift, int32_t widthShift, int32_t verticalFlip, int32_t horizontalFlip, int32_t rgbFlip);
+ RINDOW_FUNC_DECL void rindow_matlib_d_imagecopy(int32_t height, int32_t width, int32_t channels, double *a, double *b,
+ int32_t channelsFirst, int32_t heightShift, int32_t widthShift, int32_t verticalFlip, int32_t horizontalFlip, int32_t rgbFlip);
+ RINDOW_FUNC_DECL void rindow_matlib_i8_imagecopy(int32_t height, int32_t width, int32_t channels, uint8_t *a, uint8_t *b,
+ int32_t channelsFirst, int32_t heightShift, int32_t widthShift, int32_t verticalFlip, int32_t horizontalFlip, int32_t rgbFlip);
+ RINDOW_FUNC_DECL void rindow_matlib_fill(int32_t dtype, int32_t n, void *value, void *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_nan2num(int32_t n, float *x, int32_t incX, float alpha);
+ RINDOW_FUNC_DECL void rindow_matlib_d_nan2num(int32_t n, double *x, int32_t incX, double alpha);
+ RINDOW_FUNC_DECL void rindow_matlib_s_isnan(int32_t n, float *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_d_isnan(int32_t n, double *x, int32_t incX);
+ RINDOW_FUNC_DECL void rindow_matlib_s_searchsorted(int32_t m, int32_t n, float *a, int32_t ldA, float *x, int32_t incX,
+ int32_t right, int32_t dtype, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_searchsorted(int32_t m, int32_t n, double *a, int32_t ldA, double *x, int32_t incX,
+ int32_t right, int32_t dtype, void *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_cumsum(int32_t n, float *x, int32_t incX, int32_t exclusive, int32_t reverse, float *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_d_cumsum(int32_t n, double *x, int32_t incX, int32_t exclusive, int32_t reverse, double *y, int32_t incY);
+ RINDOW_FUNC_DECL void rindow_matlib_s_cumsumb(int32_t m, int32_t n, int32_t k, float *a, int32_t exclusive, int32_t reverse, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_cumsumb(int32_t m, int32_t n, int32_t k, double *a, int32_t exclusive, int32_t reverse, double *b);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_transpose(int32_t ndim, int32_t *shape, int32_t *perm, float *a, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_transpose(int32_t ndim, int32_t *shape, int32_t *perm, double *a, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_transpose(int32_t dtype, int32_t ndim, int32_t *shape, int32_t *perm, void *a, void *b);
+ RINDOW_FUNC_DECL void rindow_matlib_s_bandpart(int32_t m, int32_t n, int32_t k, float *a, int32_t lower, int32_t upper);
+ RINDOW_FUNC_DECL void rindow_matlib_d_bandpart(int32_t m, int32_t n, int32_t k, double *a, int32_t lower, int32_t upper);
+ RINDOW_FUNC_DECL void rindow_matlib_i_bandpart(int32_t m, int32_t n, int32_t k, int32_t dtype, void *a, int32_t lower, int32_t upper);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_gather(int32_t reverse, int32_t addMode, int32_t n, int32_t k, int32_t numClass, int32_t dtype, void *x, float *a, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_gather(int32_t reverse, int32_t addMode, int32_t n, int32_t k, int32_t numClass, int32_t dtype, void *x, double *a, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_gather(int32_t reverse, int32_t addMode, int32_t n, int32_t k, int32_t numClass, int32_t dtype, void *x, int32_t data_dtype, void *a, void *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_reducegather(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t numClass, int32_t dtype, void *x, float *a, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_reducegather(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t numClass, int32_t dtype, void *x, double *a, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_reducegather(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t numClass, int32_t dtype, void *x, int32_t data_dtype, void *a, void *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_gatherb(int32_t reverse, int32_t addMode, int32_t batches, int32_t m, int32_t n, int32_t k, int32_t len, int32_t numClass, float *a, int32_t *x, float *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_gatherb(int32_t reverse, int32_t addMode, int32_t batches, int32_t m, int32_t n, int32_t k, int32_t len, int32_t numClass, double *a, int32_t *x, double *b);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_i_gatherb(int32_t reverse, int32_t addMode, int32_t batches, int32_t m, int32_t n, int32_t k, int32_t len, int32_t numClass, int32_t dtype, void *a, int32_t *x, void *b);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_einsum(
+ const int32_t depth,
+ const int32_t *sizeOfIndices,
+ const float *a,
+ const int32_t *ldA,
+ const float *b,
+ const int32_t *ldB,
+ float *c,
+ const int32_t ndimC);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_einsum(
+ const int32_t depth,
+ const int32_t *sizeOfIndices,
+ const double *a,
+ const int32_t *ldA,
+ const double *b,
+ const int32_t *ldB,
+ double *c,
+ const int32_t ndimC);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_s_einsum4p1(
+ int32_t dim0,
+ int32_t dim1,
+ int32_t dim2,
+ int32_t dim3,
+ int32_t dim4,
+ float *a,
+ int32_t ldA0,
+ int32_t ldA1,
+ int32_t ldA2,
+ int32_t ldA3,
+ int32_t ldA4,
+ float *b,
+ int32_t ldB0,
+ int32_t ldB1,
+ int32_t ldB2,
+ int32_t ldB3,
+ int32_t ldB4,
+ float *c);
+ RINDOW_FUNC_DECL int32_t rindow_matlib_d_einsum4p1(
+ int32_t dim0,
+ int32_t dim1,
+ int32_t dim2,
+ int32_t dim3,
+ int32_t dim4,
+ double *a,
+ int32_t ldA0,
+ int32_t ldA1,
+ int32_t ldA2,
+ int32_t ldA3,
+ int32_t ldA4,
+ double *b,
+ int32_t ldB0,
+ int32_t ldB1,
+ int32_t ldB2,
+ int32_t ldB3,
+ int32_t ldB4,
+ double *c);
+ RINDOW_FUNC_DECL void rindow_matlib_s_slice(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t k, int32_t size, float *a, int32_t incA, float *y, int32_t incY, int32_t startAxis0, int32_t sizeAxis0, int32_t startAxis1, int32_t sizeAxis1, int32_t startAxis2, int32_t sizeAxis2);
+ RINDOW_FUNC_DECL void rindow_matlib_d_slice(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t k, int32_t size, double *a, int32_t incA, double *y, int32_t incY, int32_t startAxis0, int32_t sizeAxis0, int32_t startAxis1, int32_t sizeAxis1, int32_t startAxis2, int32_t sizeAxis2);
+ RINDOW_FUNC_DECL void rindow_matlib_i_slice(int32_t reverse, int32_t addMode, int32_t m, int32_t n, int32_t k, int32_t size, int32_t dtype, void *a, int32_t incA, void *y, int32_t incY, int32_t startAxis0, int32_t sizeAxis0, int32_t startAxis1, int32_t sizeAxis1, int32_t startAxis2, int32_t sizeAxis2);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_repeat(int32_t m, int32_t k, int32_t repeats, float *a, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_repeat(int32_t m, int32_t k, int32_t repeats, double *a, double *b);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_reducesum(int32_t m, int32_t n, int32_t k, float *a, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reducesum(int32_t m, int32_t n, int32_t k, double *a, double *b);
+ RINDOW_FUNC_DECL void rindow_matlib_s_reducemax(int32_t m, int32_t n, int32_t k, float *a, float *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reducemax(int32_t m, int32_t n, int32_t k, double *a, double *b);
+ RINDOW_FUNC_DECL void rindow_matlib_s_reduceargmax(int32_t m, int32_t n, int32_t k, float *a, int32_t dtype, void *b);
+ RINDOW_FUNC_DECL void rindow_matlib_d_reduceargmax(int32_t m, int32_t n, int32_t k, double *a, int32_t dtype, void *b);
+
+ RINDOW_FUNC_DECL void rindow_matlib_s_randomuniform(int32_t n, float *x, int32_t incX, float low, float high, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_d_randomuniform(int32_t n, double *x, int32_t incX, double low, double high, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_i_randomuniform(int32_t n, int32_t dtype, void *x, int32_t incX, int32_t low, int32_t high, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_s_randomnormal(int32_t n, float *x, int32_t incX, float mean, float scale, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_d_randomnormal(int32_t n, double *x, int32_t incX, double mean, double scale, int32_t seed);
+ RINDOW_FUNC_DECL void rindow_matlib_i_randomsequence(int32_t n, int32_t size, int32_t dtype, void *x, int32_t incX, int32_t seed);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_im2col1d(
+ int32_t dtype, int32_t reverse,
+ void *images_data,
+ int32_t images_size,
+ int32_t batches,
+ int32_t im_w,
+ int32_t channels,
+ int32_t filter_w,
+ int32_t stride_w,
+ int32_t padding, int32_t channels_first,
+ int32_t dilation_w,
+ int32_t cols_channels_first,
+ void *cols_data, int32_t cols_size);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_im2col2d(
+ int32_t dtype, int32_t reverse,
+ void *images_data, int32_t images_size,
+ int32_t batches,
+ int32_t im_h, int32_t im_w,
+ int32_t channels,
+ int32_t filter_h, int32_t filter_w,
+ int32_t stride_h, int32_t stride_w,
+ int32_t padding, int32_t channels_first,
+ int32_t dilation_h, int32_t dilation_w,
+ int32_t cols_channels_first,
+ void *cols_data, int32_t cols_size);
+
+ RINDOW_FUNC_DECL int32_t rindow_matlib_im2col3d(
+ int32_t dtype, int32_t reverse,
+ void *images_data, int32_t images_size,
+ int32_t batches,
+ int32_t im_d, int32_t im_h, int32_t im_w,
+ int32_t channels,
+ int32_t filter_d, int32_t filter_h, int32_t filter_w,
+ int32_t stride_d, int32_t stride_h, int32_t stride_w,
+ int32_t padding, int32_t channels_first,
+ int32_t dilation_d, int32_t dilation_h, int32_t dilation_w,
+ int32_t cols_channels_first,
+ void *cols_data, int32_t cols_size);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+// RINDOW_MATLIB_H_
+#endif
diff --git a/shared/windows-x86_64/include/onnxruntime.h b/shared/windows-x86_64/include/onnxruntime.h
new file mode 100644
index 0000000..127382c
--- /dev/null
+++ b/shared/windows-x86_64/include/onnxruntime.h
@@ -0,0 +1,369 @@
+#ifndef ORT_API_H
+#define ORT_API_H
+
+// https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/session/onnxruntime_c_api.h
+// keep same order
+
+typedef enum ONNXTensorElementDataType {
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128,
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16
+} ONNXTensorElementDataType;
+
+typedef enum ONNXType {
+ ONNX_TYPE_UNKNOWN,
+ ONNX_TYPE_TENSOR,
+ ONNX_TYPE_SEQUENCE,
+ ONNX_TYPE_MAP,
+ ONNX_TYPE_OPAQUE,
+ ONNX_TYPE_SPARSETENSOR,
+ ONNX_TYPE_OPTIONAL
+} ONNXType;
+
+typedef enum OrtLoggingLevel {
+ ORT_LOGGING_LEVEL_VERBOSE,
+ ORT_LOGGING_LEVEL_INFO,
+ ORT_LOGGING_LEVEL_WARNING,
+ ORT_LOGGING_LEVEL_ERROR,
+ ORT_LOGGING_LEVEL_FATAL,
+} OrtLoggingLevel;
+
+typedef enum OrtErrorCode {
+ ORT_OK,
+ ORT_FAIL,
+ ORT_INVALID_ARGUMENT,
+ ORT_NO_SUCHFILE,
+ ORT_NO_MODEL,
+ ORT_ENGINE_ERROR,
+ ORT_RUNTIME_EXCEPTION,
+ ORT_INVALID_PROTOBUF,
+ ORT_MODEL_LOADED,
+ ORT_NOT_IMPLEMENTED,
+ ORT_INVALID_GRAPH,
+ ORT_EP_FAIL,
+} OrtErrorCode;
+
+struct OrtEnv;
+typedef struct OrtEnv OrtEnv;
+
+struct OrtStatus;
+typedef struct OrtStatus OrtStatus;
+
+struct OrtMemoryInfo;
+typedef struct OrtMemoryInfo OrtMemoryInfo;
+
+struct OrtIoBinding;
+typedef struct OrtIoBinding OrtIoBinding;
+
+struct OrtSession;
+typedef struct OrtSession OrtSession;
+
+struct OrtValue;
+typedef struct OrtValue OrtValue;
+
+struct OrtRunOptions;
+typedef struct OrtRunOptions OrtRunOptions;
+
+struct OrtTypeInfo;
+typedef struct OrtTypeInfo OrtTypeInfo;
+
+struct OrtTensorTypeAndShapeInfo;
+typedef struct OrtTensorTypeAndShapeInfo OrtTensorTypeAndShapeInfo;
+
+struct OrtSessionOptions;
+typedef struct OrtSessionOptions OrtSessionOptions;
+
+struct OrtCustomOpDomain;
+typedef struct OrtCustomOpDomain OrtCustomOpDomain;
+
+struct OrtMapTypeInfo;
+typedef struct OrtMapTypeInfo OrtMapTypeInfo;
+
+struct OrtSequenceTypeInfo;
+typedef struct OrtSequenceTypeInfo OrtSequenceTypeInfo;
+
+struct OrtModelMetadata;
+typedef struct OrtModelMetadata OrtModelMetadata;
+
+struct OrtThreadPoolParams;
+typedef struct OrtThreadPoolParams OrtThreadPoolParams;
+
+struct OrtThreadingOptions;
+typedef struct OrtThreadingOptions OrtThreadingOptions;
+
+struct OrtArenaCfg;
+typedef struct OrtArenaCfg OrtArenaCfg;
+
+struct OrtPrepackedWeightsContainer;
+typedef struct OrtPrepackedWeightsContainer OrtPrepackedWeightsContainer;
+
+struct OrtTensorRTProviderOptionsV2;
+typedef struct OrtTensorRTProviderOptionsV2 OrtTensorRTProviderOptionsV2;
+
+
+
+typedef enum COREMLFlags {
+ COREML_FLAG_USE_NONE = 0x000,
+ COREML_FLAG_USE_CPU_ONLY = 0x001,
+ COREML_FLAG_ENABLE_ON_SUBGRAPH = 0x002,
+ COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE = 0x004,
+ COREML_FLAG_ONLY_ALLOW_STATIC_INPUT_SHAPES = 0x008,
+ COREML_FLAG_CREATE_MLPROGRAM = 0x010,
+ COREML_FLAG_LAST = COREML_FLAG_CREATE_MLPROGRAM
+} COREMLFlags;
+
+struct OrtOp;
+typedef struct OrtOp OrtOp;
+
+struct OrtOpAttr;
+typedef struct Ort OrtOpAttr;
+
+typedef struct OrtAllocator {
+ uint32_t version;
+ void*(* Alloc)(struct OrtAllocator* this_, size_t size);
+ void(* Free)(struct OrtAllocator* this_, void* p);
+ const struct OrtMemoryInfo*(* Info)(const struct OrtAllocator* this_);
+} OrtAllocator;
+
+typedef enum GraphOptimizationLevel {
+ ORT_DISABLE_ALL = 0,
+ ORT_ENABLE_BASIC = 1,
+ ORT_ENABLE_EXTENDED = 2,
+ ORT_ENABLE_ALL = 99
+} GraphOptimizationLevel;
+
+typedef enum ExecutionMode {
+ ORT_SEQUENTIAL = 0,
+ ORT_PARALLEL = 1,
+} ExecutionMode;
+
+struct OrtApi;
+typedef struct OrtApi OrtApi;
+
+struct OrtApiBase {
+ const OrtApi*(* GetApi)(uint32_t version);
+ const char*(* GetVersionString)(void);
+};
+typedef struct OrtApiBase OrtApiBase;
+
+const OrtApiBase* OrtGetApiBase(void);
+
+struct OrtApi {
+ OrtStatus*(* CreateStatus)(OrtErrorCode code, const char* msg);
+ OrtErrorCode(* GetErrorCode)(const OrtStatus* status);
+ const char*(* GetErrorMessage)(const OrtStatus* status);
+ OrtStatus*(* CreateEnv)(OrtLoggingLevel log_severity_level, const char* logid, OrtEnv** out);
+ OrtStatus*(* CreateEnvWithCustomLogger)();
+ OrtStatus*(* EnableTelemetryEvents)(const OrtEnv* env);
+ OrtStatus*(* DisableTelemetryEvents)(const OrtEnv* env);
+ OrtStatus*(* CreateSession)(const OrtEnv* env, const char* model_path, const OrtSessionOptions* options, OrtSession** out);
+ OrtStatus*(* CreateSessionFromArray)(const OrtEnv* env, const void* model_data, size_t model_data_length, const OrtSessionOptions* options, OrtSession** out);
+ OrtStatus*(* Run)(OrtSession* session, const OrtRunOptions* run_options, const char* const* input_names, const OrtValue* const* inputs, size_t input_len, const char* const* output_names, size_t output_names_len, OrtValue** outputs);
+ OrtStatus*(* CreateSessionOptions)(OrtSessionOptions** options);
+ OrtStatus*(* SetOptimizedModelFilePath)(OrtSessionOptions* options, const char* optimized_model_filepath);
+ OrtStatus*(* CloneSessionOptions)();
+ OrtStatus*(* SetSessionExecutionMode)(OrtSessionOptions* options, ExecutionMode execution_mode);
+ OrtStatus*(* EnableProfiling)(OrtSessionOptions* options, const char* profile_file_prefix);
+ OrtStatus*(* DisableProfiling)(OrtSessionOptions* options);
+ OrtStatus*(* EnableMemPattern)(OrtSessionOptions* options);
+ OrtStatus*(* DisableMemPattern)(OrtSessionOptions* options);
+ OrtStatus*(* EnableCpuMemArena)(OrtSessionOptions* options);
+ OrtStatus*(* DisableCpuMemArena)(OrtSessionOptions* options);
+ OrtStatus*(* SetSessionLogId)(OrtSessionOptions* options, const char* logid);
+ OrtStatus*(* SetSessionLogVerbosityLevel)(OrtSessionOptions* options, int session_log_verbosity_level);
+ OrtStatus*(* SetSessionLogSeverityLevel)(OrtSessionOptions* options, int session_log_severity_level);
+ OrtStatus*(* SetSessionGraphOptimizationLevel)(OrtSessionOptions* options, GraphOptimizationLevel graph_optimization_level);
+ OrtStatus*(* SetIntraOpNumThreads)(OrtSessionOptions* options, int intra_op_num_threads);
+ OrtStatus*(* SetInterOpNumThreads)(OrtSessionOptions* options, int inter_op_num_threads);
+ OrtStatus*(* CreateCustomOpDomain)();
+ OrtStatus*(* CustomOpDomain_Add)();
+ OrtStatus*(* AddCustomOpDomain)();
+ OrtStatus*(* RegisterCustomOpsLibrary)();
+ OrtStatus*(* SessionGetInputCount)(const OrtSession* session, size_t* out);
+ OrtStatus*(* SessionGetOutputCount)(const OrtSession* session, size_t* out);
+ OrtStatus*(* SessionGetOverridableInitializerCount)();
+ OrtStatus*(* SessionGetInputTypeInfo)(const OrtSession* session, size_t index, OrtTypeInfo** type_info);
+ OrtStatus*(* SessionGetOutputTypeInfo)(const OrtSession* session, size_t index, OrtTypeInfo** type_info);
+ OrtStatus*(* SessionGetOverridableInitializerTypeInfo)();
+ OrtStatus*(* SessionGetInputName)(const OrtSession* session, size_t index, OrtAllocator* allocator, char** value);
+ OrtStatus*(* SessionGetOutputName)(const OrtSession* session, size_t index, OrtAllocator* allocator, char** value);
+ OrtStatus*(* SessionGetOverridableInitializerName)();
+ OrtStatus*(* CreateRunOptions)(OrtRunOptions** out);
+ OrtStatus*(* RunOptionsSetRunLogVerbosityLevel)(OrtRunOptions* options, int log_verbosity_level);
+ OrtStatus*(* RunOptionsSetRunLogSeverityLevel)(OrtRunOptions* options, int log_severity_level);
+ OrtStatus*(* RunOptionsSetRunTag)(OrtRunOptions* options, const char* run_tag);
+ OrtStatus*(* RunOptionsGetRunLogVerbosityLevel)();
+ OrtStatus*(* RunOptionsGetRunLogSeverityLevel)();
+ OrtStatus*(* RunOptionsGetRunTag)();
+ OrtStatus*(* RunOptionsSetTerminate)(OrtRunOptions* options);
+ OrtStatus*(* RunOptionsUnsetTerminate)(OrtRunOptions* options);
+ OrtStatus*(* CreateTensorAsOrtValue)(OrtAllocator* allocator, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, OrtValue** out);
+ OrtStatus*(* CreateTensorWithDataAsOrtValue)(const OrtMemoryInfo* info, void* p_data, size_t p_data_len, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, OrtValue** out);
+ OrtStatus*(* IsTensor)();
+ OrtStatus*(* GetTensorMutableData)(OrtValue* value, void** out);
+ OrtStatus*(* FillStringTensor)(OrtValue* value, const char* const* s, size_t s_len);
+ OrtStatus*(* GetStringTensorDataLength)(const OrtValue* value, size_t* len);
+ OrtStatus*(* GetStringTensorContent)(const OrtValue* value, void* s, size_t s_len, size_t* offsets, size_t offsets_len);
+ OrtStatus*(* CastTypeInfoToTensorInfo)(const OrtTypeInfo* type_info, const OrtTensorTypeAndShapeInfo** out);
+ OrtStatus*(* GetOnnxTypeFromTypeInfo)(const OrtTypeInfo* type_info, enum ONNXType* out);
+ OrtStatus*(* CreateTensorTypeAndShapeInfo)();
+ OrtStatus*(* SetTensorElementType)();
+ OrtStatus*(* SetDimensions)();
+ OrtStatus*(* GetTensorElementType)(const OrtTensorTypeAndShapeInfo* info, enum ONNXTensorElementDataType* out);
+ OrtStatus*(* GetDimensionsCount)(const OrtTensorTypeAndShapeInfo* info, size_t* out);
+ OrtStatus*(* GetDimensions)(const OrtTensorTypeAndShapeInfo* info, int64_t* dim_values, size_t dim_values_length);
+ OrtStatus*(* GetSymbolicDimensions)(const OrtTensorTypeAndShapeInfo* info, const char* dim_params[], size_t dim_params_length);
+ OrtStatus*(* GetTensorShapeElementCount)(const OrtTensorTypeAndShapeInfo* info, size_t* out);
+ OrtStatus*(* GetTensorTypeAndShape)(const OrtValue* value, OrtTensorTypeAndShapeInfo** out);
+ OrtStatus*(* GetTypeInfo)();
+ OrtStatus*(* GetValueType)(const OrtValue* value, enum ONNXType* out);
+ OrtStatus*(* CreateMemoryInfo)();
+ OrtStatus*(* CreateCpuMemoryInfo)(enum OrtAllocatorType type, enum OrtMemType mem_type, OrtMemoryInfo** out);
+ OrtStatus*(* CompareMemoryInfo)();
+ OrtStatus*(* MemoryInfoGetName)();
+ OrtStatus*(* MemoryInfoGetId)();
+ OrtStatus*(* MemoryInfoGetMemType)();
+ OrtStatus*(* MemoryInfoGetType)();
+ OrtStatus*(* AllocatorAlloc)(OrtAllocator* ort_allocator, size_t size, void** out);
+ OrtStatus*(* AllocatorFree)(OrtAllocator* ort_allocator, void* p);
+ OrtStatus*(* AllocatorGetInfo)(const OrtAllocator* ort_allocator, const struct OrtMemoryInfo** out);
+ OrtStatus*(* GetAllocatorWithDefaultOptions)(OrtAllocator** out);
+ OrtStatus*(* AddFreeDimensionOverride)(OrtSessionOptions* options, const char* dim_denotation, int64_t dim_value);
+ OrtStatus*(* GetValue)(const OrtValue* value, int index, OrtAllocator* allocator, OrtValue** out);
+ OrtStatus*(* GetValueCount)(const OrtValue* value, size_t* out);
+ OrtStatus*(* CreateValue)();
+ OrtStatus*(* CreateOpaqueValue)();
+ OrtStatus*(* GetOpaqueValue)();
+ OrtStatus*(* KernelInfoGetAttribute_float)();
+ OrtStatus*(* KernelInfoGetAttribute_int64)();
+ OrtStatus*(* KernelInfoGetAttribute_string)();
+ OrtStatus*(* KernelContext_GetInputCount)();
+ OrtStatus*(* KernelContext_GetOutputCount)();
+ OrtStatus*(* KernelContext_GetInput)();
+ OrtStatus*(* KernelContext_GetOutput)();
+ void(* ReleaseEnv)(OrtEnv* input);
+ void(* ReleaseStatus)(OrtStatus* input);
+ void(* ReleaseMemoryInfo)(OrtMemoryInfo* input);
+ void(* ReleaseSession)(OrtSession* input);
+ void(* ReleaseValue)(OrtValue* input);
+ void(* ReleaseRunOptions)(OrtRunOptions* input);
+ void(* ReleaseTypeInfo)(OrtTypeInfo* input);
+ void(* ReleaseTensorTypeAndShapeInfo)(OrtTensorTypeAndShapeInfo* input);
+ void(* ReleaseSessionOptions)(OrtSessionOptions* input);
+ void(* ReleaseCustomOpDomain)();
+ OrtStatus*(* GetDenotationFromTypeInfo)();
+ OrtStatus*(* CastTypeInfoToMapTypeInfo)(const OrtTypeInfo* type_info, const OrtMapTypeInfo** out);
+ OrtStatus*(* CastTypeInfoToSequenceTypeInfo)(const OrtTypeInfo* type_info, const OrtSequenceTypeInfo** out);
+ OrtStatus*(* GetMapKeyType)(const OrtMapTypeInfo* map_type_info, enum ONNXTensorElementDataType* out);
+ OrtStatus*(* GetMapValueType)(const OrtMapTypeInfo* map_type_info, OrtTypeInfo** type_info);
+ OrtStatus*(* GetSequenceElementType)(const OrtSequenceTypeInfo* sequence_type_info, OrtTypeInfo** type_info);
+ void(* ReleaseMapTypeInfo)(OrtMapTypeInfo* input);
+ void(* ReleaseSequenceTypeInfo)(OrtSequenceTypeInfo* input);
+ OrtStatus*(* SessionEndProfiling)(OrtSession* session, OrtAllocator* allocator, char** out);
+ OrtStatus*(* SessionGetModelMetadata)(const OrtSession* session, OrtModelMetadata** out);
+ OrtStatus*(* ModelMetadataGetProducerName)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataGetGraphName)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataGetDomain)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataGetDescription)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* ModelMetadataLookupCustomMetadataMap)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, const char* key, char** value);
+ OrtStatus*(* ModelMetadataGetVersion)(const OrtModelMetadata* model_metadata, int64_t* value);
+ void(* ReleaseModelMetadata)(OrtModelMetadata* input);
+ OrtStatus*(* CreateEnvWithGlobalThreadPools)();
+ OrtStatus*(* DisablePerSessionThreads)();
+ OrtStatus*(* CreateThreadingOptions)();
+ void(* ReleaseThreadingOptions)(OrtThreadingOptions* input);
+ OrtStatus*(* ModelMetadataGetCustomMetadataMapKeys)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char*** keys, int64_t* num_keys);
+ OrtStatus*(* AddFreeDimensionOverrideByName)(OrtSessionOptions* options, const char* dim_name, int64_t dim_value);
+ OrtStatus*(* GetAvailableProviders)(char*** out_ptr, int* provider_length);
+ OrtStatus*(* ReleaseAvailableProviders)(char** ptr, int providers_length);
+ OrtStatus*(* GetStringTensorElementLength)();
+ OrtStatus*(* GetStringTensorElement)();
+ OrtStatus*(* FillStringTensorElement)();
+ OrtStatus*(* AddSessionConfigEntry)(OrtSessionOptions* options, const char* config_key, const char* config_value);
+ OrtStatus*(* CreateAllocator)();
+ void(* ReleaseAllocator)(OrtAllocator* input);
+ OrtStatus*(* RunWithBinding)();
+ OrtStatus*(* CreateIoBinding)();
+ void(* ReleaseIoBinding)(OrtIoBinding* input);
+ OrtStatus*(* BindInput)();
+ OrtStatus*(* BindOutput)();
+ OrtStatus*(* BindOutputToDevice)();
+ OrtStatus*(* GetBoundOutputNames)();
+ OrtStatus*(* GetBoundOutputValues)();
+ void(* ClearBoundInputs)();
+ void(* ClearBoundOutputs)();
+ OrtStatus*(* TensorAt)();
+ OrtStatus*(* CreateAndRegisterAllocator)();
+ OrtStatus*(* SetLanguageProjection)();
+ OrtStatus*(* SessionGetProfilingStartTimeNs)();
+ OrtStatus*(* SetGlobalIntraOpNumThreads)();
+ OrtStatus*(* SetGlobalInterOpNumThreads)();
+ OrtStatus*(* SetGlobalSpinControl)();
+ OrtStatus*(* AddInitializer)();
+ OrtStatus*(* CreateEnvWithCustomLoggerAndGlobalThreadPools)();
+
+
+ OrtStatus*(* SetGlobalDenormalAsZero)();
+ OrtStatus*(* CreateArenaCfg)();
+ void(* ReleaseArenaCfg)(OrtArenaCfg* input);
+ OrtStatus*(* ModelMetadataGetGraphDescription)(const OrtModelMetadata* model_metadata, OrtAllocator* allocator, char** value);
+ OrtStatus*(* SessionOptionsAppendExecutionProvider_TensorRT)();
+ OrtStatus*(* SetCurrentGpuDeviceId)();
+ OrtStatus*(* GetCurrentGpuDeviceId)();
+ OrtStatus*(* KernelInfoGetAttributeArray_float)();
+ OrtStatus*(* KernelInfoGetAttributeArray_int64)();
+ OrtStatus*(* CreateArenaCfgV2)();
+ OrtStatus*(* AddRunConfigEntry)();
+ OrtStatus*(* CreatePrepackedWeightsContainer)();
+ void(* PrepackedWeightsContainer)(OrtPrepackedWeightsContainer* input);
+ OrtStatus*(* CreateSessionWithPrepackedWeightsContainer)();
+ OrtStatus*(* CreateSessionFromArrayWithPrepackedWeightsContainer)();
+ OrtStatus*(* SessionOptionsAppendExecutionProvider_TensorRT_V2)();
+ OrtStatus*(* CreateTensorRTProviderOptions)();
+ OrtStatus*(* UpdateTensorRTProviderOptions)();
+ OrtStatus*(* GetTensorRTProviderOptionsAsString)();
+ void(* ReleaseTensorRTProviderOptions)(OrtTensorRTProviderOptionsV2* input);
+ OrtStatus*(* EnableOrtCustomOps)();
+ OrtStatus*(* RegisterAllocator)();
+ OrtStatus*(* UnregisterAllocator)();
+ OrtStatus*(* IsSparseTensor)();
+ OrtStatus*(* CreateSparseTensorAsOrtValue)();
+ OrtStatus*(* FillSparseTensorCoo)();
+ OrtStatus*(* FillSparseTensorCsr)();
+ OrtStatus*(* FillSparseTensorBlockSparse)();
+ OrtStatus*(* CreateSparseTensorWithValuesAsOrtValue)();
+ OrtStatus*(* UseCooIndices)();
+ OrtStatus*(* UseCsrIndices)();
+ OrtStatus*(* UseBlockSparseIndices)();
+ OrtStatus*(* GetSparseTensorFormat)();
+ OrtStatus*(* GetSparseTensorValuesTypeAndShape)();
+ OrtStatus*(* GetSparseTensorValues)();
+ OrtStatus*(* GetSparseTensorIndicesTypeShape)();
+ OrtStatus*(* GetSparseTensorIndices)();
+ OrtStatus*(* HasValue)();
+ OrtStatus*(* KernelContext_GetGPUComputeStream)();
+ OrtStatus*(* GetTensorMemoryInfo)();
+ OrtStatus*(* GetExecutionProviderApi)();
+ OrtStatus*(* SessionOptionsSetCustomCreateThreadFn)();
+ OrtStatus*(* SessionOptionsSetCustomThreadCreationOptions)();
+ OrtStatus*(* SessionOptionsSetCustomJoinThreadFn)();
+ OrtStatus*(* SetGlobalCustomCreateThreadFn)();
+ OrtStatus*(* SetGlobalCustomThreadCreationOptions)();
+ OrtStatus*(* SetGlobalCustomJoinThreadFn)();
+ OrtStatus*(* SynchronizeBoundInputs)();
+ OrtStatus*(* SynchronizeBoundOutputs)();
+};
\ No newline at end of file
diff --git a/shared/windows-x86_64/include/openblas.h b/shared/windows-x86_64/include/openblas.h
new file mode 100644
index 0000000..8e902fb
--- /dev/null
+++ b/shared/windows-x86_64/include/openblas.h
@@ -0,0 +1,426 @@
+#define FFI_SCOPE "Rindow\\OpenBLAS\\FFI"
+//#define FFI_LIB "libopenblas.dll"
+
+/////////////////////////////////////////////
+typedef int8_t cl_char;
+typedef uint8_t cl_uchar;
+typedef int16_t cl_short;
+typedef uint16_t cl_ushort;
+typedef int32_t cl_int;
+typedef uint32_t cl_uint;
+typedef int64_t cl_long;
+typedef uint64_t cl_ulong;
+/////////////////////////////////////////////
+typedef uint16_t bfloat16;
+typedef int32_t blasint;
+typedef int32_t lapack_int;
+/////////////////////////////////////////////
+//#define xdouble double
+typedef double xdouble;
+//#define OPENBLAS_COMPLEX_STRUCT
+typedef struct _openblas_complex_float { float real, imag; } openblas_complex_float;
+typedef struct _openblas_complex_double { double real, imag; } openblas_complex_double;
+typedef struct _openblas_complex_xdouble { xdouble real, imag; } openblas_complex_xdouble;
+//#define openblas_make_complex_float(real, imag) {(real), (imag)}
+//#define openblas_make_complex_double(real, imag) {(real), (imag)}
+//#define openblas_make_complex_xdouble(real, imag) {(real), (imag)}
+//#define openblas_complex_float_real(z) ((z).real)
+//#define openblas_complex_float_imag(z) ((z).imag)
+//#define openblas_complex_double_real(z) ((z).real)
+//#define openblas_complex_double_imag(z) ((z).imag)
+//#define openblas_complex_xdouble_real(z) ((z).real)
+//#define openblas_complex_xdouble_imag(z) ((z).imag)
+/////////////////////////////////////////////
+
+
+
+/*Set the number of threads on runtime.*/
+void openblas_set_num_threads(int num_threads);
+void goto_set_num_threads(int num_threads);
+
+/*Get the number of threads on runtime.*/
+int openblas_get_num_threads(void);
+
+/*Get the number of physical processors (cores).*/
+int openblas_get_num_procs(void);
+
+/*Get the build configure on runtime.*/
+char* openblas_get_config(void);
+
+/*Get the CPU corename on runtime.*/
+char* openblas_get_corename(void);
+
+/* Get the parallelization type which is used by OpenBLAS */
+int openblas_get_parallel(void);
+/* OpenBLAS is compiled for sequential use */
+#define OPENBLAS_SEQUENTIAL 0
+/* OpenBLAS is compiled using normal threading model */
+#define OPENBLAS_THREAD 1
+/* OpenBLAS is compiled using OpenMP threading model */
+#define OPENBLAS_OPENMP 2
+
+
+//#ifndef OPENBLAS_CONST
+//# define OPENBLAS_CONST const
+//#endif
+
+
+//#define CBLAS_INDEX size_t
+typedef size_t CBLAS_INDEX;
+
+
+typedef enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102} CBLAS_ORDER;
+typedef enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113, CblasConjNoTrans=114} CBLAS_TRANSPOSE;
+typedef enum CBLAS_UPLO {CblasUpper=121, CblasLower=122} CBLAS_UPLO;
+typedef enum CBLAS_DIAG {CblasNonUnit=131, CblasUnit=132} CBLAS_DIAG;
+typedef enum CBLAS_SIDE {CblasLeft=141, CblasRight=142} CBLAS_SIDE;
+typedef CBLAS_ORDER CBLAS_LAYOUT;
+
+float cblas_sdsdot(const blasint n, const float alpha, const float *x, const blasint incx, const float *y, const blasint incy);
+double cblas_dsdot (const blasint n, const float *x, const blasint incx, const float *y, const blasint incy);
+float cblas_sdot(const blasint n, const float *x, const blasint incx, const float *y, const blasint incy);
+double cblas_ddot(const blasint n, const double *x, const blasint incx, const double *y, const blasint incy);
+
+openblas_complex_float cblas_cdotu(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+openblas_complex_float cblas_cdotc(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+openblas_complex_double cblas_zdotu(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+openblas_complex_double cblas_zdotc(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy);
+
+void cblas_cdotu_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+void cblas_cdotc_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+void cblas_zdotu_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+void cblas_zdotc_sub(const blasint n, const void *x, const blasint incx, const void *y, const blasint incy, void *ret);
+
+float cblas_sasum (const blasint n, const float *x, const blasint incx);
+double cblas_dasum (const blasint n, const double *x, const blasint incx);
+float cblas_scasum(const blasint n, const void *x, const blasint incx);
+double cblas_dzasum(const blasint n, const void *x, const blasint incx);
+
+float cblas_ssum (const blasint n, const float *x, const blasint incx);
+double cblas_dsum (const blasint n, const double *x, const blasint incx);
+float cblas_scsum(const blasint n, const void *x, const blasint incx);
+double cblas_dzsum(const blasint n, const void *x, const blasint incx);
+
+float cblas_snrm2 (const blasint N, const float *X, const blasint incX);
+double cblas_dnrm2 (const blasint N, const double *X, const blasint incX);
+float cblas_scnrm2(const blasint N, const void *X, const blasint incX);
+double cblas_dznrm2(const blasint N, const void *X, const blasint incX);
+
+CBLAS_INDEX cblas_isamax(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idamax(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icamax(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izamax(const blasint n, const void *x, const blasint incx);
+
+CBLAS_INDEX cblas_isamin(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idamin(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icamin(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izamin(const blasint n, const void *x, const blasint incx);
+
+CBLAS_INDEX cblas_ismax(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idmax(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icmax(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izmax(const blasint n, const void *x, const blasint incx);
+
+CBLAS_INDEX cblas_ismin(const blasint n, const float *x, const blasint incx);
+CBLAS_INDEX cblas_idmin(const blasint n, const double *x, const blasint incx);
+CBLAS_INDEX cblas_icmin(const blasint n, const void *x, const blasint incx);
+CBLAS_INDEX cblas_izmin(const blasint n, const void *x, const blasint incx);
+
+void cblas_saxpy(const blasint n, const float alpha, const float *x, const blasint incx, float *y, const blasint incy);
+void cblas_daxpy(const blasint n, const double alpha, const double *x, const blasint incx, double *y, const blasint incy);
+void cblas_caxpy(const blasint n, const void *alpha, const void *x, const blasint incx, void *y, const blasint incy);
+void cblas_zaxpy(const blasint n, const void *alpha, const void *x, const blasint incx, void *y, const blasint incy);
+
+void cblas_scopy(const blasint n, const float *x, const blasint incx, float *y, const blasint incy);
+void cblas_dcopy(const blasint n, const double *x, const blasint incx, double *y, const blasint incy);
+void cblas_ccopy(const blasint n, const void *x, const blasint incx, void *y, const blasint incy);
+void cblas_zcopy(const blasint n, const void *x, const blasint incx, void *y, const blasint incy);
+
+void cblas_sswap(const blasint n, float *x, const blasint incx, float *y, const blasint incy);
+void cblas_dswap(const blasint n, double *x, const blasint incx, double *y, const blasint incy);
+void cblas_cswap(const blasint n, void *x, const blasint incx, void *y, const blasint incy);
+void cblas_zswap(const blasint n, void *x, const blasint incx, void *y, const blasint incy);
+
+void cblas_srot(const blasint N, float *X, const blasint incX, float *Y, const blasint incY, const float c, const float s);
+void cblas_drot(const blasint N, double *X, const blasint incX, double *Y, const blasint incY, const double c, const double s);
+//void cblas_csrot(const blasint n, const void *x, const blasint incx, void *y, const blasint incY, const float c, const float s);
+//void cblas_zdrot(const blasint n, const void *x, const blasint incx, void *y, const blasint incY, const double c, const double s);
+
+void cblas_srotg(float *a, float *b, float *c, float *s);
+void cblas_drotg(double *a, double *b, double *c, double *s);
+//void cblas_crotg(void *a, void *b, float *c, void *s);
+//void cblas_zrotg(void *a, void *b, double *c, void *s);
+
+
+void cblas_srotm(const blasint N, float *X, const blasint incX, float *Y, const blasint incY, const float *P);
+void cblas_drotm(const blasint N, double *X, const blasint incX, double *Y, const blasint incY, const double *P);
+
+void cblas_srotmg(float *d1, float *d2, float *b1, const float b2, float *P);
+void cblas_drotmg(double *d1, double *d2, double *b1, const double b2, double *P);
+
+void cblas_sscal(const blasint N, const float alpha, float *X, const blasint incX);
+void cblas_dscal(const blasint N, const double alpha, double *X, const blasint incX);
+void cblas_cscal(const blasint N, const void *alpha, void *X, const blasint incX);
+void cblas_zscal(const blasint N, const void *alpha, void *X, const blasint incX);
+void cblas_csscal(const blasint N, const float alpha, void *X, const blasint incX);
+void cblas_zdscal(const blasint N, const double alpha, void *X, const blasint incX);
+
+void cblas_sgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const float alpha, const float *a, const blasint lda, const float *x, const blasint incx, const float beta, float *y, const blasint incy);
+void cblas_dgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const double alpha, const double *a, const blasint lda, const double *x, const blasint incx, const double beta, double *y, const blasint incy);
+void cblas_cgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const void *alpha, const void *a, const blasint lda, const void *x, const blasint incx, const void *beta, void *y, const blasint incy);
+void cblas_zgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n,
+ const void *alpha, const void *a, const blasint lda, const void *x, const blasint incx, const void *beta, void *y, const blasint incy);
+
+void cblas_sger (const enum CBLAS_ORDER order, const blasint M, const blasint N, const float alpha, const float *X, const blasint incX, const float *Y, const blasint incY, float *A, const blasint lda);
+void cblas_dger (const enum CBLAS_ORDER order, const blasint M, const blasint N, const double alpha, const double *X, const blasint incX, const double *Y, const blasint incY, double *A, const blasint lda);
+void cblas_cgeru(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_cgerc(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_zgeru(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_zgerc(const enum CBLAS_ORDER order, const blasint M, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *A, const blasint lda);
+
+void cblas_strsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_strmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const blasint N, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_ssyr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *X, const blasint incX, float *A, const blasint lda);
+void cblas_dsyr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X, const blasint incX, double *A, const blasint lda);
+void cblas_cher(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const void *X, const blasint incX, void *A, const blasint lda);
+void cblas_zher(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const void *X, const blasint incX, void *A, const blasint lda);
+
+void cblas_ssyr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,const blasint N, const float alpha, const float *X,
+ const blasint incX, const float *Y, const blasint incY, float *A, const blasint lda);
+void cblas_dsyr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X,
+ const blasint incX, const double *Y, const blasint incY, double *A, const blasint lda);
+void cblas_cher2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX,
+ const void *Y, const blasint incY, void *A, const blasint lda);
+void cblas_zher2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX,
+ const void *Y, const blasint incY, void *A, const blasint lda);
+
+void cblas_sgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const float alpha, const float *A, const blasint lda, const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const double alpha, const double *A, const blasint lda, const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+void cblas_cgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zgbmv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE TransA, const blasint M, const blasint N,
+ const blasint KL, const blasint KU, const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+void cblas_ssbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K, const float alpha, const float *A,
+ const blasint lda, const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dsbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K, const double alpha, const double *A,
+ const blasint lda, const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+
+
+void cblas_stbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_stbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const float *A, const blasint lda, float *X, const blasint incX);
+void cblas_dtbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const double *A, const blasint lda, double *X, const blasint incX);
+void cblas_ctbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+void cblas_ztbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const blasint K, const void *A, const blasint lda, void *X, const blasint incX);
+
+void cblas_stpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const float *Ap, float *X, const blasint incX);
+void cblas_dtpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const double *Ap, double *X, const blasint incX);
+void cblas_ctpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+void cblas_ztpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+
+void cblas_stpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const float *Ap, float *X, const blasint incX);
+void cblas_dtpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const double *Ap, double *X, const blasint incX);
+void cblas_ctpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+void cblas_ztpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
+ const blasint N, const void *Ap, void *X, const blasint incX);
+
+void cblas_ssymv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *A,
+ const blasint lda, const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dsymv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *A,
+ const blasint lda, const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+void cblas_chemv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *A,
+ const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zhemv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *A,
+ const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+
+void cblas_sspmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *Ap,
+ const float *X, const blasint incX, const float beta, float *Y, const blasint incY);
+void cblas_dspmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *Ap,
+ const double *X, const blasint incX, const double beta, double *Y, const blasint incY);
+
+void cblas_sspr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *X, const blasint incX, float *Ap);
+void cblas_dspr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X, const blasint incX, double *Ap);
+
+void cblas_chpr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const void *X, const blasint incX, void *A);
+void cblas_zhpr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const void *X,const blasint incX, void *A);
+
+void cblas_sspr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const float alpha, const float *X, const blasint incX, const float *Y, const blasint incY, float *A);
+void cblas_dspr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const double alpha, const double *X, const blasint incX, const double *Y, const blasint incY, double *A);
+void cblas_chpr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *Ap);
+void cblas_zhpr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const void *alpha, const void *X, const blasint incX, const void *Y, const blasint incY, void *Ap);
+
+void cblas_chbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zhbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+void cblas_chpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N,
+ const void *alpha, const void *Ap, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+void cblas_zhpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const blasint N,
+ const void *alpha, const void *Ap, const void *X, const blasint incX, const void *beta, void *Y, const blasint incY);
+
+void cblas_sgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const float alpha, const float *A, const blasint lda, const float *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+void cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const double alpha, const double *A, const blasint lda, const double *B, const blasint ldb, const double beta, double *C, const blasint ldc);
+void cblas_cgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+//void cblas_cgemm3m(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+// const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+//void cblas_zgemm3m(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+// const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+
+void cblas_ssymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const float alpha, const float *A, const blasint lda, const float *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+void cblas_dsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const double alpha, const double *A, const blasint lda, const double *B, const blasint ldb, const double beta, double *C, const blasint ldc);
+void cblas_csymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+void cblas_ssyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const float alpha, const float *A, const blasint lda, const float beta, float *C, const blasint ldc);
+void cblas_dsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const double alpha, const double *A, const blasint lda, const double beta, double *C, const blasint ldc);
+void cblas_csyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *beta, void *C, const blasint ldc);
+void cblas_zsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *beta, void *C, const blasint ldc);
+
+void cblas_ssyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const float alpha, const float *A, const blasint lda, const float *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+void cblas_dsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const double alpha, const double *A, const blasint lda, const double *B, const blasint ldb, const double beta, double *C, const blasint ldc);
+void cblas_csyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans,
+ const blasint N, const blasint K, const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+
+
+void cblas_strmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const float alpha, const float *A, const blasint lda, float *B, const blasint ldb);
+void cblas_dtrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const double alpha, const double *A, const blasint lda, double *B, const blasint ldb);
+void cblas_ctrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+void cblas_ztrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+
+void cblas_strsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const float alpha, const float *A, const blasint lda, float *B, const blasint ldb);
+void cblas_dtrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const double alpha, const double *A, const blasint lda, double *B, const blasint ldb);
+void cblas_ctrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+void cblas_ztrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
+ const enum CBLAS_DIAG Diag, const blasint M, const blasint N, const void *alpha, const void *A, const blasint lda, void *B, const blasint ldb);
+
+void cblas_chemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+void cblas_zhemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const blasint M, const blasint N,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const void *beta, void *C, const blasint ldc);
+
+void cblas_cherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const float alpha, const void *A, const blasint lda, const float beta, void *C, const blasint ldc);
+void cblas_zherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const double alpha, const void *A, const blasint lda, const double beta, void *C, const blasint ldc);
+
+void cblas_cher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const float beta, void *C, const blasint ldc);
+void cblas_zher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const blasint N, const blasint K,
+ const void *alpha, const void *A, const blasint lda, const void *B, const blasint ldb, const double beta, void *C, const blasint ldc);
+
+void cblas_xerbla(blasint p, char *rout, char *form, ...);
+
+/*** BLAS extensions ***/
+
+void cblas_saxpby(const blasint n, const float alpha, const float *x, const blasint incx,const float beta, float *y, const blasint incy);
+
+void cblas_daxpby(const blasint n, const double alpha, const double *x, const blasint incx,const double beta, double *y, const blasint incy);
+
+void cblas_caxpby(const blasint n, const void *alpha, const void *x, const blasint incx,const void *beta, void *y, const blasint incy);
+
+void cblas_zaxpby(const blasint n, const void *alpha, const void *x, const blasint incx,const void *beta, void *y, const blasint incy);
+
+void cblas_somatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const float calpha, const float *a,
+ const blasint clda, float *b, const blasint cldb);
+void cblas_domatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const double calpha, const double *a,
+ const blasint clda, double *b, const blasint cldb);
+void cblas_comatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const void* calpha, const void* a,
+ const blasint clda, void *b, const blasint cldb);
+void cblas_zomatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const void* calpha, const void* a,
+ const blasint clda, void *b, const blasint cldb);
+
+void cblas_simatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const float calpha, float *a,
+ const blasint clda, const blasint cldb);
+void cblas_dimatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const double calpha, double *a,
+ const blasint clda, const blasint cldb);
+void cblas_cimatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const float* calpha, float* a,
+ const blasint clda, const blasint cldb);
+void cblas_zimatcopy(const enum CBLAS_ORDER CORDER, const enum CBLAS_TRANSPOSE CTRANS, const blasint crows, const blasint ccols, const double* calpha, double* a,
+ const blasint clda, const blasint cldb);
+
+void cblas_sgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const float calpha, float *a, const blasint clda, const float cbeta,
+ float *c, const blasint cldc);
+void cblas_dgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const double calpha, double *a, const blasint clda, const double cbeta,
+ double *c, const blasint cldc);
+void cblas_cgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const float *calpha, float *a, const blasint clda, const float *cbeta,
+ float *c, const blasint cldc);
+void cblas_zgeadd(const enum CBLAS_ORDER CORDER,const blasint crows, const blasint ccols, const double *calpha, double *a, const blasint clda, const double *cbeta,
+ double *c, const blasint cldc);
+
+/*** BFLOAT16 and INT8 extensions ***/
+/* convert float array to BFLOAT16 array by rounding */
+//void cblas_sbstobf16(const blasint n, const float *in, const blasint incin, bfloat16 *out, const blasint incout);
+/* convert double array to BFLOAT16 array by rounding */
+//void cblas_sbdtobf16(const blasint n, const double *in, const blasint incin, bfloat16 *out, const blasint incout);
+/* convert BFLOAT16 array to float array */
+//void cblas_sbf16tos(const blasint n, const bfloat16 *in, const blasint incin, float *out, const blasint incout);
+/* convert BFLOAT16 array to double array */
+//void cblas_dbf16tod(const blasint n, const bfloat16 *in, const blasint incin, double *out, const blasint incout);
+/* dot production of BFLOAT16 input arrays, and output as float */
+//float cblas_sbdot(const blasint n, const bfloat16 *x, const blasint incx, const bfloat16 *y, const blasint incy);
+//void cblas_sbgemv(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const blasint m, const blasint n, const float alpha, const bfloat16 *a, const blasint lda, const bfloat16 *x, const blasint incx, const float beta, float *y, const blasint incy);
+
+//void cblas_sbgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const blasint M, const blasint N, const blasint K,
+// const float alpha, const bfloat16 *A, const blasint lda, const bfloat16 *B, const blasint ldb, const float beta, float *C, const blasint ldc);
+
+
diff --git a/shared/windows-x86_64/include/samplerate.h b/shared/windows-x86_64/include/samplerate.h
new file mode 100644
index 0000000..436b7ff
--- /dev/null
+++ b/shared/windows-x86_64/include/samplerate.h
@@ -0,0 +1,163 @@
+#ifndef SAMPLERATE_H
+#define SAMPLERATE_H
+
+/* Opaque data type SRC_STATE. */
+typedef struct SRC_STATE_tag SRC_STATE;
+
+/* SRC_DATA is used to pass data to src_simple() and src_process(). */
+typedef struct
+{ const float *data_in ;
+ float *data_out ;
+
+ long input_frames, output_frames ;
+ long input_frames_used, output_frames_gen ;
+
+ int end_of_input ;
+
+ double src_ratio ;
+} SRC_DATA ;
+
+/*
+** User supplied callback function type for use with src_callback_new()
+** and src_callback_read(). First parameter is the same pointer that was
+** passed into src_callback_new(). Second parameter is pointer to a
+** pointer. The user supplied callback function must modify *data to
+** point to the start of the user supplied float array. The user supplied
+** function must return the number of frames that **data points to.
+*/
+
+typedef long (*src_callback_t) (void *cb_data, float **data) ;
+
+/*
+** Standard initialisation function : return an anonymous pointer to the
+** internal state of the converter. Choose a converter from the enums below.
+** Error returned in *error.
+*/
+
+SRC_STATE* src_new (int converter_type, int channels, int *error) ;
+
+/*
+** Clone a handle : return an anonymous pointer to a new converter
+** containing the same internal state as orig. Error returned in *error.
+*/
+SRC_STATE* src_clone (SRC_STATE* orig, int *error) ;
+
+/*
+** Initilisation for callback based API : return an anonymous pointer to the
+** internal state of the converter. Choose a converter from the enums below.
+** The cb_data pointer can point to any data or be set to NULL. Whatever the
+** value, when processing, user supplied function "func" gets called with
+** cb_data as first parameter.
+*/
+
+SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels,
+ int *error, void* cb_data) ;
+
+/*
+** Cleanup all internal allocations.
+** Always returns NULL.
+*/
+
+SRC_STATE* src_delete (SRC_STATE *state) ;
+
+/*
+** Standard processing function.
+** Returns non zero on error.
+*/
+
+int src_process (SRC_STATE *state, SRC_DATA *data) ;
+
+/*
+** Callback based processing function. Read up to frames worth of data from
+** the converter int *data and return frames read or -1 on error.
+*/
+long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ;
+
+/*
+** Simple interface for performing a single conversion from input buffer to
+** output buffer at a fixed conversion ratio.
+** Simple interface does not require initialisation as it can only operate on
+** a single buffer worth of audio.
+*/
+
+int src_simple (SRC_DATA *data, int converter_type, int channels) ;
+
+/*
+** This library contains a number of different sample rate converters,
+** numbered 0 through N.
+**
+** Return a string giving either a name or a more full description of each
+** sample rate converter or NULL if no sample rate converter exists for
+** the given value. The converters are sequentially numbered from 0 to N.
+*/
+
+const char *src_get_name (int converter_type) ;
+const char *src_get_description (int converter_type) ;
+const char *src_get_version (void) ;
+
+/*
+** Set a new SRC ratio. This allows step responses
+** in the conversion ratio.
+** Returns non zero on error.
+*/
+
+int src_set_ratio (SRC_STATE *state, double new_ratio) ;
+
+/*
+** Get the current channel count.
+** Returns negative on error, positive channel count otherwise
+*/
+
+int src_get_channels (SRC_STATE *state) ;
+
+/*
+** Reset the internal SRC state.
+** Does not modify the quality settings.
+** Does not free any memory allocations.
+** Returns non zero on error.
+*/
+
+int src_reset (SRC_STATE *state) ;
+
+/*
+** Return TRUE if ratio is a valid conversion ratio, FALSE
+** otherwise.
+*/
+
+int src_is_valid_ratio (double ratio) ;
+
+/*
+** Return an error number.
+*/
+
+int src_error (SRC_STATE *state) ;
+
+/*
+** Convert the error number into a string.
+*/
+const char* src_strerror (int error) ;
+
+/*
+** The following enums can be used to set the interpolator type
+** using the function src_set_converter().
+*/
+
+enum
+{
+ SRC_SINC_BEST_QUALITY = 0,
+ SRC_SINC_MEDIUM_QUALITY = 1,
+ SRC_SINC_FASTEST = 2,
+ SRC_ZERO_ORDER_HOLD = 3,
+ SRC_LINEAR = 4,
+} ;
+
+/*
+** Extra helper functions for converting from short to float and
+** back again.
+*/
+
+void src_short_to_float_array (const short *in, float *out, int len) ;
+void src_float_to_short_array (const float *in, short *out, int len) ;
+
+void src_int_to_float_array (const int *in, float *out, int len) ;
+void src_float_to_int_array (const float *in, int *out, int len) ;
\ No newline at end of file
diff --git a/shared/windows-x86_64/include/sndfile.h b/shared/windows-x86_64/include/sndfile.h
new file mode 100644
index 0000000..8c4df97
--- /dev/null
+++ b/shared/windows-x86_64/include/sndfile.h
@@ -0,0 +1,496 @@
+#ifndef SNDFILE_H
+#define SNDFILE_H
+
+#define SNDFILE_1
+
+/** File format types. */
+enum
+{ /* Major formats. */
+ SF_FORMAT_WAV = 0x010000, /* Microsoft WAV format (little endian default). */
+ SF_FORMAT_AIFF = 0x020000, /* Apple/SGI AIFF format (big endian). */
+ SF_FORMAT_AU = 0x030000, /* Sun/NeXT AU format (big endian). */
+ SF_FORMAT_RAW = 0x040000, /* RAW PCM data. */
+ SF_FORMAT_PAF = 0x050000, /* Ensoniq PARIS file format. */
+ SF_FORMAT_SVX = 0x060000, /* Amiga IFF / SVX8 / SV16 format. */
+ SF_FORMAT_NIST = 0x070000, /* Sphere NIST format. */
+ SF_FORMAT_VOC = 0x080000, /* VOC files. */
+ SF_FORMAT_IRCAM = 0x0A0000, /* Berkeley/IRCAM/CARL */
+ SF_FORMAT_W64 = 0x0B0000, /* Sonic Foundry's 64 bit RIFF/WAV */
+ SF_FORMAT_MAT4 = 0x0C0000, /* Matlab (tm) V4.2 / GNU Octave 2.0 */
+ SF_FORMAT_MAT5 = 0x0D0000, /* Matlab (tm) V5.0 / GNU Octave 2.1 */
+ SF_FORMAT_PVF = 0x0E0000, /* Portable Voice Format */
+ SF_FORMAT_XI = 0x0F0000, /* Fasttracker 2 Extended Instrument */
+ SF_FORMAT_HTK = 0x100000, /* HMM Tool Kit format */
+ SF_FORMAT_SDS = 0x110000, /* Midi Sample Dump Standard */
+ SF_FORMAT_AVR = 0x120000, /* Audio Visual Research */
+ SF_FORMAT_WAVEX = 0x130000, /* MS WAVE with WAVEFORMATEX */
+ SF_FORMAT_SD2 = 0x160000, /* Sound Designer 2 */
+ SF_FORMAT_FLAC = 0x170000, /* FLAC lossless file format */
+ SF_FORMAT_CAF = 0x180000, /* Core Audio File format */
+ SF_FORMAT_WVE = 0x190000, /* Psion WVE format */
+ SF_FORMAT_OGG = 0x200000, /* Xiph OGG container */
+ SF_FORMAT_MPC2K = 0x210000, /* Akai MPC 2000 sampler */
+ SF_FORMAT_RF64 = 0x220000, /* RF64 WAV file */
+ SF_FORMAT_MPEG = 0x230000, /* MPEG-1/2 audio stream */
+
+ /* Subtypes from here on. */
+
+ SF_FORMAT_PCM_S8 = 0x0001, /* Signed 8 bit data */
+ SF_FORMAT_PCM_16 = 0x0002, /* Signed 16 bit data */
+ SF_FORMAT_PCM_24 = 0x0003, /* Signed 24 bit data */
+ SF_FORMAT_PCM_32 = 0x0004, /* Signed 32 bit data */
+
+ SF_FORMAT_PCM_U8 = 0x0005, /* Unsigned 8 bit data (WAV and RAW only) */
+
+ SF_FORMAT_FLOAT = 0x0006, /* 32 bit float data */
+ SF_FORMAT_DOUBLE = 0x0007, /* 64 bit float data */
+
+ SF_FORMAT_ULAW = 0x0010, /* U-Law encoded. */
+ SF_FORMAT_ALAW = 0x0011, /* A-Law encoded. */
+ SF_FORMAT_IMA_ADPCM = 0x0012, /* IMA ADPCM. */
+ SF_FORMAT_MS_ADPCM = 0x0013, /* Microsoft ADPCM. */
+
+ SF_FORMAT_GSM610 = 0x0020, /* GSM 6.10 encoding. */
+ SF_FORMAT_VOX_ADPCM = 0x0021, /* OKI / Dialogix ADPCM */
+
+ SF_FORMAT_NMS_ADPCM_16 = 0x0022, /* 16kbs NMS G721-variant encoding. */
+ SF_FORMAT_NMS_ADPCM_24 = 0x0023, /* 24kbs NMS G721-variant encoding. */
+ SF_FORMAT_NMS_ADPCM_32 = 0x0024, /* 32kbs NMS G721-variant encoding. */
+
+ SF_FORMAT_G721_32 = 0x0030, /* 32kbs G721 ADPCM encoding. */
+ SF_FORMAT_G723_24 = 0x0031, /* 24kbs G723 ADPCM encoding. */
+ SF_FORMAT_G723_40 = 0x0032, /* 40kbs G723 ADPCM encoding. */
+
+ SF_FORMAT_DWVW_12 = 0x0040, /* 12 bit Delta Width Variable Word encoding. */
+ SF_FORMAT_DWVW_16 = 0x0041, /* 16 bit Delta Width Variable Word encoding. */
+ SF_FORMAT_DWVW_24 = 0x0042, /* 24 bit Delta Width Variable Word encoding. */
+ SF_FORMAT_DWVW_N = 0x0043, /* N bit Delta Width Variable Word encoding. */
+
+ SF_FORMAT_DPCM_8 = 0x0050, /* 8 bit differential PCM (XI only) */
+ SF_FORMAT_DPCM_16 = 0x0051, /* 16 bit differential PCM (XI only) */
+
+ SF_FORMAT_VORBIS = 0x0060, /* Xiph Vorbis encoding. */
+ SF_FORMAT_OPUS = 0x0064, /* Xiph/Skype Opus encoding. */
+
+ SF_FORMAT_ALAC_16 = 0x0070, /* Apple Lossless Audio Codec (16 bit). */
+ SF_FORMAT_ALAC_20 = 0x0071, /* Apple Lossless Audio Codec (20 bit). */
+ SF_FORMAT_ALAC_24 = 0x0072, /* Apple Lossless Audio Codec (24 bit). */
+ SF_FORMAT_ALAC_32 = 0x0073, /* Apple Lossless Audio Codec (32 bit). */
+
+ SF_FORMAT_MPEG_LAYER_I = 0x0080, /* MPEG-1 Audio Layer I */
+ SF_FORMAT_MPEG_LAYER_II = 0x0081, /* MPEG-1 Audio Layer II */
+ SF_FORMAT_MPEG_LAYER_III = 0x0082, /* MPEG-2 Audio Layer III */
+
+ /* Endian-ness options. */
+
+ SF_ENDIAN_FILE = 0x00000000, /* Default file endian-ness. */
+ SF_ENDIAN_LITTLE = 0x10000000, /* Force little endian-ness. */
+ SF_ENDIAN_BIG = 0x20000000, /* Force big endian-ness. */
+ SF_ENDIAN_CPU = 0x30000000, /* Force CPU endian-ness. */
+
+ SF_FORMAT_SUBMASK = 0x0000FFFF,
+ SF_FORMAT_TYPEMASK = 0x0FFF0000,
+ SF_FORMAT_ENDMASK = 0x30000000
+};
+
+/** valid command numbers for the sf_command() interface */
+enum
+{ SFC_GET_LIB_VERSION = 0x1000,
+ SFC_GET_LOG_INFO = 0x1001,
+ SFC_GET_CURRENT_SF_INFO = 0x1002,
+
+
+ SFC_GET_NORM_DOUBLE = 0x1010,
+ SFC_GET_NORM_FLOAT = 0x1011,
+ SFC_SET_NORM_DOUBLE = 0x1012,
+ SFC_SET_NORM_FLOAT = 0x1013,
+ SFC_SET_SCALE_FLOAT_INT_READ = 0x1014,
+ SFC_SET_SCALE_INT_FLOAT_WRITE = 0x1015,
+
+ SFC_GET_SIMPLE_FORMAT_COUNT = 0x1020,
+ SFC_GET_SIMPLE_FORMAT = 0x1021,
+
+ SFC_GET_FORMAT_INFO = 0x1028,
+
+ SFC_GET_FORMAT_MAJOR_COUNT = 0x1030,
+ SFC_GET_FORMAT_MAJOR = 0x1031,
+ SFC_GET_FORMAT_SUBTYPE_COUNT = 0x1032,
+ SFC_GET_FORMAT_SUBTYPE = 0x1033,
+
+ SFC_CALC_SIGNAL_MAX = 0x1040,
+ SFC_CALC_NORM_SIGNAL_MAX = 0x1041,
+ SFC_CALC_MAX_ALL_CHANNELS = 0x1042,
+ SFC_CALC_NORM_MAX_ALL_CHANNELS = 0x1043,
+ SFC_GET_SIGNAL_MAX = 0x1044,
+ SFC_GET_MAX_ALL_CHANNELS = 0x1045,
+
+ SFC_SET_ADD_PEAK_CHUNK = 0x1050,
+
+ SFC_UPDATE_HEADER_NOW = 0x1060,
+ SFC_SET_UPDATE_HEADER_AUTO = 0x1061,
+
+ SFC_FILE_TRUNCATE = 0x1080,
+
+ SFC_SET_RAW_START_OFFSET = 0x1090,
+
+ /* Commands reserved for dithering, which is not implemented. */
+ SFC_SET_DITHER_ON_WRITE = 0x10A0,
+ SFC_SET_DITHER_ON_READ = 0x10A1,
+
+ SFC_GET_DITHER_INFO_COUNT = 0x10A2,
+ SFC_GET_DITHER_INFO = 0x10A3,
+
+ SFC_GET_EMBED_FILE_INFO = 0x10B0,
+
+ SFC_SET_CLIPPING = 0x10C0,
+ SFC_GET_CLIPPING = 0x10C1,
+
+ SFC_GET_CUE_COUNT = 0x10CD,
+ SFC_GET_CUE = 0x10CE,
+ SFC_SET_CUE = 0x10CF,
+
+ SFC_GET_INSTRUMENT = 0x10D0,
+ SFC_SET_INSTRUMENT = 0x10D1,
+
+ SFC_GET_LOOP_INFO = 0x10E0,
+
+ SFC_GET_BROADCAST_INFO = 0x10F0,
+ SFC_SET_BROADCAST_INFO = 0x10F1,
+
+ SFC_GET_CHANNEL_MAP_INFO = 0x1100,
+ SFC_SET_CHANNEL_MAP_INFO = 0x1101,
+
+ SFC_RAW_DATA_NEEDS_ENDSWAP = 0x1110,
+
+ /* Support for Wavex Ambisonics Format */
+ SFC_WAVEX_SET_AMBISONIC = 0x1200,
+ SFC_WAVEX_GET_AMBISONIC = 0x1201,
+
+ /*
+ ** RF64 files can be set so that on-close, writable files that have less
+ ** than 4GB of data in them are converted to RIFF/WAV, as per EBU
+ ** recommendations.
+ */
+ SFC_RF64_AUTO_DOWNGRADE = 0x1210,
+
+ SFC_SET_VBR_ENCODING_QUALITY = 0x1300,
+ SFC_SET_COMPRESSION_LEVEL = 0x1301,
+
+ /* Ogg format commands */
+ SFC_SET_OGG_PAGE_LATENCY_MS = 0x1302,
+ SFC_SET_OGG_PAGE_LATENCY = 0x1303,
+ SFC_GET_OGG_STREAM_SERIALNO = 0x1306,
+
+ SFC_GET_BITRATE_MODE = 0x1304,
+ SFC_SET_BITRATE_MODE = 0x1305,
+
+ /* Cart Chunk support */
+ SFC_SET_CART_INFO = 0x1400,
+ SFC_GET_CART_INFO = 0x1401,
+
+ /* Opus files original samplerate metadata */
+ SFC_SET_ORIGINAL_SAMPLERATE = 0x1500,
+ SFC_GET_ORIGINAL_SAMPLERATE = 0x1501,
+
+ /* Following commands for testing only. */
+ SFC_TEST_IEEE_FLOAT_REPLACE = 0x6001,
+
+ /*
+ ** These SFC_SET_ADD_* values are deprecated and will disappear at some
+ ** time in the future. They are guaranteed to be here up to and
+ ** including version 1.0.8 to avoid breakage of existing software.
+ ** They currently do nothing and will continue to do nothing.
+ */
+ SFC_SET_ADD_HEADER_PAD_CHUNK = 0x1051,
+
+ SFC_SET_ADD_DITHER_ON_WRITE = 0x1070,
+ SFC_SET_ADD_DITHER_ON_READ = 0x1071
+};
+
+/** String types that can be set and read from files. */
+enum
+{ SF_STR_TITLE = 0x01,
+ SF_STR_COPYRIGHT = 0x02,
+ SF_STR_SOFTWARE = 0x03,
+ SF_STR_ARTIST = 0x04,
+ SF_STR_COMMENT = 0x05,
+ SF_STR_DATE = 0x06,
+ SF_STR_ALBUM = 0x07,
+ SF_STR_LICENSE = 0x08,
+ SF_STR_TRACKNUMBER = 0x09,
+ SF_STR_GENRE = 0x10
+} ;
+
+/** Start and End index when doing metadata transcoding. */
+#define SF_STR_FIRST SF_STR_TITLE
+#define SF_STR_LAST SF_STR_GENRE
+
+enum
+{ /* True and false */
+ SF_FALSE = 0,
+ SF_TRUE = 1,
+
+ /* Modes for opening files. */
+ SFM_READ = 0x10,
+ SFM_WRITE = 0x20,
+ SFM_RDWR = 0x30,
+
+ SF_AMBISONIC_NONE = 0x40,
+ SF_AMBISONIC_B_FORMAT = 0x41
+};
+
+/** Error codes. */
+enum
+{ SF_ERR_NO_ERROR = 0,
+ SF_ERR_UNRECOGNISED_FORMAT = 1,
+ SF_ERR_SYSTEM = 2,
+ SF_ERR_MALFORMED_FILE = 3,
+ SF_ERR_UNSUPPORTED_ENCODING = 4
+};
+
+/** Channel map values (used with SFC_SET/GET_CHANNEL_MAP). */
+enum
+{ SF_CHANNEL_MAP_INVALID = 0,
+ SF_CHANNEL_MAP_MONO = 1,
+ SF_CHANNEL_MAP_LEFT, /* Apple calls this 'Left' */
+ SF_CHANNEL_MAP_RIGHT, /* Apple calls this 'Right' */
+ SF_CHANNEL_MAP_CENTER, /* Apple calls this 'Center' */
+ SF_CHANNEL_MAP_FRONT_LEFT,
+ SF_CHANNEL_MAP_FRONT_RIGHT,
+ SF_CHANNEL_MAP_FRONT_CENTER,
+ SF_CHANNEL_MAP_REAR_CENTER, /* Apple calls this 'Center Surround', Msft calls this 'Back Center' */
+ SF_CHANNEL_MAP_REAR_LEFT, /* Apple calls this 'Left Surround', Msft calls this 'Back Left' */
+ SF_CHANNEL_MAP_REAR_RIGHT, /* Apple calls this 'Right Surround', Msft calls this 'Back Right' */
+ SF_CHANNEL_MAP_LFE, /* Apple calls this 'LFEScreen', Msft calls this 'Low Frequency' */
+ SF_CHANNEL_MAP_FRONT_LEFT_OF_CENTER, /* Apple calls this 'Left Center' */
+ SF_CHANNEL_MAP_FRONT_RIGHT_OF_CENTER, /* Apple calls this 'Right Center */
+ SF_CHANNEL_MAP_SIDE_LEFT, /* Apple calls this 'Left Surround Direct' */
+ SF_CHANNEL_MAP_SIDE_RIGHT, /* Apple calls this 'Right Surround Direct' */
+ SF_CHANNEL_MAP_TOP_CENTER, /* Apple calls this 'Top Center Surround' */
+ SF_CHANNEL_MAP_TOP_FRONT_LEFT, /* Apple calls this 'Vertical Height Left' */
+ SF_CHANNEL_MAP_TOP_FRONT_RIGHT, /* Apple calls this 'Vertical Height Right' */
+ SF_CHANNEL_MAP_TOP_FRONT_CENTER, /* Apple calls this 'Vertical Height Center' */
+ SF_CHANNEL_MAP_TOP_REAR_LEFT, /* Apple and MS call this 'Top Back Left' */
+ SF_CHANNEL_MAP_TOP_REAR_RIGHT, /* Apple and MS call this 'Top Back Right' */
+ SF_CHANNEL_MAP_TOP_REAR_CENTER, /* Apple and MS call this 'Top Back Center' */
+
+ SF_CHANNEL_MAP_AMBISONIC_B_W,
+ SF_CHANNEL_MAP_AMBISONIC_B_X,
+ SF_CHANNEL_MAP_AMBISONIC_B_Y,
+ SF_CHANNEL_MAP_AMBISONIC_B_Z,
+
+ SF_CHANNEL_MAP_MAX
+};
+
+/** Bitrate mode values (for use with SFC_GET/SET_BITRATE_MODE) */
+enum
+{ SF_BITRATE_MODE_CONSTANT = 0,
+ SF_BITRATE_MODE_AVERAGE,
+ SF_BITRATE_MODE_VARIABLE
+};
+
+/* A SNDFILE* pointer can be passed around much like stdio.h's FILE* pointer. */
+typedef struct sf_private_tag SNDFILE ;
+
+/* The following typedef is system specific and is defined when libsndfile is
+** compiled. sf_count_t will be a 64 bit value when the underlying OS allows
+** 64 bit file offsets.
+** On windows, we need to allow the same header file to be compiler by both GCC
+** and the Microsoft compiler.
+*/
+
+typedef int64_t sf_count_t ;
+#ifndef SF_COUNT_MAX
+#define SF_COUNT_MAX INT64_MAX
+#endif
+
+/* A pointer to a SF_INFO structure is passed to sf_open () and filled in.
+** On write, the SF_INFO structure is filled in by the user and passed into
+** sf_open ().
+*/
+struct SF_INFO
+{ sf_count_t frames ; /* Used to be called samples. Changed to avoid confusion. */
+ int samplerate ;
+ int channels ;
+ int format ;
+ int sections ;
+ int seekable ;
+} ;
+
+typedef struct SF_INFO SF_INFO ;
+
+/* The SF_FORMAT_INFO struct is used to retrieve information about the sound
+** file formats libsndfile supports using the sf_command () interface.
+*/
+typedef struct
+{ int format ;
+ const char *name ;
+ const char *extension ;
+} SF_FORMAT_INFO;
+
+/* Open the specified file for read, write or both. On error, this will
+** return a NULL pointer. To find the error number, pass a NULL SNDFILE
+** to sf_strerror ().
+** All calls to sf_open() should be matched with a call to sf_close().
+*/
+SNDFILE* sf_open (const char *path, int mode, SF_INFO *sfinfo) ;
+
+/* Use the existing file descriptor to create a SNDFILE object. If close_desc
+** is TRUE, the file descriptor will be closed when sf_close() is called. If
+** it is FALSE, the descriptor will not be closed.
+** When passed a descriptor like this, the library will assume that the start
+** of file header is at the current file offset. This allows sound files within
+** larger container files to be read and/or written.
+** On error, this will return a NULL pointer. To find the error number, pass a
+** NULL SNDFILE to sf_strerror ().
+** All calls to sf_open_fd() should be matched with a call to sf_close().
+*/
+
+SNDFILE* sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc) ;
+
+
+/* sf_error () returns a error number which can be translated to a text
+** string using sf_error_number().
+*/
+
+int sf_error (SNDFILE *sndfile) ;
+
+
+/* sf_strerror () returns to the caller a pointer to the current error message for
+** the given SNDFILE.
+*/
+
+const char* sf_strerror (SNDFILE *sndfile) ;
+
+
+/* sf_error_number () allows the retrieval of the error string for each internal
+** error number.
+**
+*/
+
+const char* sf_error_number (int errnum) ;
+
+
+/* The following two error functions are deprecated but they will remain in the
+** library for the foreseeable future. The function sf_strerror() should be used
+** in their place.
+*/
+
+int sf_perror (SNDFILE *sndfile) ;
+int sf_error_str (SNDFILE *sndfile, char* str, size_t len) ;
+
+
+/* Allow the caller to retrieve information from or change aspects of the
+** library behaviour.
+*/
+
+int sf_command (SNDFILE *sndfile, int command, void *data, int datasize) ;
+
+
+/* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */
+
+int sf_format_check (const SF_INFO *info) ;
+
+
+
+/* Functions for retrieving and setting string data within sound files.
+** Not all file types support this features; AIFF and WAV do. For both
+** functions, the str_type parameter must be one of the SF_STR_* values
+** defined above.
+** On error, sf_set_string() returns non-zero while sf_get_string()
+** returns NULL.
+*/
+
+int sf_set_string (SNDFILE *sndfile, int str_type, const char* str) ;
+
+const char* sf_get_string (SNDFILE *sndfile, int str_type) ;
+
+/* Return the library version string. */
+const char * sf_version_string (void) ;
+
+/* Return the current byterate at this point in the file. The byte rate in this
+** case is the number of bytes per second of audio data. For instance, for a
+** stereo, 18 bit PCM encoded file with an 16kHz sample rate, the byte rate
+** would be 2 (stereo) * 2 (two bytes per sample) * 16000 => 64000 bytes/sec.
+** For some file formats the returned value will be accurate and exact, for some
+** it will be a close approximation, for some it will be the average bitrate for
+** the whole file and for some it will be a time varying value that was accurate
+** when the file was most recently read or written.
+** To get the bitrate, multiple this value by 8.
+** Returns -1 for unknown.
+*/
+int sf_current_byterate (SNDFILE *sndfile) ;
+
+/* Functions for reading/writing the waveform data of a sound file.
+*/
+
+sf_count_t sf_read_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
+sf_count_t sf_write_raw (SNDFILE *sndfile, const void *ptr, sf_count_t bytes) ;
+
+/* Functions for reading and writing the data chunk in terms of frames.
+** The number of items actually read/written = frames * number of channels.
+** sf_xxxx_raw read/writes the raw data bytes from/to the file
+** sf_xxxx_short passes data in the native short format
+** sf_xxxx_int passes data in the native int format
+** sf_xxxx_float passes data in the native float format
+** sf_xxxx_double passes data in the native double format
+** All of these read/write function return number of frames read/written.
+*/
+
+sf_count_t sf_readf_short (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_short (SNDFILE *sndfile, const short *ptr, sf_count_t frames) ;
+
+sf_count_t sf_readf_int (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_int (SNDFILE *sndfile, const int *ptr, sf_count_t frames) ;
+
+sf_count_t sf_readf_float (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_float (SNDFILE *sndfile, const float *ptr, sf_count_t frames) ;
+
+sf_count_t sf_readf_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
+sf_count_t sf_writef_double (SNDFILE *sndfile, const double *ptr, sf_count_t frames) ;
+
+
+/* Functions for reading and writing the data chunk in terms of items.
+** Otherwise similar to above.
+** All of these read/write function return number of items read/written.
+*/
+
+sf_count_t sf_read_short (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
+sf_count_t sf_write_short (SNDFILE *sndfile, const short *ptr, sf_count_t items) ;
+
+sf_count_t sf_read_int (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
+sf_count_t sf_write_int (SNDFILE *sndfile, const int *ptr, sf_count_t items) ;
+
+sf_count_t sf_read_float (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
+sf_count_t sf_write_float (SNDFILE *sndfile, const float *ptr, sf_count_t items) ;
+
+sf_count_t sf_read_double (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
+sf_count_t sf_write_double (SNDFILE *sndfile, const double *ptr, sf_count_t items) ;
+
+
+/* Close the SNDFILE and clean up all memory allocations associated with this
+** file.
+** Returns 0 on success, or an error number.
+*/
+
+int sf_close (SNDFILE *sndfile) ;
+
+
+/* If the file is opened SFM_WRITE or SFM_RDWR, call fsync() on the file
+** to force the writing of data to disk. If the file is opened SFM_READ
+** no action is taken.
+*/
+
+void sf_write_sync (SNDFILE *sndfile) ;
+
+
+
+/* The function sf_wchar_open() is Windows Only!
+** Open a file passing in a Windows Unicode filename. Otherwise, this is
+** the same as sf_open().
+*/
+
+/* #ifdef _WIN32
+** SNDFILE* sf_wchar_open (const wchar_t *wpath, int mode, SF_INFO *sfinfo) ;
+** #endif
+*/
\ No newline at end of file
diff --git a/shared/windows-x86_64/include/transformersphp.h b/shared/windows-x86_64/include/transformersphp.h
new file mode 100644
index 0000000..7c9c4b8
--- /dev/null
+++ b/shared/windows-x86_64/include/transformersphp.h
@@ -0,0 +1,19 @@
+#ifndef FAST_TRANSFORMERS_UTILS_H
+#define FAST_TRANSFORMERS_UTILS_H
+
+enum {
+ LOG_MEL_NONE = 0,
+ LOG_MEL_LOG = 1,
+ LOG_MEL_LOG10 = 2,
+ LOG_MEL_DB = 3
+};
+
+void pad_reflect(float *input, int length, float *padded, int padded_length);
+
+void spectrogram(
+ float *waveform, int waveform_length, float *spectrogram, int spectrogram_length, int hop_length, int fft_length,
+ float *window,int window_length, int d1, int d1_max, float power, int center, float preemphasis, float *mel_filters,
+ int num_mel_filters, int num_frequency_bins, float mel_floor, int log_mel, int remove_dc_offset, int do_pad, int transpose
+);
+
+#endif // FAST_TRANSFORMERS_UTILS_H
diff --git a/shared/windows-x86_64/lib/libglib-2.0-0.dll b/shared/windows-x86_64/lib/libglib-2.0-0.dll
new file mode 100755
index 0000000..594da00
Binary files /dev/null and b/shared/windows-x86_64/lib/libglib-2.0-0.dll differ
diff --git a/shared/windows-x86_64/lib/libgobject-2.0-0.dll b/shared/windows-x86_64/lib/libgobject-2.0-0.dll
new file mode 100755
index 0000000..594da00
Binary files /dev/null and b/shared/windows-x86_64/lib/libgobject-2.0-0.dll differ
diff --git a/shared/windows-x86_64/lib/libvips-42.dll b/shared/windows-x86_64/lib/libvips-42.dll
new file mode 100755
index 0000000..594da00
Binary files /dev/null and b/shared/windows-x86_64/lib/libvips-42.dll differ
diff --git a/shared/windows-x86_64/lib/onnxruntime-1.21.0.dll b/shared/windows-x86_64/lib/onnxruntime-1.21.0.dll
new file mode 100644
index 0000000..f7c3556
Binary files /dev/null and b/shared/windows-x86_64/lib/onnxruntime-1.21.0.dll differ
diff --git a/shared/windows-x86_64/lib/openblas-0.3.28.dll b/shared/windows-x86_64/lib/openblas-0.3.28.dll
new file mode 100644
index 0000000..d8a3ef4
Binary files /dev/null and b/shared/windows-x86_64/lib/openblas-0.3.28.dll differ
diff --git a/shared/windows-x86_64/lib/rindowmatlib-1.1.1.dll b/shared/windows-x86_64/lib/rindowmatlib-1.1.1.dll
new file mode 100644
index 0000000..1fb6686
Binary files /dev/null and b/shared/windows-x86_64/lib/rindowmatlib-1.1.1.dll differ
diff --git a/shared/windows-x86_64/lib/samplerate-0.2.2.dll b/shared/windows-x86_64/lib/samplerate-0.2.2.dll
new file mode 100644
index 0000000..6bbb805
Binary files /dev/null and b/shared/windows-x86_64/lib/samplerate-0.2.2.dll differ
diff --git a/shared/windows-x86_64/lib/sndfile-1.2.2.dll b/shared/windows-x86_64/lib/sndfile-1.2.2.dll
new file mode 100644
index 0000000..d548a8f
Binary files /dev/null and b/shared/windows-x86_64/lib/sndfile-1.2.2.dll differ
diff --git a/shared/windows-x86_64/lib/transformersphp-1.0.0.dll b/shared/windows-x86_64/lib/transformersphp-1.0.0.dll
new file mode 100644
index 0000000..57077b3
Binary files /dev/null and b/shared/windows-x86_64/lib/transformersphp-1.0.0.dll differ
diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php
deleted file mode 100644
index ba6b6a4..0000000
--- a/src/Commands/InstallCommand.php
+++ /dev/null
@@ -1,69 +0,0 @@
-setHelp('This command initializes Transformers PHP and downloads the required shared libraries.');
- }
-
- protected function execute(InputInterface $input, OutputInterface $output): int
- {
- try {
- LibsChecker::check(output: $output);
-
- $this->askToStar($input, $output);
-
- return Command::SUCCESS;
- } catch (Exception $e) {
- $output->writeln('' . $e->getMessage() . '');
-
- return Command::FAILURE;
- }
- }
-
-
- protected function askToStar(InputInterface $input, OutputInterface $output): void
- {
- if ($input->getOption('no-interaction')) {
- return;
- }
-
- $helper = $this->getHelper('question');
- $question = new ConfirmationQuestion('? Would you like to show some love by starring the Transformers repo on GitHub? ', true);
-
- if ($helper->ask($input, $output, $question)) {
- if (PHP_OS_FAMILY === 'Darwin') {
- exec('open https://github.com/CodeWithKyrian/transformers-php');
- }
- if (PHP_OS_FAMILY === 'Linux') {
- exec('xdg-open https://github.com/CodeWithKyrian/transformers-php');
- }
- if (PHP_OS_FAMILY === 'Windows') {
- exec('start https://github.com/CodeWithKyrian/transformers-php');
- }
-
- $output->writeln('✔ Thank you!');
- } else {
- $output->writeln('✔ That\'s okay. You can always star the repo later.');
- }
- }
-}
\ No newline at end of file
diff --git a/src/Configs/AutoConfig.php b/src/Configs/AutoConfig.php
new file mode 100644
index 0000000..80c8161
--- /dev/null
+++ b/src/Configs/AutoConfig.php
@@ -0,0 +1,22 @@
+kwargs);
}
+ /**
+ * Merge multiple GenerationConfig objects or arrays, with later arguments taking precedence.
+ * @param GenerationConfig|array ...$configs
+ * @return GenerationConfig
+ */
+ public static function mergeConfigs(...$configs): GenerationConfig
+ {
+ // Start with an empty array (lowest precedence)
+ $merged = [];
+ foreach ($configs as $config) {
+ if ($config instanceof self) {
+ $arr = $config->toArray();
+ } elseif (is_array($config)) {
+ $arr = $config;
+ } elseif ($config === null) {
+ continue;
+ } else {
+ throw new \InvalidArgumentException('mergeConfigs expects GenerationConfig, array, or null');
+ }
+ // Only overwrite if value is not null
+ foreach ($arr as $k => $v) {
+ if ($v !== null) {
+ $merged[$k] = $v;
+ }
+ }
+ }
+ return new self($merged);
+ }
+
public function offsetExists(mixed $offset): bool
{
return property_exists($this, $offset) || isset($this->kwargs[$offset]);
diff --git a/src/Configs/PretrainedConfig.php b/src/Configs/PretrainedConfig.php
new file mode 100644
index 0000000..17305c5
--- /dev/null
+++ b/src/Configs/PretrainedConfig.php
@@ -0,0 +1,356 @@
+modelType = $config['model_type'] ?? null;
+ $this->isEncoderDecoder = $config['is_encoder_decoder'] ?? false;
+ $this->maxPositionEmbeddings = $config['max_position_embeddings'] ?? 0;
+
+ $this->normalizedConfig = $this->getNormalizedConfig($config);
+ }
+
+ public static function fromPretrained(
+ string $modelNameOrPath,
+ ?array $config = null,
+ ?string $cacheDir = null,
+ string $revision = 'main',
+ ?callable $onProgress = null
+ ): self {
+ $config ??= Hub::getJson(
+ $modelNameOrPath,
+ fileName: 'config.json',
+ cacheDir: $cacheDir,
+ revision: $revision,
+ fatal: false,
+ onProgress: $onProgress
+ );
+ if ($config === null) {
+ $logger = Transformers::getLogger();
+ $logger->warning('Config loading returned null, using fallback/defaults');
+ }
+ return new self($config);
+ }
+
+ public function offsetExists(mixed $offset): bool
+ {
+ return isset($this->config[$offset]);
+ }
+
+ public function offsetGet(mixed $offset): mixed
+ {
+ return $this->config[$offset];
+ }
+
+ public function offsetSet(mixed $offset, mixed $value): void
+ {
+ $this->config[$offset] = $value;
+ }
+
+ public function offsetUnset(mixed $offset): void
+ {
+ unset($this->config[$offset]);
+ }
+
+ protected function getNormalizedConfig(array $config): array
+ {
+ $mapping = [];
+ $normalizedConfig = [];
+
+ switch ($config['model_type']) {
+ // Sub-configs
+ case 'llava':
+ case 'paligemma':
+ case 'gemma3':
+ case 'florence2':
+ case 'llava_onevision':
+ case 'idefics3':
+ case 'ultravox':
+ case 'smolvlm':
+ case 'gemma3n':
+ $normalizedConfig = $this->getNormalizedConfig($config['text_config']);
+ break;
+ case 'moondream1':
+ $normalizedConfig = $this->getNormalizedConfig($config['phi_config']);
+ break;
+ case 'musicgen':
+ $normalizedConfig = $this->getNormalizedConfig($config['decoder']);
+ break;
+
+ // Decoder-only models
+ case 'gpt2':
+ case 'gptj':
+ case 'jais':
+ case 'codegen':
+ case 'gpt_bigcode':
+ $mapping = [
+ 'num_heads' => 'n_head',
+ 'num_layers' => 'n_layer',
+ 'hidden_size' => 'n_embd',
+ ];
+ break;
+ case 'gpt_neox':
+ case 'stablelm':
+ case 'opt':
+ case 'falcon':
+ $mapping = [
+ 'num_heads' => 'num_attention_heads',
+ 'num_layers' => 'num_hidden_layers',
+ 'hidden_size' => 'hidden_size',
+ ];
+ break;
+ case 'llama':
+ case 'lfm2':
+ case 'smollm3':
+ case 'olmo':
+ case 'olmo2':
+ case 'mobilellm':
+ case 'granite':
+ case 'cohere':
+ case 'mistral':
+ case 'starcoder2':
+ case 'qwen2':
+ case 'qwen2_vl':
+ case 'phi':
+ case 'phi3':
+ case 'phi3_v':
+ case 'llava_qwen2':
+ $mapping = [
+ 'num_heads' => 'num_key_value_heads',
+ 'num_layers' => 'num_hidden_layers',
+ 'hidden_size' => 'hidden_size',
+ 'num_attention_heads' => 'num_attention_heads',
+ ];
+ break;
+ case 'qwen3':
+ case 'gemma':
+ case 'gemma2':
+ case 'gemma3_text':
+ case 'gemma3n_text':
+ case 'glm':
+ case 'helium':
+ case 'ernie4_5':
+ $mapping = [
+ 'num_heads' => 'num_key_value_heads',
+ 'num_layers' => 'num_hidden_layers',
+ 'dim_kv' => 'head_dim',
+ ];
+ break;
+ case 'openelm':
+ $mapping = [
+ 'num_heads' => 'num_kv_heads',
+ 'num_layers' => 'num_transformer_layers',
+ 'dim_kv' => 'head_dim',
+ ];
+ break;
+ case 'gpt_neo':
+ case 'donut-swin':
+ $mapping = [
+ 'num_heads' => 'num_heads',
+ 'num_layers' => 'num_layers',
+ 'hidden_size' => 'hidden_size',
+ ];
+ break;
+ case 'bloom':
+ $mapping = [
+ 'num_heads' => 'n_head',
+ 'num_layers' => 'n_layer',
+ 'hidden_size' => 'hidden_size',
+ ];
+ break;
+ case 'mpt':
+ $mapping = [
+ 'num_heads' => 'n_heads',
+ 'num_layers' => 'n_layers',
+ 'hidden_size' => 'd_model',
+ ];
+ break;
+
+ // Encoder-decoder models
+ case 't5':
+ case 'mt5':
+ case 'longt5':
+ $mapping = [
+ 'num_decoder_layers' => 'num_decoder_layers',
+ 'num_decoder_heads' => 'num_heads',
+ 'decoder_dim_kv' => 'd_kv',
+ 'num_encoder_layers' => 'num_layers',
+ 'num_encoder_heads' => 'num_heads',
+ 'encoder_dim_kv' => 'd_kv',
+ ];
+ break;
+ case 'bart':
+ case 'mbart':
+ case 'marian':
+ case 'whisper':
+ case 'm2m_100':
+ case 'blenderbot':
+ case 'blenderbot-small':
+ case 'florence2_language':
+ $mapping = [
+ 'num_decoder_layers' => 'decoder_layers',
+ 'num_decoder_heads' => 'decoder_attention_heads',
+ 'decoder_hidden_size' => 'd_model',
+ 'num_encoder_layers' => 'encoder_layers',
+ 'num_encoder_heads' => 'encoder_attention_heads',
+ 'encoder_hidden_size' => 'd_model',
+ ];
+ break;
+ case 'speecht5':
+ $mapping = [
+ 'num_decoder_layers' => 'decoder_layers',
+ 'num_decoder_heads' => 'decoder_attention_heads',
+ 'decoder_hidden_size' => 'hidden_size',
+ 'num_encoder_layers' => 'encoder_layers',
+ 'num_encoder_heads' => 'encoder_attention_heads',
+ 'encoder_hidden_size' => 'hidden_size',
+ ];
+ break;
+ case 'trocr':
+ $mapping = [
+ 'num_encoder_layers' => 'decoder_layers',
+ 'num_decoder_heads' => 'decoder_attention_heads',
+ 'encoder_hidden_size' => 'd_model',
+ ];
+ break;
+ case 'musicgen_decoder':
+ $mapping = [
+ 'num_encoder_layers' => 'num_hidden_layers',
+ 'num_encoder_heads' => 'num_attention_heads',
+ 'encoder_hidden_size' => 'hidden_size',
+ ];
+ break;
+
+ case 'vision-encoder-decoder':
+ $decoderConfig = $this->getNormalizedConfig($config['decoder']);
+ $addEncoderPkv = array_key_exists('num_decoder_layers', $decoderConfig);
+ $result = array_pick($config, ['model_type', 'is_encoder_decoder']);
+
+ if ($addEncoderPkv) {
+ $result = array_merge($result, [
+ 'num_decoder_layers' => $decoderConfig['num_decoder_layers'],
+ 'num_decoder_heads' => $decoderConfig['num_decoder_heads'],
+ 'decoder_hidden_size' => $decoderConfig['decoder_hidden_size'],
+ 'num_encoder_layers' => $decoderConfig['num_encoder_layers'],
+ 'num_encoder_heads' => $decoderConfig['num_encoder_heads'],
+ 'encoder_hidden_size' => $decoderConfig['encoder_hidden_size'],
+ ]);
+ } else {
+ $result = array_merge($result, [
+ 'num_layers' => $decoderConfig['num_layers'],
+ 'num_heads' => $decoderConfig['num_heads'],
+ 'hidden_size' => $decoderConfig['hidden_size'],
+ ]);
+ }
+ return $result;
+ }
+
+ // If `num_attention_heads` is not set, assume it's equal to `num_heads`
+ $normalizedConfig = array_merge(
+ $normalizedConfig,
+ array_pick($config, ['model_type', 'multi_query', 'is_encoder_decoder'])
+ );
+
+ foreach ($mapping as $key => $value) {
+ $normalizedConfig[$key] = $config[$value];
+ }
+
+ return $normalizedConfig;
+ }
+
+
+ public function getKeyValueShapes(string $prefix = 'past_key_values'): array
+ {
+ $decoderFeeds = [];
+
+ // TODO: Support batches (i.e., batchSize > 1)
+ $batchSize = 1;
+
+ if (
+ ($this->normalizedConfig['is_encoder_decoder'] ?? false) &&
+ isset($this->normalizedConfig['num_encoder_heads'], $this->normalizedConfig['num_decoder_heads'])
+ ) {
+ $encoderDimKv = $this->normalizedConfig['encoder_dim_kv'] ?? (
+ $this->normalizedConfig['encoder_hidden_size'] / $this->normalizedConfig['num_encoder_heads']
+ );
+ $decoderDimKv = $this->normalizedConfig['decoder_dim_kv'] ?? (
+ $this->normalizedConfig['decoder_hidden_size'] / $this->normalizedConfig['num_decoder_heads']
+ );
+
+ $encoderDims = [$batchSize, $this->normalizedConfig['num_encoder_heads'], 0, $encoderDimKv];
+ $decoderDims = [$batchSize, $this->normalizedConfig['num_decoder_heads'], 0, $decoderDimKv];
+ for ($i = 0; $i < $this->normalizedConfig['num_decoder_layers']; ++$i) {
+ $decoderFeeds["{$prefix}.{$i}.encoder.key"] = $encoderDims;
+ $decoderFeeds["{$prefix}.{$i}.encoder.value"] = $encoderDims;
+ $decoderFeeds["{$prefix}.{$i}.decoder.key"] = $decoderDims;
+ $decoderFeeds["{$prefix}.{$i}.decoder.value"] = $decoderDims;
+ }
+ } else { // Decoders
+ $numHeads = $this->normalizedConfig['num_heads'];
+ $numLayers = $this->normalizedConfig['num_layers'];
+ $dimKv = $this->normalizedConfig['dim_kv'] ?? (
+ $this->normalizedConfig['hidden_size'] /
+ ($this->normalizedConfig['num_attention_heads'] ?? $numHeads)
+ );
+
+ if ($this->normalizedConfig['model_type'] === 'falcon') {
+ $shape = [$batchSize * $numHeads, 0, $dimKv];
+ for ($i = 0; $i < $numLayers; ++$i) {
+ $decoderFeeds["{$prefix}.{$i}.key"] = $shape;
+ $decoderFeeds["{$prefix}.{$i}.value"] = $shape;
+ }
+ } elseif ($this->config['multi_query'] ?? null) { // e.g., for `gpt_bigcode`
+ $shape = [$batchSize * $numHeads, 0, 2 * $dimKv];
+ for ($i = 0; $i < $numLayers; ++$i) {
+ $decoderFeeds["{$prefix}.{$i}.key_value"] = $shape;
+ }
+ } elseif ($this->normalizedConfig['model_type'] === 'bloom') {
+ $keyDims = [$batchSize * $numHeads, $dimKv, 0];
+ $valueDims = [$batchSize * $numHeads, 0, $dimKv];
+ for ($i = 0; $i < $numLayers; ++$i) {
+ $decoderFeeds["{$prefix}.{$i}.key"] = $keyDims;
+ $decoderFeeds["{$prefix}.{$i}.value"] = $valueDims;
+ }
+ } elseif ($this->normalizedConfig['model_type'] === 'openelm') {
+ for ($i = 0; $i < $numLayers; ++$i) {
+ $shape = [$batchSize, $numHeads[$i], 0, $dimKv];
+ $decoderFeeds["{$prefix}.{$i}.key"] = $shape;
+ $decoderFeeds["{$prefix}.{$i}.value"] = $shape;
+ }
+ } else { // Decoder-only
+ $shape = [$batchSize, $numHeads, 0, $dimKv];
+ for ($i = 0; $i < $numLayers; ++$i) {
+ $decoderFeeds["{$prefix}.{$i}.key"] = $shape;
+ $decoderFeeds["{$prefix}.{$i}.value"] = $shape;
+ }
+ }
+ }
+
+ return $decoderFeeds;
+ }
+}
diff --git a/src/DataStructures/CharTrie.php b/src/DataStructures/CharTrie.php
index ef0aa38..dc71576 100644
--- a/src/DataStructures/CharTrie.php
+++ b/src/DataStructures/CharTrie.php
@@ -27,9 +27,6 @@ public function __construct()
*/
public function extend(array $texts): void
{
-// foreach ($texts as $text) {
-// $this->push($text);
-// }
array_map([$this, 'push'], $texts);
}
@@ -61,7 +58,7 @@ public function commonPrefixSearch(string $text): Generator
$node = $this->root;
$prefix = "";
$length = mb_strlen($text);
-
+
for ($i = 0; $i < $length && $node != null; $i++) {
$ch = mb_substr($text, $i, 1);
$prefix .= $ch;
@@ -72,4 +69,4 @@ public function commonPrefixSearch(string $text): Generator
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Decoders/Decoder.php b/src/Decoders/Decoder.php
index f885713..99b7c46 100644
--- a/src/Decoders/Decoder.php
+++ b/src/Decoders/Decoder.php
@@ -6,6 +6,7 @@
namespace Codewithkyrian\Transformers\Decoders;
use Codewithkyrian\Transformers\Tokenizers\AddedToken;
+use Codewithkyrian\Transformers\Transformers;
/**
* The base class for token decoders.
@@ -35,9 +36,11 @@ public function __construct(protected array $config)
*/
public static function fromConfig(?array $config): ?self
{
+ $logger = Transformers::getLogger();
if ($config === null) {
return null;
}
+ $logger->debug('Creating decoder', ['type' => $config['type'] ?? 'unknown']);
return match ($config['type']) {
'WordPiece' => new WordPieceDecoder($config),
@@ -83,6 +86,4 @@ public function __invoke(array $tokens): string
{
return $this->decode($tokens);
}
-
-
-}
\ No newline at end of file
+}
diff --git a/src/Exceptions/ModelExecutionException.php b/src/Exceptions/ModelExecutionException.php
index bba30bc..5d5ae96 100644
--- a/src/Exceptions/ModelExecutionException.php
+++ b/src/Exceptions/ModelExecutionException.php
@@ -7,8 +7,8 @@
class ModelExecutionException extends \Exception implements TransformersException
{
-public static function make(string $message): self
+ public static function make(string $message, ?\Throwable $previous = null): self
{
- return new self("An error occurred during model execution: $message");
+ return new self("An error occurred during model execution: $message", 0, $previous);
}
-}
\ No newline at end of file
+}
diff --git a/src/FFI/Libvips.php b/src/FFI/Libvips.php
new file mode 100644
index 0000000..d315893
--- /dev/null
+++ b/src/FFI/Libvips.php
@@ -0,0 +1,35 @@
+getLibDirectory());
+ }
+
+ public static function setup()
+ {
+ $libvips = new Libvips();
+ }
+
+ protected function getHeaderName(): string
+ {
+ return 'vips';
+ }
+
+ protected function getLibraryName(): string
+ {
+ return 'libvips';
+ }
+
+ protected function getLibraryVersion(): string
+ {
+ return '42';
+ }
+}
diff --git a/src/FFI/NativeLibrary.php b/src/FFI/NativeLibrary.php
new file mode 100644
index 0000000..dedeb74
--- /dev/null
+++ b/src/FFI/NativeLibrary.php
@@ -0,0 +1,249 @@
+ [
+ 'directory' => 'linux-x86_64',
+ 'libraryTemplate' => 'lib{name}.so.{version}'
+ ],
+ 'linux-arm64' => [
+ 'directory' => 'linux-arm64',
+ 'libraryTemplate' => 'lib{name}.so.{version}'
+ ],
+ 'darwin-x86_64' => [
+ 'directory' => 'macosx-x86_64',
+ 'libraryTemplate' => 'lib{name}.{version}.dylib'
+ ],
+ 'darwin-arm64' => [
+ 'directory' => 'macosx-arm64',
+ 'libraryTemplate' => 'lib{name}.{version}.dylib'
+ ],
+ 'windows-x86_64' => [
+ 'directory' => 'windows-x86_64',
+ 'libraryTemplate' => '{name}-{version}.dll'
+ ],
+ ];
+
+ /**
+ * The FFI instance for this library
+ */
+ protected FFI $ffi;
+
+ /**
+ * Windows-specific kernel32 FFI instance (shared across all instances)
+ */
+ private static ?FFI $kernel32 = null;
+
+ protected array $platformConfig;
+
+ public function __construct(protected bool $loadLibrary = true)
+ {
+ $this->platformConfig = Platform::findBestMatch(self::PLATFORMS);
+
+ if ($this->loadLibrary) {
+ $this->loadLibrary();
+ $this->configurePlatformSpecifics();
+ }
+ }
+
+ public function __destruct()
+ {
+ $this->resetPlatformSpecifics();
+ }
+
+ public function getFfi(): FFI
+ {
+ return $this->ffi;
+ }
+
+ /**
+ * Get the header file name for this library
+ *
+ * @return string The header file name
+ */
+ abstract protected function getHeaderName(): string;
+
+ /**
+ * Get the library file name (without extension or version) for this library
+ *
+ * @return string The base library file name
+ */
+ abstract protected function getLibraryName(): string;
+
+ /**
+ * Get the library version string for this library
+ *
+ * @return string The library version
+ */
+ abstract protected function getLibraryVersion(): string;
+
+ public function getHeaderPath(): string
+ {
+ return joinPaths($this->getIncludeDirectory(), "{$this->getHeaderName()}.h");
+ }
+
+ public function getLibraryPath(): string
+ {
+ $template = $this->platformConfig['libraryTemplate'];
+ $name = $this->getLibraryName();
+ $version = $this->getLibraryVersion();
+
+ // Check if the template expects a 'lib' prefix and the name already has it
+ if (str_contains($template, 'lib{name}') && str_starts_with($name, 'lib')) {
+ // Remove the 'lib' prefix from the template placeholder before substitution
+ $template = str_replace('lib{name}', '{name}', $template);
+ }
+
+ $filename = str_replace(['{name}', '{version}'], [$name, $version], $template);
+
+ return joinPaths($this->getLibDirectory(), $filename);
+ }
+
+ public function getPlatformPath(): string
+ {
+ return joinPaths(dirname(__DIR__, 2), 'shared', $this->platformConfig['directory']);
+ }
+
+ public function getIncludeDirectory(): string
+ {
+ return joinPaths($this->getPlatformPath(), 'include');
+ }
+
+ public function getLibDirectory(): string
+ {
+ return joinPaths($this->getPlatformPath(), 'lib');
+ }
+
+ protected function loadLibrary() :void
+ {
+ if (!$this->platformConfig) {
+ throw new RuntimeException("No matching platform configuration found");
+ }
+
+ $headerPath = $this->getHeaderPath();
+ $libraryPath = $this->getLibraryPath();
+
+ $this->ffi = FFI::cdef(file_get_contents($headerPath), $libraryPath);
+ }
+
+ /**
+ * Creates a new instance of the specified type.
+ *
+ * @param string $type The type of the instance to create.
+ * @param bool $owned Whether the instance should be owned. Default is true.
+ * @param bool $persistent Whether the instance should be persistent. Default is false.
+ *
+ * @return CData|null The created instance, or null if the creation failed.
+ * @throws Exception
+ */
+ public function new(string $type, bool $owned = true, bool $persistent = false): ?CData
+ {
+ return $this->ffi->new($type, $owned, $persistent);
+ }
+
+ /**
+ * Casts a pointer to a different type.
+ *
+ * @param CType|string $type The type to cast to.
+ * @param CData|int|float|bool|null $ptr The pointer to cast.
+ *
+ * @return ?CData The cast pointer, or null if the cast failed.
+ * @throws Exception
+ */
+ public function cast(CType|string $type, CData|int|float|bool|null $ptr): ?CData
+ {
+ return $this->ffi->cast($type, $ptr);
+ }
+
+ /**
+ * Retrieves the value of the enum constant with the given name.
+ *
+ * @param string $name The name of the enum constant.
+ *
+ * @return mixed The value of the enum constant.
+ * @throws Exception
+ */
+ public function enum(string $name): mixed
+ {
+ return $this->ffi->{$name};
+ }
+
+ /**
+ * Configure platform-specific settings
+ *
+ * @return void
+ */
+ protected function configurePlatformSpecifics(): void
+ {
+ if (Platform::isWindows()) {
+ $this->configureWindowsDllDirectory();
+ }
+ }
+
+ /**
+ * Reset platform-specific settings
+ *
+ * @return void
+ */
+ protected function resetPlatformSpecifics(): void
+ {
+ if (Platform::isWindows()) {
+ $this->resetWindowsDllDirectory();
+ }
+ }
+
+ /**
+ * Configure Windows DLL directory
+ *
+ * @return void
+ */
+ protected function configureWindowsDllDirectory(): void
+ {
+ $platformConfig = Platform::findBestMatch(self::PLATFORMS);
+ $libraryDir = $this->getLibDirectory($platformConfig['directory']);
+
+ self::$kernel32 ??= FFI::cdef("
+ int SetDllDirectoryA(const char* lpPathName);
+ int SetDefaultDllDirectories(unsigned long DirectoryFlags);
+ ", 'kernel32.dll');
+
+ // Access the method through the FFI object
+ self::$kernel32->{'SetDllDirectoryA'}($libraryDir);
+ }
+
+ /**
+ * Reset Windows DLL directory
+ *
+ * @return void
+ */
+ protected function resetWindowsDllDirectory(): void
+ {
+ if (self::$kernel32 !== null) {
+ // Access the method through the FFI object
+ self::$kernel32->{'SetDllDirectoryA'}(null);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/FFI/OnnxRuntime.php b/src/FFI/OnnxRuntime.php
index 06c2802..388972e 100644
--- a/src/FFI/OnnxRuntime.php
+++ b/src/FFI/OnnxRuntime.php
@@ -4,79 +4,51 @@
namespace Codewithkyrian\Transformers\FFI;
-use Codewithkyrian\TransformersLibsLoader\Library;
-use Exception;
use FFI;
use FFI\CData;
-use FFI\CType;
use RuntimeException;
-use function Codewithkyrian\Transformers\Utils\basePath;
-class OnnxRuntime
+class OnnxRuntime extends NativeLibrary
{
- protected static FFI $ffi;
- protected static mixed $api;
+ protected mixed $api;
-
- /**
- * Returns an instance of the FFI class after checking if it has already been instantiated.
- * If not, it creates a new instance by defining the header contents and library path.
- *
- * @return FFI The FFI instance.
- * @throws Exception
- */
- protected static function ffi(): FFI
+ public function __construct()
{
- if (!isset(self::$ffi)) {
- self::$ffi = FFI::cdef(
- file_get_contents(Library::OnnxRuntime->header(basePath('includes'))),
- Library::OnnxRuntime->library(basePath('libs'))
- );
- }
+ parent::__construct();
+ $this->initApi();
+ }
+
- return self::$ffi;
+ protected function getHeaderName(): string
+ {
+ return 'onnxruntime';
}
- /**
- * Creates a new instance of the specified type.
- *
- * @param string $type The type of the instance to create.
- * @param bool $owned Whether the instance should be owned. Default is true.
- * @param bool $persistent Whether the instance should be persistent. Default is false.
- *
- * @return CData|null The created instance, or null if the creation failed.
- * @throws Exception
- */
- public static function new(string $type, bool $owned = true, bool $persistent = false): ?CData
+
+ protected function getLibraryName(): string
{
- return self::ffi()->new($type, $owned, $persistent);
+ return 'onnxruntime';
}
/**
- * Casts a pointer to a different type.
- *
- * @param CType|string $type The type to cast to.
- * @param CData|int|float|bool|null $ptr The pointer to cast.
- *
- * @return ?CData The cast pointer, or null if the cast failed.
- * @throws Exception
+ * Get the library version string for this library
+ *
+ * @return string The library version
*/
- public static function cast(CType|string$type, CData|int|float|bool|null$ptr): ?CData
+ protected function getLibraryVersion(): string
{
- return self::ffi()->cast($type, $ptr);
+ return '1.21.0';
}
/**
- * Retrieves the value of the enum constant with the given name.
- *
- * @param string $name The name of the enum constant.
- *
- * @return mixed The value of the enum constant.
- * @throws Exception
+ * Initialize the API
+ *
+ * @throws RuntimeException If the API cannot be initialized
*/
- public static function enum(string $name): mixed
+ protected function initApi(): void
{
- return self::ffi()->{$name};
+ $apiBase = $this->ffi->{'OrtGetApiBase'}()[0];
+ $this->api = ($apiBase->GetApi)(11)[0];
}
/**
@@ -84,280 +56,272 @@ public static function enum(string $name): mixed
*
* @return string The version of the library.
*/
- public static function version(): string
- {
- return (self::ffi()->OrtGetApiBase()[0]->GetVersionString)();
- }
-
- public static function api(): mixed
+ public function version(): string
{
- if (!isset(self::$api)) {
- self::$api = (self::ffi()->OrtGetApiBase()[0]->GetApi)(11)[0];
- }
-
- return self::$api;
+ $apiBase = $this->ffi->{'OrtGetApiBase'}()[0];
+ return ($apiBase->GetVersionString)();
}
- private static function checkStatus($status): void
+ private function checkStatus($status): void
{
if (!is_null($status)) {
- $message = (self::api()->GetErrorMessage)($status);
- (self::api()->ReleaseStatus)($status);
+ $message = (($this->api)->GetErrorMessage)($status);
+ (($this->api)->ReleaseStatus)($status);
throw new RuntimeException($message);
}
}
- public static function CreateSession($env, $modelPath, $options): CData
+ public function CreateSession($env, $modelPath, $options): CData
{
- $session = self::new('OrtSession*');
+ $session = $this->new('OrtSession*');
- self::checkStatus((self::api()->CreateSession)($env, $modelPath, $options, FFI::addr($session)));
+ $this->checkStatus((($this->api)->CreateSession)($env, $modelPath, $options, FFI::addr($session)));
return $session;
}
- public static function CreateSessionFromArray($env, $modelData, $modelDataLength, $options): CData
+ public function CreateSessionFromArray($env, $modelData, $modelDataLength, $options): CData
{
- $session = self::new('OrtSession*');
+ $session = $this->new('OrtSession*');
- self::checkStatus((self::api()->CreateSessionFromArray)($env, $modelData, $modelDataLength, $options, FFI::addr($session)));
+ $this->checkStatus((($this->api)->CreateSessionFromArray)($env, $modelData, $modelDataLength, $options, FFI::addr($session)));
return $session;
}
- public static function ReleaseSession($session): void
+ public function ReleaseSession($session): void
{
- (self::api()->ReleaseSession)($session);
+ (($this->api)->ReleaseSession)($session);
}
- public static function CreateSessionOptions(): CData
+ public function CreateSessionOptions(): CData
{
- $sessionOptions = self::new('OrtSessionOptions*');
+ $sessionOptions = $this->new('OrtSessionOptions*');
- self::checkStatus((self::api()->CreateSessionOptions)(FFI::addr($sessionOptions)));
+ $this->checkStatus((($this->api)->CreateSessionOptions)(FFI::addr($sessionOptions)));
return $sessionOptions;
}
- public static function EnableCpuMemArena($sessionOptions): void
+ public function EnableCpuMemArena($sessionOptions): void
{
- self::checkStatus((self::api()->EnableCpuMemArena)($sessionOptions));
+ $this->checkStatus((($this->api)->EnableCpuMemArena)($sessionOptions));
}
- public static function DisableCpuMemArena($sessionOptions): void
+ public function DisableCpuMemArena($sessionOptions): void
{
- self::checkStatus((self::api()->DisableCpuMemArena)($sessionOptions));
+ $this->checkStatus((($this->api)->DisableCpuMemArena)($sessionOptions));
}
- public static function EnableMemPattern($sessionOptions): void
+ public function EnableMemPattern($sessionOptions): void
{
- self::checkStatus((self::api()->EnableMemPattern)($sessionOptions));
+ $this->checkStatus((($this->api)->EnableMemPattern)($sessionOptions));
}
- public static function DisableMemPattern($sessionOptions): void
+ public function DisableMemPattern($sessionOptions): void
{
- self::checkStatus((self::api()->DisableMemPattern)($sessionOptions));
+ $this->checkStatus((($this->api)->DisableMemPattern)($sessionOptions));
}
- public static function EnableProfiling($sessionOptions, $profileFilePrefix): void
+ public function EnableProfiling($sessionOptions, $profileFilePrefix): void
{
- self::checkStatus((self::api()->EnableProfiling)($sessionOptions, $profileFilePrefix));
+ $this->checkStatus((($this->api)->EnableProfiling)($sessionOptions, $profileFilePrefix));
}
- public static function DisableProfiling($sessionOptions): void
+ public function DisableProfiling($sessionOptions): void
{
- self::checkStatus((self::api()->DisableProfiling)($sessionOptions));
+ $this->checkStatus((($this->api)->DisableProfiling)($sessionOptions));
}
- public static function SetSessionExecutionMode($sessionOptions, $executionMode): void
+ public function SetSessionExecutionMode($sessionOptions, $executionMode): void
{
- self::checkStatus((self::api()->SetSessionExecutionMode)($sessionOptions, $executionMode));
+ $this->checkStatus((($this->api)->SetSessionExecutionMode)($sessionOptions, $executionMode));
}
- public static function AddFreeDimensionOverride($sessionOptions, $dimDenotation, int $dimValue): void
+ public function AddFreeDimensionOverride($sessionOptions, $dimDenotation, int $dimValue): void
{
- self::checkStatus((self::api()->AddFreeDimensionOverride)($sessionOptions, $dimDenotation, $dimValue));
+ $this->checkStatus((($this->api)->AddFreeDimensionOverride)($sessionOptions, $dimDenotation, $dimValue));
}
- public static function AddFreeDimensionOverrideByName($sessionOptions, $dimName, int $dimValue): void
+ public function AddFreeDimensionOverrideByName($sessionOptions, $dimName, int $dimValue): void
{
- self::checkStatus((self::api()->AddFreeDimensionOverrideByName)($sessionOptions, $dimName, $dimValue));
+ $this->checkStatus((($this->api)->AddFreeDimensionOverrideByName)($sessionOptions, $dimName, $dimValue));
}
- public static function SetSessionGraphOptimizationLevel($sessionOptions, $optimizationLevel): void
+ public function SetSessionGraphOptimizationLevel($sessionOptions, $optimizationLevel): void
{
- self::checkStatus((self::api()->SetSessionGraphOptimizationLevel)($sessionOptions, $optimizationLevel));
+ $this->checkStatus((($this->api)->SetSessionGraphOptimizationLevel)($sessionOptions, $optimizationLevel));
}
- public static function SetInterOpNumThreads($sessionOptions, $optimizationLevel): void
+ public function SetInterOpNumThreads($sessionOptions, $optimizationLevel): void
{
- self::checkStatus((self::api()->SetInterOpNumThreads)($sessionOptions, $optimizationLevel));
+ $this->checkStatus((($this->api)->SetInterOpNumThreads)($sessionOptions, $optimizationLevel));
}
- public static function SetIntraOpNumThreads($sessionOptions, $optimizationLevel): void
+ public function SetIntraOpNumThreads($sessionOptions, $optimizationLevel): void
{
- self::checkStatus((self::api()->SetIntraOpNumThreads)($sessionOptions, $optimizationLevel));
+ $this->checkStatus((($this->api)->SetIntraOpNumThreads)($sessionOptions, $optimizationLevel));
}
- public static function SetSessionLogSeverityLevel($sessionOptions, $optimizationLevel): void
+ public function SetSessionLogSeverityLevel($sessionOptions, $optimizationLevel): void
{
- self::checkStatus((self::api()->SetSessionLogSeverityLevel)($sessionOptions, $optimizationLevel));
+ $this->checkStatus((($this->api)->SetSessionLogSeverityLevel)($sessionOptions, $optimizationLevel));
}
- public static function SetSessionLogVerbosityLevel($sessionOptions, $optimizationLevel): void
+ public function SetSessionLogVerbosityLevel($sessionOptions, $optimizationLevel): void
{
- self::checkStatus((self::api()->SetSessionLogVerbosityLevel)($sessionOptions, $optimizationLevel));
+ $this->checkStatus((($this->api)->SetSessionLogVerbosityLevel)($sessionOptions, $optimizationLevel));
}
- public static function SetSessionLogId($sessionOptions, $optimizationLevel): void
+ public function SetSessionLogId($sessionOptions, $optimizationLevel): void
{
- self::checkStatus((self::api()->SetSessionLogId)($sessionOptions, $optimizationLevel));
+ $this->checkStatus((($this->api)->SetSessionLogId)($sessionOptions, $optimizationLevel));
}
- public static function SetOptimizedModelFilePath($sessionOptions, $optimizationLevel): void
+ public function SetOptimizedModelFilePath($sessionOptions, $optimizationLevel): void
{
- self::checkStatus((self::api()->SetOptimizedModelFilePath)($sessionOptions, $optimizationLevel));
+ $this->checkStatus((($this->api)->SetOptimizedModelFilePath)($sessionOptions, $optimizationLevel));
}
- public static function AddSessionConfigEntry($sessionOptions, $configKey, $configValue): void
+ public function AddSessionConfigEntry($sessionOptions, $configKey, $configValue): void
{
- self::checkStatus((self::api()->AddSessionConfigEntry)($sessionOptions, $configKey, $configValue));
+ $this->checkStatus((($this->api)->AddSessionConfigEntry)($sessionOptions, $configKey, $configValue));
}
- public static function CreateCUDAProviderOptions(): CData
+ public function CreateCUDAProviderOptions(): CData
{
- $cudaOptions = self::new('OrtCUDAProviderOptionsV2*');
+ $cudaOptions = $this->new('OrtCUDAProviderOptionsV2*');
- self::checkStatus((self::api()->CreateCUDAProviderOptions)(FFI::addr($cudaOptions)));
+ $this->checkStatus((($this->api)->CreateCUDAProviderOptions)(FFI::addr($cudaOptions)));
return $cudaOptions;
}
- public static function SessionOptionsAppendExecutionProvider_CUDA_V2($sessionOptions, $cudaOptions): void
+ public function SessionOptionsAppendExecutionProvider_CUDA_V2($sessionOptions, $cudaOptions): void
{
- self::checkStatus((self::api()->SessionOptionsAppendExecutionProvider_CUDA_V2)($sessionOptions, $cudaOptions));
+ $this->checkStatus((($this->api)->SessionOptionsAppendExecutionProvider_CUDA_V2)($sessionOptions, $cudaOptions));
}
- public static function ReleaseCUDAProviderOptions($cudaOptions): void
+ public function ReleaseCUDAProviderOptions($cudaOptions): void
{
- (self::api()->ReleaseCUDAProviderOptions)($cudaOptions);
+ (($this->api)->ReleaseCUDAProviderOptions)($cudaOptions);
}
- public static function OrtSessionOptionsAppendExecutionProvider_CoreML($sessionOptions, $coreMlFlags): void
+ public function OrtSessionOptionsAppendExecutionProvider_CoreML($sessionOptions, $coreMlFlags): void
{
- self::checkStatus((self::api()->OrtSessionOptionsAppendExecutionProvider_CoreML)($sessionOptions, $coreMlFlags));
+ $this->checkStatus((($this->api)->OrtSessionOptionsAppendExecutionProvider_CoreML)($sessionOptions, $coreMlFlags));
}
- public static function ReleaseSessionOptions($sessionOptions): void
+ public function ReleaseSessionOptions($sessionOptions): void
{
- (self::api()->ReleaseSessionOptions)($sessionOptions);
+ (($this->api)->ReleaseSessionOptions)($sessionOptions);
}
- public static function SessionGetInputCount($session): int
+ public function SessionGetInputCount($session): int
{
- $numInputNodes = self::new('size_t');
+ $numInputNodes = $this->new('size_t');
- self::checkStatus((self::api()->SessionGetInputCount)($session, FFI::addr($numInputNodes)));
+ $this->checkStatus((($this->api)->SessionGetInputCount)($session, FFI::addr($numInputNodes)));
return $numInputNodes->cdata;
}
- public static function SessionGetInputName($session, int $index, $allocator): string
+ public function SessionGetInputName($session, int $index, $allocator): string
{
- $namePtr = self::new('char*');
+ $namePtr = $this->new('char*');
- self::checkStatus((self::api()->SessionGetInputName)($session, $index, $allocator, FFI::addr($namePtr)));
+ $this->checkStatus((($this->api)->SessionGetInputName)($session, $index, $allocator, FFI::addr($namePtr)));
$name = FFI::string($namePtr);
- self::AllocatorFree($allocator, $namePtr);
+ $this->AllocatorFree($allocator, $namePtr);
return $name;
}
- public static function SessionGetInputTypeInfo($session, int $index): CData
+ public function SessionGetInputTypeInfo($session, int $index): CData
{
- $typeInfo = self::new('OrtTypeInfo*');
+ $typeInfo = $this->new('OrtTypeInfo*');
- self::checkStatus((self::api()->SessionGetInputTypeInfo)($session, $index, FFI::addr($typeInfo)));
+ $this->checkStatus((($this->api)->SessionGetInputTypeInfo)($session, $index, FFI::addr($typeInfo)));
return $typeInfo;
}
- public static function SessionGetOutputCount($session): int
+ public function SessionGetOutputCount($session): int
{
- $numOutputNodes = self::new('size_t');
+ $numOutputNodes = $this->new('size_t');
- self::checkStatus((self::api()->SessionGetOutputCount)($session, FFI::addr($numOutputNodes)));
+ $this->checkStatus((($this->api)->SessionGetOutputCount)($session, FFI::addr($numOutputNodes)));
return $numOutputNodes->cdata;
}
- public static function SessionGetOutputName($session, int $index, $allocator): string
+ public function SessionGetOutputName($session, int $index, $allocator): string
{
- $namePtr = self::new('char*');
+ $namePtr = $this->new('char*');
- self::checkStatus((self::api()->SessionGetOutputName)($session, $index, $allocator, FFI::addr($namePtr)));
+ $this->checkStatus((($this->api)->SessionGetOutputName)($session, $index, $allocator, FFI::addr($namePtr)));
$name = FFI::string($namePtr);
- self::AllocatorFree($allocator, $namePtr);
+ $this->AllocatorFree($allocator, $namePtr);
return $name;
}
- public static function SessionGetOutputTypeInfo($session, int $index): CData
+ public function SessionGetOutputTypeInfo($session, int $index): CData
{
- $typeInfo = self::new('OrtTypeInfo*');
+ $typeInfo = $this->new('OrtTypeInfo*');
- self::checkStatus((self::api()->SessionGetOutputTypeInfo)($session, $index, FFI::addr($typeInfo)));
+ $this->checkStatus((($this->api)->SessionGetOutputTypeInfo)($session, $index, FFI::addr($typeInfo)));
return $typeInfo;
}
- public static function GetAvailableProviders(): array
+ public function GetAvailableProviders(): array
{
- $outPtr = self::new('char**');
- $lengthPtr = self::new('int');
+ $outPtr = $this->new('char**');
+ $lengthPtr = $this->new('int');
- self::checkStatus((self::api()->GetAvailableProviders)(FFI::addr($outPtr), FFI::addr($lengthPtr)));
+ $this->checkStatus((($this->api)->GetAvailableProviders)(FFI::addr($outPtr), FFI::addr($lengthPtr)));
return [$outPtr, $lengthPtr->cdata];
}
- public static function ReleaseAvailableProviders($ptr, int $length): void
+ public function ReleaseAvailableProviders($ptr, int $length): void
{
- (self::api()->ReleaseAvailableProviders)($ptr, $length);
+ (($this->api)->ReleaseAvailableProviders)($ptr, $length);
}
- public static function SessionEndProfiling($session, $allocator): string
+ public function SessionEndProfiling($session, $allocator): string
{
- $resultPtr = self::new('char*');
+ $resultPtr = $this->new('char*');
- self::checkStatus((self::api()->SessionEndProfiling)($session, $allocator, FFI::addr($resultPtr)));
+ $this->checkStatus((($this->api)->SessionEndProfiling)($session, $allocator, FFI::addr($resultPtr)));
$result = FFI::string($resultPtr);
- self::AllocatorFree($allocator, $resultPtr);
+ $this->AllocatorFree($allocator, $resultPtr);
return $result;
}
- public static function SessionGetModelMetadata($session): CData
+ public function SessionGetModelMetadata($session): CData
{
- $metadata = self::new('OrtModelMetadata*');
+ $metadata = $this->new('OrtModelMetadata*');
- self::checkStatus((self::api()->SessionGetModelMetadata)($session, FFI::addr($metadata)));
+ $this->checkStatus((($this->api)->SessionGetModelMetadata)($session, FFI::addr($metadata)));
return $metadata;
}
- public static function ModelMetadataGetCustomMetadataMapKeys($metadata, $allocator): array
+ public function ModelMetadataGetCustomMetadataMapKeys($metadata, $allocator): array
{
- $keyPtrs = self::new('char**');
- $numKeys = self::new('int64_t');
+ $keyPtrs = $this->new('char**');
+ $numKeys = $this->new('int64_t');
- self::checkStatus((self::api()->ModelMetadataGetCustomMetadataMapKeys)($metadata, $allocator, FFI::addr($keyPtrs), FFI::addr($numKeys)));
+ $this->checkStatus((($this->api)->ModelMetadataGetCustomMetadataMapKeys)($metadata, $allocator, FFI::addr($keyPtrs), FFI::addr($numKeys)));
$keys = [];
@@ -365,395 +329,399 @@ public static function ModelMetadataGetCustomMetadataMapKeys($metadata, $allocat
$keys[] = FFI::string($keyPtrs[$i]);
}
- self::AllocatorFree($allocator, $keyPtrs);
+ $this->AllocatorFree($allocator, $keyPtrs);
return [$keys, $numKeys->cdata];
}
- public static function ModelMetadataLookupCustomMetadataMap($metadata, $allocator, $key): string
+ public function ModelMetadataLookupCustomMetadataMap($metadata, $allocator, $key): string
{
- $valuePtr = self::new('char*');
+ $valuePtr = $this->new('char*');
- self::checkStatus((self::api()->ModelMetadataLookupCustomMetadataMap)($metadata, $allocator, $key, FFI::addr($valuePtr)));
+ $this->checkStatus((($this->api)->ModelMetadataLookupCustomMetadataMap)($metadata, $allocator, $key, FFI::addr($valuePtr)));
$value = FFI::string($valuePtr);
- self::AllocatorFree($allocator, $valuePtr);
+ $this->AllocatorFree($allocator, $valuePtr);
return $value;
}
- public static function ModelMetadataGetDescription($metadata, $allocator): string
+ public function ModelMetadataGetDescription($metadata, $allocator): string
{
- $descriptionPtr = self::new('char*');
+ $descriptionPtr = $this->new('char*');
- self::checkStatus((self::api()->ModelMetadataGetDescription)($metadata, $allocator, FFI::addr($descriptionPtr)));
+ $this->checkStatus((($this->api)->ModelMetadataGetDescription)($metadata, $allocator, FFI::addr($descriptionPtr)));
$description = FFI::string($descriptionPtr);
- self::AllocatorFree($allocator, $descriptionPtr);
+ $this->AllocatorFree($allocator, $descriptionPtr);
return $description;
}
- public static function ModelMetadataGetDomain($metadata, $allocator): string
+ public function ModelMetadataGetDomain($metadata, $allocator): string
{
- $domainPtr = self::new('char*');
+ $domainPtr = $this->new('char*');
- self::checkStatus((self::api()->ModelMetadataGetDomain)($metadata, $allocator, FFI::addr($domainPtr)));
+ $this->checkStatus((($this->api)->ModelMetadataGetDomain)($metadata, $allocator, FFI::addr($domainPtr)));
$domain = FFI::string($domainPtr);
- self::AllocatorFree($allocator, $domainPtr);
+ $this->AllocatorFree($allocator, $domainPtr);
return $domain;
}
- public static function ModelMetadataGetGraphName($metadata, $allocator): string
+ public function ModelMetadataGetGraphName($metadata, $allocator): string
{
- $graphNamePtr = self::new('char*');
+ $graphNamePtr = $this->new('char*');
- self::checkStatus((self::api()->ModelMetadataGetGraphName)($metadata, $allocator, FFI::addr($graphNamePtr)));
+ $this->checkStatus((($this->api)->ModelMetadataGetGraphName)($metadata, $allocator, FFI::addr($graphNamePtr)));
$graphName = FFI::string($graphNamePtr);
- self::AllocatorFree($allocator, $graphNamePtr);
+ $this->AllocatorFree($allocator, $graphNamePtr);
return $graphName;
}
- public static function ModelMetadataGetGraphDescription($metadata, $allocator): string
+ public function ModelMetadataGetGraphDescription($metadata, $allocator): string
{
- $graphDescriptionPtr = self::new('char*');
+ $graphDescriptionPtr = $this->new('char*');
- self::checkStatus((self::api()->ModelMetadataGetGraphDescription)($metadata, $allocator, FFI::addr($graphDescriptionPtr)));
+ $this->checkStatus((($this->api)->ModelMetadataGetGraphDescription)($metadata, $allocator, FFI::addr($graphDescriptionPtr)));
$graphDescription = FFI::string($graphDescriptionPtr);
- self::AllocatorFree($allocator, $graphDescriptionPtr);
+ $this->AllocatorFree($allocator, $graphDescriptionPtr);
return $graphDescription;
}
- public static function ModelMetadataGetProducerName($metadata, $allocator): string
+ public function ModelMetadataGetProducerName($metadata, $allocator): string
{
- $producerNamePtr = self::new('char*');
+ $producerNamePtr = $this->new('char*');
- self::checkStatus((self::api()->ModelMetadataGetProducerName)($metadata, $allocator, FFI::addr($producerNamePtr)));
+ $this->checkStatus((($this->api)->ModelMetadataGetProducerName)($metadata, $allocator, FFI::addr($producerNamePtr)));
$producerName = FFI::string($producerNamePtr);
- self::AllocatorFree($allocator, $producerNamePtr);
+ $this->AllocatorFree($allocator, $producerNamePtr);
return $producerName;
}
- public static function ModelMetadataGetVersion($metadata): int
+ public function ModelMetadataGetVersion($metadata): int
{
- $version = self::new('int64_t');
+ $version = $this->new('int64_t');
- self::checkStatus((self::api()->ModelMetadataGetVersion)($metadata, FFI::addr($version)));
+ $this->checkStatus((($this->api)->ModelMetadataGetVersion)($metadata, FFI::addr($version)));
return $version->cdata;
}
- public static function ReleaseModelMetadata($metadata): void
+ public function ReleaseModelMetadata($metadata): void
{
- (self::api()->ReleaseModelMetadata)($metadata);
+ (($this->api)->ReleaseModelMetadata)($metadata);
}
- public static function CreateRunOptions(): CData
+ public function CreateRunOptions(): CData
{
- $runOptions = self::new('OrtRunOptions*');
+ $runOptions = $this->new('OrtRunOptions*');
- self::checkStatus((self::api()->CreateRunOptions)(FFI::addr($runOptions)));
+ $this->checkStatus((($this->api)->CreateRunOptions)(FFI::addr($runOptions)));
return $runOptions;
}
- public static function RunOptionsSetRunLogSeverityLevel($runOptions, int $logSeverityLevel): void
+ public function RunOptionsSetRunLogSeverityLevel($runOptions, int $logSeverityLevel): void
{
- self::checkStatus((self::api()->RunOptionsSetRunLogSeverityLevel)($runOptions, $logSeverityLevel));
+ $this->checkStatus((($this->api)->RunOptionsSetRunLogSeverityLevel)($runOptions, $logSeverityLevel));
}
- public static function RunOptionsSetRunLogVerbosityLevel($runOptions, int $logVerbosityLevel): void
+ public function RunOptionsSetRunLogVerbosityLevel($runOptions, int $logVerbosityLevel): void
{
- self::checkStatus((self::api()->RunOptionsSetRunLogVerbosityLevel)($runOptions, $logVerbosityLevel));
+ $this->checkStatus((($this->api)->RunOptionsSetRunLogVerbosityLevel)($runOptions, $logVerbosityLevel));
}
- public static function RunOptionsSetRunTag($runOptions, string $logId): void
+ public function RunOptionsSetRunTag($runOptions, string $logId): void
{
- self::checkStatus((self::api()->RunOptionsSetRunTag)($runOptions, $logId));
+ $this->checkStatus((($this->api)->RunOptionsSetRunTag)($runOptions, $logId));
}
- public static function RunOptionsSetTerminate($runOptions): void
+ public function RunOptionsSetTerminate($runOptions): void
{
- self::checkStatus((self::api()->RunOptionsSetTerminate)($runOptions));
+ $this->checkStatus((($this->api)->RunOptionsSetTerminate)($runOptions));
}
- public static function RunOptionsUnsetTerminate($runOptions): void
+ public function RunOptionsUnsetTerminate($runOptions): void
{
- self::checkStatus((self::api()->RunOptionsUnsetTerminate)($runOptions));
+ $this->checkStatus((($this->api)->RunOptionsUnsetTerminate)($runOptions));
}
- public static function Run($session, $runOptions, $inputNames, $inputs, int $inputLength, $outputNames, int $outputLength): CData
+ public function Run($session, $runOptions, $inputNames, $inputs, int $inputLength, $outputNames, int $outputLength): CData
{
- $outputTensor = self::new("OrtValue*[$outputLength]");
+ $outputTensor = $this->new("OrtValue*[$outputLength]");
- self::checkStatus((self::api()->Run)($session, $runOptions, $inputNames, $inputs, $inputLength, $outputNames, $outputLength, $outputTensor));
+ $this->checkStatus((($this->api)->Run)($session, $runOptions, $inputNames, $inputs, $inputLength, $outputNames, $outputLength, $outputTensor));
return $outputTensor;
}
- public static function ReleaseRunOptions($runOptions): void
+ public function ReleaseRunOptions($runOptions): void
{
- (self::api()->ReleaseRunOptions)($runOptions);
+ (($this->api)->ReleaseRunOptions)($runOptions);
}
- public static function GetTensorElementType($info): ?CData
+ public function GetTensorElementType($info): ?CData
{
- $type = self::new('ONNXTensorElementDataType');
+ $type = $this->new('ONNXTensorElementDataType');
- self::checkStatus((self::api()->GetTensorElementType)($info, FFI::addr($type)));
+ $this->checkStatus((($this->api)->GetTensorElementType)($info, FFI::addr($type)));
return $type;
}
- public static function GetDimensionsCount($info): int
+ public function GetDimensionsCount($info): int
{
- $numDims = self::new('size_t');
- self::checkStatus((self::api()->GetDimensionsCount)($info, FFI::addr($numDims)));
+ $numDims = $this->new('size_t');
+ $this->checkStatus((($this->api)->GetDimensionsCount)($info, FFI::addr($numDims)));
return $numDims->cdata;
}
- public static function GetDimensions($info, int $numDims): array
+ public function GetDimensions($info, int $numDims): array
{
- $nodeDims = self::new("int64_t[$numDims]");
+ $nodeDims = $this->new("int64_t[$numDims]");
- self::checkStatus((self::api()->GetDimensions)($info, $nodeDims, $numDims));
+ $this->checkStatus((($this->api)->GetDimensions)($info, $nodeDims, $numDims));
$dims = [];
- $n = count($nodeDims);
- for ($i = 0; $i < $n; $i++) {
+ for ($i = 0; $i < $numDims; $i++) {
$dims[] = $nodeDims[$i];
}
return $dims;
}
- public static function GetSymbolicDimensions($info, int $numDims): CData
+ public function GetSymbolicDimensions($info, int $numDims): CData
{
- $symbolicDims = self::new("char*[$numDims]");
+ $symbolicDims = $this->new("char*[$numDims]");
- self::checkStatus((self::api()->GetSymbolicDimensions)($info, $symbolicDims, $numDims));
+ $this->checkStatus((($this->api)->GetSymbolicDimensions)($info, $symbolicDims, $numDims));
return $symbolicDims;
}
- public static function GetOnnxTypeFromTypeInfo($typeInfo): CData
+ public function GetOnnxTypeFromTypeInfo($typeInfo): CData
{
- $onnxType = self::new('ONNXType');
+ $onnxType = $this->new('ONNXType');
- self::checkStatus((self::api()->GetOnnxTypeFromTypeInfo)($typeInfo, FFI::addr($onnxType)));
+ $this->checkStatus((($this->api)->GetOnnxTypeFromTypeInfo)($typeInfo, FFI::addr($onnxType)));
return $onnxType;
}
- public static function CastTypeInfoToTensorInfo($typeInfo): CData
+ public function CastTypeInfoToTensorInfo($typeInfo): CData
{
- $tensorInfo = self::new('OrtTensorTypeAndShapeInfo*');
+ $tensorInfo = $this->new('OrtTensorTypeAndShapeInfo*');
- self::checkStatus((self::api()->CastTypeInfoToTensorInfo)($typeInfo, FFI::addr($tensorInfo)));
+ $this->checkStatus((($this->api)->CastTypeInfoToTensorInfo)($typeInfo, FFI::addr($tensorInfo)));
return $tensorInfo;
}
- public static function CastTypeInfoToSequenceTypeInfo($typeInfo): CData
+ public function CastTypeInfoToSequenceTypeInfo($typeInfo): CData
{
- $sequenceTypeInfo = self::new('OrtSequenceTypeInfo*');
+ $sequenceTypeInfo = $this->new('OrtSequenceTypeInfo*');
- self::checkStatus((self::api()->CastTypeInfoToSequenceTypeInfo)($typeInfo, FFI::addr($sequenceTypeInfo)));
+ $this->checkStatus((($this->api)->CastTypeInfoToSequenceTypeInfo)($typeInfo, FFI::addr($sequenceTypeInfo)));
return $sequenceTypeInfo;
}
- public static function CastTypeInfoToMapTypeInfo($typeInfo): CData
+ public function CastTypeInfoToMapTypeInfo($typeInfo): CData
{
- $mapTypeInfo = self::new('OrtMapTypeInfo*');
+ $mapTypeInfo = $this->new('OrtMapTypeInfo*');
- self::checkStatus((self::api()->CastTypeInfoToMapTypeInfo)($typeInfo, FFI::addr($mapTypeInfo)));
+ $this->checkStatus((($this->api)->CastTypeInfoToMapTypeInfo)($typeInfo, FFI::addr($mapTypeInfo)));
return $mapTypeInfo;
}
- public static function GetSequenceElementType($sequenceTypeInfo): CData
+ public function GetSequenceElementType($sequenceTypeInfo): CData
{
- $nestedTypeInfo = self::new('OrtTypeInfo*');
+ $nestedTypeInfo = $this->new('OrtTypeInfo*');
- self::checkStatus((self::api()->GetSequenceElementType)($sequenceTypeInfo, FFI::addr($nestedTypeInfo)));
+ $this->checkStatus((($this->api)->GetSequenceElementType)($sequenceTypeInfo, FFI::addr($nestedTypeInfo)));
return $nestedTypeInfo;
}
- public static function GetMapKeyType($mapTypeInfo): CData
+ public function GetMapKeyType($mapTypeInfo): CData
{
- $keyType = self::new('ONNXTensorElementDataType');
+ $keyType = $this->new('ONNXTensorElementDataType');
- self::checkStatus((self::api()->GetMapKeyType)($mapTypeInfo, FFI::addr($keyType)));
+ $this->checkStatus((($this->api)->GetMapKeyType)($mapTypeInfo, FFI::addr($keyType)));
return $keyType;
}
- public static function GetMapValueType($mapTypeInfo): CData
+ public function GetMapValueType($mapTypeInfo): CData
{
- $keyType = self::new('OrtTypeInfo');
+ $keyType = $this->new('OrtTypeInfo*');
- self::checkStatus((self::api()->GetMapValueType)($mapTypeInfo, FFI::addr($keyType)));
+ $this->checkStatus((($this->api)->GetMapValueType)($mapTypeInfo, FFI::addr($keyType)));
return $keyType;
}
- public static function GetStringTensorDataLength($value): int
+ public function GetStringTensorDataLength($value): int
{
- $len = self::new('size_t');
+ $len = $this->new('size_t');
- self::checkStatus((self::api()->GetStringTensorDataLength)($value, FFI::addr($len)));
+ $this->checkStatus((($this->api)->GetStringTensorDataLength)($value, FFI::addr($len)));
return $len->cdata;
}
- public static function GetStringTensorContent($value, int $len, int $offsetsLength): array
+ public function GetStringTensorContent($value, int $len, int $offsetsLength): array
{
- $s = self::new("char[$len]");
- $offsets = self::new("size_t[$offsetsLength]");
+ $s = $this->new("char[$len]");
+ $offsets = $this->new("size_t[$offsetsLength]");
- self::checkStatus((self::api()->GetStringTensorContent)($value, $s, $len, $offsets, $offsetsLength));
+ $this->checkStatus((($this->api)->GetStringTensorContent)($value, $s, $len, $offsets, $offsetsLength));
return [$s, $offsets];
}
- public static function GetValueType($value): CData
+ public function GetValueType($value): CData
{
- $outType = self::new('ONNXType');
+ $outType = $this->new('ONNXType');
- self::checkStatus((self::api()->GetValueType)($value, FFI::addr($outType)));
+ $this->checkStatus((($this->api)->GetValueType)($value, FFI::addr($outType)));
return $outType;
}
- public static function GetValueCount($value): int
+ public function GetValueCount($value): int
{
- $out = self::new('size_t');
+ $out = $this->new('size_t');
- self::checkStatus((self::api()->GetValueCount)($value, FFI::addr($out)));
+ $this->checkStatus((($this->api)->GetValueCount)($value, FFI::addr($out)));
return $out->cdata;
}
- public static function GetValue($value, int $index, $allocator): CData
+ public function GetValue($value, int $index, $allocator): CData
{
- $seq = self::new('OrtValue*');
+ $seq = $this->new('OrtValue*');
- self::checkStatus((self::api()->GetValue)($value, $index, $allocator, FFI::addr($seq)));
+ $this->checkStatus((($this->api)->GetValue)($value, $index, $allocator, FFI::addr($seq)));
return $seq;
}
- public static function ReleaseValue($value): void
+ public function ReleaseValue($value): void
{
- (self::api()->ReleaseValue)($value);
+ (($this->api)->ReleaseValue)($value);
}
- public static function GetTensorTypeAndShape($value): CData
+ public function GetTensorTypeAndShape($value): CData
{
- $typeInfo = self::new('OrtTensorTypeAndShapeInfo*');
+ $typeInfo = $this->new('OrtTensorTypeAndShapeInfo*');
- self::checkStatus((self::api()->GetTensorTypeAndShape)($value, FFI::addr($typeInfo)));
+ $this->checkStatus((($this->api)->GetTensorTypeAndShape)($value, FFI::addr($typeInfo)));
return $typeInfo;
}
- public static function ReleaseTensorTypeAndShapeInfo($info): void
+ public function ReleaseTensorTypeAndShapeInfo($info): void
{
- (self::api()->ReleaseTensorTypeAndShapeInfo)($info);
+ (($this->api)->ReleaseTensorTypeAndShapeInfo)($info);
}
- public static function GetTensorMutableData($value): CData
+ public function GetTensorMutableData($value): CData
{
- $tensorData = self::new('void*');
+ $tensorData = $this->new('void*');
- self::checkStatus((self::api()->GetTensorMutableData)($value, FFI::addr($tensorData)));
+ $this->checkStatus((($this->api)->GetTensorMutableData)($value, FFI::addr($tensorData)));
return $tensorData;
}
- public static function GetTensorShapeElementCount($info): int
+ public function GetTensorShapeElementCount($info): int
{
- $outSize = self::new('size_t');
+ $outSize = $this->new('size_t');
- self::checkStatus((self::api()->GetTensorShapeElementCount)($info, FFI::addr($outSize)));
+ $this->checkStatus((($this->api)->GetTensorShapeElementCount)($info, FFI::addr($outSize)));
return $outSize->cdata;
}
- public static function CreateCpuMemoryInfo(int $type, int $memType): CData
+ public function CreateCpuMemoryInfo(int $type, int $memType): CData
{
- $allocatorInfo = self::new('OrtMemoryInfo*');
- self::checkStatus((self::api()->CreateCpuMemoryInfo)($type, $memType, FFI::addr($allocatorInfo)));
+ $allocatorInfo = $this->new('OrtMemoryInfo*');
+ $this->checkStatus((($this->api)->CreateCpuMemoryInfo)($type, $memType, FFI::addr($allocatorInfo)));
return $allocatorInfo;
}
- public static function ReleaseMemoryInfo($info): void
+ public function ReleaseMemoryInfo($info): void
{
- (self::api()->ReleaseMemoryInfo)($info);
+ (($this->api)->ReleaseMemoryInfo)($info);
}
- public static function CreateTensorAsOrtValue($allocator, $shape, int $shapeLen, $type, $out): void
+ public function CreateTensorAsOrtValue($allocator, $shape, int $shapeLen, $type, $out): void
{
- self::checkStatus((self::api()->CreateTensorAsOrtValue)($allocator, $shape, $shapeLen, $type, $out));
+ $this->checkStatus((($this->api)->CreateTensorAsOrtValue)($allocator, $shape, $shapeLen, $type, $out));
}
- public static function FillStringTensor($value, $s, $len): void
+ public function FillStringTensor($value, $s, $len): void
{
- self::checkStatus((self::api()->FillStringTensor)($value, $s, $len));
+ $this->checkStatus((($this->api)->FillStringTensor)($value, $s, $len));
}
- public static function CreateTensorWithDataAsOrtValue($info, $pData, $pDataLen, $shape, int $shapeLen, $type, $out): void
+ public function CreateTensorWithDataAsOrtValue($info, $pData, $pDataLen, $shape, int $shapeLen, $type, $out): void
{
- self::checkStatus((self::api()->CreateTensorWithDataAsOrtValue)($info, $pData, $pDataLen, $shape, $shapeLen, $type, $out));
+ $this->checkStatus((($this->api)->CreateTensorWithDataAsOrtValue)($info, $pData, $pDataLen, $shape, $shapeLen, $type, $out));
}
- public static function GetAllocatorWithDefaultOptions(): CData
+ public function GetAllocatorWithDefaultOptions(): CData
{
- $allocator = self::new('OrtAllocator*');
- self::checkStatus((self::api()->GetAllocatorWithDefaultOptions)(FFI::addr($allocator)));
+ $allocator = $this->new('OrtAllocator*');
+ $this->checkStatus((($this->api)->GetAllocatorWithDefaultOptions)(FFI::addr($allocator)));
return $allocator;
}
- public static function ReleaseAllocator($allocator): void
+ public function ReleaseAllocator($allocator): void
{
- (self::api()->ReleaseAllocator)($allocator);
+ (($this->api)->ReleaseAllocator)($allocator);
}
- public static function AllocatorFree($allocator, $ptr): void
+ public function AllocatorFree($allocator, $ptr): void
{
- (self::api()->AllocatorFree)($allocator, $ptr);
+ (($this->api)->AllocatorFree)($allocator, $ptr);
}
- public static function CreateEnv(int $logSecurityLevel, string $logId): ?CData
+ public function CreateEnv(int $logSecurityLevel, string $logId): ?CData
{
- $env = static::new('OrtEnv*');
+ $env = $this->new('OrtEnv*');
- (self::api()->CreateEnv)($logSecurityLevel, $logId, FFI::addr($env));
+ (($this->api)->CreateEnv)($logSecurityLevel, $logId, FFI::addr($env));
// disable telemetry
// https://github.com/microsoft/onnxruntime/blob/master/docs/Privacy.md
- self::checkStatus((OnnxRuntime::api()->DisableTelemetryEvents)($env));
+ $this->checkStatus((($this->api)->DisableTelemetryEvents)($env));
return $env;
}
-}
\ No newline at end of file
+
+ public function ReleaseEnv($env): void
+ {
+ (($this->api)->ReleaseEnv)($env);
+ }
+}
diff --git a/src/FFI/OpenBLAS.php b/src/FFI/OpenBLAS.php
new file mode 100644
index 0000000..6a730fb
--- /dev/null
+++ b/src/FFI/OpenBLAS.php
@@ -0,0 +1,35 @@
+header(basePath('includes'))),
- Library::Samplerate->library(basePath('libs'))
- );
- }
+ // Return only the base name
+ return 'samplerate';
+ }
- return self::$ffi;
+ /**
+ * Get the library version string for this library
+ *
+ * @return string The library version
+ */
+ protected function getLibraryVersion(): string
+ {
+ return '0.2.2';
}
/**
- * Creates a new instance of the specified type.
+ * Creates a new sample rate converter.
*
- * @param string $type The type of the instance to create.
- * @param bool $owned Whether the instance should be owned. Default is true.
- * @param bool $persistent Whether the instance should be persistent. Default is false.
+ * @param int $converter_type The type of converter to create.
+ * @param int $channels The number of channels.
*
- * @return CData|null The created instance, or null if the creation failed.
+ * @return CData|null The sample rate converter, or null if creation failed.
* @throws Exception
*/
- public static function new(string $type, bool $owned = true, bool $persistent = false): ?CData
+ public function src_new(int $converter_type, int $channels): ?CData
{
- return self::ffi()->new($type, $owned, $persistent);
+ $error = $this->new('int32_t');
+
+ $state = $this->ffi->{'src_new'}($converter_type, $channels, \FFI::addr($error));
+
+ if ($error->cdata !== 0) {
+ throw new RuntimeException($this->strerror($error->cdata));
+ }
+
+ return $state;
}
/**
- * Casts a pointer to a different type.
+ * Deletes a sample rate converter.
*
- * @param CType|string $type The type to cast to.
- * @param CData|int|float|bool|null $ptr The pointer to cast.
+ * @param CData $state The sample rate converter to delete.
*
- * @return ?CData The cast pointer, or null if the cast failed.
+ * @return void
* @throws Exception
*/
- public static function cast(CType|string$type, CData|int|float|bool|null$ptr): ?CData
+ public function delete(CData $state): void
{
- return self::ffi()->cast($type, $ptr);
+ $this->ffi->{'src_delete'}($state);
}
/**
- * Retrieves the value of the enum constant with the given name.
+ * Processes a block of audio data.
*
- * @param string $name The name of the enum constant.
+ * @param CData $state The sample rate converter.
+ * @param CData $data The data to process.
*
- * @return mixed The value of the enum constant.
+ * @return int 0 on success, or an error code.
* @throws Exception
*/
- public static function enum(string $name): mixed
+ public function process(CData $state, CData $data): int
{
- return self::ffi()->{$name};
+ return $this->ffi->{'src_process'}($state, $data);
}
/**
- * Returns the version of the library as a string.
+ * Resets a sample rate converter.
*
- * @return string The version of the library.
+ * @param CData $state The sample rate converter to reset.
+ *
+ * @return int 0 on success, or an error code.
+ * @throws Exception
*/
- public static function version(): string
+ public function reset(CData $state): int
{
- return self::ffi()->src_get_version();
+ return $this->ffi->{'src_reset'}($state);
}
/**
- * Creates a new sample rate converter.
+ * Gets the error message for an error code.
*
- * @param int $converterType The type of the converter.
- * @param int $channels The number of channels.
+ * @param int $error The error code.
*
- * @return CData The state of the created converter.
- * @throws RuntimeException|Exception If the converter fails to create.
+ * @return string The error message.
+ * @throws Exception
*/
- public static function srcNew(int $converterType, int $channels): CData
+ public function strerror(int $error): string
{
- $error = self::new('int32_t');
-
- $state = self::ffi()->src_new($converterType, $channels, FFI::addr($error));
-
- if ($error->cdata !== 0) {
- $error = self::ffi()->src_strerror($error);
- throw new RuntimeException("Failed to create sample rate converter: $error");
- }
-
- return $state;
+ return $this->ffi->{'src_strerror'}($error);
}
-
/**
- * Processes the given data using the specified sample rate converter state.
+ * Gets the version of the library.
*
- * @param CData $state The state of the sample rate converter.
- * @param CData $data The data to be processed.
- *
- * @return void
- * @throws RuntimeException|Exception If the sample rate conversion fails.
+ * @return string The version of the library.
+ * @throws Exception
*/
- public static function srcProcess(CData $state, CData $data): void
+ public function version(): string
{
- $error = self::ffi()->src_process($state, $data);
-
- if ($error !== 0) {
- $error = self::ffi()->src_strerror($error);
- throw new RuntimeException("Failed to convert sample rate: $error");
- }
+ return $this->ffi->{'src_get_version'}();
}
/**
- * Cleanup all internal allocations.
+ * Performs a simple sample rate conversion.
+ *
+ * @param int $converter_type The type of converter to use.
+ * @param int $channels The number of channels.
+ * @param float $output_rate The output sample rate.
+ * @param float $input_rate The input sample rate.
+ * @param CData $input The input data.
+ * @param int $input_frames The number of input frames.
+ * @param int $output_frames_max The maximum number of output frames.
+ *
+ * @return array An array containing the output data and the number of output frames.
+ * @throws Exception
*/
- public static function srcDelete(CData $state): void
- {
- self::ffi()->src_delete($state);
+ public function simple(
+ int $converter_type,
+ int $channels,
+ float $output_rate,
+ float $input_rate,
+ CData $input,
+ int $input_frames,
+ int $output_frames_max
+ ): array {
+ $output = $this->new("float[$output_frames_max]");
+ $output_frames = $this->new('int');
+ $output_frames->cdata = $output_frames_max;
+
+ $error = $this->ffi->{'src_simple'}(
+ $output,
+ $input,
+ $input_frames,
+ $output_frames,
+ $output_rate / $input_rate,
+ $converter_type,
+ $channels
+ );
+
+ if ($error !== 0) {
+ throw new RuntimeException($this->strerror($error));
+ }
+
+ return [$output, $output_frames->cdata];
}
-}
\ No newline at end of file
+}
diff --git a/src/FFI/Sndfile.php b/src/FFI/Sndfile.php
index 87fbca3..036770b 100644
--- a/src/FFI/Sndfile.php
+++ b/src/FFI/Sndfile.php
@@ -4,178 +4,133 @@
namespace Codewithkyrian\Transformers\FFI;
-use Codewithkyrian\TransformersLibsLoader\Library;
use Exception;
-use FFI;
use FFI\CData;
-use FFI\CType;
use RuntimeException;
-use function Codewithkyrian\Transformers\Utils\basePath;
-class Sndfile
+class Sndfile extends NativeLibrary
{
- protected static FFI $ffi;
-
-
/**
- * Returns an instance of the FFI class after checking if it has already been instantiated.
- * If not, it creates a new instance by defining the header contents and library path.
- *
- * @return FFI The FFI instance.
- * @throws Exception
+ * Get the header file name for this library
+ *
+ * @return string The header file name
*/
- protected static function ffi(): FFI
+ protected function getHeaderName(): string
{
- if (!isset(self::$ffi)) {
- self::$ffi = FFI::cdef(
- file_get_contents(Library::Sndfile->header(basePath('includes'))),
- Library::Sndfile->library(basePath('libs'))
- );
- }
-
- return self::$ffi;
+ return 'sndfile';
}
/**
- * Creates a new instance of the specified type.
- *
- * @param string $type The type of the instance to create.
- * @param bool $owned Whether the instance should be owned. Default is true.
- * @param bool $persistent Whether the instance should be persistent. Default is false.
- *
- * @return CData|null The created instance, or null if the creation failed.
- * @throws Exception
+ * Get the library file name (without extension) for this library
+ *
+ * @return string The library file name
*/
- public static function new(string $type, bool $owned = true, bool $persistent = false): ?CData
+ protected function getLibraryName(): string
{
- return self::ffi()->new($type, $owned, $persistent);
+ // Return only the base name
+ return 'sndfile';
}
/**
- * Casts a pointer to a different type.
- *
- * @param CType|string $type The type to cast to.
- * @param CData|int|float|bool|null $ptr The pointer to cast.
- *
- * @return ?CData The cast pointer, or null if the cast failed.
- * @throws Exception
+ * Get the library version string for this library
+ *
+ * @return string The library version
*/
- public static function cast(CType|string $type, CData|int|float|bool|null $ptr): ?CData
+ protected function getLibraryVersion(): string
{
- return self::ffi()->cast($type, $ptr);
+ return '1.2.2';
}
/**
- * Retrieves the value of the enum constant with the given name.
+ * Opens a sound file for reading.
*
- * @param string $name The name of the enum constant.
+ * @param string $path The path to the sound file.
+ * @param int $mode The mode to open the file in.
+ * @param CData|null $info The info struct to fill.
*
- * @return mixed The value of the enum constant.
+ * @return CData|null The SNDFILE handle, or null if the file could not be opened.
* @throws Exception
*/
- public static function enum(string $name): mixed
+ public function open(string $path, int $mode, ?CData $info = null): ?CData
{
- return self::ffi()->{$name};
+ $info ??= $this->new('SF_INFO');
+ $handle = $this->ffi->{'sf_open'}($path, $mode, $info);
+
+ if ($handle === null) {
+ throw new RuntimeException($this->ffi->{'sf_strerror'}(null));
+ }
+
+ return $handle;
}
/**
- * Returns the version of the library as a string.
+ * Reads frames from a sound file.
*
- * @return string The version of the library.
+ * @param CData $handle The SNDFILE handle.
+ * @param CData $buffer The buffer to read into.
+ * @param int $frames The number of frames to read.
+ *
+ * @return int The number of frames read.
+ * @throws Exception
*/
- public static function version(): string
+ public function readf_float(CData $handle, CData $buffer, int $frames): int
{
- return self::ffi()->sf_version_string();
+ return $this->ffi->{'sf_readf_float'}($handle, $buffer, $frames);
}
- /**
- * Opens a file for read, write or both, depending on the specified mode.
+ /**
+ * Writes frames to a sound file.
*
- * @param string $path The path to the file.
- * @param int $mode The mode in which to open the file (e.g., read, write, read/write).
- * @param CData $sfinfo The structure containing information about the file.
+ * @param CData $handle The SNDFILE handle.
+ * @param CData $buffer The buffer to write.
+ * @param int $frames The number of frames to write.
*
- * @return mixed The handle to the opened file.
- * @throws RuntimeException|Exception If the file fails to open.
+ * @return int The number of frames written.
+ * @throws Exception
*/
- public static function open(string $path, int $mode, CData $sfinfo): mixed
+ public function writef_float(CData $handle, CData $buffer, int $frames): int
{
- if (PHP_OS_FAMILY === 'Windows') {
- $path = mb_convert_encoding($path, 'UTF-8', mb_detect_encoding($path));
- }
-
- $sndfile = self::ffi()->sf_open($path, $mode, $sfinfo);
-
- if ($sndfile === null) {
- $error = self::ffi()->sf_strerror($sndfile);
- throw new RuntimeException("Failed to open file: $error");
- }
-
- return $sndfile;
+ return $this->ffi->{'sf_writef_float'}($handle, $buffer, $frames);
}
/**
- * Retrieves the format information of a sound file.
+ * Closes a sound file.
*
- * @param mixed $sndfile The sound file object.
- * @param mixed $sfinfo The sound file info object.
+ * @param CData $handle The SNDFILE handle.
*
- * @return string The name of the format.
+ * @return int 0 on success, or an error code.
+ * @throws Exception
*/
- public static function getFormat(mixed $sndfile, mixed $sfinfo): string
+ public function close(CData $handle): int
{
- $info = self::ffi()->new('SF_FORMAT_INFO');
-
- $info->format = $sfinfo->format;
-
- self::ffi()->sf_command($sndfile, self::ffi()->SFC_GET_FORMAT_INFO, FFI::addr($info), FFI::sizeof($info));
-
- return $info->name;
+ return $this->ffi->{'sf_close'}($handle);
}
/**
- * Reads frames from a sound file.
+ * Gets the error message for the last error.
*
- * @param CData $sndfile The sound file to read from.
- * @param CData $ptr The pointer to the data buffer.
- * @param int $frames The number of frames to read.
- * @param string $type The type of data to read. Defaults to 'float'.
+ * @param CData|null $handle The SNDFILE handle, or null for the last error.
*
- * @return int The number of frames read.
+ * @return string The error message.
* @throws Exception
*/
- public static function readFrames(CData $sndfile, CData $ptr, int $frames, string $type = 'float'): int
+ public function strerror(?CData $handle = null): string
{
- return match ($type) {
- 'int' => self::ffi()->sf_readf_int($sndfile, $ptr, $frames),
- 'float' => self::ffi()->sf_readf_float($sndfile, $ptr, $frames),
- 'double' => self::ffi()->sf_readf_double($sndfile, $ptr, $frames),
- };
+ return $this->ffi->{'sf_strerror'}($handle);
}
/**
- * Writes frames to a sound file.
+ * Seeks to a position in a sound file.
*
- * @param CData $sndfile The sound file to write to.
- * @param CData $ptr The pointer to the data buffer.
- * @param int $frames The number of frames to write.
- * @param string $type The type of data to write. Defaults to 'float'.
+ * @param CData $handle The SNDFILE handle.
+ * @param int $frames The frame offset.
+ * @param int $whence The seek mode.
*
- * @return int The number of frames written.
+ * @return int The new position.
* @throws Exception
*/
- public static function writeFrames(CData $sndfile, CData $ptr, int $frames, string $type = 'float'): int
- {
- return match ($type) {
- 'int' => self::ffi()->sf_writef_int($sndfile, $ptr, $frames),
- 'float' => self::ffi()->sf_writef_float($sndfile, $ptr, $frames),
- 'double' => self::ffi()->sf_writef_double($sndfile, $ptr, $frames),
- };
- }
-
-
- public static function close(CData $sndfile): void
+ public function seek(CData $handle, int $frames, int $whence): int
{
- self::ffi()->sf_close($sndfile);
+ return $this->ffi->{'sf_seek'}($handle, $frames, $whence);
}
-}
\ No newline at end of file
+}
diff --git a/src/FFI/TransformersUtils.php b/src/FFI/TransformersUtils.php
index 5df7ac4..1c8d268 100644
--- a/src/FFI/TransformersUtils.php
+++ b/src/FFI/TransformersUtils.php
@@ -4,108 +4,92 @@
namespace Codewithkyrian\Transformers\FFI;
-use Codewithkyrian\TransformersLibsLoader\Library;
-use Exception;
-use FFI;
use FFI\CData;
-use FFI\CType;
-use function Codewithkyrian\Transformers\Utils\basePath;
-class TransformersUtils
+class TransformersUtils extends NativeLibrary
{
- protected static FFI $ffi;
-
-
/**
- * Returns an instance of the FFI class after checking if it has already been instantiated.
- * If not, it creates a new instance by defining the header contents and library path.
- *
- * @return FFI The FFI instance.
- * @throws Exception
+ * Get the header file name for this library
+ *
+ * @return string The header file name
*/
- protected static function ffi(): FFI
+ protected function getHeaderName(): string
{
- if (!isset(self::$ffi)) {
- self::$ffi = FFI::cdef(
- file_get_contents(Library::TransformersPHP->header(basePath('includes'))),
- Library::TransformersPHP->library(basePath('libs'))
- );
- }
-
- return self::$ffi;
+ return 'transformersphp';
}
/**
- * Creates a new instance of the specified type.
- *
- * @param CType|string $type The type of the instance to create.
- * @param bool $owned Whether the instance should be owned. Default is true.
- * @param bool $persistent Whether the instance should be persistent. Default is false.
- *
- * @return CData|null The created instance, or null if the creation failed.
- * @throws Exception
+ * Get the library file name (without extension) for this library
+ *
+ * @return string The library file name
*/
- public static function new(CType|string $type, bool $owned = true, bool $persistent = false): ?CData
+ protected function getLibraryName(): string
{
- return self::ffi()->new($type, $owned, $persistent);
+ return 'transformersphp';
}
- /**
- * Casts a pointer to a different type.
- *
- * @param CType|string $type The type to cast to.
- * @param CData|int|float|bool|null $ptr The pointer to cast.
- *
- * @return ?CData The cast pointer, or null if the cast failed.
- * @throws Exception
- */
- public static function cast(CType|string$type, CData|int|float|bool|null$ptr): ?CData
- {
- return self::ffi()->cast($type, $ptr);
- }
-
- /**
- * Retrieves the value of the enum constant with the given name.
- *
- * @param string $name The name of the enum constant.
- *
- * @return mixed The value of the enum constant.
- * @throws Exception
- */
- public static function enum(string $name): mixed
- {
- return self::ffi()->{$name};
- }
/**
* Returns the version of the library as a string.
*
* @return string The version of the library.
*/
- public static function version(): string
+ public function getLibraryVersion(): string
{
- self::ffi();
return '1.0.0';
}
- public static function padReflect($input, int $length, int $paddedLength): CData
+ /**
+ * Pad an array using reflection
+ *
+ * @param mixed $input The input array
+ * @param int $length The length of the input array
+ * @param int $paddedLength The length of the padded array
+ * @return CData The padded array
+ */
+ public function padReflect($input, int $length, int $paddedLength): CData
{
- $padded = self::new("float[$paddedLength]");
- self::ffi()->pad_reflect($input, $length, $padded, $paddedLength);
+ $padded = $this->new("float[$paddedLength]");
+ $this->ffi->{'pad_reflect'}($input, $length, $padded, $paddedLength);
return $padded;
}
- public static function spectrogram(
+ /**
+ * Generate a spectrogram from a waveform
+ *
+ * @param mixed $waveform The input waveform
+ * @param int $waveformLength The length of the waveform
+ * @param int $spectrogramLength The length of the spectrogram
+ * @param int $hopLength The hop length
+ * @param int $fftLength The FFT length
+ * @param mixed $window The window function
+ * @param int $windowLength The window length
+ * @param int $d1 The first dimension
+ * @param int $d1Max The maximum first dimension
+ * @param float $power The power
+ * @param bool $center Whether to center the window
+ * @param float $preemphasis The preemphasis
+ * @param mixed $melFilters The mel filters
+ * @param int $nMelFilters The number of mel filters
+ * @param mixed $nFreqBins The number of frequency bins
+ * @param float $melFloor The mel floor
+ * @param int $logMel Whether to use log mel
+ * @param bool|null $removeDcOffset Whether to remove DC offset
+ * @param bool $doPad Whether to pad
+ * @param bool $transpose Whether to transpose
+ * @return CData The spectrogram
+ */
+ public function spectrogram(
$waveform, int $waveformLength, int $spectrogramLength, int $hopLength, int $fftLength,
$window, int $windowLength, int $d1, int $d1Max, float $power, bool $center, float $preemphasis,
$melFilters, int $nMelFilters, $nFreqBins, float $melFloor, int $logMel, ?bool $removeDcOffset,
bool $doPad, bool $transpose
): CData
{
- $spectrogram = self::new("float[$spectrogramLength]");
+ $spectrogram = $this->new("float[$spectrogramLength]");
- self::ffi()->spectrogram(
+ $this->ffi->{'spectrogram'}(
$waveform, $waveformLength, $spectrogram, $spectrogramLength, $hopLength, $fftLength, $window,
$windowLength, $d1, $d1Max, $power, $center, $preemphasis, $melFilters, $nMelFilters, $nFreqBins,
$melFloor, $logMel, $removeDcOffset, $doPad, $transpose,
diff --git a/src/FeatureExtractors/ASTFeatureExtractor.php b/src/FeatureExtractors/ASTFeatureExtractor.php
index b825e51..8c9484d 100644
--- a/src/FeatureExtractors/ASTFeatureExtractor.php
+++ b/src/FeatureExtractors/ASTFeatureExtractor.php
@@ -46,13 +46,13 @@ public function __construct(array $config)
/**
* Extracts features from a given audio using the provided configuration.
- * @param Tensor $waveform The audio tensor to extract features from.
+ * @param Tensor $input The audio tensor to extract features from.
* @return Tensor[] The extracted features.
*/
- public function __invoke(Tensor $waveform): array
+ public function __invoke($input, ...$args): array
{
$features = Audio::spectrogram(
- $waveform,
+ $input,
$this->window,
frameLength: 400,
hopLength: 160,
@@ -72,4 +72,4 @@ public function __invoke(Tensor $waveform): array
'input_values' => $features->add(-$this->mean)->multiply(1 / $this->std)->unsqueeze(0)
];
}
-}
\ No newline at end of file
+}
diff --git a/src/FeatureExtractors/DetrFeatureExtractor.php b/src/FeatureExtractors/DetrFeatureExtractor.php
index 3ea4172..77b1658 100644
--- a/src/FeatureExtractors/DetrFeatureExtractor.php
+++ b/src/FeatureExtractors/DetrFeatureExtractor.php
@@ -16,13 +16,12 @@ class DetrFeatureExtractor extends ImageFeatureExtractor
/**
* Calls the feature extraction process on an array of images, preprocesses
* each image, and concatenates the resulting features into a single Tensor.
- * @param Image|array $images The image(s) to extract features from.
+ * @param Image|array $input The image(s) to extract features from.
* @return array An object containing the concatenated pixel values of the preprocessed images.
*/
- public function __invoke(Image|array $images, ...$args): array
+ public function __invoke($input, ...$args): array
{
- $result = parent::__invoke($images, $args);
-
+ $result = parent::__invoke($input, $args);
// TODO support differently-sized images, for now assume all images are the same size.
// TODO support different mask sizes (not just 64x64)
@@ -49,4 +48,4 @@ public function postProcessObjectDetection(ObjectDetectionOutput $outputs, float
{
return Processor::postProcessObjectDetection($outputs, $threshold, $targetSizes, $isZeroShot);
}
-}
\ No newline at end of file
+}
diff --git a/src/FeatureExtractors/FeatureExtractor.php b/src/FeatureExtractors/FeatureExtractor.php
index f1fc590..b51537a 100644
--- a/src/FeatureExtractors/FeatureExtractor.php
+++ b/src/FeatureExtractors/FeatureExtractor.php
@@ -10,7 +10,10 @@
*/
class FeatureExtractor
{
- public function __construct(public array $config)
+ public function __construct(public array $config) {}
+
+ public function __invoke($input, ...$args)
{
+ return $input;
}
-}
\ No newline at end of file
+}
diff --git a/src/FeatureExtractors/ImageFeatureExtractor.php b/src/FeatureExtractors/ImageFeatureExtractor.php
index b4d53bb..1bf5b47 100644
--- a/src/FeatureExtractors/ImageFeatureExtractor.php
+++ b/src/FeatureExtractors/ImageFeatureExtractor.php
@@ -8,7 +8,6 @@
use Codewithkyrian\Transformers\Tensor\Tensor;
use Codewithkyrian\Transformers\Utils\Image;
use Exception;
-use Imagine\Image\Point;
class ImageFeatureExtractor extends FeatureExtractor
{
@@ -78,61 +77,6 @@ public function __construct(public array $config)
}
}
-
- /**
- * Crops the margin of the image. Gray pixels are considered margin (i.e., pixels with a value below the threshold).
- *
- * @param int $grayThreshold Value below which pixels are considered to be gray.
- *
- * @return static The cropped image.
- */
- public function cropMargin(Image $image, int $grayThreshold = 200): static
- {
- $grayImage = $image->clone()->grayscale();
-
- // Get the min and max pixel values
- $minValue = min($grayImage->toTensor()->buffer())[0];
- $maxValue = max($grayImage->toTensor()->buffer())[0];
-
- $diff = $maxValue - $minValue;
-
- // If all pixels have the same value, no need to crop
- if ($diff === 0) {
- return $this;
- }
-
- $threshold = $grayThreshold / 255;
-
- $xMin = $image->width();
- $yMin = $image->height();
- $xMax = 0;
- $yMax = 0;
-
- $width = $image->width();
- $height = $image->height();
-
- // Iterate over each pixel in the image
- for ($y = 0; $y < $height; ++$y) {
- for ($x = 0; $x < $width; ++$x) {
- $color = $grayImage->image->getColorAt(new Point($x, $y));
- $pixelValue = $color->getRed(); // Assuming grayscale, so red channel is sufficient
-
- if (($pixelValue - $minValue) / $diff < $threshold) {
- // We have a non-gray pixel, so update the min/max values accordingly
- $xMin = min($xMin, $x);
- $yMin = min($yMin, $y);
- $xMax = max($xMax, $x);
- $yMax = max($yMax, $y);
- }
- }
- }
-
- // Crop the image using the calculated bounds
- $image->crop($xMin, $yMin, $xMax, $yMax);
-
- return $this;
- }
-
/**
* Pad the image by a certain amount.
*
@@ -152,8 +96,7 @@ public function padImage(
string $mode = 'constant',
bool $center = false,
int $constantValues = 0
- ): Tensor
- {
+ ): Tensor {
if ($tensorFormat === 'CHW') {
[$imageChannels, $imageHeight, $imageWidth] = $imageTensor->shape();
} else {
@@ -324,7 +267,7 @@ public function getResizeOutputImageSize(Image $image, int|array|null $size): ar
} elseif ($this->sizeDivisibility != null) {
return $this->enforceSizeDivisibility([$srcWidth, $srcHeight], $this->sizeDivisibility);
} else {
- throw new Exception("Could not resize image due to unsupported 'size' parameter passed: ".json_encode($size));
+ throw new Exception("Could not resize image due to unsupported 'size' parameter passed: " . json_encode($size));
}
}
@@ -347,8 +290,7 @@ public function preprocess(
?bool $doPad = null,
?bool $doConvertRGB = null,
?bool $doConvertGrayscale = null
- ): array
- {
+ ): array {
if ($this->doCropMargin) {
// Specific to nougat processors. This is done before resizing,
// and can be interpreted as a pre-preprocessing step.
@@ -400,7 +342,7 @@ public function preprocess(
if ($doNormalize ?? $this->doNormalize) {
if (is_array($this->imageMean)) {
// Negate the mean values to add instead of subtract
- $negatedMean = array_map(fn ($mean) => -$mean, $this->imageMean);
+ $negatedMean = array_map(fn($mean) => -$mean, $this->imageMean);
$imageMean = Tensor::repeat($negatedMean, $image->height() * $image->width(), 1);
} else {
$imageMean = Tensor::fill([$image->channels * $image->height() * $image->width()], -$this->imageMean);
@@ -409,7 +351,7 @@ public function preprocess(
if (is_array($this->imageStd)) {
// Inverse the standard deviation values to multiple instead of divide
- $inversedStd = array_map(fn ($std) => 1 / $std, $this->imageStd);
+ $inversedStd = array_map(fn($std) => 1 / $std, $this->imageStd);
$imageStd = Tensor::repeat($inversedStd, $image->height() * $image->width(), 1);
} else {
$imageStd = Tensor::fill([$image->channels * $image->height() * $image->width()], 1 / $this->imageStd);
@@ -421,7 +363,7 @@ public function preprocess(
$imageStd = $imageStd->reshape($imageTensor->shape());
if (count($imageMean) !== $image->channels || count($imageStd) !== $image->channels) {
- throw new Exception("When set to arrays, the length of `imageMean` (".count($imageMean).") and `imageStd` (".count($imageStd).") must match the number of channels in the image ({$image->channels}).");
+ throw new Exception("When set to arrays, the length of `imageMean` (" . count($imageMean) . ") and `imageStd` (" . count($imageStd) . ") must match the number of channels in the image ({$image->channels}).");
}
// Normalize pixel data
@@ -450,15 +392,17 @@ public function preprocess(
* preprocesses each image, and concatenates the resulting
* features into a single Tensor.
*
- * @param Image|Image[] $images The image(s) to extract features from.
+ * @param Image|Image[] $input The image(s) to extract features from.
* @param mixed ...$args Additional arguments.
*
* @return array An object containing the concatenated pixel values (and other metadata) of the preprocessed images.
*/
- public function __invoke(Image|array $images, ...$args): array
+ public function __invoke($input, ...$args): array
{
- if (!is_array($images)) {
- $images = [$images];
+ $images = is_array($input) ? $input : [$input];
+
+ if (count($images) === 0) {
+ throw new Exception('No images provided');
}
$imageData = array_map([$this, 'preprocess'], $images);
@@ -516,6 +460,6 @@ private function constraintToMultipleOf(int $val, int $multiple, int $minVal = 0
$x = ceil($a) * $multiple;
}
- return $x;
+ return (int)$x;
}
-}
\ No newline at end of file
+}
diff --git a/src/FeatureExtractors/WhisperFeatureExtractor.php b/src/FeatureExtractors/WhisperFeatureExtractor.php
index 5dbbb22..498a03c 100644
--- a/src/FeatureExtractors/WhisperFeatureExtractor.php
+++ b/src/FeatureExtractors/WhisperFeatureExtractor.php
@@ -7,7 +7,7 @@
use Codewithkyrian\Transformers\Tensor\Tensor;
use Codewithkyrian\Transformers\Utils\Audio;
-use function Codewithkyrian\Transformers\Utils\timeUsage;
+use Codewithkyrian\Transformers\Transformers;
class WhisperFeatureExtractor extends FeatureExtractor
{
@@ -32,25 +32,26 @@ public function __construct(array $config)
/**
* Extracts features from a given audio using the provided configuration.
- * @param Tensor $waveform The audio tensor to extract features from.
+ * @param Tensor $input The audio tensor to extract features from.
* @return Tensor[] The extracted features.
*/
- public function __invoke(Tensor $waveform): array
+ public function __invoke($input, ...$args): array
{
- if ($waveform->size() > $this->config['n_samples']) {
- trigger_error('Attempting to extract features for audio longer than 30 seconds.' .
+ if ($input->size() > $this->config['n_samples']) {
+ $logger = Transformers::getLogger();
+ $logger->warning('Attempting to extract features for audio longer than 30 seconds.' .
'If using a pipeline to extract transcript from a long audio clip,' .
- 'remember to specify `chunkLengthSecs` and/or `strideLengthSecs` in the pipeline options.', E_USER_WARNING);
+ 'remember to specify `chunkLengthSecs` and/or `strideLengthSecs` in the pipeline options.');
- $waveform = $waveform->sliceWithBounds([0], [$this->config['n_samples']]);
- } else if ($waveform->size() < $this->config['n_samples']) {
- $padLength = $this->config['n_samples'] - $waveform->size();
- $padding = Tensor::zeros([$padLength], dtype: $waveform->dtype());
- $waveform = Tensor::concat([$waveform, $padding]);
+ $input = $input->sliceWithBounds([0], [$this->config['n_samples']]);
+ } else if ($input->size() < $this->config['n_samples']) {
+ $padLength = $this->config['n_samples'] - $input->size();
+ $padding = Tensor::zeros([$padLength], dtype: $input->dtype());
+ $input = Tensor::concat([$input, $padding]);
}
$features = Audio::spectrogram(
- $waveform,
+ $input,
$this->window,
frameLength: $this->config['n_fft'],
hopLength: $this->config['hop_length'],
@@ -71,4 +72,4 @@ public function __invoke(Tensor $waveform): array
'input_features' => $features->unsqueeze(0)
];
}
-}
\ No newline at end of file
+}
diff --git a/src/Generation/LogitsProcessors/BadWordsLogitsProcessor.php b/src/Generation/LogitsProcessors/BadWordsLogitsProcessor.php
deleted file mode 100644
index 96f9059..0000000
--- a/src/Generation/LogitsProcessors/BadWordsLogitsProcessor.php
+++ /dev/null
@@ -1,48 +0,0 @@
-badWordsIds = $badWordsIds;
- $this->eosTokenId = is_array($eosTokenId) ? $eosTokenId : [$eosTokenId];
- }
-
- /**
- * @inheritDoc
- */
- public function __invoke(array $inputIds, Tensor $logits): Tensor
- {
- foreach ($this->badWordsIds as $badWordIds) {
- // Whether to modify the logits of the last token in the bad word id sequence
- $mark = true;
-
- // For each bad word in the list, if the current sequence of input ids ends with this sequence (excluding the last),
- // then we set the logits of the last bad word id to -Infinity.
- for ($i = 1; $i <= count($badWordIds) - 1 && count($badWordIds) < count($inputIds) + 1; ++$i) {
-
- if ($badWordIds[count($badWordIds) - $i - 1] !== array_slice($inputIds, -$i, 1)[0]) {
- $mark = false;
- break;
- }
- }
- if ($mark) {
- $lastBadWordIdIndex = array_pop($badWordIds);
- $logits->buffer()[$lastBadWordIdIndex] = -INF;
- }
- }
-
- return $logits;
- }
-}
\ No newline at end of file
diff --git a/src/Generation/LogitsProcessors/ForceTokensLogitsProcessor.php b/src/Generation/LogitsProcessors/ForceTokensLogitsProcessor.php
deleted file mode 100644
index a8df303..0000000
--- a/src/Generation/LogitsProcessors/ForceTokensLogitsProcessor.php
+++ /dev/null
@@ -1,41 +0,0 @@
-forceTokenMap = array_column($forcedDecoderIds, 1, 0);
- }
-
- /**
- * Apply the processor to the input logits.
- *
- * @param Tensor[] $inputIds The input IDs.
- * @param Tensor $logits The logits to process.
- * @return Tensor The processed logits.
- */
- public function __invoke(array $inputIds, Tensor $logits): Tensor
- {
- $map = $this->forceTokenMap[count($inputIds)] ?? null; // Access length from inputIds
-
- if ($map) {
- Tensor::mo()->la()->fill(-INF, $logits);
-
- $logits->buffer()[$map] = 0;
- }
-
- return $logits;
- }
-}
\ No newline at end of file
diff --git a/src/Generation/LogitsProcessors/ForcedBOSTokenLogitsProcessor.php b/src/Generation/LogitsProcessors/ForcedBOSTokenLogitsProcessor.php
index e868965..73949d8 100644
--- a/src/Generation/LogitsProcessors/ForcedBOSTokenLogitsProcessor.php
+++ b/src/Generation/LogitsProcessors/ForcedBOSTokenLogitsProcessor.php
@@ -24,9 +24,12 @@ public function __construct(
*/
public function __invoke(array $inputIds, Tensor $logits): Tensor
{
- if (count($inputIds) === 1) {
- Tensor::mo()->la()->fill(-INF, $logits);
- $logits->buffer()[$this->bosTokenId] = 0;
+ for ($i = 0; $i < count($inputIds); $i++) {
+ if (count($inputIds[$i]) === 1) {
+ $batchLogits = $logits[$i];
+ Tensor::mo()->la()->fill(-INF, $batchLogits);
+ $batchLogits->buffer()[$this->bosTokenId] = 0;
+ }
}
return $logits;
}
diff --git a/src/Generation/LogitsProcessors/LogitsProcessor.php b/src/Generation/LogitsProcessors/LogitsProcessor.php
index 0fc749b..41d02e4 100644
--- a/src/Generation/LogitsProcessors/LogitsProcessor.php
+++ b/src/Generation/LogitsProcessors/LogitsProcessor.php
@@ -17,4 +17,4 @@ abstract class LogitsProcessor
* @return Tensor The processed logits.
*/
abstract public function __invoke(array $inputIds, Tensor $logits): Tensor;
-}
\ No newline at end of file
+}
diff --git a/src/Generation/LogitsProcessors/LogitsProcessorList.php b/src/Generation/LogitsProcessors/LogitsProcessorList.php
index b394af4..1766a01 100644
--- a/src/Generation/LogitsProcessors/LogitsProcessorList.php
+++ b/src/Generation/LogitsProcessors/LogitsProcessorList.php
@@ -28,7 +28,7 @@ public function push(LogitsProcessor $item): void
*
* @param LogitsProcessor[] $items The logits processor functions to add.
*/
- public function extend(traversable $items): void
+ public function extend(Traversable $items): void
{
foreach ($items as $item) {
$this->processors[] = $item;
@@ -41,13 +41,15 @@ public function extend(traversable $items): void
* @param array $inputIds The input IDs for the language model.
* @param Tensor $batchedLogits A 2D array of logits, where each row corresponds to a single input sequence.
*/
- public function __invoke(array $inputIds, Tensor &$batchedLogits): void
+ public function __invoke(array $inputIds, Tensor &$batchedLogits): Tensor
{
- for ($i = 0; $i < count($batchedLogits); $i++) {
- foreach ($this->processors as $processor) {
- $processor($inputIds, $batchedLogits[$i]); // Apply processors in-place
- }
+ $toReturn = $batchedLogits;
+
+ foreach ($this->processors as $processor) {
+ $toReturn = $processor($inputIds, $toReturn); // Some apply processors in-place
}
+
+ return $toReturn;
}
/**
@@ -59,4 +61,4 @@ public function getIterator(): Traversable
{
yield from $this->processors;
}
-}
\ No newline at end of file
+}
diff --git a/src/Generation/LogitsProcessors/MinLengthLogitsProcessor.php b/src/Generation/LogitsProcessors/MinLengthLogitsProcessor.php
index ba0c7f6..31ef0d0 100644
--- a/src/Generation/LogitsProcessors/MinLengthLogitsProcessor.php
+++ b/src/Generation/LogitsProcessors/MinLengthLogitsProcessor.php
@@ -32,11 +32,15 @@ public function __construct(
*/
public function __invoke(array $inputIds, Tensor $logits): Tensor
{
- if (count($inputIds) < $this->minLength) {
- foreach ($this->eosTokenId as $id) {
- $logits->buffer()[$id] = -INF;
+ for ($i = 0; $i < count($inputIds); $i++) {
+ if (count($inputIds[$i]) < $this->minLength) {
+ $batchLogits = $logits[$i];
+ foreach ($this->eosTokenId as $id) {
+ $batchLogits->buffer()[$id] = -INF;
+ }
}
}
+
return $logits;
}
}
\ No newline at end of file
diff --git a/src/Generation/LogitsProcessors/MinNewTokensLengthLogitsProcessor.php b/src/Generation/LogitsProcessors/MinNewTokensLengthLogitsProcessor.php
index 3f0fafe..aa57bea 100644
--- a/src/Generation/LogitsProcessors/MinNewTokensLengthLogitsProcessor.php
+++ b/src/Generation/LogitsProcessors/MinNewTokensLengthLogitsProcessor.php
@@ -24,11 +24,15 @@ public function __construct(
*/
public function __invoke(array $inputIds, Tensor $logits): Tensor
{
- $newTokensLength = count($inputIds) - $this->promptLengthToSkip;
-
- if ($newTokensLength < $this->minNewTokens) {
- foreach ($this->eosTokenId as $eosTokenId) {
- $logits->buffer()[$eosTokenId] = -INF;
+ for ($i = 0; $i < count($inputIds); $i++) {
+ $newTokensLength = count($inputIds[$i]) - $this->promptLengthToSkip;
+
+ if ($newTokensLength < $this->minNewTokens) {
+ $batchLogits = $logits[$i];
+
+ foreach ($this->eosTokenId as $eosTokenId) {
+ $batchLogits->buffer()[$eosTokenId] = -INF;
+ }
}
}
diff --git a/src/Generation/LogitsProcessors/NoBadWordsLogitsProcessor.php b/src/Generation/LogitsProcessors/NoBadWordsLogitsProcessor.php
new file mode 100644
index 0000000..f0029a4
--- /dev/null
+++ b/src/Generation/LogitsProcessors/NoBadWordsLogitsProcessor.php
@@ -0,0 +1,58 @@
+badWordsIds = $badWordsIds;
+ $this->eosTokenId = is_array($eosTokenId) ? $eosTokenId : [$eosTokenId];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function __invoke(array $inputIds, Tensor $logits): Tensor
+ {
+ for ($i = 0; $i < count($inputIds); $i++) {
+ $batchLogits = $logits[$i];
+ $ids = $inputIds[$i];
+
+ foreach ($this->badWordsIds as $badWordIds) {
+ // There aren't enough tokens to match the banned sequence
+ if (count($ids) < count($badWordIds) - 1) {
+ continue;
+ }
+
+ // Whether to modify the logits of the last token in the bad word id sequence
+ $mark = true;
+
+ // For each bad word in the list, if the current sequence of input ids ends with this sequence (excluding the last),
+ // then we set the logits of the last bad word id to -Infinity.
+ for ($j = 1; $j <= count($badWordIds) - 1; $j++) {
+ if ($badWordIds[count($badWordIds) - $j - 1] != $ids[count($ids) - $j]) {
+ // We have found a mismatch
+ $mark = false;
+ break;
+ }
+ }
+
+ if ($mark) {
+ $batchLogits->buffer()[$badWordIds[count($badWordIds) - 1]] = -INF;
+ }
+ }
+ }
+
+ return $logits;
+ }
+}
\ No newline at end of file
diff --git a/src/Generation/LogitsProcessors/RepetitionPenaltyLogitsProcessor.php b/src/Generation/LogitsProcessors/RepetitionPenaltyLogitsProcessor.php
index 31a6acb..fabcc96 100644
--- a/src/Generation/LogitsProcessors/RepetitionPenaltyLogitsProcessor.php
+++ b/src/Generation/LogitsProcessors/RepetitionPenaltyLogitsProcessor.php
@@ -12,9 +12,7 @@
*/
class RepetitionPenaltyLogitsProcessor extends LogitsProcessor
{
- public function __construct(protected float $penalty)
- {
- }
+ public function __construct(protected float $penalty) {}
/**
* Apply the repetition penalty to the logits.
@@ -24,13 +22,16 @@ public function __invoke(array $inputIds, Tensor $logits): Tensor
// Modify the logits corresponding to each element in `input_ids`.
// As a consequence, the logits corresponding to tokens that appear
// many times in the output will be penalised more.
- foreach ($inputIds as $inputId) {
- if ($logits->buffer()[$inputId] < 0) {
- $logits->buffer()[$inputId] *= $this->penalty;
- } else {
- $logits->buffer()[$inputId] /= $this->penalty;
+ for ($i = 0; $i < count($inputIds); $i++) {
+ foreach ($inputIds[$i] as $inputId) {
+ if ($logits[$i]->buffer()[$inputId] < 0) {
+ $logits[$i]->buffer()[$inputId] *= $this->penalty;
+ } else {
+ $logits[$i]->buffer()[$inputId] /= $this->penalty;
+ }
}
}
+
return $logits;
}
-}
\ No newline at end of file
+}
diff --git a/src/Generation/LogitsProcessors/SuppressTokensAtBeginLogitsProcessor.php b/src/Generation/LogitsProcessors/SuppressTokensAtBeginLogitsProcessor.php
index f963247..8e6c284 100644
--- a/src/Generation/LogitsProcessors/SuppressTokensAtBeginLogitsProcessor.php
+++ b/src/Generation/LogitsProcessors/SuppressTokensAtBeginLogitsProcessor.php
@@ -26,12 +26,15 @@ public function __construct(
*/
public function __invoke(array $inputIds, Tensor $logits): Tensor
{
- if (count($inputIds) == $this->beginIndex) {
- foreach ($this->beginSuppressTokens as $token) {
- $logits->buffer()[$token] = -INF;
+ for ($i = 0; $i < count($inputIds); $i++) {
+ if (count($inputIds[$i]) === $this->beginIndex) {
+ $batchLogits = $logits[$i];
+ foreach ($this->beginSuppressTokens as $token) {
+ $batchLogits->buffer()[$token] = -INF;
+ }
}
}
-
+
return $logits;
}
}
\ No newline at end of file
diff --git a/src/Generation/LogitsProcessors/WhisperTimeStampLogitsProcessor.php b/src/Generation/LogitsProcessors/WhisperTimeStampLogitsProcessor.php
index 9a4e769..c3835f5 100644
--- a/src/Generation/LogitsProcessors/WhisperTimeStampLogitsProcessor.php
+++ b/src/Generation/LogitsProcessors/WhisperTimeStampLogitsProcessor.php
@@ -5,8 +5,8 @@
namespace Codewithkyrian\Transformers\Generation\LogitsProcessors;
+use Codewithkyrian\Transformers\Configs\GenerationConfig;
use Codewithkyrian\Transformers\Tensor\Tensor;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
use function Codewithkyrian\Transformers\Utils\timeUsage;
class WhisperTimeStampLogitsProcessor extends LogitsProcessor
@@ -111,4 +111,4 @@ public function __invoke(array $inputIds, Tensor $logits): Tensor
return $logits;
}
-}
\ No newline at end of file
+}
diff --git a/src/Generation/Samplers/Sampler.php b/src/Generation/Samplers/Sampler.php
index bafb5fa..71c1b4a 100644
--- a/src/Generation/Samplers/Sampler.php
+++ b/src/Generation/Samplers/Sampler.php
@@ -5,17 +5,15 @@
namespace Codewithkyrian\Transformers\Generation\Samplers;
+use Codewithkyrian\Transformers\Configs\GenerationConfig;
use Codewithkyrian\Transformers\Tensor\Tensor;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
/**
* Sampler is a base class for all sampling methods used for text generation.
*/
abstract class Sampler
{
- public function __construct(protected GenerationConfig $generationConfig)
- {
- }
+ public function __construct(protected GenerationConfig $generationConfig) {}
/**
* Executes the sampler, using the specified logits.
diff --git a/src/Generation/StoppingCriteria/EosTokenCriteria.php b/src/Generation/StoppingCriteria/EosTokenCriteria.php
new file mode 100644
index 0000000..b019ea3
--- /dev/null
+++ b/src/Generation/StoppingCriteria/EosTokenCriteria.php
@@ -0,0 +1,29 @@
+eosTokenIds = is_array($eosTokenId) ? $eosTokenId : [$eosTokenId];
+ }
+
+ public function __invoke(array $inputIds, array $scores): array
+ {
+ return array_map(function ($ids) {
+ $lastToken = end($ids);
+ return in_array($lastToken, $this->eosTokenIds, true);
+ }, $inputIds);
+ }
+}
diff --git a/src/Generation/StoppingCriteria/InterruptableStoppingCriteria.php b/src/Generation/StoppingCriteria/InterruptableStoppingCriteria.php
new file mode 100644
index 0000000..58bd589
--- /dev/null
+++ b/src/Generation/StoppingCriteria/InterruptableStoppingCriteria.php
@@ -0,0 +1,28 @@
+interrupted = true;
+ }
+
+ public function reset(): void
+ {
+ $this->interrupted = false;
+ }
+
+ public function __invoke(array $inputIds, array $scores): array
+ {
+ return array_fill(0, count($inputIds), $this->interrupted);
+ }
+}
diff --git a/src/Generation/StoppingCriteria/MaxLengthCriteria.php b/src/Generation/StoppingCriteria/MaxLengthCriteria.php
new file mode 100644
index 0000000..6ffb94e
--- /dev/null
+++ b/src/Generation/StoppingCriteria/MaxLengthCriteria.php
@@ -0,0 +1,52 @@
+= $this->maxLength;
+
+ if ($this->maxPositionEmbeddings !== null && !$isDone && $currentLength >= $this->maxPositionEmbeddings) {
+ $logger = Transformers::getLogger();
+ $logger->warning(
+ "This is a friendly reminder - the current text generation call will exceed the model's predefined " .
+ "maximum length ({$this->maxPositionEmbeddings}). Depending on the model, you may observe " .
+ "exceptions, performance degradation, or nothing at all."
+ );
+ }
+
+ $results[] = $isDone;
+ }
+
+ return $results;
+ }
+}
diff --git a/src/Generation/StoppingCriteria/MaxTimeCriteria.php b/src/Generation/StoppingCriteria/MaxTimeCriteria.php
new file mode 100644
index 0000000..794de60
--- /dev/null
+++ b/src/Generation/StoppingCriteria/MaxTimeCriteria.php
@@ -0,0 +1,38 @@
+maxTime = $maxTime;
+ $this->initialTimestamp = $initialTimestamp ?? microtime(true);
+ }
+
+ /**
+ * Evaluates whether generation should stop based on elapsed time.
+ *
+ * @param array $inputIds Array of input IDs (2D array where each sub-array is a sequence of token IDs).
+ * @param array $scores Scores for the generated tokens.
+ *
+ * @return array Boolean array indicating whether generation should stop for each sequence.
+ */
+ public function __invoke(array $inputIds, array $scores): array
+ {
+ $elapsedTime = microtime(true) - $this->initialTimestamp;
+ $isDone = $elapsedTime > $this->maxTime;
+
+ // Return the same stopping criteria for all sequences
+ return array_fill(0, count($inputIds), $isDone);
+ }
+}
diff --git a/src/Generation/StoppingCriteria/StoppingCriteria.php b/src/Generation/StoppingCriteria/StoppingCriteria.php
new file mode 100644
index 0000000..76a9bf5
--- /dev/null
+++ b/src/Generation/StoppingCriteria/StoppingCriteria.php
@@ -0,0 +1,21 @@
+criteria[] = $criteria;
+ }
+
+ public function extend(Traversable $items): void
+ {
+ foreach ($items as $item) {
+ $this->criteria[] = $item;
+ }
+ }
+
+ public function __invoke(array $inputIds, array $scores): array
+ {
+ $isDone = array_fill(0, count($inputIds), false);
+
+ foreach ($this->criteria as $criterion) {
+ $criterionDone = $criterion($inputIds, $scores);
+
+ for ($i = 0; $i < count($isDone); ++$i) {
+ $isDone[$i] = $isDone[$i] || $criterionDone[$i];
+ }
+ }
+
+ return $isDone;
+ }
+
+ public function getIterator(): Traversable
+ {
+ yield from $this->criteria;
+ }
+}
diff --git a/src/Generation/Streamers/Streamer.php b/src/Generation/Streamers/Streamer.php
index 1db9226..8c8ad12 100644
--- a/src/Generation/Streamers/Streamer.php
+++ b/src/Generation/Streamers/Streamer.php
@@ -6,21 +6,25 @@
namespace Codewithkyrian\Transformers\Generation\Streamers;
use Codewithkyrian\Transformers\PreTrainedTokenizers\PreTrainedTokenizer;
+use DateTime;
/**
* Base streamer from which all streamers inherit.
*/
abstract class Streamer
{
- protected array $promptTokens = [];
protected bool $skipPrompt = false;
- protected bool $nextTokensArePrompt;
+ protected bool $nextTokensArePrompt = true;
protected PreTrainedTokenizer $tokenizer;
protected mixed $onStreamCallback = null;
protected mixed $onStreamEndCallback = null;
protected StreamMode $streamMode = StreamMode::PARTIAL;
+ protected float $startTime;
+ protected float $tokensPerSecond = 0;
+ protected int $totalTokensProcessed = 0;
+
public static function make(): static
{
return new static();
@@ -32,13 +36,6 @@ public function setTokenizer(PreTrainedTokenizer $tokenizer): static
return $this;
}
- public function setPromptTokens(array $promptTokens): static
- {
- $this->promptTokens = $promptTokens;
- $this->nextTokensArePrompt = true;
- return $this;
- }
-
public function shouldSkipPrompt(bool $skipPrompt = true): static
{
$this->skipPrompt = $skipPrompt;
@@ -67,4 +64,8 @@ abstract public function put(mixed $value): void;
abstract public function end(): void;
+ public function getTPS(): float
+ {
+ return $this->tokensPerSecond;
+ }
}
diff --git a/src/Generation/Streamers/TextStreamer.php b/src/Generation/Streamers/TextStreamer.php
index 906e51d..88254e5 100644
--- a/src/Generation/Streamers/TextStreamer.php
+++ b/src/Generation/Streamers/TextStreamer.php
@@ -5,29 +5,30 @@
namespace Codewithkyrian\Transformers\Generation\Streamers;
use Codewithkyrian\Transformers\PreTrainedTokenizers\PreTrainedTokenizer;
+use Codewithkyrian\Transformers\Tokenizers\TokenizerModel;
+use DateTime;
use InvalidArgumentException;
+use function Codewithkyrian\Transformers\Utils\isChineseChar;
+
/**
* Simple text streamer that prints the token(s) to stdout as soon as entire words are formed.
*/
class TextStreamer extends Streamer
{
- protected string $printedText = '';
- protected StreamMode $streamMode = StreamMode::PARTIAL;
- protected int $printedLength = 0;
- protected int $lastDecodedCheckpointForToken = 0;
- protected int $lastDecodedCheckpointForText = 0;
+ private array $tokenCache = [];
+ private int $printLen = 0;
public static function make(): static
{
$streamer = parent::make();
$streamer->onStreamCallback ??= function ($value) {
- echo $value;
+ fwrite(STDOUT, $value);
};
$streamer->onStreamEndCallback ??= function () {
- echo PHP_EOL;
+ fwrite(STDOUT, PHP_EOL);
};
return $streamer;
@@ -36,61 +37,68 @@ public static function make(): static
public function put(mixed $value): void
{
if (count($value) > 1) {
- throw new InvalidArgumentException("TextStreamer only supports batch size 1");
+ throw new \Exception('TextStreamer only supports batch size of 1');
+ }
+
+ if (!isset($this->startTime)) {
+ $this->startTime = microtime(true);
}
if ($this->skipPrompt && $this->nextTokensArePrompt) {
$this->nextTokensArePrompt = false;
-// $this->printedText = $this->tokenizer->decode($this->promptTokens, skipSpecialTokens: true);
-// $this->printedLength = mb_strlen($this->printedText);
-// $this->lastDecodedCheckpointForToken = count($this->promptTokens) - 1;
-// $this->lastDecodedCheckpointForText = mb_strlen($this->printedText);
-// return;
- $prompt = $this->tokenizer->decode($this->promptTokens, skipSpecialTokens: true);
- $this->printedLength = mb_strlen($prompt);
- $this->lastDecodedCheckpointForToken = count($this->promptTokens) - 1;
return;
}
- $tokensToDecode = array_slice($value[0]['output_token_ids'], $this->lastDecodedCheckpointForToken);
-
- if (empty($tokensToDecode)) return;
-
- $decodedText = $this->tokenizer->decode($tokensToDecode, skipSpecialTokens: true);
-
- // Check for punctuation marks indicating the end of a word or sentence
- $punctuationMarks = ['.', ',', '!', '?', ';', ':'];
-
- $this->printedText = mb_substr($this->printedText, 0, $this->lastDecodedCheckpointForText)
- .($this->lastDecodedCheckpointForToken == 0 ? '' : ' ')
- .$decodedText;
-
- $newText = mb_substr($this->printedText, $this->printedLength);
+ $tokens = $value[0];
+ $this->totalTokensProcessed += count($tokens);
+
+ // Add the new token to the cache and decode the entire thing
+ $this->tokenCache = array_merge($this->tokenCache, $tokens);
+ $text = $this->tokenizer->decode($this->tokenCache, true);
+
+ if (str_ends_with($text, "\n")) {
+ // After the symbol for a new line, flush the cache.
+ $printableText = substr($text, $this->printLen);
+ $this->tokenCache = [];
+ $this->printLen = 0;
+ } elseif (strlen($text) > 0 && isChineseChar(ord($text[strlen($text) - 1]))) {
+ // If the last token is a CJK character, print the characters.
+ $printableText = substr($text, $this->printLen);
+ $this->printLen += strlen($printableText);
+ } else {
+ // Otherwise, print until the last space char (simple heuristic)
+ $lastSpaceIndex = strrpos($text, ' ');
+ $printableText = substr($text, $this->printLen, $lastSpaceIndex + 1);
+ $this->printLen += strlen($printableText);
+ }
- $this->printedLength = mb_strlen($this->printedText);
+ $elapsedTime = microtime(true) - $this->startTime;
- if (in_array(mb_substr($decodedText, -1), $punctuationMarks)) {
- $this->lastDecodedCheckpointForToken = count($value[0]['output_token_ids']);
- $this->lastDecodedCheckpointForText = mb_strlen($this->printedText);
+ if ($elapsedTime > 0) {
+ $this->tokensPerSecond = $this->totalTokensProcessed / $elapsedTime;
}
- if ($this->onStreamCallback !== null) {
- call_user_func(
- $this->onStreamCallback,
- $this->streamMode === StreamMode::PARTIAL ? $newText : $this->printedText
- );
+ if (strlen($printableText) > 0) {
+ call_user_func($this->onStreamCallback, $printableText);
}
}
public function end(): void
{
- if ($this->onStreamEndCallback !== null) {
- call_user_func($this->onStreamEndCallback, $this->printedText);
+ $printableText = '';
+ if (count($this->tokenCache) > 0) {
+ $text = $this->tokenizer->decode($this->tokenCache, true);
+ $printableText = substr($text, $this->printLen);
+ $this->tokenCache = [];
+ $this->printLen = 0;
+ }
+
+ $this->nextTokensArePrompt = true;
+
+ if (strlen($printableText) > 0) {
+ call_user_func($this->onStreamCallback, $printableText);
}
- $this->printedText = '';
- $this->printedLength = 0;
- $this->lastDecodedCheckpointForToken = 0;
- $this->lastDecodedCheckpointForText = 0;
+ call_user_func($this->onStreamEndCallback);
}
}
diff --git a/src/Generation/Streamers/WhisperTextStreamer.php b/src/Generation/Streamers/WhisperTextStreamer.php
index 516f6a6..234ef99 100644
--- a/src/Generation/Streamers/WhisperTextStreamer.php
+++ b/src/Generation/Streamers/WhisperTextStreamer.php
@@ -50,7 +50,7 @@ public function put(mixed $value): void
throw new InvalidArgumentException("WhisperTextStreamer only supports batch size 1");
}
- $tokens = $value[0]['output_token_ids'];
+ $tokens = $value[0];
if (empty($tokens)) return;
@@ -73,7 +73,7 @@ public function put(mixed $value): void
}
$lastChunk = &$this->chunksToProcess[count($this->chunksToProcess) - 1];
- $lastChunk['tokens'] = [...$value[0]['output_token_ids']];
+ $lastChunk['tokens'] = [...$value[0]];
[$decodedText, $optional] = $this->tokenizer->decodeASR($this->chunksToProcess, $this->timePrecision);
diff --git a/src/Models/Auto/AutoModel.php b/src/Models/Auto/AutoModel.php
index f7170c5..43ebf38 100644
--- a/src/Models/Auto/AutoModel.php
+++ b/src/Models/Auto/AutoModel.php
@@ -4,9 +4,9 @@
namespace Codewithkyrian\Transformers\Models\Auto;
-class AutoModel extends PretrainedMixin
+class AutoModel extends AutoModelBase
{
- const ENCODER_ONLY_MODEL_MAPPING = [
+ const ENCODER_ONLY_MODELS = [
"albert" => \Codewithkyrian\Transformers\Models\Pretrained\AlbertModel::class,
"bert" => \Codewithkyrian\Transformers\Models\Pretrained\BertModel::class,
"distilbert" => \Codewithkyrian\Transformers\Models\Pretrained\DistilBertModel::class,
@@ -18,7 +18,7 @@ class AutoModel extends PretrainedMixin
"clip" => \Codewithkyrian\Transformers\Models\Pretrained\CLIPModel::class,
"vit" => \Codewithkyrian\Transformers\Models\Pretrained\ViTModel::class,
"deit" => \Codewithkyrian\Transformers\Models\Pretrained\DeiTModel::class,
- "siglip" => \Codewithkyrian\Transformers\Models\Pretrained\SigLipModel::class,
+ "siglip" => \Codewithkyrian\Transformers\Models\Pretrained\SiglipModel::class,
"audio-spectrogram-transformer" => \Codewithkyrian\Transformers\Models\Pretrained\ASTModel::class,
"wav2vec2" => \Codewithkyrian\Transformers\Models\Pretrained\Wav2Vec2Model::class,
@@ -30,38 +30,43 @@ class AutoModel extends PretrainedMixin
'swin2sr' => \Codewithkyrian\Transformers\Models\Pretrained\Swin2SRModel::class,
];
- const ENCODER_DECODER_MODEL_MAPPING = [
+ const ENCODER_DECODER_MODELS = [
"t5" => \Codewithkyrian\Transformers\Models\Pretrained\T5Model::class,
"bart" => \Codewithkyrian\Transformers\Models\Pretrained\BartModel::class,
"m2m_100" => \Codewithkyrian\Transformers\Models\Pretrained\M2M100Model::class,
];
- const DECODER_ONLY_MODEL_MAPPING = [
+ const DECODER_ONLY_MODELS = [
"gpt2" => \Codewithkyrian\Transformers\Models\Pretrained\GPT2Model::class,
"gptj" => \Codewithkyrian\Transformers\Models\Pretrained\GPTJModel::class,
"gpt_bigcode" => \Codewithkyrian\Transformers\Models\Pretrained\GPTBigCodeModel::class,
"codegen" => \Codewithkyrian\Transformers\Models\Pretrained\CodeGenModel::class,
"llama" => \Codewithkyrian\Transformers\Models\Pretrained\LlamaModel::class,
"qwen2" => \Codewithkyrian\Transformers\Models\Pretrained\Qwen2Model::class,
+ "gemma" => \Codewithkyrian\Transformers\Models\Pretrained\GemmaModel::class,
+ "gemma2" => \Codewithkyrian\Transformers\Models\Pretrained\Gemma2Model::class,
+ "gemma3" => \Codewithkyrian\Transformers\Models\Pretrained\Gemma3Model::class,
+ "qwen3" => \Codewithkyrian\Transformers\Models\Pretrained\Qwen3Model::class,
+ "phi" => \Codewithkyrian\Transformers\Models\Pretrained\PhiModel::class,
+ "phi3" => \Codewithkyrian\Transformers\Models\Pretrained\Phi3Model::class,
];
- const MODEL_CLASS_MAPPINGS = [
- self::ENCODER_ONLY_MODEL_MAPPING,
- self::ENCODER_DECODER_MODEL_MAPPING,
- self::DECODER_ONLY_MODEL_MAPPING,
+ const MODELS = [
+ ...AutoModelForZeroShotObjectDetection::MODELS,
+ ...AutoModelForObjectDetection::MODELS,
+ ...AutoModelForVision2Seq::MODELS,
+ ...AutoModelForImageClassification::MODELS,
+ ...AutoModelForQuestionAnswering::MODELS,
+ ...AutoModelForMaskedLM::MODELS,
+ ...AutoModelForCausalLM::MODELS,
+ ...AutoModelForSeq2SeqLM::MODELS,
+ ...AutoModelForTokenClassification::MODELS,
+ ...AutoModelForSequenceClassification::MODELS,
- AutoModelForSequenceClassification::MODEL_CLASS_MAPPING,
- AutoModelForTokenClassification::MODEL_CLASS_MAPPING,
- AutoModelForSeq2SeqLM::MODEL_CLASS_MAPPING,
- AutoModelForCausalLM::MODEL_CLASS_MAPPING,
- AutoModelForMaskedLM::MODEL_CLASS_MAPPING,
- AutoModelForQuestionAnswering::MODEL_CLASS_MAPPING,
- AutoModelForImageClassification::MODEL_CLASS_MAPPING,
- AutoModelForVision2Seq::MODEL_CLASS_MAPPING,
- AutoModelForObjectDetection::MODEL_CLASS_MAPPING,
- AutoModelForZeroShotObjectDetection::MODEL_CLASS_MAPPING,
+ ...self::DECODER_ONLY_MODELS,
+ ...self::ENCODER_DECODER_MODELS,
+ ...self::ENCODER_ONLY_MODELS,
];
-
const BASE_IF_FAIL = true;
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/AutoModelBase.php b/src/Models/Auto/AutoModelBase.php
new file mode 100644
index 0000000..fe4f5bb
--- /dev/null
+++ b/src/Models/Auto/AutoModelBase.php
@@ -0,0 +1,101 @@
+> The model class mappings.
+ */
+ const MODELS = [];
+
+ /**
+ * Whether to attempt to instantiate the base class (`PretrainedModel`) if
+ * the model type is not found in the mapping.
+ */
+ const BASE_IF_FAIL = false;
+
+ /**
+ * Instantiate a model from a pretrained model configuration.
+ *
+ * @param string $modelNameOrPath The model name or path.
+ * @param bool $quantized Whether to use a quantized model.
+ * @param array|null $config The configuration for the model.
+ * @param string|null $cacheDir The cache directory to save the model in.
+ * @param string $revision The revision of the model.
+ * @param string|null $modelFilename The filename of the model.
+ * @return PretrainedModel The instantiated pretrained model.
+ */
+ public static function fromPretrained(
+ string $modelNameOrPath,
+ bool $quantized = true,
+ ?array $config = null,
+ ?string $cacheDir = null,
+ string $revision = 'main',
+ ?string $modelFilename = null,
+ ?callable $onProgress = null
+ ): PretrainedModel {
+ $config = AutoConfig::fromPretrained($modelNameOrPath, $config, $cacheDir, $revision, $onProgress);
+
+ $modelClass = static::MODELS[$config->modelType] ?? null;
+
+ if ($modelClass === null) {
+ if (static::BASE_IF_FAIL) {
+ $logger = Transformers::getLogger();
+ $logger->warning("Unknown model class for model type {$config->modelType}. Using base class PreTrainedModel.");
+
+ $modelClass = PretrainedModel::class;
+ } else {
+ throw UnsupportedModelTypeException::make($config->modelType);
+ }
+ }
+
+ $modelArchitecture = self::getModelArchitecture($modelClass);
+
+ return $modelClass::fromPretrained(
+ modelNameOrPath: $modelNameOrPath,
+ quantized: $quantized,
+ config: $config,
+ cacheDir: $cacheDir,
+ revision: $revision,
+ modelFilename: $modelFilename,
+ modelArchitecture: $modelArchitecture,
+ onProgress: $onProgress
+ );
+ }
+
+ protected static function getModelArchitecture($modelClass): ModelArchitecture
+ {
+ return match (true) {
+ in_array($modelClass, AutoModel::ENCODER_ONLY_MODELS) => ModelArchitecture::EncoderOnly,
+ in_array($modelClass, AutoModel::ENCODER_DECODER_MODELS) => ModelArchitecture::EncoderDecoder,
+ in_array($modelClass, AutoModel::DECODER_ONLY_MODELS) => ModelArchitecture::DecoderOnly,
+ in_array($modelClass, AutoModelForSequenceClassification::MODELS) => ModelArchitecture::EncoderOnly,
+ in_array($modelClass, AutoModelForSeq2SeqLM::MODELS) => ModelArchitecture::Seq2SeqLM,
+ in_array($modelClass, AutoModelForCausalLM::MODELS) => ModelArchitecture::DecoderOnly,
+ in_array($modelClass, AutoModelForTokenClassification::MODELS) => ModelArchitecture::EncoderOnly,
+ in_array($modelClass, AutoModelForQuestionAnswering::MODELS) => ModelArchitecture::EncoderOnly,
+ in_array($modelClass, AutoModelForMaskedLM::MODELS) => ModelArchitecture::EncoderOnly,
+ in_array($modelClass, AutoModelForVision2Seq::MODELS) => ModelArchitecture::Vision2Seq,
+ in_array($modelClass, AutoModelForImageClassification::MODELS) => ModelArchitecture::EncoderOnly,
+ in_array($modelClass, AutoModelForAudioClassification::MODELS) => ModelArchitecture::EncoderOnly,
+ in_array($modelClass, AutoModelForSpeechSeq2Seq::MODELS) => ModelArchitecture::Seq2SeqLM,
+ in_array($modelClass, AutoModelForCTC::MODELS) => ModelArchitecture::EncoderOnly,
+
+ default => ModelArchitecture::EncoderOnly,
+ };
+ }
+}
diff --git a/src/Models/Auto/AutoModelForAudioClassification.php b/src/Models/Auto/AutoModelForAudioClassification.php
index 70e1512..03a1c16 100644
--- a/src/Models/Auto/AutoModelForAudioClassification.php
+++ b/src/Models/Auto/AutoModelForAudioClassification.php
@@ -5,14 +5,10 @@
namespace Codewithkyrian\Transformers\Models\Auto;
-class AutoModelForAudioClassification extends PretrainedMixin
+class AutoModelForAudioClassification extends AutoModelBase
{
- const MODEL_CLASS_MAPPING = [
+ const MODELS = [
'audio-spectrogram-transformer' => \Codewithkyrian\Transformers\Models\Pretrained\ASTForAudioClassification::class,
'wav2vec2' => \Codewithkyrian\Transformers\Models\Pretrained\Wav2Vec2ForSequenceClassification::class,
];
-
- const MODEL_CLASS_MAPPINGS = [
- self::MODEL_CLASS_MAPPING,
- ];
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/AutoModelForCTC.php b/src/Models/Auto/AutoModelForCTC.php
index ce2372c..8bca399 100644
--- a/src/Models/Auto/AutoModelForCTC.php
+++ b/src/Models/Auto/AutoModelForCTC.php
@@ -5,13 +5,9 @@
namespace Codewithkyrian\Transformers\Models\Auto;
-class AutoModelForCTC extends PretrainedMixin
+class AutoModelForCTC extends AutoModelBase
{
- const MODEL_CLASS_MAPPING = [
+ const MODELS = [
'wav2vec2' => \Codewithkyrian\Transformers\Models\Pretrained\Wav2Vec2ForCTC::class,
];
-
- const MODEL_CLASS_MAPPINGS = [
- self::MODEL_CLASS_MAPPING,
- ];
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/AutoModelForCausalLM.php b/src/Models/Auto/AutoModelForCausalLM.php
index fd587b4..053da34 100644
--- a/src/Models/Auto/AutoModelForCausalLM.php
+++ b/src/Models/Auto/AutoModelForCausalLM.php
@@ -2,22 +2,23 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Auto;
-class AutoModelForCausalLM extends PretrainedMixin
+class AutoModelForCausalLM extends AutoModelBase
{
- const MODEL_CLASS_MAPPING = [
+ const MODELS = [
'gpt2' => \Codewithkyrian\Transformers\Models\Pretrained\GPT2LMHeadModel::class,
'gptj' => \Codewithkyrian\Transformers\Models\Pretrained\GPTJForCausalLM::class,
'gpt_bigcode' => \Codewithkyrian\Transformers\Models\Pretrained\GPTBigCodeForCausalLM::class,
'codegen' => \Codewithkyrian\Transformers\Models\Pretrained\CodeGenForCausalLM::class,
'llama' => \Codewithkyrian\Transformers\Models\Pretrained\LlamaForCausalLM::class,
'trocr' => \Codewithkyrian\Transformers\Models\Pretrained\TrOCRForCausalLM::class,
- 'qwen2' => \Codewithkyrian\Transformers\Models\Pretrained\Qwen2ForCausalLM::class
- ];
-
- const MODEL_CLASS_MAPPINGS = [
- self::MODEL_CLASS_MAPPING,
+ 'qwen2' => \Codewithkyrian\Transformers\Models\Pretrained\Qwen2ForCausalLM::class,
+ 'gemma' => \Codewithkyrian\Transformers\Models\Pretrained\GemmaForCausalLM::class,
+ 'gemma2' => \Codewithkyrian\Transformers\Models\Pretrained\Gemma2ForCausalLM::class,
+ 'gemma3' => \Codewithkyrian\Transformers\Models\Pretrained\Gemma3ForCausalLM::class,
+ 'qwen3' => \Codewithkyrian\Transformers\Models\Pretrained\Qwen3ForCausalLM::class,
+ 'phi' => \Codewithkyrian\Transformers\Models\Pretrained\PhiForCausalLM::class,
+ 'phi3' => \Codewithkyrian\Transformers\Models\Pretrained\Phi3ForCausalLM::class,
];
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/AutoModelForImageClassification.php b/src/Models/Auto/AutoModelForImageClassification.php
index 51b46df..edd205c 100644
--- a/src/Models/Auto/AutoModelForImageClassification.php
+++ b/src/Models/Auto/AutoModelForImageClassification.php
@@ -2,17 +2,12 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Auto;
-class AutoModelForImageClassification extends PretrainedMixin
+class AutoModelForImageClassification extends AutoModelBase
{
- const MODEL_CLASS_MAPPING = [
+ const MODELS = [
'vit' => \Codewithkyrian\Transformers\Models\Pretrained\ViTForImageClassification::class,
'deit' => \Codewithkyrian\Transformers\Models\Pretrained\DeiTForImageClassification::class,
];
-
- const MODEL_CLASS_MAPPINGS = [
- self::MODEL_CLASS_MAPPING,
- ];
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/AutoModelForImageFeatureExtraction.php b/src/Models/Auto/AutoModelForImageFeatureExtraction.php
index ccb7b02..6868873 100644
--- a/src/Models/Auto/AutoModelForImageFeatureExtraction.php
+++ b/src/Models/Auto/AutoModelForImageFeatureExtraction.php
@@ -5,16 +5,10 @@
namespace Codewithkyrian\Transformers\Models\Auto;
-class AutoModelForImageFeatureExtraction extends PretrainedMixin
+class AutoModelForImageFeatureExtraction extends AutoModelBase
{
- const MODEL_CLASS_MAPPING = [
+ const MODELS = [
'clip' => \Codewithkyrian\Transformers\Models\Pretrained\CLIPVisionModelWithProjection::class,
'siglip' => \Codewithkyrian\Transformers\Models\Pretrained\SiglipVisionModel::class,
];
-
- const MODEL_CLASS_MAPPINGS = [
- self::MODEL_CLASS_MAPPING,
- AutoModel::ENCODER_ONLY_MODEL_MAPPING,
- AutoModel::DECODER_ONLY_MODEL_MAPPING,
- ];
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/AutoModelForImageToImage.php b/src/Models/Auto/AutoModelForImageToImage.php
index fb10b7c..b65e850 100644
--- a/src/Models/Auto/AutoModelForImageToImage.php
+++ b/src/Models/Auto/AutoModelForImageToImage.php
@@ -5,13 +5,9 @@
namespace Codewithkyrian\Transformers\Models\Auto;
-class AutoModelForImageToImage extends PretrainedMixin
+class AutoModelForImageToImage extends AutoModelBase
{
- const MODEL_CLASS_MAPPING = [
+ const MODELS = [
'swin2sr' => \Codewithkyrian\Transformers\Models\Pretrained\Swin2SRForImageSuperResolution::class,
];
-
- const MODEL_CLASS_MAPPINGS = [
- self::MODEL_CLASS_MAPPING,
- ];
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/AutoModelForMaskedLM.php b/src/Models/Auto/AutoModelForMaskedLM.php
index 8aa8f16..92a717c 100644
--- a/src/Models/Auto/AutoModelForMaskedLM.php
+++ b/src/Models/Auto/AutoModelForMaskedLM.php
@@ -2,12 +2,11 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Auto;
-class AutoModelForMaskedLM extends PretrainedMixin
+class AutoModelForMaskedLM extends AutoModelBase
{
- const MODEL_CLASS_MAPPING = [
+ const MODELS = [
"albert" => \Codewithkyrian\Transformers\Models\Pretrained\AlbertForMaskedLM::class,
"bert" => \Codewithkyrian\Transformers\Models\Pretrained\BertForMaskedLM::class,
"deberta" => \Codewithkyrian\Transformers\Models\Pretrained\DebertaForMaskedLM::class,
@@ -17,8 +16,4 @@ class AutoModelForMaskedLM extends PretrainedMixin
"roberta" => \Codewithkyrian\Transformers\Models\Pretrained\RobertaForMaskedLM::class,
"roformer" => \Codewithkyrian\Transformers\Models\Pretrained\RoFormerForMaskedLM::class,
];
-
- const MODEL_CLASS_MAPPINGS = [
- self::MODEL_CLASS_MAPPING,
- ];
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/AutoModelForObjectDetection.php b/src/Models/Auto/AutoModelForObjectDetection.php
index 72520e1..8b41f2b 100644
--- a/src/Models/Auto/AutoModelForObjectDetection.php
+++ b/src/Models/Auto/AutoModelForObjectDetection.php
@@ -2,18 +2,12 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Auto;
-class AutoModelForObjectDetection extends PretrainedMixin
+class AutoModelForObjectDetection extends AutoModelBase
{
- const MODEL_CLASS_MAPPING = [
+ const MODELS = [
'detr' => \Codewithkyrian\Transformers\Models\Pretrained\DetrForObjectDetection::class,
'yolos' => \Codewithkyrian\Transformers\Models\Pretrained\YolosForObjectDetection::class,
];
-
- const MODEL_CLASS_MAPPINGS = [
- self::MODEL_CLASS_MAPPING,
- ];
-
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/AutoModelForQuestionAnswering.php b/src/Models/Auto/AutoModelForQuestionAnswering.php
index 700f4f6..5bb2a1e 100644
--- a/src/Models/Auto/AutoModelForQuestionAnswering.php
+++ b/src/Models/Auto/AutoModelForQuestionAnswering.php
@@ -2,12 +2,11 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Auto;
-class AutoModelForQuestionAnswering extends PretrainedMixin
+class AutoModelForQuestionAnswering extends AutoModelBase
{
- const MODEL_CLASS_MAPPING = [
+ const MODELS = [
'albert' => \Codewithkyrian\Transformers\Models\Pretrained\AlbertForQuestionAnswering::class,
'bert' => \Codewithkyrian\Transformers\Models\Pretrained\BertForQuestionAnswering::class,
'deberta' => \Codewithkyrian\Transformers\Models\Pretrained\DebertaForQuestionAnswering::class,
@@ -17,8 +16,4 @@ class AutoModelForQuestionAnswering extends PretrainedMixin
'roberta' => \Codewithkyrian\Transformers\Models\Pretrained\RobertaForQuestionAnswering::class,
'roformer' => \Codewithkyrian\Transformers\Models\Pretrained\RoFormerForQuestionAnswering::class,
];
-
- const MODEL_CLASS_MAPPINGS = [
- self::MODEL_CLASS_MAPPING,
- ];
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/AutoModelForSeq2SeqLM.php b/src/Models/Auto/AutoModelForSeq2SeqLM.php
index 9866e61..1c5de1b 100644
--- a/src/Models/Auto/AutoModelForSeq2SeqLM.php
+++ b/src/Models/Auto/AutoModelForSeq2SeqLM.php
@@ -4,15 +4,11 @@
namespace Codewithkyrian\Transformers\Models\Auto;
-class AutoModelForSeq2SeqLM extends PretrainedMixin
+class AutoModelForSeq2SeqLM extends AutoModelBase
{
- const MODEL_CLASS_MAPPING = [
+ const MODELS = [
'bart' => \Codewithkyrian\Transformers\Models\Pretrained\BartForConditionalGeneration::class,
't5' => \Codewithkyrian\Transformers\Models\Pretrained\T5ForConditionalGeneration::class,
'm2m_100' => \Codewithkyrian\Transformers\Models\Pretrained\M2M100ForConditionalGeneration::class,
];
-
- const MODEL_CLASS_MAPPINGS = [
- self::MODEL_CLASS_MAPPING,
- ];
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/AutoModelForSequenceClassification.php b/src/Models/Auto/AutoModelForSequenceClassification.php
index fc77579..68eaba6 100644
--- a/src/Models/Auto/AutoModelForSequenceClassification.php
+++ b/src/Models/Auto/AutoModelForSequenceClassification.php
@@ -2,13 +2,11 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Auto;
-
-class AutoModelForSequenceClassification extends PretrainedMixin
+class AutoModelForSequenceClassification extends AutoModelBase
{
- const MODEL_CLASS_MAPPING = [
+ const MODELS = [
'albert' => \Codewithkyrian\Transformers\Models\Pretrained\AlbertForSequenceClassification::class,
'bert' => \Codewithkyrian\Transformers\Models\Pretrained\BertForSequenceClassification::class,
'bart' => \Codewithkyrian\Transformers\Models\Pretrained\BartForSequenceClassification::class,
@@ -19,8 +17,4 @@ class AutoModelForSequenceClassification extends PretrainedMixin
'roberta' => \Codewithkyrian\Transformers\Models\Pretrained\RobertaForSequenceClassification::class,
'roformer' => \Codewithkyrian\Transformers\Models\Pretrained\RoFormerForSequenceClassification::class,
];
-
- const MODEL_CLASS_MAPPINGS = [
- self::MODEL_CLASS_MAPPING,
- ];
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/AutoModelForSpeechSeq2Seq.php b/src/Models/Auto/AutoModelForSpeechSeq2Seq.php
index 848fe71..ae96b03 100644
--- a/src/Models/Auto/AutoModelForSpeechSeq2Seq.php
+++ b/src/Models/Auto/AutoModelForSpeechSeq2Seq.php
@@ -5,13 +5,9 @@
namespace Codewithkyrian\Transformers\Models\Auto;
-class AutoModelForSpeechSeq2Seq extends PretrainedMixin
+class AutoModelForSpeechSeq2Seq extends AutoModelBase
{
- const MODEL_CLASS_MAPPING = [
+ const MODELS = [
"whisper" => \Codewithkyrian\Transformers\Models\Pretrained\WhisperForConditionalGeneration::class,
];
-
- const MODEL_CLASS_MAPPINGS = [
- self::MODEL_CLASS_MAPPING,
- ];
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/AutoModelForTokenClassification.php b/src/Models/Auto/AutoModelForTokenClassification.php
index 26bb1ee..46bff82 100644
--- a/src/Models/Auto/AutoModelForTokenClassification.php
+++ b/src/Models/Auto/AutoModelForTokenClassification.php
@@ -2,20 +2,15 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Auto;
-class AutoModelForTokenClassification extends PretrainedMixin
+class AutoModelForTokenClassification extends AutoModelBase
{
- const MODEL_CLASS_MAPPING = [
+ const MODELS = [
"bert" => \Codewithkyrian\Transformers\Models\Pretrained\BertForTokenClassification::class,
"deberta" => \Codewithkyrian\Transformers\Models\Pretrained\DebertaForTokenClassification::class,
"deberta-v2" => \Codewithkyrian\Transformers\Models\Pretrained\DebertaV2ForTokenClassification::class,
"roberta" => \Codewithkyrian\Transformers\Models\Pretrained\RobertaForTokenClassification::class,
'roformer' => \Codewithkyrian\Transformers\Models\Pretrained\RoFormerForTokenClassification::class,
];
-
- const MODEL_CLASS_MAPPINGS = [
- self::MODEL_CLASS_MAPPING,
- ];
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/AutoModelForVision2Seq.php b/src/Models/Auto/AutoModelForVision2Seq.php
index 712ac6d..3754cde 100644
--- a/src/Models/Auto/AutoModelForVision2Seq.php
+++ b/src/Models/Auto/AutoModelForVision2Seq.php
@@ -2,16 +2,11 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Auto;
-class AutoModelForVision2Seq extends PretrainedMixin
+class AutoModelForVision2Seq extends AutoModelBase
{
- const MODEL_CLASS_MAPPING = [
+ const MODELS = [
'vision-encoder-decoder' => \Codewithkyrian\Transformers\Models\Pretrained\VisionEncoderDecoderModel::class
];
-
- const MODEL_CLASS_MAPPINGS = [
- self::MODEL_CLASS_MAPPING,
- ];
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/AutoModelForZeroShotObjectDetection.php b/src/Models/Auto/AutoModelForZeroShotObjectDetection.php
index a152bda..cde3e04 100644
--- a/src/Models/Auto/AutoModelForZeroShotObjectDetection.php
+++ b/src/Models/Auto/AutoModelForZeroShotObjectDetection.php
@@ -2,18 +2,12 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Auto;
-class AutoModelForZeroShotObjectDetection extends PretrainedMixin
+class AutoModelForZeroShotObjectDetection extends AutoModelBase
{
- const MODEL_CLASS_MAPPING = [
+ const MODELS = [
'owlvit' => \Codewithkyrian\Transformers\Models\Pretrained\OwlViTForObjectDetection::class,
'owlv2' => \Codewithkyrian\Transformers\Models\Pretrained\Owlv2ForObjectDetection::class,
];
-
- const MODEL_CLASS_MAPPINGS = [
- self::MODEL_CLASS_MAPPING,
- ];
-
-}
\ No newline at end of file
+}
diff --git a/src/Models/Auto/PretrainedMixin.php b/src/Models/Auto/PretrainedMixin.php
deleted file mode 100644
index cb71e63..0000000
--- a/src/Models/Auto/PretrainedMixin.php
+++ /dev/null
@@ -1,114 +0,0 @@
-> The model class mappings.
- */
- const MODEL_CLASS_MAPPINGS = [];
-
- /**
- * Whether to attempt to instantiate the base class (`PretrainedModel`) if
- * the model type is not found in the mapping.
- */
- const BASE_IF_FAIL = false;
-
- /**
- * Instantiate a model from a pretrained model configuration.
- *
- * @param string $modelNameOrPath The model name or path.
- * @param bool $quantized Whether to use a quantized model.
- * @param array|null $config The configuration for the model.
- * @param string|null $cacheDir The cache directory to save the model in.
- * @param string $revision The revision of the model.
- * @param string|null $modelFilename The filename of the model.
- *
- * @return PretrainedModel The instantiated pretrained model.
- */
- public static function fromPretrained(
- string $modelNameOrPath,
- bool $quantized = true,
- ?array $config = null,
- ?string $cacheDir = null,
- string $revision = 'main',
- ?string $modelFilename = null,
- ?callable $onProgress = null
- ): PretrainedModel
- {
- $config = AutoConfig::fromPretrained($modelNameOrPath, $config, $cacheDir, $revision, $onProgress);
-
- foreach (static::MODEL_CLASS_MAPPINGS as $modelClassMapping) {
- $modelClass = $modelClassMapping[$config->modelType] ?? null;
-
- if ($modelClass === null) continue;
-
- $modelArchitecture = self::getModelArchitecture($modelClass);
-
- return $modelClass::fromPretrained(
- modelNameOrPath: $modelNameOrPath,
- quantized: $quantized,
- config: $config,
- cacheDir: $cacheDir,
- revision: $revision,
- modelFilename: $modelFilename,
- modelArchitecture: $modelArchitecture,
- onProgress: $onProgress
- );
- }
-
- if (static::BASE_IF_FAIL) {
- Transformers::getLogger()?->warning("Unknown model class for model type {$config->modelType}. Using base class PreTrainedModel.");
-
- return PretrainedModel::fromPretrained(
- modelNameOrPath: $modelNameOrPath,
- quantized: $quantized,
- config: $config,
- cacheDir: $cacheDir,
- revision: $revision,
- modelFilename: $modelFilename,
- onProgress: $onProgress
- );
- } else {
- throw UnsupportedModelTypeException::make($config->modelType);
- }
- }
-
- protected static function getModelArchitecture($modelClass): ModelArchitecture
- {
- return match (true) {
- in_array($modelClass, AutoModel::ENCODER_ONLY_MODEL_MAPPING) => ModelArchitecture::EncoderOnly,
- in_array($modelClass, AutoModel::ENCODER_DECODER_MODEL_MAPPING) => ModelArchitecture::EncoderDecoder,
- in_array($modelClass, AutoModel::DECODER_ONLY_MODEL_MAPPING) => ModelArchitecture::DecoderOnly,
- in_array($modelClass, AutoModelForSequenceClassification::MODEL_CLASS_MAPPING) => ModelArchitecture::EncoderOnly,
- in_array($modelClass, AutoModelForSeq2SeqLM::MODEL_CLASS_MAPPING) => ModelArchitecture::Seq2SeqLM,
- in_array($modelClass, AutoModelForCausalLM::MODEL_CLASS_MAPPING) => ModelArchitecture::DecoderOnly,
- in_array($modelClass, AutoModelForTokenClassification::MODEL_CLASS_MAPPING) => ModelArchitecture::EncoderOnly,
- in_array($modelClass, AutoModelForQuestionAnswering::MODEL_CLASS_MAPPING) => ModelArchitecture::EncoderOnly,
- in_array($modelClass, AutoModelForMaskedLM::MODEL_CLASS_MAPPING) => ModelArchitecture::EncoderOnly,
- in_array($modelClass, AutoModelForVision2Seq::MODEL_CLASS_MAPPING) => ModelArchitecture::Vision2Seq,
- in_array($modelClass, AutoModelForImageClassification::MODEL_CLASS_MAPPING) => ModelArchitecture::EncoderOnly,
- in_array($modelClass, AutoModelForAudioClassification::MODEL_CLASS_MAPPING) => ModelArchitecture::EncoderOnly,
- in_array($modelClass, AutoModelForSpeechSeq2Seq::MODEL_CLASS_MAPPING) => ModelArchitecture::Seq2SeqLM,
- in_array($modelClass, AutoModelForCTC::MODEL_CLASS_MAPPING) => ModelArchitecture::EncoderOnly,
-
- default => ModelArchitecture::EncoderOnly,
- };
- }
-}
diff --git a/src/Models/ModelArchitecture.php b/src/Models/ModelArchitecture.php
index b20cfc7..f602ad5 100644
--- a/src/Models/ModelArchitecture.php
+++ b/src/Models/ModelArchitecture.php
@@ -4,12 +4,11 @@
namespace Codewithkyrian\Transformers\Models;
-use Codewithkyrian\Transformers\Exceptions\MissingModelInputException;
-use Codewithkyrian\Transformers\Exceptions\ModelExecutionException;
use Codewithkyrian\Transformers\Models\Pretrained\PretrainedModel;
use Codewithkyrian\Transformers\Tensor\Tensor;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
-use Interop\Polite\Math\Matrix\NDArray;
+
+use function Codewithkyrian\Transformers\Utils\array_pick;
+use function Codewithkyrian\Transformers\Utils\array_pop_key;
enum ModelArchitecture: string
{
@@ -21,8 +20,6 @@ enum ModelArchitecture: string
case MaskGeneration = 'MaskGeneration';
- //
-
public function canGenerate(): bool
{
return match ($this) {
@@ -31,36 +28,11 @@ public function canGenerate(): bool
};
}
- public function runBeam(PretrainedModel $model, array &$beam): array
- {
- return match ($this) {
- self::DecoderOnly => $this->decoderRunBeam($model, $beam),
- self::Seq2SeqLM, self::Vision2Seq => $this->seq2seqRunBeam($model, $beam),
- default => throw new \Error('This model type does not support beam search'),
- };
- }
-
- public function startBeams(
- PretrainedModel $model,
- Tensor $inputTokenIds,
- GenerationConfig $generationConfig,
- int $numOutputTokens,
- Tensor $inputsAttentionMask = null
- ): array
+ public function prepareInputsForGeneration(PretrainedModel $model, $inputIds, array $modelInputs): array
{
return match ($this) {
- self::DecoderOnly => $this->decoderStartBeams($model, $inputTokenIds, $generationConfig, $numOutputTokens, $inputsAttentionMask),
- self::Seq2SeqLM, self::Vision2Seq => $this->seq2seqStartBeams($model, $inputTokenIds, $generationConfig, $numOutputTokens),
- default => throw new \Error('This model type does not support beam search'),
- };
- }
-
- public function updateBeam(array &$beam, int $newTokenId): void
- {
- match ($this) {
- self::DecoderOnly => $this->decoderUpdatebeam($beam, $newTokenId),
- self::Seq2SeqLM, self::Vision2Seq => $this->seq2seqUpdatebeam($beam, $newTokenId),
- default => throw new \Error('This model type does not support beam search'),
+ self::DecoderOnly => $this->decoderPrepareInputsForGeneration($model, $inputIds, $modelInputs),
+ self::Seq2SeqLM, self::Vision2Seq => $this->encoderDecoderPrepareInputsForGeneration($model, $inputIds, $modelInputs),
};
}
@@ -69,318 +41,176 @@ public function forward(PretrainedModel $model, array $modelInputs): array
return match ($this) {
self::EncoderOnly => $this->encoderForward($model, $modelInputs),
self::DecoderOnly => $this->decoderForward($model, $modelInputs),
- self::Seq2SeqLM, self::Vision2Seq => $this->seq2seqForward($model, $modelInputs),
+ self::Seq2SeqLM, self::Vision2Seq, self::EncoderDecoder => $this->seq2seqForward($model, $modelInputs),
default => throw new \Error('This model type does not have a forward method'),
};
}
- //
+ function encoderDecoderPrepareInputsForGeneration(PretrainedModel $model, $inputIds, array $modelInputs): array
+ {
+ if (isset($modelInputs['past_key_values'])) {
+ $inputIds = array_map(fn($x) => [array_slice($x, -1)[0]], $inputIds);
+ }
- //
+ return array_merge(
+ $modelInputs,
+ ['decoder_input_ids' => Tensor::fromArray($inputIds)]
+ );
+ }
- protected function encoderForward(PretrainedModel $model, array $modelInputs): array
+ public function encoderForward(PretrainedModel $model, array $modelInputs): array
{
- $encoderFeeds = [];
+ $inputNames = array_column($model->sessions['encoder']->inputs(), 'name');
- $inputNames = array_column($model->session->inputs(), 'name');
+ $encoderFeeds = array_pick($modelInputs, $inputNames);
- foreach ($inputNames as $inputName) {
- $encoderFeeds[$inputName] = $modelInputs[$inputName];
- }
+ if (in_array('inputs_embeds', $inputNames) && !isset($encoderFeeds['inputs_embeds'])) {
+ if (!isset($modelInputs['input_ids'])) {
+ throw new \Exception('Both `input_ids` and `inputs_embeds` are missing in the model inputs.');
+ }
- $hasTokenTypeIds = in_array('token_type_ids', $inputNames);
+ $encoderFeeds['inputs_embeds'] = $model->encodeText(['input_ids' => $modelInputs['input_ids']]);
+ }
- if ($hasTokenTypeIds) {
+ if (in_array('token_type_ids', $inputNames)) {
// Assign default `token_type_ids` (all zeroes) to the `encoderFeeds` if the model expects it,
// but they weren't created by the tokenizer.
$encoderFeeds['token_type_ids'] ??= Tensor::zerosLike($encoderFeeds['input_ids']);
}
- return $model->runSession($model->session, $encoderFeeds);
+ return $model->runSession($model->sessions['encoder'], $encoderFeeds);
}
- //
-
- //
-
- /**
- * Runs a single step of the text generation process for a given beam.
- * @param PretrainedModel $model The text generation model object.
- * @param array $beam The beam to run the generation process for.
- * @return array The output of the generation process for the given beam.
- */
- protected function decoderRunBeam(PretrainedModel $model, array &$beam): array
+ function decoderPrepareInputsForGeneration(PretrainedModel $model, $inputIds, array $modelInputs): array
{
- $attnMaskLength = count($beam['output_token_ids']);
- $attnMaskData = array_fill(0, $attnMaskLength, 1);
-
- // 1. Prepare
- $modelInputs = [
- 'input_ids' => $beam['model_input_ids'],
- 'attention_mask' => new Tensor($attnMaskData, Tensor::int64, [1, $attnMaskLength]),
- 'past_key_values' => $beam['prev_model_outputs']['past_key_values'] ?? null,
- ];
-
-
- // 2. Run
- $output = $model->forward($modelInputs);
-
- // 3. Update
- $beam['prev_model_outputs'] = $output;
-
- return $output;
- }
-
- /** Starts the generation of text by initializing the beams for the given input token IDs.
- * @param PretrainedModel $model The text generation model object.
- * @param Tensor $inputTokenIds A tensor of input token IDs to generate text from.
- * @param GenerationConfig $generationConfig The generation config.
- * @param int $numOutputTokens The maximum number of tokens to generate for each beam.
- * @param Tensor|null $inputsAttentionMask The attention mask tensor for the input token IDs.
- * @return array An array of beams initialized with the given inputs and parameters.
- */
- protected function decoderStartBeams(
- PretrainedModel $model,
- Tensor $inputTokenIds,
- GenerationConfig $generationConfig,
- int $numOutputTokens,
- Tensor $inputsAttentionMask = null
- ): array
- {
- $beams = [];
- $beamId = 0;
-
- foreach ($inputTokenIds as $tokens) {
- $outputTokenIds = array_map('intval', $tokens->toArray());
-
- // TODO: Improve for parallel execution
- $tokens = $tokens->reshape([1, ...$tokens->shape()]);
-
- $attnMask = null;
- if ($inputsAttentionMask !== null) {
- $attnMask = $inputsAttentionMask[$beamId];
- $attnMask = $attnMask->reshape([1, ...$attnMask->shape()]);
- } else {
- $attnMask = $model->prepareAttentionMask($tokens);
+ if (isset($modelInputs['past_key_values'])) {
+ $pastKeyValues = $modelInputs['past_key_values'];
+ $pkvShape = array_values($pastKeyValues)[0]->shape();
+ $pastLength = $pkvShape[count($pkvShape) - 2];
+ $inputIds = $modelInputs['input_ids'];
+ $attentionMask = $modelInputs['attention_mask'] ?? null;
+
+ // Case 1: Attention mask is longer than input IDs
+ if ($attentionMask && $attentionMask->shape()[1] > $inputIds->shape()[1]) {
+ // This is not required for this implementation as the tokens passed are already handled.
+ } // Case 2: Past length < Input IDs
+ elseif ($pastLength < $inputIds->shape()[1]) {
+ // Only keep the unprocessed tokens
+ $modelInputs['input_ids'] = $inputIds->slice(null, [$pastLength, null]);
+ } // Case 3: Past length >= Input IDs
+ else {
+ if (
+ isset($model->config['image_token_index']) &&
+ in_array($model->config['image_token_index'], $inputIds->toArray())
+ ) {
+ // Support for multiple image tokens
+ $numImageTokens = $model->config['num_image_tokens'] ?? null;
+ if (!$numImageTokens) {
+ throw new \Exception('`num_image_tokens` is missing in the model configuration.');
+ }
+
+ $numNewTokens = $inputIds->shape()[1] - ($pastLength - $numImageTokens);
+ $modelInputs['input_ids'] = $inputIds->slice(null, [-$numNewTokens, null]);
+
+ // Create the attention mask from scratch
+ $modelInputs['attention_mask'] = Tensor::ones([1, $pastLength + $numNewTokens], Tensor::int64);
+ }
}
-
- $start = [
- 'input' => $tokens,
- 'model_input_ids' => $tokens,
- 'attention_mask' => $attnMask,
- 'prev_model_outputs' => null,
-
- 'output_token_ids' => $outputTokenIds,
- 'num_output_tokens' => $numOutputTokens,
-
- 'done' => false,
- 'score' => 0,
- 'id' => $beamId++ // assign unique id to beams
- ];
-
- $beams[] = $start;
}
- return $beams;
+ return $modelInputs;
}
- /**
- * Update a beam with a new token ID.
- * @param array $beam The beam to update.
- * @param int $newTokenId The new token ID to add to the beam.
- * @return void
- */
- protected function decoderUpdatebeam(array &$beam, int $newTokenId): void
- {
- $beam['output_token_ids'][] = $newTokenId;
- $beam['model_input_ids'] = new Tensor([$newTokenId], NDArray::int64, [1, 1]);
- }
-
- /**
- * Forward pass for the decoder model.
- * @param PretrainedModel $model The model to use for the forward pass.
- * @param array $modelInputs The inputs to the model.
- * @return array The output of the forward pass.
- * @throws MissingModelInputException|ModelExecutionException
- */
protected function decoderForward(PretrainedModel $model, array $modelInputs): array
{
- ['input_ids' => $inputIds, 'past_key_values' => $pastKeyValues, 'attention_mask' => $attentionMask]
- = $modelInputs;
-
+ $session = $model->sessions['decoder'];
- $decoderFeeds = [
- 'input_ids' => $inputIds,
- 'attention_mask' => $attentionMask ?? $model->prepareAttentionMask($inputIds),
- ];
+ $inputNames = array_column($session->inputs(), 'name');
- $useCacheBranch = !!$pastKeyValues;
-
- $inputNames = array_column($model->session->inputs(), 'name');
+ $pastKeyValues = array_pop_key($modelInputs, 'past_key_values');
if (in_array('use_cache_branch', $inputNames)) {
- $decoderFeeds['use_cache_branch'] = new Tensor([$useCacheBranch], Tensor::bool, [1]);
+ $modelInputs['use_cache_branch'] = new Tensor([!empty($pastKeyValues)], Tensor::bool, [1]);
}
- $model->preparePositionIds($inputNames, $decoderFeeds, $useCacheBranch);
- $model->addPastKeyValues($decoderFeeds, $pastKeyValues);
-
- $decoderResults = $model->runSession($model->session, $decoderFeeds);
+ if (
+ in_array('position_ids', $inputNames) &&
+ isset($modelInputs['attention_mask']) &&
+ !isset($modelInputs['position_ids'])
+ ) {
+ $modelInputs['position_ids'] = $this->createPositionIds($modelInputs, $pastKeyValues);
+ }
- $logits = $decoderResults['logits'];
+ $model->addPastKeyValues($modelInputs, $pastKeyValues);
- $pastKeyValues = $model->getPastKeyValues($decoderResults, $pastKeyValues);
+ $decoderFeeds = array_pick($modelInputs, $inputNames);
- return ['logits' => $logits, 'past_key_values' => $pastKeyValues];
+ return $model->runSession($session, $decoderFeeds);
}
- //
-
- //
-
- protected function seq2seqRunBeam(PretrainedModel $model, array &$beam): array
+ protected function seq2seqForward(PretrainedModel $model, array $modelInputs): array
{
- $inputName = $model->mainInputName;
-
- $decoderInputIds = $beam['output_token_ids'];
-
- if ($beam['prev_model_outputs']) {
- // After the first step, `prev_model_outputs` won't be null.
- // So, we cut decoder_input_ids if past is used
- $decoderInputIds = array_slice($decoderInputIds, -1);
+ $decoderFeeds = $modelInputs;
+ $encoderOutputs = array_pop_key($decoderFeeds, 'encoder_outputs');
+ $decoderInputIds = array_pop_key($decoderFeeds, 'decoder_input_ids');
+
+ if (!$encoderOutputs) {
+ $inputNames = array_column($model->sessions['encoder']->inputs(), 'name');
+ $encoderInputs = array_pick($modelInputs, $inputNames);
+ $encoderOutputs = $this->encoderForward($model, $encoderInputs)['last_hidden_state'];
}
- // 1. Prepare
- $modelInputs = [
- $inputName => $beam['inputs'],
- 'decoder_input_ids' => new Tensor($decoderInputIds, Tensor::int64, [1, count($decoderInputIds)]),
- 'encoder_outputs' => $beam['encoder_outputs'],
- 'past_key_values' => $beam['prev_model_outputs']['past_key_values'] ?? null,
- ];
+ $decoderFeeds['input_ids'] = $decoderInputIds;
+ $decoderFeeds['encoder_hidden_states'] = $encoderOutputs;
+ $inputNames = array_column($model->sessions['decoder']->inputs(), 'name');
- if (isset($beam['attention_mask'])) {
- $modelInputs['attention_mask'] = $beam['attention_mask'];
+ if (in_array('encoder_attention_mask', $inputNames)) {
+ $decoderFeeds['encoder_attention_mask'] = $modelInputs['attention_mask'];
}
- // 2. Run
- $output = $model->forward($modelInputs);
-
- // 3. Update
- $beam['prev_model_outputs'] = $output;
- $beam['encoder_outputs'] = $output['encoder_outputs'];
-
- return $output;
+ return $this->decoderForward($model, $decoderFeeds);
}
- /** Start the beam search process for the seq2seq model.
- * @param PretrainedModel $model The model to use for the beam search.
- * @param Tensor $inputTokenIds Array of input token ids for each input sequence.
- * @param GenerationConfig $generationConfig The generation configuration.
- * @param int $numOutputTokens The maximum number of output tokens for the model.
- * @return array Array of beam search objects.
+ /**
+ * Create position IDs based on the attention mask.
+ *
+ * @param array{input_ids: Tensor, inputs_embeds: Tensor, attention_mask: Tensor} $modelInputs
+ * @param array|null $pastKeyValues
+ * @return Tensor
*/
- protected function seq2seqStartBeams(
- PretrainedModel $model,
- Tensor $inputTokenIds,
- GenerationConfig $generationConfig,
- int $numOutputTokens,
- ): array
+ protected function createPositionIds(array $modelInputs, ?array $pastKeyValues = null): Tensor
{
- $beams = [];
- $beamId = 0;
-
- $requiresAttentionMask = !property_exists($model, 'requiresAttentionMask') || $model->requiresAttentionMask;
-
- $decoder_input_ids = $generationConfig->decoder_input_ids
- ?? $generationConfig->decoder_start_token_id
- ?? $generationConfig->bos_token_id
- ?? $generationConfig->eos_token_id;
-
- // TODO support batched decoder_input_ids
- if (!is_array($decoder_input_ids)) {
- $decoder_input_ids = [$decoder_input_ids];
- }
-
- foreach ($inputTokenIds as $tokens) {
- // TODO: Improve
- // Currently, just add back batch dimension.
- // In future, allow for true parallel execution
- $tokens = $tokens->reshape([1, ...$tokens->shape()]);
-
- // Create beam
- $start = [
- 'inputs' => $tokens,
- 'encoder_outputs' => null,
- 'prev_model_outputs' => null,
- 'output_token_ids' => $decoder_input_ids,
- 'done' => false,
- 'score' => 0,
- 'id' => $beamId++, // assign unique id to beams
- ];
-
- if ($requiresAttentionMask) {
- $start['attention_mask'] = $model->prepareAttentionMask($tokens);
+ $inputIds = $modelInputs['input_ids'] ?? null;
+ $inputsEmbeds = $modelInputs['inputs_embeds'] ?? null;
+ $attentionMask = $modelInputs['attention_mask'];
+
+ [$batchSize, $seqLen] = $attentionMask->shape();
+
+ $data = array_fill(0, $attentionMask->size(), 0);
+
+ for ($i = 0; $i < $batchSize; ++$i) {
+ $start = $i * $seqLen;
+ $sum = 0;
+
+ for ($j = 0; $j < $seqLen; ++$j) {
+ $index = $start + $j;
+ if ($attentionMask->buffer()[$index] === 0) {
+ $data[$index] = 1;
+ } else { // === 1
+ $data[$index] = $sum;
+ $sum += $attentionMask->buffer()[$index];
+ }
}
-
- $beams[] = $start;
- }
-
- return $beams;
- }
-
- protected function seq2seqUpdatebeam(array &$beam, int $newTokenId): void
- {
- $beam['output_token_ids'][] = $newTokenId;
- }
-
- protected function seq2seqForward(PretrainedModel $model, array $modelInputs): array
- {
-
- ['encoder_outputs' => $encoderOutputs, 'past_key_values' => $pastKeyValues] = $modelInputs;
-
- if ($encoderOutputs === null) {
- // Encoder outputs are not given, so we must compute them.
- $encoderOutputs = $this->encoderForward($model, $modelInputs)['last_hidden_state'];
}
+ $positionIds = new Tensor($data, Tensor::int64, $attentionMask->shape());
- $decoderFeeds = [
- 'input_ids' => $modelInputs['decoder_input_ids'],
- 'encoder_hidden_states' => $encoderOutputs,
- ];
-
- $useCacheBranch = !!$pastKeyValues;
-
- $inputNames = array_column($model->decoderMergedSession->inputs(), 'name');
-
-
- if (in_array('use_cache_branch', $inputNames)) {
- $decoderFeeds['use_cache_branch'] = new Tensor([$useCacheBranch], Tensor::bool, [1]);
- }
-
- if (in_array('encoder_attention_mask', $inputNames)) {
- $decoderFeeds['encoder_attention_mask'] = $modelInputs['attention_mask'];
+ if ($pastKeyValues) {
+ $offset = - (($inputIds ?? $inputsEmbeds)->shape()[1]);
+ $positionIds = $positionIds->slice(null, [$offset, null]); // position_ids[:, -input_ids.shape[1] :]
}
- $model->preparePositionIds($inputNames, $decoderFeeds, $useCacheBranch);
- $model->addPastKeyValues($decoderFeeds, $pastKeyValues);
-
- $decoderResults = $model->runSession($model->decoderMergedSession, $decoderFeeds);
- $logits = $decoderResults['logits'];
- $pastKeyValues = $model->getPastKeyValues($decoderResults, $pastKeyValues);
-
- // Get cross attention and/or decoder attentions if they are present
- $attns = $model->getAttentions($decoderResults);
-
- return [
- 'logits' => $logits,
- 'past_key_values' => $pastKeyValues,
- 'encoder_outputs' => $encoderOutputs,
- ...$attns,
- ];
+ return $positionIds;
}
-
- //
-
}
diff --git a/src/Models/Pretrained/BartForConditionalGeneration.php b/src/Models/Pretrained/BartForConditionalGeneration.php
index bae788f..16b13d6 100644
--- a/src/Models/Pretrained/BartForConditionalGeneration.php
+++ b/src/Models/Pretrained/BartForConditionalGeneration.php
@@ -2,42 +2,9 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Pretrained;
-use Codewithkyrian\Transformers\Models\ModelArchitecture;
-use Codewithkyrian\Transformers\Utils\AutoConfig;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
-use Codewithkyrian\Transformers\Utils\InferenceSession;
-
/**
* The BART Model with a language modeling head. Can be used for summarization.
*/
-class BartForConditionalGeneration extends BartPretrainedModel
-{
- public mixed $numDecoderLayers;
- public mixed $numDecoderHeads;
- public mixed $decoderDimKv;
- public mixed $numEncoderLayers;
- public mixed $numEncoderHeads;
- public mixed $encoderDimKv;
-
- public function __construct(
- AutoConfig $config,
- InferenceSession $session,
- public InferenceSession $decoderMergedSession,
- public ModelArchitecture $modelArchitecture,
- public GenerationConfig $generationConfig
- )
- {
- parent::__construct($config, $session, $modelArchitecture);
-
- $this->numDecoderLayers = $this->config['decoder_layers'];
- $this->numDecoderHeads = $this->config['decoder_attention_heads'];
- $this->decoderDimKv = $this->config['d_model'] / $this->numDecoderHeads;
-
- $this->numEncoderLayers = $this->config['encoder_layers'];
- $this->numEncoderHeads = $this->config['encoder_attention_heads'];
- $this->encoderDimKv = $this->config['d_model'] / $this->numEncoderHeads;
- }
-}
\ No newline at end of file
+class BartForConditionalGeneration extends BartPretrainedModel {}
diff --git a/src/Models/Pretrained/CLIPVisionModelWithProjection.php b/src/Models/Pretrained/CLIPVisionModelWithProjection.php
index 488a8da..5980952 100644
--- a/src/Models/Pretrained/CLIPVisionModelWithProjection.php
+++ b/src/Models/Pretrained/CLIPVisionModelWithProjection.php
@@ -2,11 +2,10 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Pretrained;
+use Codewithkyrian\Transformers\Configs\PretrainedConfig;
use Codewithkyrian\Transformers\Models\ModelArchitecture;
-use Codewithkyrian\Transformers\Utils\AutoConfig;
/**
* CLIP Vision Model with a projection layer on top (a linear layer on top of the pooled output)
@@ -18,17 +17,15 @@ class CLIPVisionModelWithProjection extends CLIPPretrainedModel
public static function fromPretrained(
string $modelNameOrPath,
bool $quantized = true,
- AutoConfig|array $config = null,
+ array|PretrainedConfig|null $config = null,
?string $cacheDir = null,
?string $token = null,
string $revision = 'main',
?string $modelFilename = null,
ModelArchitecture $modelArchitecture = ModelArchitecture::EncoderOnly,
?callable $onProgress = null
- ): PretrainedModel
- {
- // Update default model file name if not provided
+ ): PretrainedModel {
$modelFilename ??= 'vision_model';
return parent::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $token, $revision, $modelFilename, $modelArchitecture, $onProgress);
}
-}
\ No newline at end of file
+}
diff --git a/src/Models/Pretrained/CodeGenPretrainedModel.php b/src/Models/Pretrained/CodeGenPretrainedModel.php
index 5d2d786..6731713 100644
--- a/src/Models/Pretrained/CodeGenPretrainedModel.php
+++ b/src/Models/Pretrained/CodeGenPretrainedModel.php
@@ -5,32 +5,10 @@
namespace Codewithkyrian\Transformers\Models\Pretrained;
+use Codewithkyrian\Transformers\Configs\PretrainedConfig;
use Codewithkyrian\Transformers\Models\ModelArchitecture;
-use Codewithkyrian\Transformers\Utils\AutoConfig;
use Codewithkyrian\Transformers\Utils\InferenceSession;
class CodeGenPretrainedModel extends PretrainedModel
{
- protected int $numHeads;
- protected int $numLayers;
- protected int $dimKv;
-
- public function __construct(
- AutoConfig $config,
- InferenceSession $session,
- ModelArchitecture $modelArchitecture = ModelArchitecture::EncoderOnly,
- ...$args
- )
- {
- parent::__construct($config, $session, $modelArchitecture, $args);
-
- // config doesn't contain pad_token_id, so we assume it is the eos_token_id
- $this->config['pad_token_id'] = $this->config['eos_token_id'];
- $this->config->padTokenId = $this->config['eos_token_id'];
-
- $this->numHeads = $this->config['n_head'];
- $this->numLayers = $this->config['n_layer'];
- $this->dimKv = $this->config['n_embd'] / $this->numHeads;
-
- }
-}
\ No newline at end of file
+}
diff --git a/src/Models/Pretrained/GPT2PretrainedModel.php b/src/Models/Pretrained/GPT2PretrainedModel.php
index 277631f..f790e7e 100644
--- a/src/Models/Pretrained/GPT2PretrainedModel.php
+++ b/src/Models/Pretrained/GPT2PretrainedModel.php
@@ -2,35 +2,6 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Pretrained;
-use Codewithkyrian\Transformers\Models\ModelArchitecture;
-use Codewithkyrian\Transformers\Utils\AutoConfig;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
-use Codewithkyrian\Transformers\Utils\InferenceSession;
-
-class GPT2PretrainedModel extends PretrainedModel
-{
- public int $numHeads;
- public int $numLayers;
- public int $dimKv;
-
- public function __construct(
- AutoConfig $config,
- InferenceSession $session,
- public ModelArchitecture $modelArchitecture,
- public GenerationConfig $generationConfig
- )
- {
- parent::__construct($config, $session, $modelArchitecture);
-
- // config doesn't contain pad_token_id, so we assume it is the eos_token_id
- $this->config['pad_token_id'] = $this->config['eos_token_id'];
- $this->config->padTokenId = $this->config['eos_token_id'];
-
- $this->numHeads = $this->config['n_head'];
- $this->numLayers = $this->config['n_layer'];
- $this->dimKv = $this->config['n_embd'] / $this->numHeads;
- }
-}
\ No newline at end of file
+class GPT2PretrainedModel extends PretrainedModel {}
diff --git a/src/Models/Pretrained/GPTBigCodePretrainedModel.php b/src/Models/Pretrained/GPTBigCodePretrainedModel.php
index b5786d0..2ce2d74 100644
--- a/src/Models/Pretrained/GPTBigCodePretrainedModel.php
+++ b/src/Models/Pretrained/GPTBigCodePretrainedModel.php
@@ -2,35 +2,6 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Pretrained;
-use Codewithkyrian\Transformers\Models\ModelArchitecture;
-use Codewithkyrian\Transformers\Utils\AutoConfig;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
-use Codewithkyrian\Transformers\Utils\InferenceSession;
-
-class GPTBigCodePretrainedModel extends PretrainedModel
-{
- protected int $numHeads;
- protected int $numLayers;
- protected int $dimKv;
-
- public function __construct(
- AutoConfig $config,
- InferenceSession $session,
- public ModelArchitecture $modelArchitecture,
- public GenerationConfig $generationConfig
- )
- {
- parent::__construct($config, $session, $modelArchitecture);
-
- // config doesn't contain pad_token_id, so we assume it is the eos_token_id
- $this->config['pad_token_id'] = $this->config['eos_token_id'];
- $this->config->padTokenId = $this->config['eos_token_id'];
-
- $this->numHeads = $this->config['n_head'];
- $this->numLayers = $this->config['n_layer'];
- $this->dimKv = $this->config['n_embd'] / $this->numHeads;
- }
-}
\ No newline at end of file
+class GPTBigCodePretrainedModel extends PretrainedModel {}
diff --git a/src/Models/Pretrained/GPTJPretrainedModel.php b/src/Models/Pretrained/GPTJPretrainedModel.php
index 4232a41..9626b79 100644
--- a/src/Models/Pretrained/GPTJPretrainedModel.php
+++ b/src/Models/Pretrained/GPTJPretrainedModel.php
@@ -2,35 +2,6 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Pretrained;
-use Codewithkyrian\Transformers\Models\ModelArchitecture;
-use Codewithkyrian\Transformers\Utils\AutoConfig;
-use Codewithkyrian\Transformers\Utils\InferenceSession;
-
-class GPTJPretrainedModel extends PretrainedModel
-{
- protected int $numHeads;
- protected int $numLayers;
- protected int $dimKv;
-
- public function __construct(
- AutoConfig $config,
- InferenceSession $session,
- ModelArchitecture $modelArchitecture = ModelArchitecture::EncoderOnly,
- ...$args
- )
- {
- parent::__construct($config, $session, $modelArchitecture, $args);
-
- // config doesn't contain pad_token_id, so we assume it is the eos_token_id
- $this->config['pad_token_id'] = $this->config['eos_token_id'];
- $this->config->padTokenId = $this->config['eos_token_id'];
-
- $this->numHeads = $this->config['n_head'];
- $this->numLayers = $this->config['n_layer'];
- $this->dimKv = $this->config['n_embd'] / $this->numHeads;
-
- }
-}
\ No newline at end of file
+class GPTJPretrainedModel extends PretrainedModel {}
diff --git a/src/Models/Pretrained/Gemma2ForCausalLM.php b/src/Models/Pretrained/Gemma2ForCausalLM.php
new file mode 100644
index 0000000..7fd0b14
--- /dev/null
+++ b/src/Models/Pretrained/Gemma2ForCausalLM.php
@@ -0,0 +1,7 @@
+config['pad_token_id'] = $this->config['eos_token_id'];
- $this->config->padTokenId = $this->config['eos_token_id'];
-
- $this->numHeads = $this->config['num_key_value_heads'] ?? $this->config['num_attention_heads'];
- $this->numLayers = $this->config['num_hidden_layers'];
- $this->dimKv = $this->config['hidden_size'] / $this->config['num_attention_heads'];
- }
-}
\ No newline at end of file
+class LlamaPretrainedModel extends PretrainedModel {}
diff --git a/src/Models/Pretrained/M2M100ForConditionalGeneration.php b/src/Models/Pretrained/M2M100ForConditionalGeneration.php
index 1796b08..3f18ed6 100644
--- a/src/Models/Pretrained/M2M100ForConditionalGeneration.php
+++ b/src/Models/Pretrained/M2M100ForConditionalGeneration.php
@@ -2,40 +2,6 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Pretrained;
-use Codewithkyrian\Transformers\Models\ModelArchitecture;
-use Codewithkyrian\Transformers\Utils\AutoConfig;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
-use Codewithkyrian\Transformers\Utils\InferenceSession;
-
-class M2M100ForConditionalGeneration extends M2M100PretrainedModel
-{
- protected mixed $numDecoderLayers;
- protected mixed $numDecoderHeads;
- protected mixed $decoderDimKv;
- protected mixed $numEncoderLayers;
- protected mixed $numEncoderHeads;
- protected mixed $encoderDimKv;
-
- public function __construct(
- AutoConfig $config,
- InferenceSession $session,
- public InferenceSession $decoderMergedSession,
- public ModelArchitecture $modelArchitecture,
- public GenerationConfig $generationConfig
- )
- {
- parent::__construct($config, $session, $modelArchitecture);
-
- $this->numDecoderLayers = $this->config['decoder_layers'];
- $this->numDecoderHeads = $this->config['decoder_attention_heads'];
- $this->decoderDimKv = $this->config['d_model'] / $this->numDecoderHeads;
-
- $this->numEncoderLayers = $this->config['encoder_layers'];
- $this->numEncoderHeads = $this->config['encoder_attention_heads'];
- $this->encoderDimKv = $this->config['d_model'] / $this->numEncoderHeads;
- }
-
-}
\ No newline at end of file
+class M2M100ForConditionalGeneration extends M2M100PretrainedModel {}
diff --git a/src/Models/Pretrained/Phi3ForCausalLM.php b/src/Models/Pretrained/Phi3ForCausalLM.php
new file mode 100644
index 0000000..06b492a
--- /dev/null
+++ b/src/Models/Pretrained/Phi3ForCausalLM.php
@@ -0,0 +1,7 @@
+ $sessions The ONNX sessions for this this model.
+ * @param ModelArchitecture $modelArchitecture The model architecture.
+ * @param GenerationConfig|null $generationConfig The generation configuration (for models that can generate)
*/
public function __construct(
- public AutoConfig $config,
- public InferenceSession $session,
+ public PretrainedConfig $config,
+ public array $sessions,
public ModelArchitecture $modelArchitecture = ModelArchitecture::EncoderOnly,
- ...$args
- ) {}
+ public ?GenerationConfig $generationConfig = null
+ ) {
+ if ($this->modelArchitecture->canGenerate()) {
+ $this->forwardParams = array_merge($this->forwardParams, ['past_key_values']);
+ }
+
+ $this->logger = Transformers::getLogger();
+ }
/**
@@ -65,177 +86,167 @@ public function __construct(
* user or organization name, like `dbmdz/bert-base-german-cased`.
* - A path to a *directory* containing model weights, e.g., `./my_model_directory/`.
* @param bool $quantized Whether to load the quantized version of a model (as opposed to the original one).
- * @param array|AutoConfig|null $config The configuration object used to instantiate the model.
+ * @param array|PretrainedConfig|null $config The configuration object used to instantiate the model.
* @param string|null $cacheDir Path to a directory in which a downloaded pretrained model configuration should
* @param string|null $token The token to use as an authorization to download from private model repos.
* @param string $revision The specific model version to use. It can be a branch name, a tag name,
* @param string|null $modelFilename The name of the model file to load. If not provided, will default to the
* @param ModelArchitecture $modelArchitecture
+ * @param callable|null $onProgress
*
* @return self The model instantiated from the configuration.
* @throws HubException
*/
public static function fromPretrained(
- string $modelNameOrPath,
- bool $quantized = true,
- array|AutoConfig $config = null,
- ?string $cacheDir = null,
- ?string $token = null,
- string $revision = 'main',
- ?string $modelFilename = null,
- ModelArchitecture $modelArchitecture = ModelArchitecture::EncoderOnly,
- ?callable $onProgress = null
- ): self
- {
+ string $modelNameOrPath,
+ bool $quantized = true,
+ array|PretrainedConfig|null $config = null,
+ ?string $cacheDir = null,
+ ?string $token = null,
+ string $revision = 'main',
+ ?string $modelFilename = null,
+ ModelArchitecture $modelArchitecture = ModelArchitecture::EncoderOnly,
+ ?callable $onProgress = null
+ ): self {
+ $logger = Transformers::getLogger();
if (is_array($config)) {
$config = AutoConfig::fromPretrained($modelNameOrPath, $config, $cacheDir, $revision, $onProgress);
}
$quantizedSuffix = $quantized ? '_quantized' : '';
- switch ($modelArchitecture) {
- case ModelArchitecture::DecoderOnly:
- {
- $session = self::constructSession(
- modelNameOrPath: $modelNameOrPath,
- fileName: $modelFilename ?? "decoder_model_merged$quantizedSuffix",
- cacheDir: $cacheDir,
- revision: $revision,
- onProgress: $onProgress,
- );
-
- $generatorConfigArr = Hub::getJson(
- pathOrRepoID: $modelNameOrPath,
- fileName: 'generation_config.json',
- cacheDir: $cacheDir,
- revision: $revision,
- fatal: false,
- onProgress: $onProgress
- );
-
- $generatorConfig = new GenerationConfig($generatorConfigArr);
+ $logger->info('Loading model', [
+ 'model' => $modelNameOrPath,
+ 'quantized' => $quantized,
+ 'architecture' => $modelArchitecture->value,
+ ]);
- return new static(
- config: $config,
- session: $session,
- modelArchitecture: $modelArchitecture,
- generationConfig: $generatorConfig
- );
- }
+ switch ($modelArchitecture) {
+ case ModelArchitecture::DecoderOnly: {
+ $session = self::constructSession(
+ modelNameOrPath: $modelNameOrPath,
+ fileName: $modelFilename ?? "model$quantizedSuffix",
+ cacheDir: $cacheDir,
+ revision: $revision,
+ onProgress: $onProgress,
+ );
+ $generationConfig = new GenerationConfig(Hub::getJson(
+ pathOrRepoID: $modelNameOrPath,
+ fileName: 'generation_config.json',
+ cacheDir: $cacheDir,
+ revision: $revision,
+ fatal: false,
+ onProgress: $onProgress
+ ));
+
+ return new static(
+ config: $config,
+ sessions: ['decoder' => $session],
+ modelArchitecture: $modelArchitecture,
+ generationConfig: $generationConfig
+ );
+ }
case ModelArchitecture::Seq2SeqLM:
- case ModelArchitecture::Vision2Seq:
- {
- $encoderSession = self::constructSession(
- modelNameOrPath: $modelNameOrPath,
- fileName: "encoder_model$quantizedSuffix",
- cacheDir: $cacheDir,
- revision: $revision,
- onProgress: $onProgress,
- );
-
- $decoderSession = self::constructSession(
- modelNameOrPath: $modelNameOrPath,
- fileName: "decoder_model_merged$quantizedSuffix",
- cacheDir: $cacheDir,
- revision: $revision,
- onProgress: $onProgress,
- );
-
- $generatorConfigArr = Hub::getJson(
- pathOrRepoID: $modelNameOrPath,
- fileName: 'generation_config.json',
- cacheDir: $cacheDir,
- revision: $revision,
- fatal: false,
- onProgress: $onProgress
- );
-
- $generatorConfig = new GenerationConfig($generatorConfigArr);
-
- return new static(
- config: $config,
- session: $encoderSession,
- modelArchitecture: $modelArchitecture,
- generationConfig: $generatorConfig,
- decoderMergedSession: $decoderSession
- );
- }
-
- case ModelArchitecture::MaskGeneration:
- {
- $visionEncoder = self::constructSession(
- modelNameOrPath: $modelNameOrPath,
- fileName: "vision_encoder$quantizedSuffix",
- cacheDir: $cacheDir,
- revision: $revision,
- onProgress: $onProgress
- );
-
- $promptMaskEncoder = self::constructSession(
- modelNameOrPath: $modelNameOrPath,
- fileName: "prompt_encoder_mask_decoder$quantizedSuffix",
- cacheDir: $cacheDir,
- revision: $revision,
- onProgress: $onProgress
- );
-
- return new static(
- config: $config,
- session: $visionEncoder,
- promptMaskEncoderSession: $promptMaskEncoder,
- modelArchitecture: $modelArchitecture
- );
- }
+ case ModelArchitecture::Vision2Seq: {
+ $encoderSession = self::constructSession(
+ modelNameOrPath: $modelNameOrPath,
+ fileName: "encoder_model$quantizedSuffix",
+ cacheDir: $cacheDir,
+ revision: $revision,
+ onProgress: $onProgress,
+ );
- case ModelArchitecture::EncoderDecoder:
- {
- $encoderSession = self::constructSession(
- modelNameOrPath: $modelNameOrPath,
- fileName: "encoder_model$quantizedSuffix",
- cacheDir: $cacheDir,
- revision: $revision,
- onProgress: $onProgress
- );
+ $decoderSession = self::constructSession(
+ modelNameOrPath: $modelNameOrPath,
+ fileName: "decoder_model_merged$quantizedSuffix",
+ cacheDir: $cacheDir,
+ revision: $revision,
+ onProgress: $onProgress,
+ );
- $decoderSession = self::constructSession(
- modelNameOrPath: $modelNameOrPath,
- fileName: "decoder_model_merged$quantizedSuffix",
- cacheDir: $cacheDir,
- revision: $revision,
- onProgress: $onProgress
- );
+ $generationConfig = new GenerationConfig(Hub::getJson(
+ pathOrRepoID: $modelNameOrPath,
+ fileName: 'generation_config.json',
+ cacheDir: $cacheDir,
+ revision: $revision,
+ fatal: false,
+ onProgress: $onProgress
+ ));
+
+ return new static(
+ config: $config,
+ sessions: ['encoder' => $encoderSession, 'decoder' => $decoderSession],
+ modelArchitecture: $modelArchitecture,
+ generationConfig: $generationConfig,
+ );
+ }
+ case ModelArchitecture::MaskGeneration: {
+ $visionEncoder = self::constructSession(
+ modelNameOrPath: $modelNameOrPath,
+ fileName: "vision_encoder$quantizedSuffix",
+ cacheDir: $cacheDir,
+ revision: $revision,
+ onProgress: $onProgress
+ );
- return new static(
- config: $config,
- session: $encoderSession,
- decoderMergedSession: $decoderSession,
- modelArchitecture: $modelArchitecture
- );
- }
+ $promptMaskEncoder = self::constructSession(
+ modelNameOrPath: $modelNameOrPath,
+ fileName: "prompt_encoder_mask_decoder$quantizedSuffix",
+ cacheDir: $cacheDir,
+ revision: $revision,
+ onProgress: $onProgress
+ );
- default:
- {
- if ($modelArchitecture != ModelArchitecture::EncoderOnly) {
- Transformers::getLogger()?->warning("{$modelArchitecture->value} is not a valid model group. Defaulting to EncoderOnly.");
+ return new static(
+ config: $config,
+ sessions: ['vision_encoder' => $visionEncoder, 'prompt_mask_decoder' => $promptMaskEncoder],
+ modelArchitecture: $modelArchitecture
+ );
}
+ case ModelArchitecture::EncoderDecoder: {
+ $encoderSession = self::constructSession(
+ modelNameOrPath: $modelNameOrPath,
+ fileName: "encoder_model$quantizedSuffix",
+ cacheDir: $cacheDir,
+ revision: $revision,
+ onProgress: $onProgress
+ );
+ $decoderSession = self::constructSession(
+ modelNameOrPath: $modelNameOrPath,
+ fileName: "decoder_model_merged$quantizedSuffix",
+ cacheDir: $cacheDir,
+ revision: $revision,
+ onProgress: $onProgress
+ );
- $session = self::constructSession(
- modelNameOrPath: $modelNameOrPath,
- fileName: $modelFilename ?? "model$quantizedSuffix",
- cacheDir: $cacheDir,
- revision: $revision,
- onProgress: $onProgress
- );
+ return new static(
+ config: $config,
+ sessions: ['encoder' => $encoderSession, 'decoder' => $decoderSession],
+ modelArchitecture: $modelArchitecture
+ );
+ }
+ default: {
+ if ($modelArchitecture != ModelArchitecture::EncoderOnly) {
+ $logger->warning("{$modelArchitecture->value} is not a valid model group. Defaulting to EncoderOnly.");
+ $modelArchitecture = ModelArchitecture::EncoderOnly;
+ }
+ $session = self::constructSession(
+ modelNameOrPath: $modelNameOrPath,
+ fileName: $modelFilename ?? "model$quantizedSuffix",
+ cacheDir: $cacheDir,
+ revision: $revision,
+ onProgress: $onProgress
+ );
- return new static(
- config: $config,
- session: $session,
- modelArchitecture: $modelArchitecture
- );
- }
+ return new static(
+ config: $config,
+ sessions: ['encoder' => $session],
+ modelArchitecture: $modelArchitecture
+ );
+ }
}
}
@@ -252,10 +263,10 @@ public static function fromPretrained(
* @param callable|null $onProgress
* @param mixed ...$sessionOptions
*
+ *
* @return InferenceSession|null
* @throws HubException
*/
-
public static function constructSession(
string $modelNameOrPath,
string $fileName,
@@ -264,9 +275,8 @@ public static function constructSession(
string $subFolder = 'onnx',
bool $fatal = true,
?callable $onProgress = null,
- ...$sessionOptions
- ): ?InferenceSession
- {
+ ...$sessionOptions
+ ): ?InferenceSession {
$modelFileName = "$fileName.onnx";
$file = Hub::getFile($modelNameOrPath, $modelFileName, $cacheDir, $revision, $subFolder, $fatal, $onProgress);
@@ -276,17 +286,24 @@ public static function constructSession(
return new InferenceSession($file, ...$sessionOptions);
}
+ /**
+ * Makes the model callable. Alias for the forward method.
+ *
+ * @param array $modelInputs
+ * @return array|ModelOutput
+ */
public function __invoke(array $modelInputs): array|ModelOutput
{
return $this->forward($modelInputs);
}
/**
- * Forward method for a pretrained model. If not overridden by a subclass, the correct forward method
- * will be chosen based on the model type.
+ * Forward method for a pretrained model. Delegates to the appropriate forward
+ * method based on model architecture.
*
* @param array $modelInputs The input data to the model in the format specified in the ONNX model.
*
+ *
* @return array{logits: Tensor, hidden_states: Tensor, attentions: Tensor} The output data from the model in the format specified in the ONNX model.
*/
public function forward(array $modelInputs): array
@@ -294,292 +311,271 @@ public function forward(array $modelInputs): array
return $this->modelArchitecture->forward($this, $modelInputs);
}
- /**
- * @throws ModelExecutionException
- * @throws MissingModelInputException
+ /** Generates text based on the given inputs and generation configuration using the model.
+ *
+ * @param Tensor $inputs The input token ids.
+ * @param GenerationConfig|null $generationConfig The generation configuration to use. If null, default configuration will be used.
+ * @param LogitsProcessorList|null $logitsProcessor An optional logits processor to use. If null, a new LogitsProcessorList instance will be created.
+ * @param Streamer|null $streamer
+ * @param mixed ...$kwargs
+ *
+ * @return array|Tensor An array of generated output sequences, where each sequence is an array of token IDs.
+ * @throws Exception
*/
- public function runSession(InferenceSession $session, array $inputs): array
- {
- try {
- $inputNames = array_column($session->inputs(), 'name');
+ public function generate(
+ Tensor $inputs,
+ ?GenerationConfig $generationConfig = null,
+ ?LogitsProcessorList $logitsProcessor = null,
+ ?StoppingCriteria $stoppingCriteria = null,
+ ?Streamer $streamer = null,
+ ...$kwargs
+ ): array|Tensor {
+ $this->logger->debug('Starting generation', [
+ 'input_shape' => $inputs->shape(),
+ 'generation_config' => $generationConfig ? $generationConfig->toArray() : null
+ ]);
+ $this->ensureModelCanGenerate();
- $inputs = $this->validateInputs($inputNames, $inputs);
+ $kwargs = array_keys_to_snake_case($kwargs);
- $outputNames = array_column($session->outputs(), 'name');
+ // 1. Prepare generation config
+ $generationConfig = $this->prepareGenerationConfig($generationConfig);
- return $session->run($outputNames, $inputs);
- } catch (MissingModelInputException $e) {
- throw $e;
- } catch (Exception $e) {
- throw ModelExecutionException::make($e->getMessage());
- }
- }
-
- /**
- * @param InferenceSession $session
- * @param Tensor[] $inputs
- *
- * @return Tensor[]
- * @throws MissingModelInputException
- */
- public function validateInputs(array $inputNames, array $inputs): array
- {
- $checkedInputs = [];
- $missingInputs = [];
+ // 2. Prepare encoder inputs
+ [$modelInputs, $modelInputName] = $this->prepareEncoderInputs($inputs, $kwargs);
- foreach ($inputNames as $inputName) {
- $tensor = $inputs[$inputName];
+ $isEncoderDecoder = $this->config->isEncoderDecoder;
- // Check if the input is an instance of Tensor
- if (!($tensor instanceof Tensor)) {
- $missingInputs[] = $inputName;
- continue;
- }
+ // 3. Run encoder forward pass if model is encoder decoder
+ if ($isEncoderDecoder && !isset($modelInputs['encoder_outputs'])) {
+ $modelInputs = $this->runEncoderForwardPass($modelInputs, $generationConfig);
+ }
- $checkedInputs[$inputName] = $tensor;
+ // 4. Prepare decoder inputs
+ if ($isEncoderDecoder) {
+ [$inputIds, $modelInputs] = $this->prepareDecoderInputs(
+ $modelInputs[$modelInputName]->shape()[0],
+ $modelInputs,
+ $generationConfig
+ );
+ } else {
+ $inputIds = $modelInputs[$modelInputName];
}
+ // 5. Prepare `max_length` depending on other stopping criteria.
+ $inputIdsLength = $inputs->shape()[count($inputs->shape()) - 1];
- if (!empty($missingInputs)) {
- throw MissingModelInputException::make($missingInputs);
+ if ($generationConfig->max_new_tokens !== null) {
+ $generationConfig->max_length = $inputIdsLength + $generationConfig->max_new_tokens;
}
- $numInputsProvided = count($inputs);
- $numInputsNeeded = count($inputNames);
+ // 6. Prepare logits processor, stopping criteria and sampler
+ $logitsProcessor = $this->prepareLogitsProcessor($generationConfig, $inputIdsLength, $logitsProcessor);
+ $stoppingCriteria = $this->prepareStoppingCriteria($generationConfig, $stoppingCriteria);
+ $sampler = Sampler::getSampler($generationConfig);
+ // 7. Final preparation before generation
+ $attentions = [];
+ $numInputs = $modelInputs[$modelInputName]->shape()[0];
+ $scores = array_fill(0, $numInputs, 0);
+ $allInputIds = $inputIds->toArray();
+ $streamer?->put($allInputIds);
+
+ // 9. Generation loop
+ $step = 0;
+ while (true) {
+ $modelInputs = $this->prepareInputsForGeneration($allInputIds, $modelInputs);
+
+ $outputs = $this->forward($modelInputs);
+
+ if ($generationConfig->output_attentions && $generationConfig->return_dict_in_generate) {
+ $tokenAttentions = $this->getAttentions($outputs);
+ foreach ($tokenAttentions as $key => $value) {
+ if (!array_key_exists($key, $attentions)) {
+ $attentions[$key] = [];
+ }
+ $attentions[$key][] = $value;
+ }
+ }
- if ($numInputsProvided > $numInputsNeeded) {
- // No missing inputs, but too many inputs were provided so we warn the user and ignore the extra inputs.
- $ignored = array_diff(array_keys($inputs), $inputNames);
+ // Logits are of the form [batch_size, out_seq_length, vocab_size]. In most cases, this will be [batch_size, 1, vocab_size]
+ // So, we select the last token's logits: (equivalent to `logits = outputs.logits[:, -1, :]`)
+ $logits = $outputs['logits']->slice(null, -1, null);
- $warning = sprintf(
- 'Too many inputs were provided (%d > %d). The following inputs will be ignored: "%s".',
- $numInputsProvided,
- $numInputsNeeded,
- implode(', ', $ignored)
- );
+ // Apply logits processor
+ $nextTokenScores = $logitsProcessor($allInputIds, $logits);
- Transformers::getLogger()?->warning($warning);
- }
+ $generatedInputIds = [];
- return $inputs;
- }
+ // Loop over each batch
+ for ($batchIdx = 0; $batchIdx < $nextTokenScores->shape()[0]; ++$batchIdx) {
+ $logs = $nextTokenScores[$batchIdx];
- /**
- * Prepares an attention mask for a sequence of tokens based on configuration options.
- *
- * @param Tensor $tokens The input tokens.
- *
- * @return Tensor The attention mask tensor.
- * @private
- */
- public function prepareAttentionMask(Tensor $tokens): Tensor
- {
+ $sampledTokens = $sampler($logs);
- // Prepare attention mask
- $padTokenId = $this->config['pad_token_id'] ?? null;
- $eosTokenId = $this->config['eos_token_id'] ?? null;
+ foreach ($sampledTokens as [$newTokenId, $logProb]) {
+ // update generated ids, model inputs, and length for next step
+ $scores[$batchIdx] += $logProb;
+ $allInputIds[$batchIdx][] = $newTokenId;
+ $generatedInputIds[] = [$newTokenId];
- if (is_int($eosTokenId)) {
- $eosTokenId = [$eosTokenId];
+ // TODO: Support beam search
+ break;
+ }
+ }
+
+ $streamer?->put($generatedInputIds);
+
+ $stop = $stoppingCriteria($generatedInputIds, $scores);
+ if (array_every($stop, fn($x) => $x)) {
+ break;
+ }
+
+ $modelInputs = $this->updateInputsAfterGeneration($generatedInputIds, $outputs, $modelInputs, $isEncoderDecoder);
+ $step++;
}
- $isPadTokenInInputs = in_array($padTokenId, $tokens->toArray());
- $isPadTokenNotEqualToEosTokenId = ($eosTokenId === null) || !in_array($padTokenId, $eosTokenId);
+ $streamer?->end();
- if ($isPadTokenInInputs && $isPadTokenNotEqualToEosTokenId) {
- $mo = Tensor::mo();
+ // 9. Retrieve and dispose all final past key values (including encoder attentions)
+ $pastKeyValues = $this->getPastKeyValues($outputs, $modelInputs['past_key_values'] ?? null);
- $data = $mo->f(fn ($x) => $x != $padTokenId, $tokens);
+ $sequences = Tensor::fromArray($allInputIds, Tensor::int64);
+ $this->logger->info('Generation completed', [
+ 'steps' => $step,
+ 'output_shape' => $sequences->shape(),
+ ]);
- return new Tensor($data, $tokens->dtype(), $tokens->shape());
+ if ($generationConfig->return_dict_in_generate) {
+ return [
+ 'sequences' => $sequences,
+ 'past_key_values' => $pastKeyValues,
+ ...$attentions
+ ];
} else {
- return Tensor::onesLike($tokens);
+ return $sequences;
}
}
/**
- * Add position IDs to the feeds object.
- *
- * @param array $inputNames The names of the inputs to the model.
- * @param array $feeds The input to the model.
- * @param bool $useCacheBranch Whether to use the cache branch of the model.
+ * Encodes an image using the vision encoder session.
*
- * @return void
+ * @param array{pixel_values: Tensor} $inputs
+ * @return Tensor The image features.
*/
- public function preparePositionIds(array $inputNames, array &$feeds, bool $useCacheBranch): void
+ public function encodeImage(array $inputs): Tensor
{
- if (!in_array('position_ids', $inputNames)) {
- return;
- }
-
- // TODO: Verify this works properly!!!
- $data = array_fill(0, count($feeds['attention_mask']->buffer()), 0);
-
- // Compute cumulative sum of the attention mask along the sequence length dimension
- for ($i = 0; $i < $feeds['attention_mask']->shape()[0]; ++$i) {
- $start = $i * $feeds['attention_mask']->shape()[1];
- $sum = 0;
- for ($j = 0; $j < $feeds['attention_mask']->shape()[1]; ++$j) {
- $index = $start + $j;
- if ($feeds['attention_mask']->buffer()[$index] === 0) {
- $data[$index] = 1;
- } else { // === 1
- $data[$index] = $sum;
- $sum += $feeds['attention_mask']->buffer()[$index];
- }
- }
- }
- $feeds['position_ids'] = new Tensor($data, Tensor::int64, $feeds['attention_mask']->shape());
-
- if ($useCacheBranch) {
- // TODO: Fix this
- $feeds['position_ids'] = $feeds['position_ids']->slice(null, -1);
- }
+ $result = $this->runSession($this->sessions['vision_encoder'], $inputs);
+ return $result['image_features'] ?? throw new \RuntimeException('image_features not found in session output');
}
/**
- * Returns an object containing past key values from the given decoder results object.
- *
- * @param array $decoderResults The decoder results object.
- * @param ?array $pastKeyValues The previous past key values.
+ * Encodes text using the embed tokens session.
*
- * @return array An object containing past key values.
+ * @param array{input_ids: Tensor, attention_mask?: Tensor} $inputs
+ * @return Tensor The text embeddings.
*/
- public function getPastKeyValues(array $decoderResults, ?array $pastKeyValues): array
+ public function encodeText(array $inputs): Tensor
{
- $pkvs = [];
-
- foreach ($decoderResults as $name => $value) {
- if (str_starts_with($name, 'present')) {
- $newName = str_replace('present', 'past_key_values', $name);
-
- if ($pastKeyValues && str_contains($name, 'encoder')) {
- // Optimization introduced by optimum to reuse past key values.
- // So, we just replace the constant outputs with the previous past key values.
- // https://github.com/huggingface/optimum/blob/0bf2c05fb7e1182b52d21b703cfc95fd9e4ea3dc/optimum/onnxruntime/base.py#L677-L704
- $pkvs[$newName] = $pastKeyValues[$newName];
- } else {
- $pkvs[$newName] = $value;
- }
- }
- }
-
- return $pkvs;
+ $result = $this->runSession($this->sessions['embed_tokens'], $inputs);
+ return $result['inputs_embeds'] ?? throw new \RuntimeException('inputs_embeds not found in session output');
}
/**
- * Returns an object containing attentions from the given decoder results object.
+ * Encodes audio using the audio encoder session.
*
- * @param array $decoderResults The decoder results object.
+ * @param array{audio_values: Tensor} $inputs
+ * @return Tensor The audio features.
+ */
+ public function encodeAudio(array $inputs): Tensor
+ {
+ $result = $this->runSession($this->sessions['audio_encoder'], $inputs);
+ return $result['audio_features'] ?? throw new \RuntimeException('audio_features not found in session output');
+ }
+
+
+ /**
+ * Runs the ONNX session with the provided inputs.
*
- * @return array An object containing attentions.
+ * @param InferenceSession $session The ONNX session to run.
+ * @param array $inputs The inputs to the session.
+ * @return array The outputs from the session.
+ * @throws ModelExecutionException If an error occurs during session run.
+ * @throws MissingModelInputException If required inputs are missing.
*/
- public function getAttentions(array $decoderResults): array
+ public function runSession(InferenceSession $session, array $inputs): array
{
- $attns = [];
+ try {
+ $inputNames = array_column($session->inputs(), 'name');
- foreach (['cross_attentions', 'decoder_attentions'] as $attnName) {
- $result = [];
- foreach ($decoderResults as $name => $value) {
- if (str_starts_with($name, $attnName)) {
- $index = intval(substr(strrchr($name, '.'), 1));
- $result[$index] = $value;
- }
- }
- $attns[$attnName] = $result;
- }
+ $inputs = $this->validateInputs($inputNames, $inputs);
- return $attns;
+ $outputNames = array_column($session->outputs(), 'name');
+
+ return $session->run($outputNames, $inputs);
+ } catch (MissingModelInputException $e) {
+ throw $e;
+ } catch (Exception $e) {
+ $this->logger->error('ONNX session run failed', ['exception' => $e]);
+ throw ModelExecutionException::make($e->getMessage(), $e);
+ }
}
/**
- * Adds past key values to the decoder feeds object. If pastKeyValues is null, creates new tensors for past key values.
+ * Validates the inputs against the expected input names of the ONNX session.
*
- * @param array $decoderFeeds The decoder feeds object to add past key values to.
- * @param ?array $pastKeyValues An object containing past key values.
+ * @param string[] $inputNames Expected input names.
+ * @param array $inputs Provided inputs.
+ * @return array Validated inputs.
+ * @throws MissingModelInputException If required inputs are missing.
*/
- public function addPastKeyValues(array &$decoderFeeds, ?array $pastKeyValues): void
+ public function validateInputs(array $inputNames, array $inputs): array
{
- if ($pastKeyValues !== null) {
- $decoderFeeds = array_merge($decoderFeeds, $pastKeyValues);
- } else {
- // TODO support batches (i.e., batch_size > 1)
- $batchSize = 1;
+ $checkedInputs = [];
+ $missingInputs = [];
- if ($this->config->isEncoderDecoder && ($this->addEncoderPkv ?? true)) {
- $encoderShape = [$batchSize, $this->numEncoderHeads, 0, $this->encoderDimKv];
- $decoderShape = [$batchSize, $this->numDecoderHeads, 0, $this->decoderDimKv];
+ foreach ($inputNames as $inputName) {
+ $tensor = $inputs[$inputName] ?? null;
+ if (!($tensor instanceof Tensor)) {
+ $missingInputs[] = $inputName;
+ continue;
+ }
- for ($i = 0; $i < $this->numDecoderLayers; ++$i) {
- $decoderFeeds["past_key_values.$i.encoder.key"]
- = $decoderFeeds["past_key_values.$i.encoder.value"]
- = new Tensor([], shape: $encoderShape);
- $decoderFeeds["past_key_values.$i.decoder.key"]
- = $decoderFeeds["past_key_values.$i.decoder.value"]
- = new Tensor([], shape: $decoderShape);
- }
- } else if ($this->config->modelType === 'falcon') {
- // NOTE: Custom implementation for Falcon
- $shape = [$batchSize * $this->numHeads, 0, $this->dimKv];
+ $checkedInputs[$inputName] = $tensor;
+ }
- for ($i = 0; $i < $this->numLayers; ++$i) {
- $decoderFeeds["past_key_values.$i.key"] = new Tensor([], shape: $shape);
- $decoderFeeds["past_key_values.$i.value"] = new Tensor([], shape: $shape);
- }
- } else if ($this->config['multi_query'] ?? null) { // e.g., for `gpt_bigcode`
- $shape = [$batchSize * $this->numHeads, 0, 2 * $this->dimKv];
+ if (!empty($missingInputs)) {
+ $this->logger->warning('Missing required model inputs', ['missing' => $missingInputs]);
+ throw MissingModelInputException::make($missingInputs);
+ }
- for ($i = 0; $i < $this->numLayers; ++$i) {
- $decoderFeeds["past_key_values.$i.key_value"] = new Tensor([], shape: $shape);
- }
- } else if ($this->config['model_type'] === 'bloom') {
- // NOTE: Custom implementation for Bloom
- $keyShape = [$batchSize * $this->numHeads, $this->dimKv, 0];
- $valueShape = [$batchSize * $this->numHeads, 0, $this->dimKv];
-
- for ($i = 0; $i < $this->numLayers; ++$i) {
- $decoderFeeds["past_key_values.$i.key"] = new Tensor([], shape: $keyShape);
- $decoderFeeds["past_key_values.$i.value"] = new Tensor([], shape: $valueShape);
- }
- } else { // Decoder-only
- $shape = [$batchSize, $this->numHeads, 0, $this->dimKv];
+ $numInputsProvided = count($inputs);
+ $numInputsNeeded = count($inputNames);
- for ($i = 0; $i < $this->numLayers; ++$i) {
- $decoderFeeds["past_key_values.$i.key"] = new Tensor([], shape: $shape);
- $decoderFeeds["past_key_values.$i.value"] = new Tensor([], shape: $shape);
- }
- }
+ if ($numInputsProvided > $numInputsNeeded) {
+ $ignored = array_diff(array_keys($inputs), $inputNames);
+ $this->logger->warning('Too many inputs were provided (' . $numInputsProvided . ' > ' . $numInputsNeeded . ').
+ The following inputs will be ignored: "' . implode(', ', $ignored) . '".');
}
+
+ return $inputs;
}
- /** Generates text based on the given inputs and generation configuration using the model.
- *
- * @param Tensor $inputs The input token ids.
- * @param GenerationConfig|null $generationConfig The generation configuration to use. If null, default configuration will be used.
- * @param LogitsProcessorList|null $logitsProcessor An optional logits processor to use. If null, a new LogitsProcessorList instance will be created.
- * @param Tensor|null $inputsAttentionMask An optional attention mask for the inputs.
- * @param Streamer|null $streamer
- *
- * @return array An array of generated output sequences, where each sequence is an array of token IDs.
- * @throws Exception
+ /**
+ * Validates that the current model class is suitable for generation.
+ * @throws Error If the model class cannot perform generation.
+ * @return void
*/
- public function generate(
- Tensor $inputs,
- ?GenerationConfig $generationConfig = null,
- ?LogitsProcessorList $logitsProcessor = null,
- Tensor $inputsAttentionMask = null,
- ?Streamer $streamer = null,
- ): array
+ public function ensureModelCanGenerate(): void
{
if (!$this->modelArchitecture->canGenerate()) {
$className = get_called_class();
- $errorMsg = "The current model class {$className} is not is not compatible with \`generate()\`, as it doesn't have a language model head.";
+ $errorMsg = "The current model class $className is not is not compatible with \`generate()\`, as it doesn't have a language model head.";
$possibleInfo =
- AutoModelForCausalLM::MODEL_CLASS_MAPPING[$this->config->modelType]
- ?? AutoModelForSeq2SeqLM::MODEL_CLASS_MAPPING[$this->config->modelType]
+ AutoModelForCausalLM::MODELS[$this->config->modelType]
+ ?? AutoModelForSeq2SeqLM::MODELS[$this->config->modelType]
?? null;
if ($possibleInfo) {
@@ -587,222 +583,170 @@ public function generate(
}
throw new Error($errorMsg);
-
}
+ }
-
- $inputIdsSeqLength = 0;
-
- // Prepare `input_ids` which will be used for auto-regressive generation
- // TODO: Update to align with HF transformers' implementation
- if (!$this->config->isEncoderDecoder) {
- $inputIdsSeqLength = $inputs->shape()[count($inputs->shape()) - 1];
-
- // decoder-only
- if ($inputIdsSeqLength === 0) {
- throw new Error("Must supply a non-empty Tensor of input token ids.");
+ /**
+ * Merges multiple generation configs to create the final configuration for generation.
+ *
+ * @param ?GenerationConfig $generationConfig User-provided generation config.
+ * @return GenerationConfig The final generation config.
+ */
+ protected function prepareGenerationConfig(?GenerationConfig $userProvidedConfig): GenerationConfig
+ {
+ $modelConfig = $this->config->config;
+ foreach (["decoder", "generator", "text_config"] as $key) {
+ if (array_key_exists($key, $modelConfig)) {
+ $modelConfig = array_merge($modelConfig, $modelConfig[$key]);
}
}
- // Update generation config with defaults
- $generationConfig = $this->getGenerationConfig($generationConfig);
-
- $logitsProcessor ??= new LogitsProcessorList();
-
- // Update logits processor
- $logitsProcessor = $this->getLogitsProcessor($generationConfig, $inputIdsSeqLength, $logitsProcessor);
+ return GenerationConfig::mergeConfigs($modelConfig, $this->generationConfig, $userProvidedConfig);
+ }
- $eosTokenIds = $generationConfig->eos_token_id;
+ /**
+ * Prepares the encoder inputs for generation, handling potential conflicts.
+ *
+ * @param ?Tensor $inputs The input tensor.
+ * @param array $modelKwargs Additional model-specific arguments.
+ * @return array An array containing the prepared model inputs and the main input name.
+ * @throws Exception If `inputs` and main input name are both passed.
+ */
+ function prepareEncoderInputs(?Tensor $inputs = null, array $modelKwargs = []): array
+ {
+ $modelInputs = array_pick($modelKwargs, $this->forwardParams);
+ $inputName = $this->mainInputName;
- if ($eosTokenIds !== null && !is_array($eosTokenIds)) {
- $eosTokenIds = [$eosTokenIds];
+ if (array_key_exists($inputName, $modelInputs)) {
+ if ($inputs) {
+ throw new Exception(
+ "`inputs` were passed alongside `{$inputName}` which is not allowed. " .
+ "Make sure to either pass `inputs` or `{$inputName}`."
+ );
+ }
+ } else {
+ $modelInputs[$inputName] = $inputs;
}
- // TODO implement early_stopping
- // https://huggingface.co/blog/how-to-generate
-
- $numOutputTokens = 1;
- $maxOutputTokens = $numOutputTokens + ($generationConfig->max_new_tokens ?? INF);
-
- // Only use max length if max_new_tokens is not provided
- $useMaxLength = is_null($generationConfig->max_new_tokens);
-
- $sampler = Sampler::getSampler($generationConfig);
-
-
- $beams = $this->getStartBeams($inputs, $generationConfig, $numOutputTokens, $inputsAttentionMask);
-
- while (array_some($beams, fn ($beam) => !$beam['done']) && $numOutputTokens < $maxOutputTokens) {
- $newestBeams = [];
- foreach ($beams as $beam) {
- if ($beam['done']) {
- // Add this beam back into the pool
- $newestBeams[] = $beam;
- continue;
- }
- if ($useMaxLength && count($beam['output_token_ids']) >= $generationConfig->max_length) {
- // Set this beam to done and add it back into the pool
- $beam['done'] = true;
- $newestBeams[] = $beam;
- continue;
- }
-
- $output = $this->runBeam($beam);
-
- // add attentions/scores to beam only if user requested
- if ($generationConfig->output_attentions) {
- $this->addAttentionsToBeam($beam, $output);
- }
-
-
- if ($generationConfig->output_scores) {
- // TODO add
- }
-
- // Logits are of the form [batch_size, out_seq_length, vocab_size]
- // In most cases, this will be [batch_size, 1, vocab_size]
- // So, we select the last token's logits:
- // (equivalent to `logits = outputs.logits[:, -1, :]`)
- $logits = $output['logits']->slice(null, -1, null);
-
- // Apply logits processor
- $logitsProcessor($beam['output_token_ids'], $logits);
-
- $sampledTokens = $sampler($logits);
+ return [$modelInputs, $inputName];
+ }
- foreach ($sampledTokens as [$newTokenId, $logProb]) {
- // use previous beam as a starting point
- $newBeam = $beam;
+ /**
+ * Runs the forward pass for the encoder part of an encoder-decoder model.
+ *
+ * @param array $modelInputs The model inputs.
+ * @param GenerationConfig $generationConfig The generation configuration.
+ * @return array The updated model inputs including encoder outputs.
+ * @throws Exception If batch sizes mismatch or other errors occur.
+ */
+ function runEncoderForwardPass($modelInputs, GenerationConfig $generationConfig)
+ {
+ $inputNames = array_column($this->sessions['encoder']->inputs(), 'name');
+
+ if (
+ in_array('inputs_embeds', $inputNames) &&
+ !isset($modelInputs['inputs_embeds']) &&
+ method_exists($this, 'prepareInputsEmbeds')
+ ) {
+ // Encoder expects `inputs_embeds` instead of `input_ids`
+ $kwargs = array_diff_key($modelInputs, array_flip(['input_ids', 'pixel_values', 'attention_mask']));
+ $preparedInputs = call_user_func([$this, 'prepareInputsEmbeds'], $modelInputs);
+ $modelInputs = array_merge(
+ $kwargs,
+ array_pick($preparedInputs, ['inputs_embeds', 'attention_mask'])
+ );
+ }
- // update new beam
- $this->updateBeam($newBeam, $newTokenId);
+ $encoderOutputs = $this->modelArchitecture->encoderForward($this, $modelInputs);
- $newBeam['score'] += $logProb;
+ $lastHiddenState = $encoderOutputs['last_hidden_state'];
- if ($eosTokenIds && in_array($newTokenId, $eosTokenIds, true)) {
- $newBeam['done'] = true;
- }
+ // Handle classifier-free guidance
+ if (!is_null($generationConfig['guidance_scale'] ?? null) && $generationConfig['guidance_scale'] > 1) {
+ $lastHiddenState = Tensor::concat([$lastHiddenState, Tensor::zerosLike($lastHiddenState)]);
- $newestBeams[] = $newBeam;
+ if (isset($model_inputs['attention_mask'])) {
+ $modelInputs['attention_mask'] = Tensor::concat([
+ $modelInputs['attention_mask'],
+ Tensor::zerosLike($modelInputs['attention_mask'])
+ ]);
+ }
+ } elseif (isset($modelInputs['decoder_input_ids'])) {
+ $decoderBatchSize = $modelInputs['decoder_input_ids']->shape()[0];
+ if ($decoderBatchSize !== $lastHiddenState->shape()[0]) {
+ if ($lastHiddenState->shape()[0] !== 1) {
+ throw new Exception(sprintf(
+ "The encoder outputs have a different batch size (%d) than the decoder inputs (%d).",
+ $lastHiddenState->shape()[0],
+ $decoderBatchSize
+ ));
}
-
+ $lastHiddenState = Tensor::concat(array_fill(0, $decoderBatchSize, $lastHiddenState));
}
-
- ++$numOutputTokens;
-
- // Group and select best beams
- $newestBeams = array_merge(...array_map(
- function ($group) use ($generationConfig) {
- usort($group, fn ($a, $b) => $b['score'] <=> $a['score']);
- return array_slice(
- $group,
- 0,
- $generationConfig->num_beams
- );
- },
- $this->groupBeams($newestBeams)
- ));
-
- // Flatten beams
- $beams = $newestBeams;
-
- // Stream the beams if a streamer is provided
- $streamer?->put($beams);
}
- // TODO: Ensure that we can return non-batched outputs
-
- $groupedBeams = $this->groupBeams($beams);
-
- $getFlattened = function ($key) use ($groupedBeams, $generationConfig) {
- $flattened = array_map(
- function ($batch) use ($key, $generationConfig) {
- if ($generationConfig->num_return_sequences > 1) {
- return array_slice(
- array_map(fn ($beam) => $beam[$key], $batch),
- 0,
- $generationConfig->num_return_sequences
- );
- } else {
- // Only extract the first element's key value
- return [$batch[0][$key]];
- }
- },
- $groupedBeams
- );
-
- return array_merge(...$flattened); // Flatten the resulting array
- };
+ $modelInputs['encoder_outputs'] = $lastHiddenState;
- $sequences = $getFlattened('output_token_ids'); // [1, seqLength]
-
- // End the streamer if it was provided
- $streamer?->end();
-
-
- if ($generationConfig->return_dict_in_generate) {
- // NOTE: `decoder_attentions` and `cross_attentions` should be:
- // list (one element for each generated token)
- // of list (one element for each layer of the decoder)
- // of torch.FloatTensor of shape (batch_size, num_heads, generated_length, sequence_length)
- // However, since we are only generating one batch at a time, they are of the form:
- // list (batches)
- // of list (one element for each generated token)
- // of list (one element for each layer of the decoder)
- // of torch.FloatTensor of shape (1, num_heads, generated_length, sequence_length)
- //
- // TODO: In future (when true parallelism, we should be able to return the correct shape)
-
- $decoderAttentions = $getFlattened('decoder_attentions');
- $crossAttentions = $getFlattened('cross_attentions');
-
- return [
- 'sequences' => $sequences,
- 'decoder_attentions' => $decoderAttentions,
- 'cross_attentions' => $crossAttentions,
- ];
- } else {
- return $sequences;
- }
+ return $modelInputs;
}
/**
- * This function merges multiple generation configs together to form a final generation config to be used by the model for text generation.
- * It first creates an empty `GenerationConfig` object, then it applies the model's own `generation_config` property to it. Finally, if a `generation_config` object was passed in the arguments, it overwrites the corresponding properties in the final config with those of the passed config object.
- *
- * @param ?GenerationConfig $generationConfig A `GenerationConfig` object containing generation parameters.
+ * Prepares the initial decoder inputs for generation.
*
- * @return GenerationConfig The final generation config object to be used by the model for text generation.
+ * @param int $batchSize The batch size.
+ * @param array $modelInputs The current model inputs.
+ * @param GenerationConfig $generationConfig The generation configuration.
+ * @return array An array containing the decoder input IDs and updated model inputs.
+ * @throws Exception If `decoder_start_token_id` has incorrect length.
*/
- protected function getGenerationConfig(?GenerationConfig $generationConfig): GenerationConfig
+ function prepareDecoderInputs($batchSize, $modelInputs, GenerationConfig $generationConfig): array
{
- // Create empty generation config (contains defaults)
- // We pass `$this->config` so that if `eos_token_id` or `bos_token_id` exist in the model's config, we will use them
- $genConfig = new GenerationConfig($this->config->config);
-
- $genConfigArray = $genConfig->toArray();
-
- // Apply model's generation config, if it exists
- if (property_exists($this, 'generationConfig')) {
- $genConfigArray = array_merge($genConfigArray, $this->generationConfig->toArray());
- }
+ $decoderInputIds = array_pop_key($modelInputs, 'decoder_input_ids');
+
+ // Prepare input IDs if not manually defined
+ if (!$decoderInputIds instanceof Tensor) {
+ if (empty($decoderInputIds)) {
+ $decoderStartTokenId = $generationConfig->decoder_start_token_id ?? $generationConfig->bos_token_id;
+
+ if ($this->config['model_type'] === 'musicgen') {
+ $decoderInputIds = array_fill(0, $batchSize * $this->config['decoder']['num_codebooks'], [$decoderStartTokenId]);
+ } elseif (is_array($decoderStartTokenId)) {
+ if (count($decoderStartTokenId) !== $batchSize) {
+ throw new Exception(sprintf(
+ "`decoder_start_token_id` expected to have length %d but got %d",
+ $batchSize,
+ count($decoderStartTokenId)
+ ));
+ }
+ $decoderInputIds = $decoderStartTokenId;
+ } else {
+ $decoderInputIds = array_fill(0, $batchSize, [$decoderStartTokenId]);
+ }
+ } elseif (!is_array($decoderInputIds[0])) {
+ $decoderInputIds = array_fill(0, $batchSize, $decoderInputIds);
+ }
- // Finally, use any generation config specified by the user
- // when calling `generate`
- if ($generationConfig !== null) {
- $genConfigArray = array_merge($genConfigArray, $generationConfig->toArray());
+ $decoderInputIds = Tensor::fromArray($decoderInputIds, Tensor::int64);
}
+ $modelInputs['decoder_attention_mask'] = Tensor::onesLike($decoderInputIds);
- return new GenerationConfig($genConfigArray);
+ return [$decoderInputIds, $modelInputs];
}
- protected function getLogitsProcessor(
+ /**
+ * Prepares the list of logits processors based on the generation configuration.
+ *
+ * @param GenerationConfig $generationConfig The generation configuration.
+ * @param int $inputIdsSeqLength The length of the initial input IDs sequence.
+ * @param ?LogitsProcessorList $logitsProcessor Optional existing logits processors list.
+ * @return LogitsProcessorList The configured list of logits processors.
+ */
+ protected function prepareLogitsProcessor(
GenerationConfig $generationConfig,
int $inputIdsSeqLength,
?LogitsProcessorList $logitsProcessor = null
- ): LogitsProcessorList
- {
+ ): LogitsProcessorList {
$processors = new LogitsProcessorList();
if ($generationConfig->repetition_penalty != null && $generationConfig->repetition_penalty !== 1.0) {
@@ -814,7 +758,7 @@ protected function getLogitsProcessor(
}
if ($generationConfig->bad_words_ids != null) {
- $processors->push(new BadWordsLogitsProcessor($generationConfig->bad_words_ids, $inputIdsSeqLength));
+ $processors->push(new NoBadWordsLogitsProcessor($generationConfig->bad_words_ids, $inputIdsSeqLength));
}
if ($generationConfig->min_length != null && $generationConfig->eos_token_id != null && $generationConfig->min_length > 0) {
@@ -822,10 +766,12 @@ protected function getLogitsProcessor(
}
if ($generationConfig->min_new_tokens != null && $generationConfig->eos_token_id != null && $generationConfig->min_new_tokens > 0) {
- $processors->push(new MinNewTokensLengthLogitsProcessor(
+ $processors->push(
+ new MinNewTokensLengthLogitsProcessor(
$inputIdsSeqLength,
$generationConfig->min_new_tokens,
- $generationConfig->eos_token_id)
+ $generationConfig->eos_token_id
+ )
);
}
@@ -849,130 +795,162 @@ protected function getLogitsProcessor(
$processors->push(new SuppressTokensAtBeginLogitsProcessor($generationConfig->begin_suppress_tokens, $beginIndex));
}
- if ($generationConfig->forced_decoder_ids !== null) {
- $processors->push(new ForceTokensLogitsProcessor($generationConfig->forced_decoder_ids));
- }
-
if ($logitsProcessor !== null) {
$processors->extend($logitsProcessor);
}
-// `LogitNormalization` should always be the last logit processor, when present
-// if($generationConfig->renormalize_logits) {
-// $processors->push(new LogitNormalization());
-// }
+ // `LogitNormalization` should always be the last logit processor, when present
+ // if($generationConfig->renormalize_logits) {
+ // $processors->push(new LogitNormalization());
+ // }
return $processors;
-
}
/**
- * Initializes and returns the beam for text generation task
- *
- * @param Tensor $inputTokenIds The input token ids.
- * @param GenerationConfig $generationConfig The generation config.
- * @param int $numOutputTokens The number of tokens to generate.
- * @param Tensor|null $inputsAttentionMask The attention mask for the input token ids.
- *
- * @return array{ inputs: Tensor, output_token_ids: Tensor, score: float, done: bool, id: int } The initial beam for text generation.
+ * Prepares the list of stopping criteria based on the generation configuration.
*
+ * @param GenerationConfig $generationConfig The generation configuration.
+ * @param ?StoppingCriteriaList $stoppingCriteria Optional existing stopping criteria list.
+ * @return StoppingCriteriaList The configured list of stopping criteria.
*/
- public function getStartBeams(
- Tensor $inputTokenIds,
- GenerationConfig $generationConfig,
- int $numOutputTokens,
- Tensor $inputsAttentionMask = null
- ): array
+ public function prepareStoppingCriteria(GenerationConfig $generationConfig, ?StoppingCriteriaList $stoppingCriteria = null): StoppingCriteriaList
{
- return $this->modelArchitecture->startBeams(
- $this,
- $inputTokenIds,
- $generationConfig,
- $numOutputTokens,
- $inputsAttentionMask
+ $criteria = $stoppingCriteria ?? new StoppingCriteriaList();
+
+ $criteria->push(
+ new MaxLengthCriteria($generationConfig->max_length, $generationConfig['max_position_embeddings'] ?? null)
);
+
+ if ($generationConfig->max_time !== null) {
+ $criteria->push(new MaxTimeCriteria($generationConfig->max_time));
+ }
+
+ if ($generationConfig->eos_token_id !== null) {
+ $criteria->push(new EosTokenCriteria($generationConfig->eos_token_id));
+ }
+
+ return $criteria;
}
+
/**
- * Runs the beam for text generation task
- *
- * @param array $beam The current beam being generated.
- *
- * @return array The updated beam after a single generation step.
+ * Prepares the inputs required for the model's forward pass within the generation loop.
+ * Delegates to the model architecture specific implementation.
*
+ * @param array $inputs Current input IDs.
+ * @param array $modelInputs Current model inputs (including past states).
+ * @return array Prepared model inputs for the next forward pass.
*/
- public function runBeam(array &$beam): array
+ function prepareInputsForGeneration(array $inputs, array $modelInputs)
{
- return $this->modelArchitecture->runBeam($this, $beam);
+ return $this->modelArchitecture->prepareInputsForGeneration($this, $inputs, $modelInputs);
}
/**
- * Helper function to add attentions to beam.
+ * Updates the model inputs dictionary for the next generation step.
*
- * @param array $beam
- * @param array $output
+ * @param array $generatedInputIds The newly generated token IDs for the current step.
+ * @param array $outputs The outputs from the model's forward pass in the current step.
+ * @param array $modelInputs The model inputs used in the current step.
+ * @param bool $isEncoderDecoder Whether the model is an encoder-decoder architecture.
+ * @return array The updated model inputs for the next generation step.
+ */
+ function updateInputsAfterGeneration(array $generatedInputIds, $outputs, $modelInputs, $isEncoderDecoder)
+ {
+ $modelInputs['past_key_values'] = $this->getPastKeyValues($outputs, $modelInputs['past_key_values'] ?? null);
+
+ // Update input_ids for the next run
+ $flatGeneratedInputIds = array_merge(...$generatedInputIds);
+ $modelInputs['input_ids'] = new Tensor($flatGeneratedInputIds, Tensor::int64, [count($generatedInputIds), 1]);
+
+ if (!$isEncoderDecoder) {
+ // Update attention mask
+ $modelInputs['attention_mask'] = Tensor::concat([
+ $modelInputs['attention_mask'],
+ Tensor::ones([$modelInputs['attention_mask']->shape()[0], 1], Tensor::int64)
+ ], 1);
+ } elseif (array_key_exists('decoder_attention_mask', $modelInputs)) {
+ // TODO: Update decoder attention mask if the model requires it
+ }
+
+ // Force recreate position_ids in the next iteration
+ $modelInputs['position_ids'] = null;
+
+ return $modelInputs;
+ }
+
+ /**
+ * Extracts past key values from the decoder/model outputs.
*
- * @throws Exception
+ * @param array $decoderResults The outputs from the decoder/model forward pass.
+ * @param ?array $pastKeyValues The previous past key values.
+ * @return array An object containing the updated past key values.
*/
- public function addAttentionsToBeam(array &$beam, array $output): void
+ public function getPastKeyValues(array $decoderResults, ?array $pastKeyValues): array
{
- if ($this->config->isEncoderDecoder) {
- if (empty($output['cross_attentions'])) {
- throw new Exception(
- "`output_attentions` is true, but the model did not produce cross-attentions. ".
- "This is most likely because the model was not exported with `output_attentions=True`."
- );
- }
- if (!isset($beam['cross_attentions'])) {
- $beam['cross_attentions'] = [];
+ $pkvs = [];
+
+ foreach ($decoderResults as $name => $value) {
+ if (str_starts_with($name, 'present')) {
+ $newName = str_replace('present', 'past_key_values', $name);
+
+ if ($pastKeyValues && str_contains($name, 'encoder')) {
+ // Optimization introduced by optimum to reuse past key values.
+ // So, we just replace the constant outputs with the previous past key values.
+ // https://github.com/huggingface/optimum/blob/0bf2c05fb7e1182b52d21b703cfc95fd9e4ea3dc/optimum/onnxruntime/base.py#L677-L704
+ $pkvs[$newName] = $pastKeyValues[$newName];
+ } else {
+ $pkvs[$newName] = $value;
+ }
}
- $beam['cross_attentions'][] = $output['cross_attentions'];
}
- if (empty($output['decoder_attentions'])) {
- throw new Exception(
- "`output_attentions` is true, but the model did not produce decoder-attentions. ".
- "This is most likely because the model was not exported with `output_attentions=True`."
- );
- }
- if (!isset($beam['decoder_attentions'])) {
- $beam['decoder_attentions'] = [];
- }
- $beam['decoder_attentions'][] = $output['decoder_attentions'];
+ return $pkvs;
}
/**
- * Update a beam with a new token ID.
- *
- * @param array $beam The beam to update.
- * @param int $newTokenId The new token id to add to the beam.
+ * Extracts attention values from the decoder/model outputs.
*
+ * @param array $decoderResults The outputs from the decoder/model forward pass.
+ * @return array An object containing attentions.
*/
- public function updateBeam(array &$beam, int $newTokenId): void
+ public function getAttentions(array $decoderResults): array
{
- $this->modelArchitecture->updateBeam($beam, $newTokenId);
+ $attns = [];
+
+ foreach (['cross_attentions', 'decoder_attentions'] as $attnName) {
+ $result = [];
+ foreach ($decoderResults as $name => $value) {
+ if (str_starts_with($name, $attnName)) {
+ $index = intval(substr(strrchr($name, '.'), 1));
+ $result[$index] = $value;
+ }
+ }
+ $attns[$attnName] = $result;
+ }
+
+ return $attns;
}
/**
- * Groups an array of beam objects by their ids.
+ * Adds past key values to the decoder feeds object for the ONNX session.
+ * Initializes tensors if `pastKeyValues` is null.
*
- * @param array $beams The array of beam objects to group.
- *
- * @return array An array of arrays, where each inner array contains beam objects with the same id.
+ * @param array $decoderFeeds The decoder feeds object (passed by reference).
+ * @param ?array $pastKeyValues An object containing past key values.
+ * @return void
*/
- public function groupBeams(array $beams): array
+ public function addPastKeyValues(array &$decoderFeeds, ?array $pastKeyValues): void
{
- $groups = [];
-
- foreach ($beams as $obj) {
-// $groups[$obj['id']][] = $obj;
- if (!isset($groups[$obj['id']])) {
- $groups[$obj['id']] = [$obj];
- } else {
- $groups[$obj['id']][] = $obj;
+ if ($pastKeyValues !== null) {
+ $decoderFeeds = array_merge($decoderFeeds, $pastKeyValues);
+ } else {
+ $shapes = $this->config->getKeyValueShapes();
+
+ foreach ($shapes as $name => $shape) {
+ $decoderFeeds[$name] = new Tensor([], shape: $shape);
}
}
-
- return array_values($groups);
}
}
diff --git a/src/Models/Pretrained/Qwen2PreTrainedModel.php b/src/Models/Pretrained/Qwen2PreTrainedModel.php
index 1f158d2..7f9856f 100644
--- a/src/Models/Pretrained/Qwen2PreTrainedModel.php
+++ b/src/Models/Pretrained/Qwen2PreTrainedModel.php
@@ -2,38 +2,9 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Pretrained;
-use Codewithkyrian\Transformers\Models\ModelArchitecture;
-use Codewithkyrian\Transformers\Utils\AutoConfig;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
-use Codewithkyrian\Transformers\Utils\InferenceSession;
-
/**
* The bare Qwen2 Model outputting raw hidden-states without any specific head on top.
*/
-class Qwen2PreTrainedModel extends PretrainedModel
-{
- protected int $numHeads;
- protected int $numLayers;
- protected int $dimKv;
-
- public function __construct(
- AutoConfig $config,
- InferenceSession $session,
- public ModelArchitecture $modelArchitecture,
- public GenerationConfig $generationConfig
- )
- {
- parent::__construct($config, $session, $modelArchitecture);
-
- // config doesn't contain pad_token_id, so we assume it is the eos_token_id
- $this->config['pad_token_id'] = $this->config['eos_token_id'];
- $this->config->padTokenId = $this->config['eos_token_id'];
-
- $this->numHeads = $this->config['num_key_value_heads'] ?? $this->config['num_attention_heads'];
- $this->numLayers = $this->config['num_hidden_layers'];
- $this->dimKv = $this->config['hidden_size'] / $this->config['num_attention_heads'];
- }
-}
+class Qwen2PreTrainedModel extends PretrainedModel {}
diff --git a/src/Models/Pretrained/Qwen3ForCausalLM.php b/src/Models/Pretrained/Qwen3ForCausalLM.php
new file mode 100644
index 0000000..731b88d
--- /dev/null
+++ b/src/Models/Pretrained/Qwen3ForCausalLM.php
@@ -0,0 +1,7 @@
+numDecoderLayers = $this->config['num_decoder_layers'];
- $this->numDecoderHeads = $this->config['num_heads'];
- $this->decoderDimKv = $this->config['d_kv'];
-
- $this->numEncoderLayers = $this->config['num_layers'];
- $this->numEncoderHeads = $this->config['num_heads'];
- $this->encoderDimKv = $this->config['d_kv'];
- }
-}
\ No newline at end of file
+class T5ForConditionalGeneration extends T5PretrainedModel {}
diff --git a/src/Models/Pretrained/T5PretrainedModel.php b/src/Models/Pretrained/T5PretrainedModel.php
index 2dd64a8..959009e 100644
--- a/src/Models/Pretrained/T5PretrainedModel.php
+++ b/src/Models/Pretrained/T5PretrainedModel.php
@@ -7,5 +7,12 @@
class T5PretrainedModel extends PretrainedModel
{
-
-}
\ No newline at end of file
+ protected array $forwardParams = [
+ 'input_ids',
+ 'attention_mask',
+ 'encoder_outputs',
+ 'decoder_input_ids',
+ 'decoder_attention_mask',
+ 'past_key_values',
+ ];
+}
diff --git a/src/Models/Pretrained/TrOCRPretrainedModel.php b/src/Models/Pretrained/TrOCRPretrainedModel.php
index f192db7..b4410fd 100644
--- a/src/Models/Pretrained/TrOCRPretrainedModel.php
+++ b/src/Models/Pretrained/TrOCRPretrainedModel.php
@@ -2,35 +2,6 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Pretrained;
-use Codewithkyrian\Transformers\Models\ModelArchitecture;
-use Codewithkyrian\Transformers\Utils\AutoConfig;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
-use Codewithkyrian\Transformers\Utils\InferenceSession;
-
-class TrOCRPretrainedModel extends PretrainedModel
-{
- public mixed $numDecoderLayers;
- public mixed $numDecoderHeads;
- public mixed $decoderDimKv;
- public mixed $numEncoderLayers;
- public mixed $numEncoderHeads;
- public mixed $encoderDimKv;
-
- public function __construct(
- AutoConfig $config,
- InferenceSession $session,
- public ModelArchitecture $modelArchitecture,
- public GenerationConfig $generationConfig
- )
- {
- parent::__construct($config, $session, $modelArchitecture);
-
-
- $this->numEncoderLayers = $this->numDecoderLayers = $this->config['decoder_layers'];
- $this->numEncoderHeads = $this->numDecoderHeads = $this->config['decoder_attention_heads'];
- $this->encoderDimKv = $this->decoderDimKv = $this->config['d_model'] / $this->numDecoderHeads;
- }
-}
\ No newline at end of file
+class TrOCRPretrainedModel extends PretrainedModel {}
diff --git a/src/Models/Pretrained/VisionEncoderDecoderModel.php b/src/Models/Pretrained/VisionEncoderDecoderModel.php
index 3c888cd..a9a7e6e 100644
--- a/src/Models/Pretrained/VisionEncoderDecoderModel.php
+++ b/src/Models/Pretrained/VisionEncoderDecoderModel.php
@@ -2,94 +2,21 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Pretrained;
-
-use Codewithkyrian\Transformers\Models\Auto\AutoModel;
-use Codewithkyrian\Transformers\Models\Auto\AutoModelForCausalLM;
-use Codewithkyrian\Transformers\Models\ModelArchitecture;
-use Codewithkyrian\Transformers\Transformers;
-use Codewithkyrian\Transformers\Utils\AutoConfig;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
-use Codewithkyrian\Transformers\Utils\InferenceSession;
-
/**
* Vision Encoder-Decoder model based on OpenAI's GPT architecture for image captioning and other vision tasks
*/
class VisionEncoderDecoderModel extends PretrainedModel
{
public string $mainInputName = 'pixel_values';
- protected bool $addEncoderPkv;
- protected mixed $numDecoderLayers;
- protected mixed $numDecoderHeads;
- protected mixed $decoderDimKv;
- protected mixed $numEncoderLayers;
- protected mixed $numEncoderHeads;
- protected mixed $encoderDimKv;
- protected $numLayers;
- protected $numHeads;
- protected $dimKv;
-
- /**
- * Creates a new instance of the `VisionEncoderDecoderModel` class.
- *
- * @param AutoConfig $config The configuration array specifying the hyperparameters and other model settings.
- * @param mixed $session The ONNX session containing the encoder model.
- * @param InferenceSession $decoderMergedSession The ONNX session containing the merged decoder model.
- * @param ModelArchitecture $modelArchitecture
- * @param GenerationConfig $generationConfig Configuration object for the generation process.
- */
- public function __construct(
- AutoConfig $config,
- InferenceSession $session,
- public InferenceSession $decoderMergedSession,
- public ModelArchitecture $modelArchitecture,
- public GenerationConfig $generationConfig
- )
- {
- parent::__construct($config, $session, $this->modelArchitecture);
-
- // Extract configs
- $encoderConfig = $this->config['encoder'];
- $decoderConfig = $this->config['decoder'];
-
- $decoderConfig = AutoConfig::fromPretrained('', $decoderConfig);
-
- // Validate encoder
- $encoderModelType = $encoderConfig['model_type'];
- $encoderModel = AutoModel::ENCODER_ONLY_MODEL_MAPPING[$encoderModelType]
- ?? AutoModel::ENCODER_DECODER_MODEL_MAPPING[$encoderModelType];
-
- if (!$encoderModel) {
- Transformers::getLogger()?->warning("Model type for encoder '{$encoderModelType}' not found, assuming encoder-only architecture. Please report this at https://github.com/CodeWithKyrian/transformers-php/issues/new/choose.");
- }
-
- // Validate decoder
- $decoderModel = AutoModelForCausalLM::MODEL_CLASS_MAPPING[$decoderConfig['model_type']];
-
- if (!$decoderModel) {
- throw new \Exception("Unable to construct `VisionEncoderDecoder` due to unsupported decoder: '{$this->config['decoder']['model_type']}'");
- }
-
- $decoder = new $decoderModel($decoderConfig, $this->decoderMergedSession, ModelArchitecture::DecoderOnly, $this->generationConfig);
-
- $this->addEncoderPkv = property_exists($decoder, 'numDecoderLayers');
-
- if ($this->addEncoderPkv) {
- // Decoder is part of an encoder-decoder model
- $this->numDecoderLayers = $decoder->numDecoderLayers;
- $this->numDecoderHeads = $decoder->numDecoderHeads;
- $this->decoderDimKv = $decoder->decoderDimKv;
-
- $this->numEncoderLayers = $decoder->numEncoderLayers;
- $this->numEncoderHeads = $decoder->numEncoderHeads;
- $this->encoderDimKv = $decoder->encoderDimKv;
- } else {
- // Decoder is a decoder-only model
- $this->numLayers = $decoder->numLayers;
- $this->numHeads = $decoder->numHeads;
- $this->dimKv = $decoder->dimKv;
- }
- }
+ protected array $forwardParams = [
+ // Encoder inputs
+ 'pixel_values',
+
+ // Decoder inputs
+ 'decoder_input_ids',
+ 'encoder_hidden_states',
+ 'past_key_values',
+ ];
}
diff --git a/src/Models/Pretrained/WhisperForConditionalGeneration.php b/src/Models/Pretrained/WhisperForConditionalGeneration.php
index 8381967..5d95a08 100644
--- a/src/Models/Pretrained/WhisperForConditionalGeneration.php
+++ b/src/Models/Pretrained/WhisperForConditionalGeneration.php
@@ -2,63 +2,32 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Models\Pretrained;
+use Codewithkyrian\Transformers\Configs\GenerationConfig;
use Codewithkyrian\Transformers\Generation\LogitsProcessors\LogitsProcessorList;
use Codewithkyrian\Transformers\Generation\LogitsProcessors\WhisperTimeStampLogitsProcessor;
+use Codewithkyrian\Transformers\Generation\StoppingCriteria\StoppingCriteria;
use Codewithkyrian\Transformers\Generation\Streamers\Streamer;
-use Codewithkyrian\Transformers\Models\ModelArchitecture;
use Codewithkyrian\Transformers\Tensor\Tensor;
-use Codewithkyrian\Transformers\Utils\AutoConfig;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
-use Codewithkyrian\Transformers\Utils\InferenceSession;
+use Codewithkyrian\Transformers\Transformers;
use Exception;
use InvalidArgumentException;
-use function Codewithkyrian\Transformers\Utils\timeUsage;
class WhisperForConditionalGeneration extends WhisperPretrainedModel
{
- public bool $requiresAttentionMask = false;
public string $mainInputName = 'input_features';
- protected mixed $numDecoderLayers;
- protected mixed $numDecoderHeads;
- protected mixed $decoderDimKv;
- protected mixed $numEncoderLayers;
- protected mixed $numEncoderHeads;
- protected mixed $encoderDimKv;
-
- public function __construct(
- AutoConfig $config,
- InferenceSession $session,
- public InferenceSession $decoderMergedSession,
- public ModelArchitecture $modelArchitecture,
- public GenerationConfig $generationConfig
- )
- {
- parent::__construct($config, $session, $modelArchitecture);
-
- $this->numDecoderLayers = $this->config['decoder_layers'];
- $this->numDecoderHeads = $this->config['decoder_attention_heads'];
- $this->decoderDimKv = $this->config['d_model'] / $this->numDecoderHeads;
-
- $this->numEncoderLayers = $this->config['encoder_layers'];
- $this->numEncoderHeads = $this->config['encoder_attention_heads'];
- $this->encoderDimKv = $this->config['d_model'] / $this->numEncoderHeads;
- }
-
public function generate(
Tensor $inputs,
?GenerationConfig $generationConfig = null,
?LogitsProcessorList $logitsProcessor = null,
- Tensor $inputsAttentionMask = null,
- ?Streamer $streamer = null
- ): array
- {
- $generationConfig = $this->getGenerationConfig($generationConfig);
+ ?StoppingCriteria $stoppingCriteria = null,
+ ?Streamer $streamer = null,
+ ...$kwargs
+ ): array|Tensor {
+ $generationConfig = $this->prepareGenerationConfig($generationConfig);
- // Whisper has additional options for returning timestamps
$generationConfig['return_timestamps'] ??= false;
if ($generationConfig['return_timestamps']) {
@@ -66,19 +35,19 @@ public function generate(
$logitsProcessor->push(new WhisperTimeStampLogitsProcessor($generationConfig));
}
-
if (isset($generationConfig['return_token_timestamps'])) {
$generationConfig['output_attentions'] = true;
$generationConfig['return_dict_in_generate'] = true;
if ($generationConfig['task'] ?? '' === 'translate') {
- trigger_error("Token-level timestamps may not be reliable for task 'translate'.", E_USER_WARNING);
+ $logger = Transformers::getLogger();
+ $logger->warning("Token-level timestamps may not be reliable for task 'translate'.");
}
if (!isset($generationConfig['alignment_heads'])) {
throw new Exception(
"Model generation config has no `alignment_heads`, token-level timestamps not available. " .
- "See https://gist.github.com/hollance/42e32852f24243b748ae6bc1f985b13a on how to add this property to the generation config."
+ "See https://gist.github.com/hollance/42e32852f24243b748ae6bc1f985b13a on how to add this property to the generation config."
);
}
}
@@ -104,6 +73,7 @@ public function generate(
* @param array $alignmentHeads Alignment heads of the model
* @param int|null $numFrames Number of frames in the input audio
* @param float $timePrecision Precision of the timestamps in seconds
+ *
* @return Tensor Tensor containing the timestamps in seconds for each predicted token
* @throws Exception If the model outputs do not contain cross attentions
*/
@@ -112,18 +82,18 @@ public function extractTokenTimestamps(
array $alignmentHeads,
int|null $numFrames = null,
float $timePrecision = 0.02
- ): Tensor
- {
+ ): Tensor {
if (!isset($generateOutputs['cross_attentions'])) {
throw new Exception(
"Model outputs must contain cross attentions to extract timestamps. " .
- "This is most likely because the model was not exported with `output_attentions=True`."
+ "This is most likely because the model was not exported with `output_attentions=True`."
);
}
$medianFilterWidth = $this->config['median_filter_width'] ?? null;
if ($medianFilterWidth === null) {
- trigger_error("Model config has no `median_filter_width`, using default value of 7.", E_USER_WARNING);
+ $logger = Transformers::getLogger();
+ $logger->warning("Model config has no `median_filter_width`, using default value of 7.");
$medianFilterWidth = 7;
}
@@ -211,8 +181,10 @@ public function extractTokenTimestamps(
* Applies a median filter of width `$windowSize` along the last dimension of the input.
*
* The `$input` tensor is assumed to be 3- or 4-dimensional.
+ *
* @param Tensor $input
* @param int $windowSize
+ *
* @return Tensor
*/
function medianFilter(Tensor $input, int $windowSize): Tensor
@@ -252,7 +224,9 @@ function medianFilter(Tensor $input, int $windowSize): Tensor
* Measures
* similarity between two temporal sequences: the input audio and the output tokens. Used to generate
* token-level timestamps.
+ *
* @param Tensor $tensor
+ *
* @return array
*/
private function dynamicTimeWarping(Tensor $tensor): array
@@ -324,5 +298,4 @@ private function dynamicTimeWarping(Tensor $tensor): array
return [$textIndices, $timeIndices];
}
-
-}
\ No newline at end of file
+}
diff --git a/src/Models/Pretrained/WhisperPretrainedModel.php b/src/Models/Pretrained/WhisperPretrainedModel.php
index 65cabe5..547004e 100644
--- a/src/Models/Pretrained/WhisperPretrainedModel.php
+++ b/src/Models/Pretrained/WhisperPretrainedModel.php
@@ -7,5 +7,12 @@
class WhisperPretrainedModel extends PretrainedModel
{
-
-}
\ No newline at end of file
+ public string $mainInputName = 'input_features';
+ protected array $forwardParams = [
+ 'input_features',
+ 'attention_mask',
+ 'decoder_input_ids',
+ 'decoder_attention_mask',
+ 'past_key_values',
+ ];
+}
diff --git a/src/Normalizers/BertNormalizer.php b/src/Normalizers/BertNormalizer.php
index 21c2500..5a56019 100644
--- a/src/Normalizers/BertNormalizer.php
+++ b/src/Normalizers/BertNormalizer.php
@@ -2,16 +2,59 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Normalizers;
-use Codewithkyrian\Transformers\Tokenizers\TokenizerModel;
+use function Codewithkyrian\Transformers\Utils\isChineseChar;
/**
* A class representing a normalizer used in BERT tokenization.
*/
class BertNormalizer extends Normalizer
{
+ /**
+ * Performs invalid character removal and whitespace cleanup on text.
+ * @param string $text The text to clean.
+ * @return string The cleaned text.
+ * @private
+ */
+ function cleanText(string $text): string
+ {
+ $output = [];
+ for ($i = 0; $i < mb_strlen($text); ++$i) {
+ $char = mb_substr($text, $i, 1);
+ $cp = mb_ord($char);
+ if ($cp === 0 || $cp === 0xFFFD || $this->isControl($char)) {
+ continue;
+ }
+ if (preg_match('/^\s$/', $char)) { // is whitespace
+ $output[] = " ";
+ } else {
+ $output[] = $char;
+ }
+ }
+ return implode("", $output);
+ }
+
+ public function normalize(string $text): string
+ {
+ if ($this->config['clean_text'] ?? false) {
+ $text = $this->cleanText($text);
+ }
+
+ if ($this->config['handle_chinese_chars'] ?? false) {
+ $text = $this->tokenizeChineseChars($text);
+ }
+
+ if ($this->config['lowercase'] ?? false) {
+ $text = mb_strtolower($text);
+ }
+
+ if ($this->config['strip_accents'] ?? false) {
+ $text = $this->stripAccents($text);
+ }
+
+ return $text;
+ }
/**
* Strips accents from the given text.
@@ -43,21 +86,21 @@ protected function isControl(string $char): bool
}
/**
- * Performs invalid character removal and whitespace cleanup on text.
- * @param string $text The text to clean.
- * @return string The cleaned text.
- * @private
+ * Adds whitespace around any CJK (Chinese, Japanese, or Korean) character in the input text.
+ *
+ * @param string $text The input text to tokenize.
+ *
+ * @return string The tokenized text with whitespace added around CJK characters.
*/
- function cleanText(string $text): string
+ public function tokenizeChineseChars(string $text): string
{
$output = [];
for ($i = 0; $i < mb_strlen($text); ++$i) {
$char = mb_substr($text, $i, 1);
$cp = mb_ord($char);
- if ($cp === 0 || $cp === 0xFFFD || $this->isControl($char)) {
- continue;
- }
- if (preg_match('/^\s$/', $char)) { // is whitespace
+ if (isChineseChar($cp)) {
+ $output[] = " ";
+ $output[] = $char;
$output[] = " ";
} else {
$output[] = $char;
@@ -65,25 +108,4 @@ function cleanText(string $text): string
}
return implode("", $output);
}
-
- public function normalize(string $text): string
- {
- if ($this->config['clean_text'] ?? false) {
- $text = $this->cleanText($text);
- }
-
- if ($this->config['handle_chinese_chars'] ?? false) {
- $text = TokenizerModel::tokenizeChineseChars($text);
- }
-
- if ($this->config['lowercase'] ?? false) {
- $text = mb_strtolower($text);
- }
-
- if ($this->config['strip_accents'] ?? false) {
- $text = $this->stripAccents($text);
- }
-
- return $text;
- }
}
diff --git a/src/Normalizers/Normalizer.php b/src/Normalizers/Normalizer.php
index bd63892..5a6816f 100644
--- a/src/Normalizers/Normalizer.php
+++ b/src/Normalizers/Normalizer.php
@@ -5,14 +5,14 @@
namespace Codewithkyrian\Transformers\Normalizers;
+use Codewithkyrian\Transformers\Transformers;
+
/**
* A base class for text normalization.
*/
abstract class Normalizer
{
- public function __construct(protected array $config)
- {
- }
+ public function __construct(protected array $config) {}
public static function fromConfig(?array $config): ?self
{
@@ -20,6 +20,9 @@ public static function fromConfig(?array $config): ?self
return null;
}
+ $logger = Transformers::getLogger();
+ $logger->debug('Creating normalizer', ['type' => $config['type'] ?? 'unknown']);
+
return match ($config['type'] ?? null) {
'BertNormalizer' => new BertNormalizer($config),
'Precompiled' => new Precompiled($config),
@@ -40,6 +43,6 @@ abstract public function normalize(string $text): string;
public function __invoke(): string
{
- return $this->normalize(...func_get_args());
+ return $this->normalize(...func_get_args());
}
-}
\ No newline at end of file
+}
diff --git a/src/Normalizers/StripAccents.php b/src/Normalizers/StripAccents.php
index 1f660c0..dbdf61d 100644
--- a/src/Normalizers/StripAccents.php
+++ b/src/Normalizers/StripAccents.php
@@ -2,19 +2,20 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Normalizers;
-use Codewithkyrian\Transformers\Tokenizers\TokenizerModel;
-
/**
* StripAccents normalizer removes all accents from the text.
*/
class StripAccents extends Normalizer
{
-
+ /**
+ * Removes accents from the text.
+ * @param string $text The text to remove accents from.
+ * @return string The text with accents removed.
+ */
public function normalize(string $text): string
{
- return TokenizerModel::removeAccents($text);
+ return preg_replace('/[\x{0300}-\x{036f}]/u', '', $text);
}
}
diff --git a/src/Pipelines/AudioClassificationPipeline.php b/src/Pipelines/AudioClassificationPipeline.php
index 7978124..b99ac91 100644
--- a/src/Pipelines/AudioClassificationPipeline.php
+++ b/src/Pipelines/AudioClassificationPipeline.php
@@ -54,7 +54,7 @@ public function __invoke(array|string $inputs, ...$args): array
$toReturn = [];
foreach ($inputs as $input) {
- $audio = Audio::read($input);
+ $audio = new Audio($input);
$audioTensor = $audio->toTensor(samplerate: $sampleRate);
$processedInputs = ($this->processor)($audioTensor);
diff --git a/src/Pipelines/AutomaticSpeechRecognitionPipeline.php b/src/Pipelines/AutomaticSpeechRecognitionPipeline.php
index ca8025b..fc04e1d 100644
--- a/src/Pipelines/AutomaticSpeechRecognitionPipeline.php
+++ b/src/Pipelines/AutomaticSpeechRecognitionPipeline.php
@@ -2,14 +2,15 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Pipelines;
+use Codewithkyrian\Transformers\Configs\GenerationConfig;
use Codewithkyrian\Transformers\Generation\Streamers\WhisperTextStreamer;
use Codewithkyrian\Transformers\Tensor\Tensor;
use Codewithkyrian\Transformers\Utils\Audio;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
use Codewithkyrian\Transformers\Utils\Image;
+use Codewithkyrian\Transformers\Transformers;
+
use function Codewithkyrian\Transformers\Utils\array_pop_key;
use function Codewithkyrian\Transformers\Utils\array_keys_to_snake_case;
@@ -115,7 +116,10 @@ private function __invokeWhisper(array|string $inputs, ...$args): array|Tensor|I
throw new \InvalidArgumentException('`streamer` must be an instance of `WhisperTextStreamer`');
}
-// if (!is_null($streamer)) trigger_error('`streamer` is not supported yet for Whisper', E_USER_WARNING);
+ if (!is_null($streamer)) {
+ $logger = Transformers::getLogger();
+ $logger->warning('`streamer` is not supported yet for Whisper');
+ }
$kwargs = array_keys_to_snake_case($args);
@@ -126,7 +130,11 @@ private function __invokeWhisper(array|string $inputs, ...$args): array|Tensor|I
throw new \InvalidArgumentException('Cannot specify `forcedDecoderIds` when specifying `language`, `task`, or `returnTimestamps`');
}
- $decoderPromptIds = $this->tokenizer->getDecoderPromptIds(language: $language, task: $task, noTimestamps: !$returnTimestamps);
+ if (!method_exists($this->tokenizer, 'getDecoderPromptIds')) {
+ throw new \InvalidArgumentException('Tokenizer not supported for Automatic Speech Recognition');
+ }
+
+ $decoderPromptIds = call_user_func([$this->tokenizer, 'getDecoderPromptIds'], language: $language, task: $task, noTimestamps: !$returnTimestamps);
if (count($decoderPromptIds) > 0) {
$generationConfig['forced_decoder_ids'] = $decoderPromptIds;
@@ -150,7 +158,7 @@ private function __invokeWhisper(array|string $inputs, ...$args): array|Tensor|I
?->setTimestampBegin($timestampBegin);
foreach ($inputs as $input) {
- $audio = Audio::read($input);
+ $audio = new Audio($input);
$audioTensor = $audio->toTensor(samplerate: $samplingRate);
$chunks = [];
@@ -200,7 +208,6 @@ private function __invokeWhisper(array|string $inputs, ...$args): array|Tensor|I
'is_last' => true
]
];
-
}
// Generate for each set of input features
@@ -223,8 +230,14 @@ private function __invokeWhisper(array|string $inputs, ...$args): array|Tensor|I
$streamer?->putChunk($chunk);
}
+ if (!method_exists($this->tokenizer, 'decodeASR')) {
+ throw new \InvalidArgumentException('Tokenizer not supported for Automatic Speech Recognition');
+ }
+
// Merge text chunks
- [$fullText, $optional] = $this->tokenizer->decodeASR($chunks,
+ [$fullText, $optional] = call_user_func(
+ [$this->tokenizer, 'decodeASR'],
+ $chunks,
timePrecision: $timePrecision,
returnTimestamps: $returnTimestamps,
forceFullSequences: $forceFullSequences
@@ -247,7 +260,7 @@ private function __invokeWav2Vec2(array|string $inputs, ...$args): array|Tensor|
$toReturn = [];
foreach ($inputs as $input) {
- $audio = Audio::read($input);
+ $audio = new Audio($input);
$audioTensor = $audio->toTensor(samplerate: $samplingRate);
$processedInputs = ($this->processor)($audioTensor);
$outputs = ($this->model)($processedInputs);
@@ -262,6 +275,7 @@ private function __invokeWav2Vec2(array|string $inputs, ...$args): array|Tensor|
$predictedSentences = $this->tokenizer->decode($predictedIds);
$toReturn[] = ['text' => $predictedSentences];
}
+
return $isBatched ? $toReturn : $toReturn[0];
}
}
diff --git a/src/Pipelines/FeatureExtractionPipeline.php b/src/Pipelines/FeatureExtractionPipeline.php
index 7fbe963..c4cdc26 100644
--- a/src/Pipelines/FeatureExtractionPipeline.php
+++ b/src/Pipelines/FeatureExtractionPipeline.php
@@ -2,7 +2,6 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Pipelines;
use Codewithkyrian\Transformers\Tensor\Tensor;
@@ -80,15 +79,23 @@ public function __invoke(array|string $inputs, ...$args): array
case 'none':
// No pooling, return the full tensor
break;
+
case 'mean':
$result = $result->meanPooling($modelInputs["attention_mask"]);
break;
+
+ case 'first_token':
case 'cls':
$result = $result->slice(null, 0);
break;
+ case 'last_token':
+ case 'eos':
+ $result = $result->slice(null, -1);
+ break;
+
default:
- throw new \Error("Pooling method not supported. Please use 'mean', 'cls', or 'none'.");
+ throw new \Error("Pooling method not supported. Please use 'mean', 'cls', 'first_token', 'last_token', or 'none'.");
}
if ($normalize) {
@@ -97,4 +104,4 @@ public function __invoke(array|string $inputs, ...$args): array
return $result->toArray();
}
-}
\ No newline at end of file
+}
diff --git a/src/Pipelines/ImageToTextPipeline.php b/src/Pipelines/ImageToTextPipeline.php
index 81e481d..110075e 100644
--- a/src/Pipelines/ImageToTextPipeline.php
+++ b/src/Pipelines/ImageToTextPipeline.php
@@ -5,7 +5,8 @@
namespace Codewithkyrian\Transformers\Pipelines;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
+use Codewithkyrian\Transformers\Configs\GenerationConfig;
+
use function Codewithkyrian\Transformers\Utils\camelCaseToSnakeCase;
use function Codewithkyrian\Transformers\Utils\prepareImages;
@@ -71,5 +72,4 @@ public function __invoke(array|string $inputs, ...$args): array
return $isBatched ? $toReturn : $toReturn[0];
}
-
-}
\ No newline at end of file
+}
diff --git a/src/Pipelines/Pipeline.php b/src/Pipelines/Pipeline.php
index c820c17..43fa176 100644
--- a/src/Pipelines/Pipeline.php
+++ b/src/Pipelines/Pipeline.php
@@ -18,9 +18,7 @@ public function __construct(
protected PretrainedModel $model,
public ?PreTrainedTokenizer $tokenizer = null,
protected ?Processor $processor = null,
- )
- {
- }
+ ) {}
/**
* @param string[]|string $inputs
@@ -31,7 +29,6 @@ public function __invoke(array|string $inputs, ...$args): array|Tensor|Image
{
return [];
}
-
}
/**
@@ -64,8 +61,7 @@ function pipeline(
string $revision = 'main',
?string $modelFilename = null,
?callable $onProgress = null
-): Pipeline
-{
+): Pipeline {
if (is_string($task)) {
$stringTask = $task;
$task = Task::tryFrom($stringTask);
@@ -77,7 +73,25 @@ function pipeline(
$modelName ??= $task->defaultModelName();
- $model = $task->autoModel($modelName, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress);
+ $modelClass = $task->autoModelClass();
+
+ $modelClass = is_array($modelClass) ? $modelClass : [$modelClass];
+
+ $model = null;
+ $lastException = null;
+
+ foreach ($modelClass as $modelClass) {
+ try {
+ $model = $modelClass::fromPretrained($modelName, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress);
+ break;
+ } catch (\Throwable $e) {
+ $lastException = $e;
+ }
+ }
+
+ if ($model === null) {
+ throw new \RuntimeException('Could not instantiate model for task: ' . $task->value, 0, $lastException);
+ }
$tokenizer = $task->autoTokenizer($modelName, $cacheDir, $revision, $onProgress);
diff --git a/src/Pipelines/Task.php b/src/Pipelines/Task.php
index 3994f0c..d8286a0 100644
--- a/src/Pipelines/Task.php
+++ b/src/Pipelines/Task.php
@@ -151,61 +151,50 @@ public function defaultModelName(): string
};
}
- public function autoModel(
- string $modelNameOrPath,
- bool $quantized = true,
- ?array $config = null,
- ?string $cacheDir = null,
- string $revision = 'main',
- ?string $modelFilename = null,
- ?callable $onProgress = null
- ): PretrainedModel
+ /**
+ * @return class-string|array>
+ */
+ public function autoModelClass(): string|array
{
return match ($this) {
self::SentimentAnalysis,
self::TextClassification,
- self::ZeroShotClassification => AutoModelForSequenceClassification::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress),
+ self::ZeroShotClassification => AutoModelForSequenceClassification::class,
- self::FillMask => AutoModelForMaskedLM::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress),
+ self::FillMask => AutoModelForMaskedLM::class,
- self::QuestionAnswering => AutoModelForQuestionAnswering::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress),
+ self::QuestionAnswering => AutoModelForQuestionAnswering::class,
self::FeatureExtraction,
- self::Embeddings => AutoModel::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress),
+ self::Embeddings => AutoModel::class,
self::Text2TextGeneration,
self::Translation,
- self::Summarization => AutoModelForSeq2SeqLM::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress),
+ self::Summarization => AutoModelForSeq2SeqLM::class,
- self::TextGeneration => AutoModelForCausalLM::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress),
+ self::TextGeneration => AutoModelForCausalLM::class,
self::TokenClassification,
- self::Ner => AutoModelForTokenClassification::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress),
+ self::Ner => AutoModelForTokenClassification::class,
- self::ImageToText => AutoModelForVision2Seq::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress),
+ self::ImageToText => AutoModelForVision2Seq::class,
- self::ImageClassification => AutoModelForImageClassification::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress),
+ self::ImageClassification => AutoModelForImageClassification::class,
- self::ImageFeatureExtraction => AutoModelForImageFeatureExtraction::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress),
+ self::ImageFeatureExtraction => [AutoModelForImageFeatureExtraction::class, AutoModel::class],
- self::ZeroShotImageClassification => AutoModel::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress),
+ self::ZeroShotImageClassification => AutoModel::class,
- self::ImageToImage => AutoModelForImageToImage::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress),
+ self::ImageToImage => AutoModelForImageToImage::class,
- self::ObjectDetection => AutoModelForObjectDetection::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress),
+ self::ObjectDetection => AutoModelForObjectDetection::class,
- self::ZeroShotObjectDetection => AutoModelForZeroShotObjectDetection::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress),
+ self::ZeroShotObjectDetection => AutoModelForZeroShotObjectDetection::class,
- self::AudioClassification => AutoModelForAudioClassification::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress),
+ self::AudioClassification => AutoModelForAudioClassification::class,
self::ASR,
- self::AutomaticSpeechRecognition => (function () use ($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress) {
- try {
- return AutoModelForSpeechSeq2Seq::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress);
- } catch (UnsupportedModelTypeException) {
- return AutoModelForCTC::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $onProgress);
- }
- })(),
+ self::AutomaticSpeechRecognition => [AutoModelForSpeechSeq2Seq::class, AutoModelForCTC::class],
};
}
@@ -214,8 +203,7 @@ public function autoTokenizer(
?string $cacheDir = null,
string $revision = 'main',
?callable $onProgress = null
- ): ?PreTrainedTokenizer
- {
+ ): ?PreTrainedTokenizer {
return match ($this) {
self::ImageClassification,
@@ -252,8 +240,7 @@ public function autoProcessor(
?string $cacheDir = null,
string $revision = 'main',
?callable $onProgress = null
- ): ?Processor
- {
+ ): ?Processor {
return match ($this) {
self::ImageToText,
diff --git a/src/Pipelines/Text2TextGenerationPipeline.php b/src/Pipelines/Text2TextGenerationPipeline.php
index d1e43ba..f36f5c0 100644
--- a/src/Pipelines/Text2TextGenerationPipeline.php
+++ b/src/Pipelines/Text2TextGenerationPipeline.php
@@ -5,8 +5,9 @@
namespace Codewithkyrian\Transformers\Pipelines;
+use Codewithkyrian\Transformers\Configs\GenerationConfig;
use Codewithkyrian\Transformers\Generation\Streamers\Streamer;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
+
use function Codewithkyrian\Transformers\Utils\array_pop_key;
use function Codewithkyrian\Transformers\Utils\array_keys_to_snake_case;
@@ -35,8 +36,7 @@ public function __invoke(array|string $inputs, ...$args): array
$kwargs = array_keys_to_snake_case($args);
- $generateKwargs = new GenerationConfig($kwargs);
-
+ $generationConfig = new GenerationConfig($kwargs);
if (!is_array($inputs)) {
$inputs = [$inputs];
@@ -44,48 +44,35 @@ public function __invoke(array|string $inputs, ...$args): array
// Add global prefix, if present
$prefix = $this->model->config['prefix'] ?? null;
- if ($prefix) {
- $inputs = array_map(fn($x) => $prefix . $x, $inputs);
- }
+ if ($prefix) $inputs = array_map(fn($x) => $prefix . $x, $inputs);
// Handle task specific params
$taskSpecificParams = $this->model->config['task_specific_params'] ?? null;
-
-
if ($taskSpecificParams && isset($taskSpecificParams[$this->task->value])) {
// Add prefixes, if present
$taskPrefix = $taskSpecificParams[$this->task->value]['prefix'] ?? null;
-
- if ($taskPrefix) {
- $inputs = array_map(fn($x) => $taskPrefix . $x, $inputs);
- }
+ if ($taskPrefix) $inputs = array_map(fn($x) => $taskPrefix . $x, $inputs);
// TODO: update generation config
}
- // Tokenize texts
- $tokenizer = $this->tokenizer;
+ $inputs = $this instanceof TranslationPipeline && method_exists($this->tokenizer, 'buildTranslationInputs')
+ ? call_user_func([$this->tokenizer, 'buildTranslationInputs'], $inputs, $generationConfig, padding: true, truncation: true)
+ : call_user_func([$this->tokenizer, '__invoke'], $inputs, padding: true, truncation: true);
- $inputIds = $this instanceof TranslationPipeline && method_exists($tokenizer, 'buildTranslationInputs')
- ? $tokenizer->buildTranslationInputs($inputs, $generateKwargs, padding: true, truncation: true)['input_ids']
- : $tokenizer->__invoke($inputs, padding: true, truncation: true)['input_ids'];
-
-
- // Streamer can only handle one input at a time for now, so we only pass the first input
$streamer?->setTokenizer($this->tokenizer)?->shouldSkipPrompt(false);
- // Generate output token ids
- $outputTokenIds = $this->model->generate($inputIds, generationConfig: $generateKwargs, streamer: $streamer);
+ $outputTokenIds = $this->model->generate(
+ $inputs['input_ids'],
+ generationConfig: $generationConfig,
+ streamer: $streamer,
+ attentionMask: $inputs['attention_mask']
+ );
// Decode token ids to text
return array_map(
fn($text) => [$this->key => $text],
- $tokenizer->batchDecode($outputTokenIds, skipSpecialTokens: true)
+ $this->tokenizer->batchDecode($outputTokenIds, skipSpecialTokens: true)
);
}
-
- protected function camelCaseToSnakeCase(string $input): string
- {
- return strtolower(preg_replace('/(?setTokenizer($this->tokenizer)?->setPromptTokens($inputIds[0]->toArray());
+ $streamer?->setTokenizer($this->tokenizer);
- $outputTokenIds = $this->model->generate($inputIds,
+ $outputTokenIds = $this->model->generate(
+ inputs: $inputIds,
generationConfig: $generationConfig,
- inputsAttentionMask: $attentionMask,
- streamer: $streamer
+ streamer: $streamer,
+ attentionMask: $attentionMask
);
$decoded = $this->tokenizer->batchDecode($outputTokenIds, skipSpecialTokens: true);
$promptLengths = null;
if (!$returnFullText && $inputIds->shape()[count($inputIds->shape()) - 1] > 0) {
- $promptLengths = array_map(fn($x) => mb_strlen($x), $this->tokenizer->batchDecode($inputIds->toArray(), skipSpecialTokens: true));
+ $promptLengths = array_map(fn($x) => mb_strlen($x), $this->tokenizer->batchDecode($inputIds, skipSpecialTokens: true));
}
$toReturn = array_fill(0, count($inputs), []);
@@ -142,7 +141,6 @@ public function __invoke(array|string $inputs, ...$args): array
}
return (!$isBatched && count($toReturn) === 1) ? $toReturn[0] : $toReturn;
-
}
// Detect chat mode
@@ -150,5 +148,4 @@ function isChat($x): bool
{
return is_array($x) && array_every($x, fn($item) => isset($item['role']) && isset($item['content']));
}
-
-}
\ No newline at end of file
+}
diff --git a/src/Pipelines/ZeroShotClassificationPipeline.php b/src/Pipelines/ZeroShotClassificationPipeline.php
index f3e8fde..b97fc0a 100644
--- a/src/Pipelines/ZeroShotClassificationPipeline.php
+++ b/src/Pipelines/ZeroShotClassificationPipeline.php
@@ -10,7 +10,7 @@
use Codewithkyrian\Transformers\PreTrainedTokenizers\PreTrainedTokenizer;
use Codewithkyrian\Transformers\Transformers;
use Codewithkyrian\Transformers\Utils\Math;
-use function Codewithkyrian\Transformers\Utils\timeUsage;
+use Codewithkyrian\Transformers\Transformers;
/**
* NLI-based zero-shot classification pipeline using any model that has been fine-tuned on NLI (natural language inference)
@@ -68,14 +68,16 @@ public function __construct(Task|string $task, PretrainedModel $model, ?PreTrain
$this->entailmentId = $this->label2id['entailment'] ?? null;
+ $logger = Transformers::getLogger();
+
if ($this->entailmentId === null) {
- Transformers::getLogger()?->warning("Could not find 'entailment' in label2id mapping. Using 2 as entailment_id.");
+ $logger->warning("Could not find 'entailment' in label2id mapping. Using 2 as entailment_id.");
$this->entailmentId = 2;
}
$this->contradictionId = $this->label2id['contradiction'] ?? $this->label2id['not_entailment'] ?? null;
if ($this->contradictionId === null) {
- Transformers::getLogger()?->warning("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id.");
+ $logger->warning("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id.");
$this->contradictionId = 0;
}
}
@@ -121,7 +123,6 @@ public function __invoke(array|string $inputs, ...$args): array
} else {
$entailsLogits[] = $outputs->logits->buffer()[$this->entailmentId];
}
-
}
$scores = $softmaxEach
diff --git a/src/PostProcessors/PostProcessor.php b/src/PostProcessors/PostProcessor.php
index 123ae26..7b9e1bd 100644
--- a/src/PostProcessors/PostProcessor.php
+++ b/src/PostProcessors/PostProcessor.php
@@ -7,9 +7,7 @@
abstract class PostProcessor
{
- public function __construct(public array $config)
- {
- }
+ public function __construct(public array $config) {}
/**
* Factory method to create a PostProcessor object from a configuration object.
@@ -45,5 +43,4 @@ public function __invoke(array $tokens, ...$args): PostProcessedOutput
{
return $this->postProcess($tokens, ...$args);
}
-
-}
\ No newline at end of file
+}
diff --git a/src/PreTrainedTokenizers/AutoTokenizer.php b/src/PreTrainedTokenizers/AutoTokenizer.php
index e40fe85..ada09d5 100644
--- a/src/PreTrainedTokenizers/AutoTokenizer.php
+++ b/src/PreTrainedTokenizers/AutoTokenizer.php
@@ -43,6 +43,7 @@ class AutoTokenizer
'CodeGenTokenizer' => CodeGenTokenizer::class,
'CLIPTokenizer' => CLIPTokenizer::class,
'SiglipTokenizer' => SiglipTokenizer::class,
+ 'SiglipTokenizer' => SiglipTokenizer::class,
// 'MarianTokenizer' => MarianTokenizer::class,
'BloomTokenizer' => BloomTokenizer::class,
'NllbTokenizer' => NllbTokenizer::class,
@@ -92,8 +93,7 @@ public static function fromPretrained(
string $revision = 'main',
mixed $legacy = null,
?callable $onProgress = null
- ): ?PreTrainedTokenizer
- {
+ ): ?PreTrainedTokenizer {
['tokenizerJson' => $tokenizerJson, 'tokenizerConfig' => $tokenizerConfig] =
TokenizerModel::load($modelNameOrPath, $cacheDir, $revision, $legacy, $onProgress);
@@ -106,7 +106,8 @@ public static function fromPretrained(
$cls = self::TOKENIZER_CLASS_MAPPING[$tokenizerClassName] ?? null;
if ($cls == null) {
- Transformers::getLogger()?->warning("Unknown tokenizer class $tokenizerClassName. Using PreTrainedTokenizer.");
+ $logger = Transformers::getLogger();
+ $logger->warning("Unknown tokenizer class $tokenizerClassName. Using PreTrainedTokenizer.");
$cls = PreTrainedTokenizer::class;
}
diff --git a/src/PreTrainedTokenizers/LlamaTokenizer.php b/src/PreTrainedTokenizers/LlamaTokenizer.php
index 1a5a5ef..94620a2 100644
--- a/src/PreTrainedTokenizers/LlamaTokenizer.php
+++ b/src/PreTrainedTokenizers/LlamaTokenizer.php
@@ -14,7 +14,7 @@ class LlamaTokenizer extends PreTrainedTokenizer
protected string $defaultChatTemplate = "{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% elif USE_DEFAULT_PROMPT == true and not '<>' in messages[0]['content'] %}{% set loop_messages = messages %}{% set system_message = 'DEFAULT_SYSTEM_MESSAGE' %}{% else %}{% set loop_messages = messages %}{% set system_message = false %}{% endif %}{% for message in loop_messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if loop.index0 == 0 and system_message != false %}{% set content = '<>\n' + system_message + '\n<>\n\n' + message['content'] %}{% else %}{% set content = message['content'] %}{% endif %}{% if message['role'] == 'user' %}{{ bos_token + '[INST] ' + content.strip() + ' [/INST]' }}{% elif message['role'] == 'system' %}{{ '<>\n' + content.strip() + '\n<>\n\n' }}{% elif message['role'] == 'assistant' %}{{ ' ' + content.strip() + ' ' + eos_token }}{% endif %}{% endfor %}";
public const DEFAULT_SYSTEM_PROMPT =
- "You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your " .
+ "You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your " .
"answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure " .
"that your responses are socially unbiased and positive in nature.\n\n" .
"If a question does not make any sense, or is not factually coherent, explain why instead of answering something not " .
@@ -38,7 +38,6 @@ public function __construct(array $tokenizerJSON, array $tokenizerConfig)
'prepend_scheme' => 'first',
]);
}
-
}
/**
@@ -50,7 +49,7 @@ public function __construct(array $tokenizerJSON, array $tokenizerConfig)
* @param bool $addSpecialTokens
* @return ?array
*/
- public function encodeText(?string $text, string $textPair = null, bool $addSpecialTokens = true): ?array
+ public function encodeText(?string $text, ?string $textPair = null, bool $addSpecialTokens = true): ?array
{
if ($text === null) {
return null;
diff --git a/src/PreTrainedTokenizers/M2M100Tokenizer.php b/src/PreTrainedTokenizers/M2M100Tokenizer.php
index 840b99f..253b89f 100644
--- a/src/PreTrainedTokenizers/M2M100Tokenizer.php
+++ b/src/PreTrainedTokenizers/M2M100Tokenizer.php
@@ -5,8 +5,8 @@
namespace Codewithkyrian\Transformers\PreTrainedTokenizers;
+use Codewithkyrian\Transformers\Configs\GenerationConfig;
use Codewithkyrian\Transformers\Tensor\Tensor;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
class M2M100Tokenizer extends PreTrainedTokenizer
{
@@ -50,8 +50,7 @@ public function buildTranslationInputs(
bool $truncation = false,
?int $maxLength = null,
bool $addSpecialTokens = true,
- ): array
- {
+ ): array {
$srcLangToken = $generationConfig['src_lang'] ?? null;
$tgtLangToken = $generationConfig['tgt_lang'];
@@ -71,7 +70,7 @@ public function buildTranslationInputs(
// In the same way as the Python library, we override the post-processor
// to force the source language to be first:
- foreach ($this->postProcessor->single as &$item) {
+ foreach ($this->postProcessor->config['single'] as &$item) {
if (isset($item['SpecialToken']) && preg_match($this->languageRegex, $item['SpecialToken']['id'])) {
$item['SpecialToken']['id'] = call_user_func($this->langToToken, $srcLangToken);
break;
diff --git a/src/PreTrainedTokenizers/MBartTokenizer.php b/src/PreTrainedTokenizers/MBartTokenizer.php
index 74efbc2..237f7a4 100644
--- a/src/PreTrainedTokenizers/MBartTokenizer.php
+++ b/src/PreTrainedTokenizers/MBartTokenizer.php
@@ -2,11 +2,10 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\PreTrainedTokenizers;
+use Codewithkyrian\Transformers\Configs\GenerationConfig;
use Codewithkyrian\Transformers\Tensor\Tensor;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
class MBartTokenizer extends PreTrainedTokenizer
{
@@ -46,8 +45,7 @@ public function buildTranslationInputs(
bool $truncation = false,
?int $maxLength = null,
bool $addSpecialTokens = true,
- ): array
- {
+ ): array {
$srcLangToken = $generationConfig['src_lang'] ?? null;
$tgtLangToken = $generationConfig['tgt_lang'];
@@ -67,7 +65,7 @@ public function buildTranslationInputs(
// In the same way as the Python library, we override the post-processor
// to force the source language to be first:
- foreach ($this->postProcessor->single as &$item) {
+ foreach ($this->postProcessor->config['single'] as &$item) {
if (isset($item['SpecialToken']) && preg_match($this->languageRegex, $item['SpecialToken']['id'])) {
$item['SpecialToken']['id'] = call_user_func($this->langToToken, $srcLangToken);
break;
diff --git a/src/PreTrainedTokenizers/NllbTokenizer.php b/src/PreTrainedTokenizers/NllbTokenizer.php
index cc470bc..3762230 100644
--- a/src/PreTrainedTokenizers/NllbTokenizer.php
+++ b/src/PreTrainedTokenizers/NllbTokenizer.php
@@ -2,11 +2,10 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\PreTrainedTokenizers;
+use Codewithkyrian\Transformers\Configs\GenerationConfig;
use Codewithkyrian\Transformers\Tensor\Tensor;
-use Codewithkyrian\Transformers\Utils\GenerationConfig;
class NllbTokenizer extends PreTrainedTokenizer
{
@@ -49,8 +48,7 @@ public function buildTranslationInputs(
bool $truncation = false,
?int $maxLength = null,
bool $addSpecialTokens = true,
- ): array
- {
+ ): array {
$srcLangToken = $generationConfig['src_lang'] ?? null;
$tgtLangToken = $generationConfig['tgt_lang'];
@@ -70,7 +68,7 @@ public function buildTranslationInputs(
// In the same way as the Python library, we override the post-processor
// to force the source language to be first:
- foreach ($this->postProcessor->single as &$item) {
+ foreach ($this->postProcessor->config['single'] as &$item) {
if (isset($item['SpecialToken']) && preg_match($this->languageRegex, $item['SpecialToken']['id'])) {
$item['SpecialToken']['id'] = call_user_func($this->langToToken, $srcLangToken);
break;
diff --git a/src/PreTrainedTokenizers/PreTrainedTokenizer.php b/src/PreTrainedTokenizers/PreTrainedTokenizer.php
index cf18858..771e009 100644
--- a/src/PreTrainedTokenizers/PreTrainedTokenizer.php
+++ b/src/PreTrainedTokenizers/PreTrainedTokenizer.php
@@ -18,6 +18,8 @@
use Error;
use Exception;
use function Codewithkyrian\Transformers\Utils\timeUsage;
+use Codewithkyrian\Transformers\Transformers;
+use Psr\Log\LoggerInterface;
class PreTrainedTokenizer
{
@@ -54,6 +56,8 @@ class PreTrainedTokenizer
protected mixed $chatTemplate;
protected array $compiledTemplateCache = [];
+ protected LoggerInterface $logger;
+
/**
* @param array $tokenizerJSON The JSON of the tokenizer.
* @param ?array $tokenizerConfig The config of the tokenizer.
@@ -62,7 +66,8 @@ class PreTrainedTokenizer
*/
public function __construct(protected array $tokenizerJSON, protected ?array $tokenizerConfig)
{
- // Construct parts of the tokenizer from the JSON
+ $this->logger = Transformers::getLogger();
+
$this->normalizer = Normalizer::fromConfig($this->tokenizerJSON['normalizer']);
$this->preTokenizer = PreTokenizer::fromConfig($this->tokenizerJSON['pre_tokenizer']);
$this->model = TokenizerModel::fromConfig(
@@ -74,6 +79,10 @@ public function __construct(protected array $tokenizerJSON, protected ?array $to
$this->postProcessor = PostProcessor::fromConfig($this->tokenizerJSON['post_processor'] ?? null);
$this->decoder = Decoder::fromConfig($this->tokenizerJSON['decoder']);
+ $this->logger->info('Tokenizer loaded', [
+ 'model' => (new \ReflectionClass($this->model))->getShortName(),
+ 'vocab_size' => isset($this->model->vocab) ? count($this->model->vocab) : null,
+ ]);
foreach ($this->tokenizerJSON['added_tokens'] as $addedToken) {
$token = AddedToken::make($addedToken);
@@ -88,7 +97,6 @@ public function __construct(protected array $tokenizerJSON, protected ?array $to
}
}
- // Update additional_special_tokens
$this->additionalSpecialTokens = $this->tokenizerConfig['additional_special_tokens'] ?? [];
$this->specialTokens = [...$this->specialTokens, ...$this->additionalSpecialTokens];
$this->specialTokens = array_unique($this->specialTokens);
@@ -103,10 +111,10 @@ public function __construct(protected array $tokenizerJSON, protected ?array $to
$addedTokensPatterns = array_map(function ($x) {
$lstrip = $x->lStrip ? '\s*' : '';
$rstrip = $x->rStrip ? '\s*' : '';
- return $lstrip.'('.preg_quote($x->content, '/').')'.$rstrip;
+ return $lstrip . '(' . preg_quote($x->content, '/') . ')' . $rstrip;
}, $this->addedTokens);
- $this->addedTokensRegex = '/'.implode('|', $addedTokensPatterns).'/';
+ $this->addedTokensRegex = '/' . implode('|', $addedTokensPatterns) . '/';
}
// Set mask token if present
@@ -160,7 +168,7 @@ protected function getToken(string ...$keys): ?string
if ($item['__type'] == 'AddedToken') {
return $item['content'];
} else {
- throw new Exception("Unknown token: ".json_encode($item));
+ throw new Exception("Unknown token: " . json_encode($item));
}
} else {
return $item;
@@ -184,9 +192,8 @@ public static function fromPretrained(
string $modelNameOrPath,
?string $cacheDir = null,
string $revision = 'main',
- $legacy = null,
- ): PreTrainedTokenizer
- {
+ $legacy = null,
+ ): PreTrainedTokenizer {
['tokenizerJson' => $tokenizerJson, 'tokenizerConfig' => $tokenizerConfig] =
TokenizerModel::load($modelNameOrPath, $cacheDir, $revision, $legacy);
@@ -213,8 +220,7 @@ public function tokenize(
bool $truncation = false,
?int $maxLength = null,
bool $returnTensor = true
- ): array
- {
+ ): array {
return $this->__invoke($text, $textPair, $padding, $addSpecialTokens, $truncation, $maxLength, $returnTensor);
}
@@ -239,37 +245,40 @@ public function __invoke(
bool $truncation = false,
?int $maxLength = null,
bool $returnTensor = true
- ): array
- {
+ ): array {
$isBatched = is_array($text);
$encodedTokens = [];
if ($isBatched) {
if (count($text) === 0) {
+ $this->logger->error('Tokenization called with empty text array');
throw new Exception('$text array must be non-empty');
}
if ($textPair !== null) {
if (!is_array($textPair)) {
+ $this->logger->error('Tokenization called with mismatched text/textPair types');
throw new Exception('$textPair must also be an array');
} elseif (count($text) !== count($textPair)) {
+ $this->logger->error('Tokenization called with text/textPair of different lengths');
throw new Exception('$text and $textPair must have the same length');
}
$encodedTokens = array_map(
- fn ($t, $i) => $this->encodePlus($t, $textPair[$i], $addSpecialTokens),
+ fn($t, $i) => $this->encodePlus($t, $textPair[$i], $addSpecialTokens),
$text,
array_keys($text)
);
} else {
$encodedTokens = array_map(
- fn ($x) => $this->encodePlus($x, addSpecialTokens: $addSpecialTokens),
+ fn($x) => $this->encodePlus($x, addSpecialTokens: $addSpecialTokens),
$text
);
}
} else {
if (is_array($textPair)) {
+ $this->logger->error('Tokenization called with string text and array textPair');
throw new Exception('When specifying `$textPair`, since `$text` is a string, `$textPair` must also be a string (i.e., not an array).');
}
@@ -285,11 +294,11 @@ public function __invoke(
$maxLength = $this->modelMaxLength;
} else {
// Calculate max length from sequences
- $maxLength = max(array_map(fn ($x) => count($x['input_ids']), $encodedTokens));
+ $maxLength = max(array_map(fn($x) => count($x['input_ids']), $encodedTokens));
}
} else {
if (!$truncation) {
- trigger_error("Truncation was not explicitly activated but `maxLength` is provided a specific value, please use `truncation=true` to explicitly truncate examples to max length.", E_USER_WARNING);
+ $this->logger->warning('Truncation was not explicitly activated but `maxLength` is provided a specific value, please use `truncation=true` to explicitly truncate examples to max length.');
}
}
@@ -314,7 +323,7 @@ public function __invoke(
$this->padHelper(
$token,
$maxLength,
- fn ($key) => $key === 'input_ids' ? $this->padTokenId : 0,
+ fn($key) => $key === 'input_ids' ? $this->padTokenId : 0,
$this->paddingSide
);
}
@@ -353,7 +362,7 @@ public function __invoke(
continue;
}
- $array = array_map(fn ($x) => $x[$key], $encodedTokens);
+ $array = array_map(fn($x) => $x[$key], $encodedTokens);
$result[$key] = new Tensor($array, Tensor::int64, $shape);
}
@@ -361,7 +370,7 @@ public function __invoke(
$result = [];
foreach ($encodedTokens[0] as $key => $value) {
- $result[$key] = array_map(fn ($x) => $x[$key], $encodedTokens);
+ $result[$key] = array_map(fn($x) => $x[$key], $encodedTokens);
}
// If not returning a tensor, we match the input type
@@ -388,8 +397,7 @@ public function encodePlus(
string|null $text,
string|null $textPair = null,
bool $addSpecialTokens = true
- ): array
- {
+ ): array {
// Function called by users to encode possibly multiple texts
$tokens = $this->encodeText($text);
@@ -443,9 +451,8 @@ protected function encodeText(?string $text): ?array
$x = preg_replace('/\s+/', ' ', trim($x));
}
-
if ($this->doLowerCaseAndRemoveAccent) {
- $x = TokenizerModel::lowerCaseAndRemoveAccents($x);
+ $x = $this->lowerCaseAndRemoveAccents($x);
}
if ($this->normalizer !== null) {
@@ -454,8 +461,7 @@ protected function encodeText(?string $text): ?array
// If, after normalization, this section is empty (e.g., trimming whitespace),
// we return an empty array
- if (mb_strlen($x) === 0)
- {
+ if (mb_strlen($x) === 0) {
return [];
}
@@ -523,7 +529,7 @@ protected function padHelper(array &$item, int $length, Closure $value_fn, strin
*
* @return array
*/
- public function encode(string $text, string $textPair = null, bool $addSpecialTokens = true): array
+ public function encode(string $text, ?string $textPair = null, bool $addSpecialTokens = true): array
{
return $this->encodePlus($text, $textPair, $addSpecialTokens)['input_ids'];
}
@@ -537,9 +543,10 @@ public function encode(string $text, string $textPair = null, bool $addSpecialTo
*
* @return string[]
*/
- public function batchDecode(array $batch, bool $skipSpecialTokens = false, ?bool $cleanUpTokenizationSpaces = null): array
+ public function batchDecode(array|Tensor $batch, bool $skipSpecialTokens = false, ?bool $cleanUpTokenizationSpaces = null): array
{
- return array_map(fn ($x) => $this->decode($x, $skipSpecialTokens, $cleanUpTokenizationSpaces), $batch);
+ if ($batch instanceof Tensor) $batch = $batch->toArray();
+ return array_map(fn($x) => $this->decode($x, $skipSpecialTokens, $cleanUpTokenizationSpaces), $batch);
}
/**
@@ -554,6 +561,7 @@ public function batchDecode(array $batch, bool $skipSpecialTokens = false, ?bool
public function decode(array $tokenIds, bool $skipSpecialTokens = false, ?bool $cleanUpTokenizationSpaces = null): string
{
if (empty($tokenIds) || !is_int($tokenIds[0])) {
+ $this->logger->error('decode called with invalid input', ['token_ids' => $tokenIds]);
throw new Exception("token_ids must be a non-empty array of integers.");
}
@@ -574,7 +582,7 @@ private function decodeSingle(array $tokenIds, bool $skipSpecialTokens = false,
$tokens = $this->model->convertIdsToTokens($tokenIds);
if ($skipSpecialTokens) {
- $tokens = array_values(array_filter($tokens, fn ($x) => !in_array($x, $this->specialTokens)));
+ $tokens = array_values(array_filter($tokens, fn($x) => !in_array($x, $this->specialTokens)));
}
// If `this.decoder` is null, we just join tokens with a space:
@@ -592,7 +600,6 @@ private function decodeSingle(array $tokenIds, bool $skipSpecialTokens = false,
}
}
-
if ($cleanUpTokenizationSpaces ?? $this->cleanUpTokenizationSpaces) {
$decoded = TokenizerModel::cleanUpTokenization($decoded);
}
@@ -643,9 +650,8 @@ public function applyChatTemplate(
bool $padding = false,
bool $truncation = false,
?int $maxLength = null,
- bool $returnTensor = true
- ): string|array
- {
+ bool $returnTensor = true
+ ): string|array {
$chatTemplate ??= $this->chatTemplate ?? $this->getDefaultChatTemplate();
// Compilation function uses a cache to avoid recompiling the same template
@@ -686,11 +692,35 @@ public function applyChatTemplate(
protected function getDefaultChatTemplate(): string
{
- // if (!$this->warnedAboutChatTemplate) {
- // trigger_error("The default chat template is deprecated and will be removed in a future version. Please use the `chat_template` option instead.", E_USER_WARNING);
- // $this->warnedAboutChatTemplate = true;
- // }
+ if (!$this->warnedAboutChatTemplate) {
+ $this->logger->warning("The default chat template is deprecated and will be removed in a future version. Please use the `chat_template` option instead.");
+ $this->warnedAboutChatTemplate = true;
+ }
return $this->defaultChatTemplate;
}
+
+ /**
+ * Helper function to lowercase a string and remove accents.
+ *
+ * @param string $text The text to lowercase and remove accents from.
+ *
+ * @return string The text with accents removed and lowercased.
+ */
+ protected function lowerCaseAndRemoveAccents(string $text): string
+ {
+ return mb_strtolower($this->removeAccents($text));
+ }
+
+ /**
+ * Helper function to remove accents from a string.
+ *
+ * @param string $text The text to remove accents from.
+ *
+ * @return string The text with accents removed.
+ */
+ protected function removeAccents(string $text): string
+ {
+ return preg_replace('/[\x{0300}-\x{036f}]/u', '', $text);
+ }
}
diff --git a/src/PreTrainedTokenizers/XLMTokenizer.php b/src/PreTrainedTokenizers/XLMTokenizer.php
index a484f3b..d90266d 100644
--- a/src/PreTrainedTokenizers/XLMTokenizer.php
+++ b/src/PreTrainedTokenizers/XLMTokenizer.php
@@ -5,6 +5,8 @@
namespace Codewithkyrian\Transformers\PreTrainedTokenizers;
+use Codewithkyrian\Transformers\Transformers;
+
class XLMTokenizer extends PreTrainedTokenizer
{
protected bool $returnTokenTypeIds = true;
@@ -13,6 +15,7 @@ public function __construct(array $tokenizerJSON, array $tokenizerConfig)
{
parent::__construct($tokenizerJSON, $tokenizerConfig);
- trigger_error("WARNING: `XLMTokenizer` is not yet supported by Hugging Face\'s `fast` tokenizers library. Therefore, you may experience slightly inaccurate results.");
+ $logger = Transformers::getLogger();
+ $logger->warning("`XLMTokenizer` is not yet supported by Hugging Face\'s `fast` tokenizers library. Therefore, you may experience slightly inaccurate results.");
}
}
diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php
index c08ad60..db1a252 100644
--- a/src/Processors/Processor.php
+++ b/src/Processors/Processor.php
@@ -9,6 +9,7 @@
use Codewithkyrian\Transformers\Models\Output\ObjectDetectionOutput;
use Codewithkyrian\Transformers\Utils\Math;
use Exception;
+use Codewithkyrian\Transformers\Transformers;
/**
* Represents a Processor that extracts features from an input.
@@ -17,9 +18,7 @@ class Processor
{
public function __construct(
public FeatureExtractor $featureExtractor
- )
- {
- }
+ ) {}
/**
* Post-processes the outputs of the model (for object detection).
@@ -31,19 +30,18 @@ public function __construct(
*/
public static function postProcessObjectDetection(ObjectDetectionOutput $outputs, float $threshold = 0.5, ?array $targetSizes = null, bool $isZeroShot = false): array
{
-
+ $logger = Transformers::getLogger();
$outLogits = $outputs->logits;
$outBbox = $outputs->predBoxes;
-
[$batchSize, $numBoxes, $numClasses] = $outLogits->shape();
-
-
if ($targetSizes !== null && count($targetSizes) !== $batchSize) {
+ $logger->warning('Target sizes count does not match batch size', [
+ 'targetSizes_count' => count($targetSizes),
+ 'batchSize' => $batchSize
+ ]);
throw new Exception("Make sure that you pass in as many target sizes as the batch dimension of the logits");
}
-
$toReturn = [];
-
for ($i = 0; $i < $batchSize; ++$i) {
$targetSize = $targetSizes !== null ? $targetSizes[$i] : null;
$info = [
@@ -53,14 +51,12 @@ public static function postProcessObjectDetection(ObjectDetectionOutput $outputs
];
$logits = $outLogits[$i];
$bbox = $outBbox[$i];
-
+ $detectionCount = 0;
for ($j = 0; $j < $numBoxes; ++$j) {
$logit = $logits[$j];
-
$indices = [];
$probs = [];
if ($isZeroShot) {
- // Get indices of classes with high enough probability
$logitSigmoid = $logit->sigmoid();
foreach ($logitSigmoid as $k => $prob) {
if ($prob > $threshold) {
@@ -69,26 +65,17 @@ public static function postProcessObjectDetection(ObjectDetectionOutput $outputs
}
$probs = $logitSigmoid;
} else {
- // Get most probable class
$maxIndex = $logit->argMax();
-
if ($maxIndex === $numClasses - 1) {
- // This is the background class, skip it
continue;
}
$indices[] = $maxIndex;
-
- // Compute softmax over classes
$probs = $logit->softmax();
}
-
foreach ($indices as $index) {
$box = $bbox[$j]->toArray();
-
-
// convert to [x0, y0, x1, y1] format
$box = self::centerToCornersFormat($box);
-
if ($targetSize !== null) {
$box = array_map(fn($x, $i) => $x * $targetSize[($i + 1) % 2], $box, array_keys($box));
}
@@ -96,9 +83,13 @@ public static function postProcessObjectDetection(ObjectDetectionOutput $outputs
$info['boxes'][] = $box;
$info['classes'][] = $index;
$info['scores'][] = $probs[$index];
+ $detectionCount++;
}
-
}
+ $logger->info('Object detection post-processing complete for batch item', [
+ 'item' => $i,
+ 'detections' => $detectionCount
+ ]);
$toReturn[] = $info;
}
return $toReturn;
@@ -128,5 +119,4 @@ public function __invoke(mixed $input, ...$args)
{
return $this->featureExtractor->__invoke($input, ...$args);
}
-
-}
\ No newline at end of file
+}
diff --git a/src/Tensor/Tensor.php b/src/Tensor/Tensor.php
index 5e83ae2..e5f34f1 100644
--- a/src/Tensor/Tensor.php
+++ b/src/Tensor/Tensor.php
@@ -65,8 +65,7 @@ public function __construct(
int $dtype = null,
array $shape = null,
int $offset = null,
- )
- {
+ ) {
if ($array === null && $dtype === null && $shape === null && $offset === null) {
// Empty definition for Unserialize
return;
@@ -174,7 +173,7 @@ protected function isBuffer(mixed $buffer): bool
return $buffer instanceof Buffer;
}
- protected function isComplex(int $dtype = null): bool
+ protected function isComplex(?int $dtype = null): bool
{
$dtype = $dtype ?? $this->dtype;
return $this->cistype($dtype);
@@ -193,11 +192,13 @@ protected function assertShape(array $shape): void
foreach ($shape as $num) {
if (!is_int($num)) {
throw new InvalidArgumentException(
- "Invalid shape numbers. It gives ".gettype($num));
+ "Invalid shape numbers. It gives " . gettype($num)
+ );
}
if ($num < 0) {
throw new InvalidArgumentException(
- "Invalid shape numbers. It gives ".$num);
+ "Invalid shape numbers. It gives " . $num
+ );
}
}
}
@@ -282,7 +283,7 @@ public static function service(): Service
{
if (!isset(self::$service)) {
self::$service = new TensorService();
-// self::$service = new MatlibPhp();
+ // self::$service = new MatlibPhp();
}
return self::$service;
@@ -361,8 +362,8 @@ public function reshape(array $shape): static
$this->assertShape($shape);
if ($this->size() != array_product($shape)) {
- throw new InvalidArgumentException("Unmatched size to reshape: ".
- "[".implode(',', $this->shape())."]=>[".implode(',', $shape)."]");
+ throw new InvalidArgumentException("Unmatched size to reshape: " .
+ "[" . implode(',', $this->shape()) . "]=>[" . implode(',', $shape) . "]");
}
return new self($this->buffer(), $this->dtype(), $shape, $this->offset());
@@ -392,7 +393,7 @@ public static function random(array $shape, ?int $dtype = null): static
{
$dtype ??= NDArray::float32;
$size = array_product($shape);
-
+
$buffer = Tensor::newBuffer($size, $dtype);
$buffer->load(random_bytes($size * TensorBuffer::$valueSize[$dtype]));
return new static($buffer, shape: $shape, offset: 0);
@@ -422,7 +423,7 @@ public function toString(): string
*/
public function toBufferArray(): array
{
- $fmt = self::$pack[$this->dtype].'*';
+ $fmt = self::$pack[$this->dtype] . '*';
return array_values(unpack($fmt, $this->buffer->dump()));
}
@@ -565,8 +566,9 @@ public static function concat(array $tensors, int $axis = 0): Tensor
public static function safeIndex(int $index, int $size, ?int $axis = null): int
{
if ($index < -$size || $index >= $size) {
- throw new InvalidArgumentException("IndexError: index $index is out of bounds for axis"
- .($axis === null ? '' : ' '.$axis)." with size $size"
+ throw new InvalidArgumentException(
+ "IndexError: index $index is out of bounds for axis"
+ . ($axis === null ? '' : ' ' . $axis) . " with size $size"
);
}
@@ -643,7 +645,7 @@ public function sigmoid(): self
{
$mo = self::mo();
- $ndArray = $mo->f(fn ($x) => 1 / (1 + exp(-$x)), $this);
+ $ndArray = $mo->f(fn($x) => 1 / (1 + exp(-$x)), $this);
return new static($ndArray->buffer(), $ndArray->dtype(), $ndArray->shape(), $ndArray->offset());
}
@@ -692,7 +694,7 @@ public function matmul(Tensor $other, ?bool $transposeA = null, ?bool $transpose
{
$mo = self::mo();
- $result = $mo->la()->matmul($this, $other, $transposeA, $transposeB);
+ $result = $mo->la()->matmul($this, $other, $transposeA, $transposeB);
return new static($result->buffer(), $result->dtype(), $result->shape(), $result->offset());
}
@@ -791,6 +793,7 @@ public function reciprocal(): self
* Calculates the cosine similarity between this Tensor and another Tensor.
*
* @param Tensor $other The Tensor to calculate the cosine similarity with.
+ *
* @return float|int The cosine similarity between this Tensor and the other Tensor.
*/
public function cosSimilarity(Tensor $other): float|int
@@ -855,7 +858,7 @@ public function norm(int $ord = 2, ?int $axis = null, bool $keepShape = false):
$mo = self::mo();
if ($axis === null) {
- $val = pow(array_reduce($this->toBufferArray(), fn ($carry, $item) => $carry + pow($item, $ord), 0), 1 / $ord);
+ $val = pow(array_reduce($this->toBufferArray(), fn($carry, $item) => $carry + pow($item, $ord), 0), 1 / $ord);
return new Tensor([$val], $this->dtype(), []);
}
@@ -917,7 +920,7 @@ public function clamp(float|int $min, float|int $max): static
{
$mo = self::mo();
- $result = $mo->f(fn ($x) => max($min, min($max, $x)), $this);
+ $result = $mo->f(fn($x) => max($min, min($max, $x)), $this);
return new static($result->buffer(), $result->dtype(), $result->shape(), $result->offset());
}
@@ -931,7 +934,7 @@ public function round(int $precision = 0): static
{
$mo = self::mo();
- $result = $mo->f(fn ($x) => round($x, $precision), $this);
+ $result = $mo->f(fn($x) => round($x, $precision), $this);
return new static($result->buffer(), $result->dtype(), $result->shape(), $result->offset());
}
@@ -1003,7 +1006,11 @@ public function stdMean(?int $axis = null, int $correction = 1, bool $keepShape
$std = sqrt(
$mo->sum(
$mo->la()->pow(
- $mo->la()->increment($this, -$mean), 2)) / ($this->size() - $correction));
+ $mo->la()->increment($this, -$mean),
+ 2
+ )
+ ) / ($this->size() - $correction)
+ );
return [$std, $mean];
}
@@ -1110,7 +1117,7 @@ public function sliceWithBounds(array $start, array $size): Tensor
/**
* Slices the tensor with the given slices.
*
- * @param array ...$slices The slices to apply.
+ * @param mixed ...$slices The slices to apply.
*
* @return Tensor The sliced tensor.
*/
@@ -1126,25 +1133,30 @@ public function slice(...$slices): Tensor
// null or undefined means take the whole dimension
$start[] = 0;
$size[] = $this->shape()[$sliceIndex];
-
} elseif (is_int($slice)) {
// An integer means take a single element
$slice = $this->safeIndex($slice, $this->shape()[$sliceIndex], $sliceIndex);
$start[] = $slice;
$size[] = 1;
-
} elseif (is_array($slice) && count($slice) === 2) {
+ [$first, $second] = $slice;
+
+ $first = $first === null ? 0
+ : $this->safeIndex($first, $this->shape[$sliceIndex], $sliceIndex);
+
+ $second = $second === null ? $this->shape[$sliceIndex]
+ : $this->safeIndex($second, $this->shape[$sliceIndex], $sliceIndex);
+
// An array of length 2 means take a range of elements
- if ($slice[0] > $slice[1]) {
- throw new InvalidArgumentException("Invalid slice: ".json_encode($slice));
+ if ($first > $second) {
+ throw new InvalidArgumentException("Invalid slice: " . json_encode($slice));
}
- $start[] = max($slice[0], 0);
- $size[] = min($slice[1], $this->shape()[$sliceIndex]);
-
+ $start[] = $first;
+ $size[] = $second - $first;
} else {
- throw new InvalidArgumentException("Invalid slice: ".json_encode($slice));
+ throw new InvalidArgumentException("Invalid slice: " . json_encode($slice));
}
}
@@ -1321,7 +1333,7 @@ public function topk(int $k = -1, bool $sorted = true): array
if ($sorted) {
// Sort the heap to get the top k elements in descending order
- usort($heap, fn ($a, $b) => $b['value'] <=> $a['value']);
+ usort($heap, fn($a, $b) => $b['value'] <=> $a['value']);
}
// Extract top K values and indices from the heap
@@ -1421,13 +1433,15 @@ public function offsetExists($offset): bool
return false;
if (is_array($offset)) {
- if (count($offset) != 2 ||
+ if (
+ count($offset) != 2 ||
!array_key_exists(0, $offset) || !array_key_exists(1, $offset) ||
- $offset[0] > $offset[1]) {
+ $offset[0] > $offset[1]
+ ) {
$det = '';
if (is_numeric($offset[0]) && is_numeric($offset[1]))
- $det = ':['.implode(',', $offset).']';
- throw new OutOfRangeException("Illegal range specification.".$det);
+ $det = ':[' . implode(',', $offset) . ']';
+ throw new OutOfRangeException("Illegal range specification." . $det);
}
$start = $offset[0];
$limit = $offset[1];
@@ -1442,8 +1456,8 @@ public function offsetExists($offset): bool
$limit = $offset->limit();
$delta = $offset->delta();
if ($start >= $limit || $delta != 1) {
- $det = ":[$start,$limit".(($delta != 1) ? ",$delta" : "").']';
- throw new OutOfRangeException("Illegal range specification.".$det);
+ $det = ":[$start,$limit" . (($delta != 1) ? ",$delta" : "") . ']';
+ throw new OutOfRangeException("Illegal range specification." . $det);
}
} else {
throw new OutOfRangeException("Dimension must be integer");
@@ -1490,7 +1504,7 @@ public function offsetGet($offset): mixed
$start = $offset->start();
$limit = $offset->limit();
if ($offset->delta() != 1) {
- throw new OutOfRangeException("Illegal range specification.:delta=".$offset->delta());
+ throw new OutOfRangeException("Illegal range specification.:delta=" . $offset->delta());
}
}
@@ -1507,8 +1521,12 @@ public function offsetGet($offset): mixed
array_unshift($shape, $rowsCount);
- return new self($this->buffer, $this->dtype,
- $shape, $this->offset + $start * $itemSize);
+ return new self(
+ $this->buffer,
+ $this->dtype,
+ $shape,
+ $this->offset + $start * $itemSize
+ );
}
@@ -1585,7 +1603,7 @@ public function setPortableSerializeMode(bool $mode): void
public function serialize(): ?string
{
- return static::SERIALIZE_NDARRAY_KEYWORD.serialize($this->__serialize());
+ return static::SERIALIZE_NDARRAY_KEYWORD . serialize($this->__serialize());
}
public function __serialize()
@@ -1622,8 +1640,10 @@ public function unserialize($data): void
$buffer = $data->buffer();
if (get_class($data->service()) !== get_class(self::service())) {
$newBuffer = self::service()->buffer()->Buffer($buffer->count(), $buffer->dtype());
- if ($data->service()->serviceLevel() >= Service::LV_ADVANCED &&
- self::service()->serviceLevel() >= Service::LV_ADVANCED) {
+ if (
+ $data->service()->serviceLevel() >= Service::LV_ADVANCED &&
+ self::service()->serviceLevel() >= Service::LV_ADVANCED
+ ) {
$newBuffer->load($buffer->dump());
} else {
$count = $buffer->count();
@@ -1657,7 +1677,7 @@ public function __unserialize($data)
$this->buffer[$key] = $value;
}
} else {
- throw new RuntimeException('Illegal save mode: '.$mode);
+ throw new RuntimeException('Illegal save mode: ' . $mode);
}
}
@@ -1665,7 +1685,8 @@ public function __clone()
{
if (self::service()->serviceLevel() >= Service::LV_ADVANCED) {
$newBuffer = self::service()->buffer()->Buffer(
- count($this->buffer), $this->buffer->dtype()
+ count($this->buffer),
+ $this->buffer->dtype()
);
$newBuffer->load($this->buffer->dump());
@@ -1674,8 +1695,7 @@ public function __clone()
} elseif (self::service()->serviceLevel() >= Service::LV_BASIC) {
$this->buffer = clone $this->buffer;
} else {
- throw new RuntimeException('Unknown buffer type is uncloneable:'.get_class($this->buffer));
+ throw new RuntimeException('Unknown buffer type is uncloneable:' . get_class($this->buffer));
}
}
-
-}
\ No newline at end of file
+}
diff --git a/src/Tensor/TensorBuffer.php b/src/Tensor/TensorBuffer.php
index bdaca2c..084beff 100644
--- a/src/Tensor/TensorBuffer.php
+++ b/src/Tensor/TensorBuffer.php
@@ -69,7 +69,10 @@ class TensorBuffer implements LinearBuffer
public function __construct(int $size, int $dtype)
{
if (self::$ffi === null) {
- $code = file_get_contents(__DIR__ . '/../../includes/buffer.h');
+ $code = "
+ typedef struct _rindow_complex_float { float real, imag; } rindow_complex_float;
+ typedef struct _rindow_complex_double { double real, imag; } rindow_complex_double;
+ ";
self::$ffi = FFI::cdef($code);
}
diff --git a/src/Tensor/TensorService.php b/src/Tensor/TensorService.php
index 61e8808..44333e0 100644
--- a/src/Tensor/TensorService.php
+++ b/src/Tensor/TensorService.php
@@ -4,7 +4,8 @@
namespace Codewithkyrian\Transformers\Tensor;
-use Codewithkyrian\TransformersLibsLoader\Library;
+use Codewithkyrian\Transformers\FFI\OpenBLAS;
+use Codewithkyrian\Transformers\FFI\RindowMatlib;
use Rindow\Math\Matrix\Drivers\AbstractMatlibService;
use Rindow\Matlib\FFI\MatlibFactory;
use function Codewithkyrian\Transformers\Utils\basePath;
@@ -15,13 +16,15 @@ protected function injectDefaultFactories(): void
{
$this->bufferFactory = new TensorBufferFactory();
+ $openBlas = new OpenBLAS();
$this->openblasFactory = new OpenBLASFactory(
- headerFile: Library::OpenBlas->header(basePath('includes')),
- libFiles: [Library::OpenBlas->library(basePath('libs'))],
+ headerFile: $openBlas->getHeaderPath(),
+ libFiles: [$openBlas->getLibraryPath()],
);
+ $rindowMatlib = new RindowMatlib();
$this->mathFactory = new MatlibFactory(
- libFiles: [Library::RindowMatlib->library(basePath('libs'))]
+ libFiles: [$rindowMatlib->getLibraryPath()]
);
}
}
\ No newline at end of file
diff --git a/src/Tokenizers/BPEModel.php b/src/Tokenizers/BPEModel.php
index 4f5c8ba..fae284c 100644
--- a/src/Tokenizers/BPEModel.php
+++ b/src/Tokenizers/BPEModel.php
@@ -2,14 +2,20 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Tokenizers;
-use SplDoublyLinkedList;
use SplPriorityQueue;
/**
* BPE class for encoding text into Byte-Pair-Encoding (BPE) tokens.
+ *
+ * Byte-Pair Encoding (BPE) is a subword tokenization technique that iteratively merges the most frequent pair of adjacent subwords in a vocabulary.
+ * This process continues until a desired vocabulary size is reached.
+ *
+ * The algorithm works as follows:
+ * 1. Initialize the vocabulary with the most frequent characters.
+ * 2. Iteratively merge the most frequent pair of adjacent subwords in the vocabulary.
+ * 3. Continue until the desired vocabulary size is reached.
*/
class BPEModel extends TokenizerModel
{
@@ -48,22 +54,36 @@ public function __construct(array $config)
$vocab = $moreConfig['vocab'] ?? $this->config['vocab'];
- $this->tokenToIds = self::toMap($vocab);
+ $this->tokenToIds = $vocab;
$this->unkTokenId = $this->tokenToIds[$config['unk_token']] ?? null;
$this->unkToken = $config['unk_token'];
$this->vocab = array_flip($vocab);
- $this->bpeRanks = array_flip($config['merges']);
+ // Check if using new merge format (Tokenizers >= 0.20.0)
+ $useNewMergeFormat = is_array($config['merges'][0]);
+
+ if ($useNewMergeFormat) {
+ $this->merges = $config['merges'];
+ } else {
+ $this->merges = array_map(
+ fn($merge) => explode(' ', $merge, 2),
+ $config['merges']
+ );
+ }
+
+ $this->bpeRanks = [];
- $this->merges = array_map(fn($merge) => explode(' ', $merge), $config['merges']);
+ foreach ($this->merges as $i => $pair) {
+ $key = json_encode($pair);
+ $this->bpeRanks[$key] = $i;
+ }
$this->endOfWordSuffix = $config['end_of_word_suffix'] ?? null;
$this->continuingSubwordSuffix = $config['continuing_subword_suffix'] ?? null;
$this->byteFallback = $config['byte_fallback'] ?? false;
-
}
/**
@@ -189,16 +209,20 @@ protected function bpe(string $token): array
return $result;
}
-
+ /**
+ * Add a node to the priority queue.
+ *
+ * `score` is a measure of the merge priority: lower means higher priority.
+ * We use the BPE rank as a measure of priority (i.e., the local of the merge in the merges list)
+ * We also add a fractional component to the score to break ties (with the earlier character having higher priority)
+ */
public function addNodeToQueue(SplPriorityQueue $queue, BPENode $node): void
{
- // `score` is a measure of the merge priority: lower means higher priority.
- // We use the BPE rank as a measure of priority (i.e., the local of the merge in the merges list)
- // We also add a fractional component to the score to break ties (with the earlier character having higher priority)
- $rank = $this->bpeRanks[$node->token . self::BPE_SPLIT_TOKEN . $node->next?->token] ?? null;
+ $pairKey = json_encode([$node->token, $node->next->token]);
+ $rank = $this->bpeRanks[$pairKey] ?? null;
if ($rank !== null) {
- $node->score = -($rank + $node->bias);
+ $node->score = - ($rank + $node->bias);
$queue->insert($node, $node->score);
}
}
@@ -219,8 +243,7 @@ function encode(array $tokens): array
foreach ($bpeTokenList as $bpeToken) {
if (array_key_exists($bpeToken, $this->tokenToIds)) {
$outputTokens[] = $bpeToken;
- }
- else {
+ } else {
if ($this->byteFallback) {
$bytes = unpack('C*', $bpeToken);
diff --git a/src/Tokenizers/BPENode.php b/src/Tokenizers/BPENode.php
index b4ba17e..e964350 100644
--- a/src/Tokenizers/BPENode.php
+++ b/src/Tokenizers/BPENode.php
@@ -2,9 +2,11 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Tokenizers;
+/**
+ * A class representing a node in a BPE tokenizer.
+ */
class BPENode
{
public float $score = 0.0;
@@ -16,7 +18,5 @@ public function __construct(
public float $bias,
public ?BPENode $prev = null,
public ?BPENode $next = null,
- )
- {
- }
-}
\ No newline at end of file
+ ) {}
+}
diff --git a/src/Tokenizers/LegacyModel.php b/src/Tokenizers/LegacyModel.php
index 7dc169c..ceb67e4 100644
--- a/src/Tokenizers/LegacyModel.php
+++ b/src/Tokenizers/LegacyModel.php
@@ -25,14 +25,6 @@ class LegacyModel extends TokenizerModel
public function __construct(array $config, ...$moreConfig)
{
parent::__construct($config);
-
-// $vocab = $moreConfig['vocab'] ?? $this->config['vocab'];
-// $this->tokenToIds = self::toMap(
-// $moreConfig['target_lang'] ?? false
-// ? $vocab[$moreConfig['target_lang']]
-// : $vocab
-// );
-
$vocab = $moreConfig['target_lang'] ?? false
? $config['vocab'][$moreConfig['target_lang']]
: $config['vocab'];
@@ -53,7 +45,6 @@ public function __construct(array $config, ...$moreConfig)
$this->unkToken = $moreConfig['unk_token'] ?? null;
$this->unkTokenId = $this->tokenToIds[$this->unkToken] ?? null;
-
foreach ($this->tokenToIds as $token => $id) {
$this->vocab[$id] = $token;
}
diff --git a/src/Tokenizers/TokenizerModel.php b/src/Tokenizers/TokenizerModel.php
index 5d35734..768051d 100644
--- a/src/Tokenizers/TokenizerModel.php
+++ b/src/Tokenizers/TokenizerModel.php
@@ -4,12 +4,9 @@
namespace Codewithkyrian\Transformers\Tokenizers;
-use ArrayObject;
use Codewithkyrian\Transformers\Exceptions\HubException;
use Codewithkyrian\Transformers\Utils\Hub;
use Exception;
-use function Codewithkyrian\Jinja\slice;
-use function Codewithkyrian\Transformers\Utils\array_pop_key;
abstract class TokenizerModel
{
@@ -30,18 +27,29 @@ abstract class TokenizerModel
* @var string[]
*/
public array $vocab = [];
+
/**
* A mapping of tokens to ids.
*
* @var array
*/
public array $tokenToIds = [];
+
+ /**
+ * The suffix of the end of word.
+ */
public ?string $endOfWordSuffix = null;
+
+ /**
+ * The prefix of the continuing subword.
+ */
public ?string $continuingSubwordPrefix = null;
+
/**
*The id of the unknown token.
*/
protected ?int $unkTokenId = null;
+
/**
* The unknown token string.
*/
@@ -52,6 +60,11 @@ abstract class TokenizerModel
*/
protected bool $fuseUnk = false;
+ /**
+ * Constructs a new TokenizerModel instance.
+ *
+ * @param array $config The configuration for the tokenizer model.
+ */
public function __construct(protected array $config)
{
$this->continuingSubwordPrefix = $config['continuing_subword_prefix'] ?? null;
@@ -67,11 +80,13 @@ public function __construct(protected array $config)
*/
public static function fromConfig(array $config, ...$args): self
{
- return match ($config['type'] ?? null) {
+ $type = $config['type'] ?? null;
+
+ return match ($type) {
'WordPiece' => new WordPieceModel($config),
'Unigram' => new UnigramModel($config, ...$args),
'BPE' => new BPEModel($config),
- default => self::inferTokenizerModel($config, $args),
+ default => self::inferTokenizerModel($type, $config, $args),
};
}
@@ -80,43 +95,29 @@ public static function fromConfig(array $config, ...$args): self
*
* This function is necessary for legacy tokenizer.json files that do not contain the model.type key.
*
+ * @param string $type The tokenizer type.
* @param array $config The tokenizer configuration.
* @param array $args Additional arguments that may include pretokenizerConfig.
* @return TokenizerModel The inferred tokenizer model instance.
* @throws Exception If the tokenizer type is unknown.
*/
- private static function inferTokenizerModel(array $config, array &$args): TokenizerModel
+ private static function inferTokenizerModel(?string $type, array $config, array &$args): TokenizerModel
{
- $pretokenizerConfig = array_pop_key($args, 'pretokenizerConfig');
- $decoderConfig = array_pop_key($args, 'decoderConfig');
-
- if ($pretokenizerConfig) {
- if ($pretokenizerConfig['type'] === 'ByteLevel') {
- return new BPEModel($config);
- } elseif ($pretokenizerConfig['type'] === 'MetaSpace') {
+ if (isset($config['vocab'])) {
+ if (is_array($config['vocab']) && array_is_list($config['vocab'])) {
return new UnigramModel($config, ...$args);
- } elseif ($pretokenizerConfig['type'] === 'Sequence') {
- foreach ($pretokenizerConfig['pretokenizers'] as $pretokenizer) {
- if ($pretokenizer['type'] === 'ByteLevel') {
- return new BPEModel($config);
- } elseif ($pretokenizer['type'] === 'Metaspace') {
- return new UnigramModel($config, ...$args);
- }
+ } elseif (array_key_exists('continuing_subword_prefix', $config) && array_key_exists('unk_token', $config)) {
+ if (array_key_exists('merges', $config)) {
+ return new BPEModel($config);
+ } else {
+ return new WordPieceModel($config);
}
+ } else {
+ return new LegacyModel($config, ...$args);
}
}
- if ($decoderConfig) {
- if ($decoderConfig['type'] === 'WordPiece') {
- return new WordPieceModel($config);
- }
- }
-
- if ($config['vocab'] ?? false) {
- return new LegacyModel($config, ...$args);
- }
-
- throw new Exception("Unknown tokenizer type {$config['type']}");
+ throw new Exception("Unknown tokenizer type: " . $type ?? 'undefined');
}
/**
@@ -166,42 +167,6 @@ public static function load(
];
}
- /**
- * Helper function to split a string on whitespace.
- *
- * @param string $text The text to split.
- *
- * @return string[] The split text.
- */
- public static function whitespaceSplit(string $text): array
- {
- return preg_split('/\s+/', $text, -1, PREG_SPLIT_NO_EMPTY);
- }
-
- /**
- * Helper function to lowercase a string and remove accents.
- *
- * @param string $text The text to lowercase and remove accents from.
- *
- * @return string The text with accents removed and lowercased.
- */
- public static function lowerCaseAndRemoveAccents(string $text): string
- {
- return mb_strtolower(self::removeAccents($text));
- }
-
- /**
- * Helper function to remove accents from a string.
- *
- * @param string $text The text to remove accents from.
- *
- * @return string The text with accents removed.
- */
- public static function removeAccents(string $text): string
- {
- return preg_replace('/[\x{0300}-\x{036f}]/u', '', $text);
- }
-
/**
* Clean up a list of simple English tokenization artifacts like spaces before punctuations and abbreviated forms
*
@@ -228,13 +193,6 @@ public static function cleanUpTokenization(string|int $text): string
return preg_replace('/ \'re/', "'re", $text);
}
- public static function toMap(array $arr): array
- {
- $arrayObject = new ArrayObject($arr);
-
- return $arrayObject->getArrayCopy();
- }
-
/**
* Internal function to call the TokenizerModel instance.
*
@@ -295,53 +253,6 @@ protected function fuse(array $arr, mixed $value, array $mapping): array
return $fused;
}
- /**
- * Adds whitespace around any CJK (Chinese, Japanese, or Korean) character in the input text.
- *
- * @param string $text The input text to tokenize.
- *
- * @return string The tokenized text with whitespace added around CJK characters.
- */
- public static function tokenizeChineseChars(string $text): string
- {
- $output = [];
- for ($i = 0; $i < mb_strlen($text); ++$i) {
- $char = mb_substr($text, $i, 1);
- $cp = mb_ord($char);
- if (self::isChineseChar($cp)) {
- $output[] = " ";
- $output[] = $char;
- $output[] = " ";
- } else {
- $output[] = $char;
- }
- }
- return implode("", $output);
- }
-
- /**
- * Checks whether the given Unicode codepoint represents a CJK (Chinese, Japanese, or Korean) character.
- *
- * A "chinese character" is defined as anything in the CJK Unicode block.
- *
- * @param int $cp The Unicode codepoint to check.
- *
- * @return bool True if the codepoint represents a CJK character, false otherwise.
- */
- public static function isChineseChar(int $cp): bool
- {
- return (
- ($cp >= 0x4E00 && $cp <= 0x9FFF)
- || ($cp >= 0x3400 && $cp <= 0x4DBF)
- || ($cp >= 0x20000 && $cp <= 0x2A6DF)
- || ($cp >= 0x2A700 && $cp <= 0x2B73F)
- || ($cp >= 0x2B740 && $cp <= 0x2B81F)
- || ($cp >= 0x2B820 && $cp <= 0x2CEAF)
- || ($cp >= 0xF900 && $cp <= 0xFAFF)
- || ($cp >= 0x2F800 && $cp <= 0x2FA1F)
- );
- }
-
/**
* Converts a list of tokens into a list of token IDs.
*
diff --git a/src/Tokenizers/UnigramModel.php b/src/Tokenizers/UnigramModel.php
index dc79e76..84f9a53 100644
--- a/src/Tokenizers/UnigramModel.php
+++ b/src/Tokenizers/UnigramModel.php
@@ -2,7 +2,6 @@
declare(strict_types=1);
-
namespace Codewithkyrian\Transformers\Tokenizers;
use Codewithkyrian\Transformers\DataStructures\CharTrie;
diff --git a/src/Tokenizers/WordPieceModel.php b/src/Tokenizers/WordPieceModel.php
index 0a8ad1f..2839e72 100644
--- a/src/Tokenizers/WordPieceModel.php
+++ b/src/Tokenizers/WordPieceModel.php
@@ -18,7 +18,7 @@ public function __construct(array $config)
{
parent::__construct($config);
- $this->tokenToIds = self::toMap($config['vocab']);
+ $this->tokenToIds = $config['vocab'];
$this->unkToken = $this->config['unk_token'] ?? '[UNK]';
$this->unkTokenId = $this->tokenToIds[$this->unkToken];
diff --git a/src/Transformers.php b/src/Transformers.php
index d2c6d69..0596f03 100644
--- a/src/Transformers.php
+++ b/src/Transformers.php
@@ -7,6 +7,7 @@
use Codewithkyrian\Transformers\Utils\ImageDriver;
use Psr\Log\LoggerInterface;
use RuntimeException;
+use Psr\Log\NullLogger;
class Transformers
{
@@ -18,9 +19,9 @@ class Transformers
protected static ?string $authToken = null;
- protected static ?string $userAgent = 'transformers-php/0.4.0';
+ protected static ?string $userAgent = 'transformers-php/0.5.3';
- protected static ImageDriver $imageDriver;
+ protected static ImageDriver $imageDriver = ImageDriver::VIPS;
protected static ?LoggerInterface $logger = null;
@@ -125,16 +126,14 @@ public function setImageDriver(ImageDriver $imageDriver): static
}
/**
- * Set the logger for debugging.
+ * Set the global logger for Transformers.
*
* @param LoggerInterface $logger
- *
* @return $this
*/
- public function setLogger(LoggerInterface $logger) : static
+ public function setLogger(LoggerInterface $logger): static
{
self::$logger = $logger;
-
return $this;
}
@@ -172,8 +171,12 @@ public static function getImageDriver(): ?ImageDriver
return self::$imageDriver;
}
- public static function getLogger(): ?LoggerInterface
+ public static function getLogger(): LoggerInterface
{
+ if (!isset(self::$logger)) {
+ self::$logger = new NullLogger();
+ }
+
return self::$logger;
}
}
diff --git a/src/Utils/Audio.php b/src/Utils/Audio.php
index 5b69bbf..b95fb51 100644
--- a/src/Utils/Audio.php
+++ b/src/Utils/Audio.php
@@ -13,21 +13,35 @@
use InvalidArgumentException;
use RuntimeException;
use SplFixedArray;
+use Codewithkyrian\Transformers\Transformers;
+use Psr\Log\LoggerInterface;
class Audio
{
- public function __construct(protected $sndfile, protected $sfinfo) {}
+ protected Sndfile $snd;
+ protected Samplerate $src;
- public static function read(string $filename): static
- {
- $sfinfo = Sndfile::new('SF_INFO');
+ protected $sfinfo;
+ protected $sndfile;
- $sndfile = Sndfile::open($filename, Sndfile::enum('SFM_READ'), FFI::addr($sfinfo));
+ protected LoggerInterface $logger;
- return new static($sndfile, $sfinfo);
+ public function __construct(string $filename)
+ {
+ $this->logger = Transformers::getLogger();
+ $this->snd = new Sndfile();
+ $this->src = new Samplerate();
+
+ $this->sfinfo = $this->snd->new('SF_INFO');
+ $this->sndfile = $this->snd->open($filename, $this->snd->enum('SFM_READ'), FFI::addr($this->sfinfo));
+ $this->logger->info('Audio file loaded', [
+ 'file' => $filename,
+ 'samplerate' => $this->sfinfo->samplerate,
+ 'channels' => $this->sfinfo->channels,
+ 'frames' => $this->sfinfo->frames
+ ]);
}
-
public function channels(): int
{
return $this->sfinfo->channels;
@@ -53,24 +67,20 @@ public function toTensor(int $samplerate = 41000, int $chunkSize = 2048): Tensor
$tensorData = '';
$totalOutputFrames = 0;
- $state = Samplerate::srcNew(Samplerate::enum('SRC_SINC_FASTEST'), $this->channels());
-
+ $state = $this->src->src_new($this->src->enum('SRC_SINC_FASTEST'), $this->channels());
$inputSize = $chunkSize * $this->channels();
- $inputData = Samplerate::new("float[$inputSize]");
+ $inputData = $this->src->new("float[$inputSize]");
$outputSize = $chunkSize * $this->channels();
- $outputData = Samplerate::new("float[$outputSize]");
+ $outputData = $this->src->new("float[$outputSize]");
- $srcData = Samplerate::new('SRC_DATA');
- $srcData->data_in = Samplerate::cast('float *', $inputData);
+ $srcData = $this->src->new('SRC_DATA');
+ $srcData->data_in = $this->src->cast('float *', $inputData);
$srcData->output_frames = $chunkSize / $this->channels();
- $srcData->data_out = Samplerate::cast('float *', $outputData);
+ $srcData->data_out = $this->src->cast('float *', $outputData);
$srcData->src_ratio = $samplerate / $this->samplerate();
while (true) {
- /* Read the chunk of data */
- $srcData->input_frames = Sndfile::readFrames($this->sndfile, $inputData, $chunkSize);
-
- /* Add to tensor data without resample if the sample rate is the same */
+ $srcData->input_frames = $this->snd->readf_float($this->sndfile, $inputData, $chunkSize);
if ($this->samplerate() === $samplerate) {
$strBuffer = FFI::string($inputData, $srcData->input_frames * $this->channels() * FFI::sizeof($inputData[0]));
$tensorData .= $strBuffer;
@@ -81,55 +91,63 @@ public function toTensor(int $samplerate = 41000, int $chunkSize = 2048): Tensor
continue;
}
- /* The last read will not be a full buffer, so snd_of_input. */
+ $this->logger->info('Resampling audio segment', [
+ 'input_samplerate' => $this->samplerate(),
+ 'output_samplerate' => $samplerate,
+ 'input_frames' => $srcData->input_frames,
+ 'output_frames' => $srcData->output_frames_gen
+ ]);
+
if ($srcData->input_frames < $chunkSize) {
- $srcData->end_of_input = Sndfile::enum('SF_TRUE');
+ $srcData->end_of_input = $this->snd->enum('SF_TRUE');
}
- /* Process current block. */
- Samplerate::srcProcess($state, FFI::addr($srcData));
-
- /* Terminate if done. */
+ $this->src->process($state, FFI::addr($srcData));
if ($srcData->end_of_input && $srcData->output_frames_gen === 0) {
break;
}
- /* Add the processed data to the tensor data */
$outputSize = $srcData->output_frames_gen * $this->channels() * FFI::sizeof($outputData[0]);
$strBuffer = FFI::string($outputData, $outputSize);
$tensorData .= $strBuffer;
$totalOutputFrames += $srcData->output_frames_gen;
}
- Samplerate::srcDelete($state);
-
+ $this->src->delete($state);
$audioTensor = Tensor::fromString($tensorData, Tensor::float32, [$totalOutputFrames, $this->channels()]);
if ($this->channels() > 1) {
+ $this->logger->info('Averaging channels to mono', ['channels' => $this->channels()]);
$audioTensor = $audioTensor->mean(1)->multiply(sqrt(2));
}
+ $this->logger->info('Audio tensor conversion complete', ['shape' => $audioTensor->shape()]);
return $audioTensor->squeeze();
}
public function fromTensor(Tensor $tensor): void
{
$size = $tensor->size();
- $buffer = Sndfile::new("float[$size]");
+ $buffer = $this->snd->new("float[$size]");
$bufferString = $tensor->toString();
- $buffer->cdata = Sndfile::cast('float *', (int)$bufferString);
-
- $write = Sndfile::writeFrames($this->sndfile, $buffer, $size);
+ $buffer->cdata = $this->snd->cast('float *', (int)$bufferString);
+ $write = $this->snd->writef_float($this->sndfile, $buffer, $size);
if ($write !== $size) {
+ $this->logger->warning('Wrote fewer frames than expected to audio file', [
+ 'expected' => $size,
+ 'actual' => $write
+ ]);
throw new RuntimeException("Failed to write to file");
}
+
+ $this->logger->info('Audio tensor written to file successfully', ['frames' => $write]);
}
public function __destruct()
{
- Sndfile::close($this->sndfile);
+ $this->snd->close($this->sndfile);
}
/**
@@ -158,8 +176,7 @@ public static function melFilterBank(
?string $norm = null,
string $melScale = "htk",
bool $triangularizeInMelSpace = false
- ): array
- {
+ ): array {
if ($norm !== null && $norm !== "slaney") {
throw new InvalidArgumentException('norm must be one of null or "slaney"');
}
@@ -173,7 +190,7 @@ public static function melFilterBank(
if ($triangularizeInMelSpace) {
$fft_bin_width = $samplingRate / ($nFrequencyBins * 2);
- $fftFreqs = self::hertzToMel(array_map(fn ($i) => $i * $fft_bin_width, range(0, $nFrequencyBins - 1)), $melScale);
+ $fftFreqs = self::hertzToMel(array_map(fn($i) => $i * $fft_bin_width, range(0, $nFrequencyBins - 1)), $melScale);
$filterFreqs = $melFreqs;
} else {
$fftFreqs = self::linspace(0, floor($samplingRate / 2), $nFrequencyBins);
@@ -252,13 +269,13 @@ private static function createTriangularFilterBank(array $fftFreqs, array $filte
private static function linspace(float $start, float $end, int $num): array
{
$step = ($end - $start) / ($num - 1);
- return array_map(fn ($i) => $start + $step * $i, range(0, $num - 1));
+ return array_map(fn($i) => $start + $step * $i, range(0, $num - 1));
}
public static function hertzToMel(array|float|int $hz, string $melScale = "htk"): float|int|array
{
if (is_array($hz)) {
- return array_map(fn ($i) => self::hertzToMel($i, $melScale), $hz);
+ return array_map(fn($i) => self::hertzToMel($i, $melScale), $hz);
}
if ($melScale === "htk") {
@@ -283,7 +300,7 @@ public static function hertzToMel(array|float|int $hz, string $melScale = "htk")
public static function melToHertz(array|float|int $mel, string $melScale = "htk"): float|int|array
{
if (is_array($mel)) {
- return array_map(fn ($i) => self::melToHertz($i, $melScale), $mel);
+ return array_map(fn($i) => self::melToHertz($i, $melScale), $mel);
}
if ($melScale === "htk") {
@@ -314,8 +331,7 @@ private static function dBConversionHelper(
float $reference,
float $minValue,
?float $dbRange
- ): Tensor
- {
+ ): Tensor {
if ($reference <= 0) {
throw new InvalidArgumentException('reference must be greater than zero');
}
@@ -327,10 +343,10 @@ private static function dBConversionHelper(
$reference = max($minValue, $reference);
$logReference = log10($reference);
-// for ($i = 0; $i < count($spectrogram); $i++) {
-// $spectrogram->buffer()[$i] = $factor * log10(max($minValue, $spectrogram->buffer()[$i]) - $logReference);
-// }
- $spectrogram->u(fn ($x) => $factor * log10(max($minValue, $x) - $logReference));
+ // for ($i = 0; $i < count($spectrogram); $i++) {
+ // $spectrogram->buffer()[$i] = $factor * log10(max($minValue, $spectrogram->buffer()[$i]) - $logReference);
+ // }
+ $spectrogram->u(fn($x) => $factor * log10(max($minValue, $x) - $logReference));
if ($dbRange !== null) {
if ($dbRange <= 0) {
@@ -339,10 +355,10 @@ private static function dBConversionHelper(
$maxValue = $spectrogram->max() - $dbRange;
-// for ($i = 0; $i < count($spectrogram); $i++) {
-// $spectrogram->buffer()[$i] = max($spectrogram->buffer()[$i], $maxValue);
-// }
- $spectrogram->u(fn ($x) => max($x, $maxValue));
+ // for ($i = 0; $i < count($spectrogram); $i++) {
+ // $spectrogram->buffer()[$i] = max($spectrogram->buffer()[$i], $maxValue);
+ // }
+ $spectrogram->u(fn($x) => max($x, $maxValue));
}
return $spectrogram;
@@ -352,20 +368,19 @@ private static function dBConversionHelper(
* Converts an amplitude spectrogram to the decibel scale. This computes `20 * log10(spectrogram / reference)`,
* using basic logarithm properties for numerical stability. NOTE: Operates in-place.
*
- * @param SplFixedArray $spectrogram The input amplitude (mel) spectrogram.
+ * @param Tensor $spectrogram The input amplitude (mel) spectrogram.
* @param float $reference Sets the input spectrogram value that corresponds to 0 dB.
* @param float $minValue Minimum threshold for `spectrogram` and `reference` values.
* @param float|null $dbRange Dynamic range of the resulting decibel scale. If set, the decibel scale is compressed
*
- * @return SplFixedArray
+ * @return Tensor
*/
public static function amplitudeToDB(
Tensor $spectrogram,
float $reference = 1.0,
float $minValue = 1e-5,
?float $dbRange = null
- ): Tensor
- {
+ ): Tensor {
return self::dBConversionHelper($spectrogram, 20.0, $reference, $minValue, $dbRange);
}
@@ -373,20 +388,19 @@ public static function amplitudeToDB(
* Converts a power spectrogram (amplitude squared) to the decibel scale. This computes `10 * log10(spectrogram / reference)`,
* using basic logarithm properties for numerical stability. NOTE: Operates in-place.
*
- * @param SplFixedArray $spectrogram The input power spectrogram.
+ * @param Tensor $spectrogram The input power spectrogram.
* @param float $reference Sets the input spectrogram value that corresponds to 0 dB.
* @param float $minValue Minimum threshold for `spectrogram` and `reference` values.
* @param float|null $dbRange Dynamic range of the resulting decibel scale. If set, the decibel scale is compressed
*
- * @return SplFixedArray
+ * @return Tensor
*/
public static function powerToDB(
Tensor $spectrogram,
float $reference = 1.0,
float $minValue = 1e-5,
?float $dbRange = null
- ): Tensor
- {
+ ): Tensor {
return self::dBConversionHelper($spectrogram, 10.0, $reference, $minValue, $dbRange);
}
@@ -426,8 +440,9 @@ public static function spectrogram(
?int $maxNumFrames = null, // -1 for c
bool $doPad = true,
bool $transpose = false
- ): Tensor
- {
+ ): Tensor {
+ $transformersLib = new TransformersUtils();
+
$fftLength ??= $frameLength;
if ($frameLength > $fftLength) {
throw new InvalidArgumentException("frameLength ($frameLength) may not be larger than fftLength ($fftLength)");
@@ -450,7 +465,7 @@ public static function spectrogram(
$halfWindow = (int)floor(($fftLength - 1) / 2) + 1;
$paddedLength = $waveform->size() + (2 * $halfWindow);
- $padded = TransformersUtils::padReflect(
+ $padded = $transformersLib->padReflect(
$waveform->buffer()->addr($waveform->offset()),
$waveform->size(),
$paddedLength
@@ -480,13 +495,13 @@ public static function spectrogram(
$melFilters = Tensor::fromArray($melFilters, Tensor::float32);
$spectrogramShape = $transpose ? [$d1Max, $melFilters->count()] : [$melFilters->count(), $d1Max];
$logMel = match ($logMel) {
- 'log' => TransformersUtils::enum('LOG_MEL_LOG'),
- 'log10' => TransformersUtils::enum('LOG_MEL_LOG10'),
- 'dB' => TransformersUtils::enum('LOG_MEL_DB'),
- default => TransformersUtils::enum('LOG_MEL_NONE'),
+ 'log' => $transformersLib->enum('LOG_MEL_LOG'),
+ 'log10' => $transformersLib->enum('LOG_MEL_LOG10'),
+ 'dB' => $transformersLib->enum('LOG_MEL_DB'),
+ default => $transformersLib->enum('LOG_MEL_NONE'),
};
- $spectrogram = TransformersUtils::spectrogram(
+ $spectrogram = $transformersLib->spectrogram(
$waveform->buffer()->addr($waveform->offset()),
$waveform->size(),
array_product($spectrogramShape),
@@ -558,10 +573,9 @@ public static function windowFunction(
int $windowLength,
string $name,
bool $periodic = true,
- int $frameLength = null,
+ ?int $frameLength = null,
bool $center = true
- ): Tensor
- {
+ ): Tensor {
$length = $periodic ? $windowLength + 1 : $windowLength;
@@ -586,5 +600,4 @@ public static function windowFunction(
return $window;
}
-
-}
\ No newline at end of file
+}
diff --git a/src/Utils/AutoConfig.php b/src/Utils/AutoConfig.php
deleted file mode 100644
index 6a5d869..0000000
--- a/src/Utils/AutoConfig.php
+++ /dev/null
@@ -1,74 +0,0 @@
-modelType = $this->config['model_type'] ?? null;
- $this->isEncoderDecoder = $this->config['is_encoder_decoder'] ?? false;
- $this->architectures = $this->config['architectures'] ?? [];
- $this->padTokenId = $this->config['pad_token_id'] ?? 0;
- $this->vocabSize = $this->config['vocab_size'] ?? 0;
- $this->hiddenSize = $this->config['hidden_size'] ?? 0;
- }
-
- public static function fromPretrained(
- string $modelNameOrPath,
- ?array $config = null,
- ?string $cacheDir = null,
- string $revision = 'main',
- ?callable $onProgress = null
- ): self
- {
- $data = $config ?? Hub::getJson(
- $modelNameOrPath,
- fileName: 'config.json',
- cacheDir: $cacheDir,
- revision: $revision,
- fatal: false,
- onProgress: $onProgress
- );
-
- return new self($data);
- }
-
- public function offsetExists(mixed $offset): bool
- {
- return isset($this->config[$offset]);
- }
-
- public function offsetGet(mixed $offset): mixed
- {
- return $this->config[$offset];
- }
-
- public function offsetSet(mixed $offset, mixed $value): void
- {
- $this->config[$offset] = $value;
- }
-
- public function offsetUnset(mixed $offset): void
- {
- unset($this->config[$offset]);
- }
-}
\ No newline at end of file
diff --git a/src/Utils/Downloader.php b/src/Utils/Downloader.php
index 4d9b32f..5e5cd1a 100644
--- a/src/Utils/Downloader.php
+++ b/src/Utils/Downloader.php
@@ -35,7 +35,7 @@ class Downloader
* @param callable|null $onProgress Callback to notify about the download progress
* @return false|string
*/
- public static function download(string $url, string $to, array $options = [], callable $onProgress = null): bool|string
+ public static function download(string $url, string $to, array $options = [], ?callable $onProgress = null): bool|string
{
$curlHandle = curl_init();
@@ -137,4 +137,4 @@ public static function download(string $url, string $to, array $options = [], ca
return $headers;
}
-}
\ No newline at end of file
+}
diff --git a/src/Utils/Helpers.php b/src/Utils/Helpers.php
index 21fa416..0d2ac5f 100644
--- a/src/Utils/Helpers.php
+++ b/src/Utils/Helpers.php
@@ -11,7 +11,7 @@ function memoryUsage(): string
$mem = memory_get_usage(true);
$unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
- return @round($mem / pow(1024, ($i = floor(log($mem, 1024)))), 2).' '.$unit[$i];
+ return @round($mem / pow(1024, ($i = floor(log($mem, 1024)))), 2) . ' ' . $unit[$i];
}
function memoryPeak(): string
@@ -19,7 +19,7 @@ function memoryPeak(): string
$mem = memory_get_peak_usage(true);
$unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
- return @round($mem / pow(1024, ($i = floor(log($mem, 1024)))), 2).' '.$unit[$i];
+ return @round($mem / pow(1024, ($i = floor(log($mem, 1024)))), 2) . ' ' . $unit[$i];
}
@@ -37,8 +37,8 @@ function timeUsage(bool $milliseconds = false, bool $sinceLastCall = true, bool
$timeDiff = $milliseconds ? $timeDiff * 1000 : $timeDiff;
-// return @round($timeDiff, 4) . ($milliseconds ? ' ms' : ' s');
- return $returnString ? @round($timeDiff, 4).($milliseconds ? ' ms' : ' s') : @round($timeDiff, 4);
+ // return @round($timeDiff, 4) . ($milliseconds ? ' ms' : ' s');
+ return $returnString ? @round($timeDiff, 4) . ($milliseconds ? ' ms' : ' s') : @round($timeDiff, 4);
}
function array_some(array $array, callable $callback): bool
@@ -84,6 +84,11 @@ function array_keys_to_snake_case(array $array): array
return $snakeCasedArray;
}
+function array_pick(array $array, array $keys): array
+{
+ return array_intersect_key($array, array_flip($keys));
+}
+
function camelCaseToSnakeCase(string $input): string
{
return strtolower(preg_replace('/(? (int)$x, $box);
+ $box = array_map(fn($x) => (int)$x, $box);
}
[$xmin, $ymin, $xmax, $ymax] = $box;
@@ -190,7 +195,31 @@ function createPattern(array $pattern, bool $invert = true): ?string
// NOTE: if invert is true, we wrap the pattern in a group so that it is kept when performing split
return $invert ? $escaped : "($escaped)";
} else {
- Transformers::getLogger()?->error('Unknown pattern type: '.print_r($pattern, true));
+ $logger = Transformers::getLogger();
+ $logger->warning('Unknown pattern type: ' . print_r($pattern, true));
return null;
}
}
+
+/**
+ * Checks whether the given Unicode codepoint represents a CJK (Chinese, Japanese, or Korean) character.
+ *
+ * A "chinese character" is defined as anything in the CJK Unicode block.
+ *
+ * @param int $cp The Unicode codepoint to check.
+ *
+ * @return bool True if the codepoint represents a CJK character, false otherwise.
+ */
+function isChineseChar(int $cp): bool
+{
+ return (
+ ($cp >= 0x4E00 && $cp <= 0x9FFF)
+ || ($cp >= 0x3400 && $cp <= 0x4DBF)
+ || ($cp >= 0x20000 && $cp <= 0x2A6DF)
+ || ($cp >= 0x2A700 && $cp <= 0x2B73F)
+ || ($cp >= 0x2B740 && $cp <= 0x2B81F)
+ || ($cp >= 0x2B820 && $cp <= 0x2CEAF)
+ || ($cp >= 0xF900 && $cp <= 0xFAFF)
+ || ($cp >= 0x2F800 && $cp <= 0x2FA1F)
+ );
+}
diff --git a/src/Utils/Hub.php b/src/Utils/Hub.php
index 50ca1b0..9a962b7 100644
--- a/src/Utils/Hub.php
+++ b/src/Utils/Hub.php
@@ -8,7 +8,6 @@
use Codewithkyrian\Transformers\Transformers;
use Exception;
use RuntimeException;
-use Symfony\Component\Console\Helper\ProgressBar;
/**
* Utility class to download files from the Hugging Face Hub
@@ -55,8 +54,7 @@ public static function getFile(
string $subFolder = '',
bool $fatal = true,
?callable $onProgress = null
- ): ?string
- {
+ ): ?string {
# Local cache and file paths
$cacheDir ??= Transformers::getCacheDir();
@@ -72,17 +70,17 @@ public static function getFile(
$partCounter = 1;
$partBasePath = "$filePath.part";
- while (file_exists($partBasePath.$partCounter)) {
+ while (file_exists($partBasePath . $partCounter)) {
$partCounter++;
}
- $partPath = $partBasePath.$partCounter;
+ $partPath = $partBasePath . $partCounter;
# Resume download if partially downloaded
$downloadedBytes = 0;
if ($partCounter > 1) {
for ($i = 1; $i < $partCounter; $i++) {
- $downloadedBytes += filesize($partBasePath.$i);
+ $downloadedBytes += filesize($partBasePath . $i);
}
}
@@ -92,14 +90,14 @@ public static function getFile(
$options = [
'http' => [
'header' => [
- 'Range: bytes='.$downloadedBytes.'-',
+ 'Range: bytes=' . $downloadedBytes . '-',
],
'User-Agent' => Transformers::getUserAgent(),
],
];
if (Transformers::getAuthToken()) {
- $options['http']['header'][] = 'Authorization: Bearer '.Transformers::getAuthToken();
+ $options['http']['header'][] = 'Authorization: Bearer ' . Transformers::getAuthToken();
}
try {
@@ -146,8 +144,7 @@ public static function getJson(
string $subFolder = '',
bool $fatal = true,
?callable $onProgress = null
- ): ?array
- {
+ ): ?array {
$file = self::getFile($pathOrRepoID, $fileName, $cacheDir, $revision, $subFolder, $fatal, $onProgress);
if ($file === null) {
@@ -166,23 +163,11 @@ public static function getJson(
return $data;
}
-
- private static function onProgress(ProgressBar $progressBar): callable
- {
- return function ($totalDownload, $downloadedBytes) use ($progressBar) {
- if ($totalDownload == 0) return;
-
- $percent = round(($downloadedBytes / $totalDownload) * 100, 2);
- $progressBar->setProgress((int)$percent);
- };
- }
-
-
public static function combinePartFiles($filePath, $partBasePath, $partCount): void
{
$fileHandle = fopen($filePath, 'w');
for ($i = 1; $i <= $partCount; $i++) {
- $partPath = $partBasePath.$i;
+ $partPath = $partBasePath . $i;
$partFileHandle = fopen($partPath, 'r');
stream_copy_to_stream($partFileHandle, $fileHandle);
fclose($partFileHandle);
diff --git a/src/Utils/Image.php b/src/Utils/Image.php
index 4c75d13..fd88a4c 100644
--- a/src/Utils/Image.php
+++ b/src/Utils/Image.php
@@ -4,6 +4,7 @@
namespace Codewithkyrian\Transformers\Utils;
+use Codewithkyrian\Transformers\FFI\Libvips;
use Codewithkyrian\Transformers\Tensor\Tensor;
use Codewithkyrian\Transformers\Transformers;
use Exception;
@@ -12,8 +13,8 @@
use Imagine\Image\Box;
use Imagine\Image\ImageInterface;
use Imagine\Image\Metadata\MetadataBag;
+use Imagine\Image\Palette\Color\ColorInterface;
use Imagine\Image\Point;
-use Imagine\Vips\Imagine;
use InvalidArgumentException;
use RuntimeException;
@@ -27,57 +28,393 @@ class Image
public static AbstractImagine $imagine;
public const CHR = [
- "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x09", "\x0A", "\x0B", "\x0C", "\x0D", "\x0E", "\x0F",
- "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17", "\x18", "\x19", "\x1A", "\x1B", "\x1C", "\x1D", "\x1E", "\x1F",
- "\x20", "\x21", "\x22", "\x23", "\x24", "\x25", "\x26", "\x27", "\x28", "\x29", "\x2A", "\x2B", "\x2C", "\x2D", "\x2E", "\x2F",
- "\x30", "\x31", "\x32", "\x33", "\x34", "\x35", "\x36", "\x37", "\x38", "\x39", "\x3A", "\x3B", "\x3C", "\x3D", "\x3E", "\x3F",
- "\x40", "\x41", "\x42", "\x43", "\x44", "\x45", "\x46", "\x47", "\x48", "\x49", "\x4A", "\x4B", "\x4C", "\x4D", "\x4E", "\x4F",
- "\x50", "\x51", "\x52", "\x53", "\x54", "\x55", "\x56", "\x57", "\x58", "\x59", "\x5A", "\x5B", "\x5C", "\x5D", "\x5E", "\x5F",
- "\x60", "\x61", "\x62", "\x63", "\x64", "\x65", "\x66", "\x67", "\x68", "\x69", "\x6A", "\x6B", "\x6C", "\x6D", "\x6E", "\x6F",
- "\x70", "\x71", "\x72", "\x73", "\x74", "\x75", "\x76", "\x77", "\x78", "\x79", "\x7A", "\x7B", "\x7C", "\x7D", "\x7E", "\x7F",
- "\x80", "\x81", "\x82", "\x83", "\x84", "\x85", "\x86", "\x87", "\x88", "\x89", "\x8A", "\x8B", "\x8C", "\x8D", "\x8E", "\x8F",
- "\x90", "\x91", "\x92", "\x93", "\x94", "\x95", "\x96", "\x97", "\x98", "\x99", "\x9A", "\x9B", "\x9C", "\x9D", "\x9E", "\x9F",
- "\xA0", "\xA1", "\xA2", "\xA3", "\xA4", "\xA5", "\xA6", "\xA7", "\xA8", "\xA9", "\xAA", "\xAB", "\xAC", "\xAD", "\xAE", "\xAF",
- "\xB0", "\xB1", "\xB2", "\xB3", "\xB4", "\xB5", "\xB6", "\xB7", "\xB8", "\xB9", "\xBA", "\xBB", "\xBC", "\xBD", "\xBE", "\xBF",
- "\xC0", "\xC1", "\xC2", "\xC3", "\xC4", "\xC5", "\xC6", "\xC7", "\xC8", "\xC9", "\xCA", "\xCB", "\xCC", "\xCD", "\xCE", "\xCF",
- "\xD0", "\xD1", "\xD2", "\xD3", "\xD4", "\xD5", "\xD6", "\xD7", "\xD8", "\xD9", "\xDA", "\xDB", "\xDC", "\xDD", "\xDE", "\xDF",
- "\xE0", "\xE1", "\xE2", "\xE3", "\xE4", "\xE5", "\xE6", "\xE7", "\xE8", "\xE9", "\xEA", "\xEB", "\xEC", "\xED", "\xEE", "\xEF",
- "\xF0", "\xF1", "\xF2", "\xF3", "\xF4", "\xF5", "\xF6", "\xF7", "\xF8", "\xF9", "\xFA", "\xFB", "\xFC", "\xFD", "\xFE", "\xFF",
+ "\x00",
+ "\x01",
+ "\x02",
+ "\x03",
+ "\x04",
+ "\x05",
+ "\x06",
+ "\x07",
+ "\x08",
+ "\x09",
+ "\x0A",
+ "\x0B",
+ "\x0C",
+ "\x0D",
+ "\x0E",
+ "\x0F",
+ "\x10",
+ "\x11",
+ "\x12",
+ "\x13",
+ "\x14",
+ "\x15",
+ "\x16",
+ "\x17",
+ "\x18",
+ "\x19",
+ "\x1A",
+ "\x1B",
+ "\x1C",
+ "\x1D",
+ "\x1E",
+ "\x1F",
+ "\x20",
+ "\x21",
+ "\x22",
+ "\x23",
+ "\x24",
+ "\x25",
+ "\x26",
+ "\x27",
+ "\x28",
+ "\x29",
+ "\x2A",
+ "\x2B",
+ "\x2C",
+ "\x2D",
+ "\x2E",
+ "\x2F",
+ "\x30",
+ "\x31",
+ "\x32",
+ "\x33",
+ "\x34",
+ "\x35",
+ "\x36",
+ "\x37",
+ "\x38",
+ "\x39",
+ "\x3A",
+ "\x3B",
+ "\x3C",
+ "\x3D",
+ "\x3E",
+ "\x3F",
+ "\x40",
+ "\x41",
+ "\x42",
+ "\x43",
+ "\x44",
+ "\x45",
+ "\x46",
+ "\x47",
+ "\x48",
+ "\x49",
+ "\x4A",
+ "\x4B",
+ "\x4C",
+ "\x4D",
+ "\x4E",
+ "\x4F",
+ "\x50",
+ "\x51",
+ "\x52",
+ "\x53",
+ "\x54",
+ "\x55",
+ "\x56",
+ "\x57",
+ "\x58",
+ "\x59",
+ "\x5A",
+ "\x5B",
+ "\x5C",
+ "\x5D",
+ "\x5E",
+ "\x5F",
+ "\x60",
+ "\x61",
+ "\x62",
+ "\x63",
+ "\x64",
+ "\x65",
+ "\x66",
+ "\x67",
+ "\x68",
+ "\x69",
+ "\x6A",
+ "\x6B",
+ "\x6C",
+ "\x6D",
+ "\x6E",
+ "\x6F",
+ "\x70",
+ "\x71",
+ "\x72",
+ "\x73",
+ "\x74",
+ "\x75",
+ "\x76",
+ "\x77",
+ "\x78",
+ "\x79",
+ "\x7A",
+ "\x7B",
+ "\x7C",
+ "\x7D",
+ "\x7E",
+ "\x7F",
+ "\x80",
+ "\x81",
+ "\x82",
+ "\x83",
+ "\x84",
+ "\x85",
+ "\x86",
+ "\x87",
+ "\x88",
+ "\x89",
+ "\x8A",
+ "\x8B",
+ "\x8C",
+ "\x8D",
+ "\x8E",
+ "\x8F",
+ "\x90",
+ "\x91",
+ "\x92",
+ "\x93",
+ "\x94",
+ "\x95",
+ "\x96",
+ "\x97",
+ "\x98",
+ "\x99",
+ "\x9A",
+ "\x9B",
+ "\x9C",
+ "\x9D",
+ "\x9E",
+ "\x9F",
+ "\xA0",
+ "\xA1",
+ "\xA2",
+ "\xA3",
+ "\xA4",
+ "\xA5",
+ "\xA6",
+ "\xA7",
+ "\xA8",
+ "\xA9",
+ "\xAA",
+ "\xAB",
+ "\xAC",
+ "\xAD",
+ "\xAE",
+ "\xAF",
+ "\xB0",
+ "\xB1",
+ "\xB2",
+ "\xB3",
+ "\xB4",
+ "\xB5",
+ "\xB6",
+ "\xB7",
+ "\xB8",
+ "\xB9",
+ "\xBA",
+ "\xBB",
+ "\xBC",
+ "\xBD",
+ "\xBE",
+ "\xBF",
+ "\xC0",
+ "\xC1",
+ "\xC2",
+ "\xC3",
+ "\xC4",
+ "\xC5",
+ "\xC6",
+ "\xC7",
+ "\xC8",
+ "\xC9",
+ "\xCA",
+ "\xCB",
+ "\xCC",
+ "\xCD",
+ "\xCE",
+ "\xCF",
+ "\xD0",
+ "\xD1",
+ "\xD2",
+ "\xD3",
+ "\xD4",
+ "\xD5",
+ "\xD6",
+ "\xD7",
+ "\xD8",
+ "\xD9",
+ "\xDA",
+ "\xDB",
+ "\xDC",
+ "\xDD",
+ "\xDE",
+ "\xDF",
+ "\xE0",
+ "\xE1",
+ "\xE2",
+ "\xE3",
+ "\xE4",
+ "\xE5",
+ "\xE6",
+ "\xE7",
+ "\xE8",
+ "\xE9",
+ "\xEA",
+ "\xEB",
+ "\xEC",
+ "\xED",
+ "\xEE",
+ "\xEF",
+ "\xF0",
+ "\xF1",
+ "\xF2",
+ "\xF3",
+ "\xF4",
+ "\xF5",
+ "\xF6",
+ "\xF7",
+ "\xF8",
+ "\xF9",
+ "\xFA",
+ "\xFB",
+ "\xFC",
+ "\xFD",
+ "\xFE",
+ "\xFF",
]; // Lookup for chr($x): much faster.
public const ALPHA_LOOKUP = [
- 0x00000000 => "\xff", 0x01000000 => "\xfd", 0x02000000 => "\xfb", 0x03000000 => "\xf9",
- 0x04000000 => "\xf7", 0x05000000 => "\xf5", 0x06000000 => "\xf3", 0x07000000 => "\xf1",
- 0x08000000 => "\xef", 0x09000000 => "\xed", 0x0a000000 => "\xeb", 0x0b000000 => "\xe9",
- 0x0c000000 => "\xe7", 0x0d000000 => "\xe5", 0x0e000000 => "\xe3", 0x0f000000 => "\xe1",
- 0x10000000 => "\xdf", 0x11000000 => "\xdd", 0x12000000 => "\xdb", 0x13000000 => "\xd9",
- 0x14000000 => "\xd7", 0x15000000 => "\xd5", 0x16000000 => "\xd3", 0x17000000 => "\xd1",
- 0x18000000 => "\xcf", 0x19000000 => "\xcd", 0x1a000000 => "\xcb", 0x1b000000 => "\xc9",
- 0x1c000000 => "\xc7", 0x1d000000 => "\xc5", 0x1e000000 => "\xc3", 0x1f000000 => "\xc1",
- 0x20000000 => "\xbf", 0x21000000 => "\xbd", 0x22000000 => "\xbb", 0x23000000 => "\xb9",
- 0x24000000 => "\xb7", 0x25000000 => "\xb5", 0x26000000 => "\xb3", 0x27000000 => "\xb1",
- 0x28000000 => "\xaf", 0x29000000 => "\xad", 0x2a000000 => "\xab", 0x2b000000 => "\xa9",
- 0x2c000000 => "\xa7", 0x2d000000 => "\xa5", 0x2e000000 => "\xa3", 0x2f000000 => "\xa1",
- 0x30000000 => "\x9f", 0x31000000 => "\x9d", 0x32000000 => "\x9b", 0x33000000 => "\x99",
- 0x34000000 => "\x97", 0x35000000 => "\x95", 0x36000000 => "\x93", 0x37000000 => "\x91",
- 0x38000000 => "\x8f", 0x39000000 => "\x8d", 0x3a000000 => "\x8b", 0x3b000000 => "\x89",
- 0x3c000000 => "\x87", 0x3d000000 => "\x85", 0x3e000000 => "\x83", 0x3f000000 => "\x81",
- 0x40000000 => "\x7f", 0x41000000 => "\x7d", 0x42000000 => "\x7b", 0x43000000 => "\x79",
- 0x44000000 => "\x77", 0x45000000 => "\x75", 0x46000000 => "\x73", 0x47000000 => "\x71",
- 0x48000000 => "\x6f", 0x49000000 => "\x6d", 0x4a000000 => "\x6b", 0x4b000000 => "\x69",
- 0x4c000000 => "\x67", 0x4d000000 => "\x65", 0x4e000000 => "\x63", 0x4f000000 => "\x61",
- 0x50000000 => "\x5f", 0x51000000 => "\x5d", 0x52000000 => "\x5b", 0x53000000 => "\x59",
- 0x54000000 => "\x57", 0x55000000 => "\x55", 0x56000000 => "\x53", 0x57000000 => "\x51",
- 0x58000000 => "\x4f", 0x59000000 => "\x4d", 0x5a000000 => "\x4b", 0x5b000000 => "\x49",
- 0x5c000000 => "\x47", 0x5d000000 => "\x45", 0x5e000000 => "\x43", 0x5f000000 => "\x41",
- 0x60000000 => "\x3f", 0x61000000 => "\x3d", 0x62000000 => "\x3b", 0x63000000 => "\x39",
- 0x64000000 => "\x37", 0x65000000 => "\x35", 0x66000000 => "\x33", 0x67000000 => "\x31",
- 0x68000000 => "\x2f", 0x69000000 => "\x2d", 0x6a000000 => "\x2b", 0x6b000000 => "\x29",
- 0x6c000000 => "\x27", 0x6d000000 => "\x25", 0x6e000000 => "\x23", 0x6f000000 => "\x21",
- 0x70000000 => "\x1f", 0x71000000 => "\x1d", 0x72000000 => "\x1b", 0x73000000 => "\x19",
- 0x74000000 => "\x17", 0x75000000 => "\x15", 0x76000000 => "\x13", 0x77000000 => "\x11",
- 0x78000000 => "\x0f", 0x79000000 => "\x0d", 0x7a000000 => "\x0b", 0x7b000000 => "\x09",
- 0x7c000000 => "\x07", 0x7d000000 => "\x05", 0x7e000000 => "\x03", 0x7f000000 => "\x00"
+ 0x00000000 => "\xff",
+ 0x01000000 => "\xfd",
+ 0x02000000 => "\xfb",
+ 0x03000000 => "\xf9",
+ 0x04000000 => "\xf7",
+ 0x05000000 => "\xf5",
+ 0x06000000 => "\xf3",
+ 0x07000000 => "\xf1",
+ 0x08000000 => "\xef",
+ 0x09000000 => "\xed",
+ 0x0a000000 => "\xeb",
+ 0x0b000000 => "\xe9",
+ 0x0c000000 => "\xe7",
+ 0x0d000000 => "\xe5",
+ 0x0e000000 => "\xe3",
+ 0x0f000000 => "\xe1",
+ 0x10000000 => "\xdf",
+ 0x11000000 => "\xdd",
+ 0x12000000 => "\xdb",
+ 0x13000000 => "\xd9",
+ 0x14000000 => "\xd7",
+ 0x15000000 => "\xd5",
+ 0x16000000 => "\xd3",
+ 0x17000000 => "\xd1",
+ 0x18000000 => "\xcf",
+ 0x19000000 => "\xcd",
+ 0x1a000000 => "\xcb",
+ 0x1b000000 => "\xc9",
+ 0x1c000000 => "\xc7",
+ 0x1d000000 => "\xc5",
+ 0x1e000000 => "\xc3",
+ 0x1f000000 => "\xc1",
+ 0x20000000 => "\xbf",
+ 0x21000000 => "\xbd",
+ 0x22000000 => "\xbb",
+ 0x23000000 => "\xb9",
+ 0x24000000 => "\xb7",
+ 0x25000000 => "\xb5",
+ 0x26000000 => "\xb3",
+ 0x27000000 => "\xb1",
+ 0x28000000 => "\xaf",
+ 0x29000000 => "\xad",
+ 0x2a000000 => "\xab",
+ 0x2b000000 => "\xa9",
+ 0x2c000000 => "\xa7",
+ 0x2d000000 => "\xa5",
+ 0x2e000000 => "\xa3",
+ 0x2f000000 => "\xa1",
+ 0x30000000 => "\x9f",
+ 0x31000000 => "\x9d",
+ 0x32000000 => "\x9b",
+ 0x33000000 => "\x99",
+ 0x34000000 => "\x97",
+ 0x35000000 => "\x95",
+ 0x36000000 => "\x93",
+ 0x37000000 => "\x91",
+ 0x38000000 => "\x8f",
+ 0x39000000 => "\x8d",
+ 0x3a000000 => "\x8b",
+ 0x3b000000 => "\x89",
+ 0x3c000000 => "\x87",
+ 0x3d000000 => "\x85",
+ 0x3e000000 => "\x83",
+ 0x3f000000 => "\x81",
+ 0x40000000 => "\x7f",
+ 0x41000000 => "\x7d",
+ 0x42000000 => "\x7b",
+ 0x43000000 => "\x79",
+ 0x44000000 => "\x77",
+ 0x45000000 => "\x75",
+ 0x46000000 => "\x73",
+ 0x47000000 => "\x71",
+ 0x48000000 => "\x6f",
+ 0x49000000 => "\x6d",
+ 0x4a000000 => "\x6b",
+ 0x4b000000 => "\x69",
+ 0x4c000000 => "\x67",
+ 0x4d000000 => "\x65",
+ 0x4e000000 => "\x63",
+ 0x4f000000 => "\x61",
+ 0x50000000 => "\x5f",
+ 0x51000000 => "\x5d",
+ 0x52000000 => "\x5b",
+ 0x53000000 => "\x59",
+ 0x54000000 => "\x57",
+ 0x55000000 => "\x55",
+ 0x56000000 => "\x53",
+ 0x57000000 => "\x51",
+ 0x58000000 => "\x4f",
+ 0x59000000 => "\x4d",
+ 0x5a000000 => "\x4b",
+ 0x5b000000 => "\x49",
+ 0x5c000000 => "\x47",
+ 0x5d000000 => "\x45",
+ 0x5e000000 => "\x43",
+ 0x5f000000 => "\x41",
+ 0x60000000 => "\x3f",
+ 0x61000000 => "\x3d",
+ 0x62000000 => "\x3b",
+ 0x63000000 => "\x39",
+ 0x64000000 => "\x37",
+ 0x65000000 => "\x35",
+ 0x66000000 => "\x33",
+ 0x67000000 => "\x31",
+ 0x68000000 => "\x2f",
+ 0x69000000 => "\x2d",
+ 0x6a000000 => "\x2b",
+ 0x6b000000 => "\x29",
+ 0x6c000000 => "\x27",
+ 0x6d000000 => "\x25",
+ 0x6e000000 => "\x23",
+ 0x6f000000 => "\x21",
+ 0x70000000 => "\x1f",
+ 0x71000000 => "\x1d",
+ 0x72000000 => "\x1b",
+ 0x73000000 => "\x19",
+ 0x74000000 => "\x17",
+ 0x75000000 => "\x15",
+ 0x76000000 => "\x13",
+ 0x77000000 => "\x11",
+ 0x78000000 => "\x0f",
+ 0x79000000 => "\x0d",
+ 0x7a000000 => "\x0b",
+ 0x7b000000 => "\x09",
+ 0x7c000000 => "\x07",
+ 0x7d000000 => "\x05",
+ 0x7e000000 => "\x03",
+ 0x7f000000 => "\x00"
]; // Lookup table for chr(255-(($x >> 23) & 0x7f)).
public function __construct(public ImageInterface $image, public int $channels = 4)
@@ -92,12 +429,11 @@ public static function setDriver(ImageDriver $imageDriver): void
self::$imagine = match ($imageDriver) {
ImageDriver::IMAGICK => new \Imagine\Imagick\Imagine(),
ImageDriver::GD => new \Imagine\Gd\Imagine(),
- ImageDriver::VIPS => new Imagine(),
+ ImageDriver::VIPS => new \Imagine\Vips\Imagine(),
};
if ($imageDriver === ImageDriver::VIPS) {
- $libsDir = basePath('libs');
- putenv("VIPSHOME=$libsDir");
+ Libvips::setup();
}
}
@@ -114,6 +450,14 @@ public static function read(string $input, array $options = []): static
{
$image = self::getImagine()->open($input, $options);
+ $logger = Transformers::getLogger();
+ $logger->debug('Image file loaded', [
+ 'filepath' => $image->metadata()->get('filepath'),
+ 'size' => (string) $image->getSize(),
+ 'palette' => $image->palette()->name(),
+ 'mime_type' => $image->metadata()->get('file.MimeType')
+ ]);
+
return new self($image);
}
@@ -160,6 +504,15 @@ public function clone(): static
*/
public function resize(int $width, int $height, int|Resample $resample = 2): static
{
+ if ($width === $this->width() && $height === $this->height()) {
+ return $this->clone();
+ }
+
+ $logger = Transformers::getLogger();
+ $logger->debug('Resizing image', [
+ 'from' => $this->size(),
+ 'to' => [$width, $height],
+ ]);
$resampleMethod = $resample instanceof Resample ? $resample : Resample::from($resample) ?? Resample::NEAREST;
$image = $this->image->copy()->resize(new Box($width, $height), $resampleMethod->toString());
@@ -200,6 +553,10 @@ public function thumbnail(int $width, int $height, int|Resample $resample = 2):
*/
public function grayscale(bool $force = false): static
{
+ $logger = Transformers::getLogger();
+ $logger->debug('Converting image to grayscale', [
+ 'channels_before' => $this->channels
+ ]);
if ($this->channels === 1 && !$force) {
return $this->clone();
}
@@ -217,12 +574,14 @@ public function grayscale(bool $force = false): static
*/
public function rgb(bool $force = false): static
{
- // If the image is already in RGB format, return it as is
+ $logger = Transformers::getLogger();
+ $logger->debug('Converting image to RGB', [
+ 'channels_before' => $this->channels
+ ]);
if ($this->channels === 3 && !$force) {
return $this->clone();
}
- // If it's a Vips image, we can extract the RGB channels
if ($this->image instanceof \Imagine\Vips\Image) {
/** @var \Imagine\Vips\Image $image */
$image = $this->image->copy();
@@ -241,19 +600,22 @@ public function rgb(bool $force = false): static
*/
public function rgba(bool $force = false): static
{
- // If the image is already in RGBA format, return it as is
+ $logger = Transformers::getLogger();
+ $logger->debug('Converting image to RGBA', [
+ 'channels_before' => $this->channels
+ ]);
if ($this->channels === 4 && !$force) {
return $this->clone();
}
- // If it's a Vips image, we can handle the RGBA channels
if ($this->image instanceof \Imagine\Vips\Image) {
+ $vipsInternalImage = $this->image->getVips()->copy();
- $vipImage = $this->image->copy()->getVips();
+ $vipsInternalImage = $vipsInternalImage->hasAlpha() ? $vipsInternalImage->extract_band(0, ['n' => 4]) : $vipsInternalImage->bandjoin([255]);
- $vipImage = $vipImage->hasAlpha() ? $vipImage->extract_band(0, ['n' => 4]) : $vipImage->bandjoin([255]);
+ $vipsImage = new \Imagine\Vips\Image($vipsInternalImage, $this->image->palette(), $this->image->metadata());
- return new self($vipImage, 4);
+ return new self($vipsImage, 4);
}
return new self($this->image->copy(), 4);
@@ -261,6 +623,11 @@ public function rgba(bool $force = false): static
public function centerCrop(int $cropWidth, int $cropHeight): static
{
+ $logger = Transformers::getLogger();
+ $logger->debug('Center cropping image', [
+ 'original_size' => $this->size(),
+ 'crop_size' => [$cropWidth, $cropHeight],
+ ]);
$originalWidth = $this->image->getSize()->getWidth();
$originalHeight = $this->image->getSize()->getHeight();
@@ -268,7 +635,6 @@ public function centerCrop(int $cropWidth, int $cropHeight): static
return $this->clone();
}
- // Calculate the coordinates for center cropping
$xOffset = max(0, ($originalWidth - $cropWidth) / 2);
$yOffset = max(0, ($originalHeight - $cropHeight) / 2);
@@ -279,13 +645,18 @@ public function centerCrop(int $cropWidth, int $cropHeight): static
public function crop(int $xMin, int $yMin, int $xMax, int $yMax): static
{
+ $logger = Transformers::getLogger();
+ $logger->debug('Cropping image', [
+ 'from' => $this->size(),
+ 'crop_coords' => [$xMin, $yMin, $xMax, $yMax],
+ ]);
$originalWidth = $this->image->getSize()->getWidth();
$originalHeight = $this->image->getSize()->getHeight();
if ($xMin === 0 && $yMin === 0 && $xMax === $originalWidth && $yMax === $originalHeight) {
return $this->clone();
}
- // Ensure crop bounds are within the image
+
$xMin = max($xMin, 0);
$yMin = max($yMin, 0);
$xMax = min($xMax, $originalWidth - 1);
@@ -311,13 +682,11 @@ public function cropMargin(int $grayThreshold = 200): static
{
$grayImage = $this->grayscale();
- // Get the min and max pixel values
$minValue = min($grayImage->toTensor()->buffer())[0];
$maxValue = max($grayImage->toTensor()->buffer())[0];
$diff = $maxValue - $minValue;
- // If all pixels have the same value, no need to crop
if ($diff === 0) {
return $this->clone();
}
@@ -330,14 +699,12 @@ public function cropMargin(int $grayThreshold = 200): static
[$width, $height] = $this->size();
- // Iterate over each pixel in the image
for ($y = 0; $y < $height; ++$y) {
for ($x = 0; $x < $width; ++$x) {
$color = $grayImage->image->getColorAt(new Point($x, $y));
- $pixelValue = $color->getRed(); // Assuming grayscale, so red channel is sufficient
+ $pixelValue = $color->getValue(ColorInterface::COLOR_RED);
if (($pixelValue - $minValue) / $diff < $threshold) {
- // We have a non-gray pixel, so update the min/max values accordingly
$xMin = min($xMin, $x);
$yMin = min($yMin, $y);
$xMax = max($xMax, $x);
@@ -346,12 +713,16 @@ public function cropMargin(int $grayThreshold = 200): static
}
}
- // Crop the image using the calculated bounds
return $this->crop($xMin, $yMin, $xMax, $yMax);
}
public function pad(int $left, int $right, int $top, int $bottom): static
{
+ $logger = Transformers::getLogger();
+ $logger->debug('Padding image', [
+ 'original_size' => $this->size(),
+ 'pad' => [$left, $right, $top, $bottom],
+ ]);
if ($left === 0 && $right === 0 && $top === 0 && $bottom === 0) {
return $this;
}
@@ -370,6 +741,8 @@ public function pad(int $left, int $right, int $top, int $bottom): static
public function invert(): static
{
+ $logger = Transformers::getLogger();
+ $logger->debug('Inverting image');
$image = $this->image->copy();
$image->effects()->negative();
@@ -392,7 +765,8 @@ public function applyMask(Image $mask): static
if ($size != $maskSize) {
throw new InvalidArgumentException(
- sprintf("The given mask doesn't match current image's size, current mask's dimensions are %s, while image's dimensions are %s",
+ sprintf(
+ "The given mask doesn't match current image's size, current mask's dimensions are %s, while image's dimensions are %s",
json_encode($maskSize),
json_encode($size)
)
@@ -403,16 +777,6 @@ public function applyMask(Image $mask): static
$this->image instanceof \Imagine\Vips\Image => $this->image->copy()->applyMask($mask->image),
$this->image instanceof \Imagine\Imagick\Image => (function () use ($mask) {
-// $maskImagick = $mask->image->copy()->mask()->getImagick();
-// $imageImagick = clone $this->image->getImagick();
-//
-// $maskImagick->compositeImage($imageImagick, Imagick::COMPOSITE_DSTIN, 0, 0);
-// $imageImagick->compositeImage($maskImagick, Imagick::COMPOSITE_COPYOPACITY, 0, 0);
-//
-// $maskImagick->clear();
-// $maskImagick->destroy();
-//
-// return new \Imagine\Imagick\Image($imageImagick, $this->image->palette(), $this->image->metadata());
$image = $this->image->copy();
$maskImage = $mask->image->copy();
$maskImage->effects()->negative();
@@ -421,20 +785,22 @@ public function applyMask(Image $mask): static
})(),
$this->image instanceof \Imagine\Gd\Image => (function () use ($mask) {
- $gdResource = $this->image->getGdResource();
+ /** @var \Imagine\Gd\Image $gdImage */
+ $gdImage = $this->image;
+ $gdResource = $gdImage->getGdResource();
for ($x = 0, $width = $this->width(); $x < $width; $x++) {
for ($y = 0, $height = $this->height(); $y < $height; $y++) {
$position = new Point($x, $y);
$color = $this->image->getColorAt($position);
$maskColor = $mask->image->getColorAt($position);
- $newAlpha = 127 - (int)floor($maskColor->getRed() / 2);
+ $newAlpha = 127 - (int)floor($maskColor->getValue(ColorInterface::COLOR_RED) / 2);
$newColor = imagecolorallocatealpha(
- $this->image->getGdResource(),
- $color->getRed(),
- $color->getGreen(),
- $color->getBlue(),
+ $gdResource,
+ $color->getValue(ColorInterface::COLOR_RED),
+ $color->getValue(ColorInterface::COLOR_GREEN),
+ $color->getValue(ColorInterface::COLOR_BLUE),
$newAlpha
);
@@ -444,8 +810,9 @@ public function applyMask(Image $mask): static
}
}
- return new \Imagine\Gd\Image($gdResource, $this->image->palette(), $this->image->metadata());
+ return new \Imagine\Gd\Image($gdResource, $gdImage->palette(), $gdImage->metadata());
})(),
+
default => throw new InvalidArgumentException('Unsupported image driver'),
};
@@ -463,18 +830,19 @@ public function applyMask(Image $mask): static
*/
public static function fromTensor(Tensor $tensor, string $channelFormat = 'CHW'): static
{
+ $logger = Transformers::getLogger();
+ $logger->debug('Creating image from tensor', [
+ 'tensor_shape' => $tensor->shape(),
+ 'channel_format' => $channelFormat
+ ]);
$tensor = $channelFormat === 'CHW' ? $tensor->permute(1, 2, 0) : $tensor;
[$height, $width, $channels] = $tensor->shape();
$image = self::getImagine()->create(new Box($width, $height));
- // Make sure the tensor is the right data type
$tensor = $tensor->to(Tensor::uint8);
- /**
- * Handle Vips images
- */
if ($image instanceof \Imagine\Vips\Image) {
$vipImage = $image->getVips()::newFromMemory($tensor->buffer()->dump(), $width, $height, $channels, 'uchar');
@@ -483,9 +851,6 @@ public static function fromTensor(Tensor $tensor, string $channelFormat = 'CHW')
return new self($image, $channels);
}
- /**
- * Handle Imagick images
- */
if ($image instanceof \Imagine\Imagick\Image) {
$map = match ($channels) {
1 => 'I',
@@ -502,51 +867,47 @@ public static function fromTensor(Tensor $tensor, string $channelFormat = 'CHW')
return new self($image, $channels);
}
- /**
- * Handle GD images
- */
-
-
- $gdImage = $image->getGdResource();
- $imageData = $tensor->buffer()->dump();
-
- $reverseCHR = array_flip(self::CHR);
- $reverseAlphaLookup = array_flip(self::ALPHA_LOOKUP);
-
- $j = 0;
- // Iterate through each pixel's worth of string data
- for ($y = 0; $y < $height; $y++) {
- for ($x = 0; $x < $width; $x++) {
- if ($channels === 1) {
- // Grayscale: get the single channel value and set it to R, G, B equally
- $gray = $reverseCHR[$imageData[$j++]];
- $argb = imagecolorallocate($gdImage, $gray, $gray, $gray);
- } else {
- $argb = 0;
- if ($channels >= 1) {
- $argb |= ($reverseCHR[$imageData[$j++]] << 16); // R
- }
- if ($channels >= 2) {
- $argb |= ($reverseCHR[$imageData[$j++]] << 8); // G
- }
- if ($channels >= 3) {
- $argb |= $reverseCHR[$imageData[$j++]]; // B
- }
- if ($channels === 4) {
- // Ensure alpha value is handled
- $alpha = $reverseAlphaLookup[$imageData[$j++]];
- $argb |= $alpha << 24;
+ if ($image instanceof \Imagine\Gd\Image) {
+ $gdResource = $image->getGdResource();
+ $imageData = $tensor->buffer()->dump();
+
+ $reverseCHR = array_flip(self::CHR);
+ $reverseAlphaLookup = array_flip(self::ALPHA_LOOKUP);
+
+ $j = 0;
+ for ($y = 0; $y < $height; $y++) {
+ for ($x = 0; $x < $width; $x++) {
+ if ($channels === 1) {
+ $gray = $reverseCHR[$imageData[$j++]];
+ $argb = imagecolorallocate($gdResource, $gray, $gray, $gray);
} else {
- $argb |= 0xFF000000; // Set full opacity for RGB images
+ $argb = 0;
+ if ($channels >= 1) {
+ $argb |= ($reverseCHR[$imageData[$j++]] << 16); // R
+ }
+ if ($channels >= 2) {
+ $argb |= ($reverseCHR[$imageData[$j++]] << 8); // G
+ }
+ if ($channels >= 3) {
+ $argb |= $reverseCHR[$imageData[$j++]]; // B
+ }
+ if ($channels === 4) {
+ $alpha = $reverseAlphaLookup[$imageData[$j++]];
+ $argb |= $alpha << 24;
+ } else {
+ $argb |= 0xFF000000;
+ }
}
- }
- // Set the pixel at (x, y) to the ARGB value
- imagesetpixel($gdImage, $x, $y, $argb);
+ imagesetpixel($gdResource, $x, $y, $argb);
+ }
}
+
+ return new self($image, $channels);
}
- return new self($image, $channels);
+ $logger->error('Unsupported image driver');
+ throw new \Exception('Unsupported image driver');
}
/**
@@ -568,8 +929,7 @@ public function toTensor(string $channelFormat = 'CHW'): Tensor
->to(Tensor::float32);
if ($channelFormat === 'HWC') {
- // Do nothing
- } else if ($channelFormat === 'CHW') { // hwc -> chw
+ } else if ($channelFormat === 'CHW') {
$tensor = $tensor->permute(2, 0, 1);
} else {
throw new Exception("Unsupported channel format: $channelFormat");
@@ -583,12 +943,10 @@ public function getPixelData(): string
$width = $this->width();
$height = $this->height();
- /** For Vips images, we can export the pixel data directly */
if ($this->image instanceof \Imagine\Vips\Image) {
return $this->image->getVips()->writeToMemory();
}
- /** For Imagick images, we can export the pixel data directly */
if ($this->image instanceof \Imagine\Imagick\Image) {
$map = match ($this->channels) {
1 => 'I',
@@ -603,42 +961,42 @@ public function getPixelData(): string
return pack('C*', ...$pixels);
}
- /** For GD images, we need to extract the pixel data manually
- *
- * I didn't find an in-built method to extract pixel data from a GD image, so I'm using this ugly
- * brute-force method, suggested by @DewiMorgan on StackOverflow: https://stackoverflow.com/a/30136602/11209184.
- * It's tons faster than other methods I tried, and rivals the speed of the Imagick method, so I'll keep it for now.
- */
- $imageData = str_repeat("\x00", $width * $height * $this->channels);
- $gdImage = $this->image->getGdResource();
-
- // Loop over each single pixel.
- $j = 0;
- for ($y = 0; $y < $height; $y++) {
- for ($x = 0; $x < $width; $x++) {
- // Grab the pixel data.
- $argb = imagecolorat($gdImage, $x, $y);
-
- if ($this->channels >= 1) {
- $imageData[$j++] = self::CHR[($argb >> 16) & 0xFF]; // R
- }
- if ($this->channels >= 2) {
- $imageData[$j++] = self::CHR[($argb >> 8) & 0xFF]; // G
- }
- if ($this->channels >= 3) {
- $imageData[$j++] = self::CHR[$argb & 0xFF]; // B
- }
- if ($this->channels >= 4) {
- $imageData[$j++] = self::ALPHA_LOOKUP[$argb & 0x7f000000]; // A
+ if ($this->image instanceof \Imagine\Gd\Image) {
+ $imageData = str_repeat("\x00", $width * $height * $this->channels);
+ $gdResource = $this->image->getGdResource();
+
+ $j = 0;
+ for ($y = 0; $y < $height; $y++) {
+ for ($x = 0; $x < $width; $x++) {
+ $argb = imagecolorat($gdResource, $x, $y);
+
+ if ($this->channels >= 1) {
+ $imageData[$j++] = self::CHR[($argb >> 16) & 0xFF]; // R
+ }
+ if ($this->channels >= 2) {
+ $imageData[$j++] = self::CHR[($argb >> 8) & 0xFF]; // G
+ }
+ if ($this->channels >= 3) {
+ $imageData[$j++] = self::CHR[$argb & 0xFF]; // B
+ }
+ if ($this->channels >= 4) {
+ $imageData[$j++] = self::ALPHA_LOOKUP[$argb & 0x7f000000]; // A
+ }
}
}
+
+ return $imageData;
}
- return $imageData;
+ throw new Exception('Unsupported image driver');
}
public function save(string $path): void
{
+ $logger = Transformers::getLogger();
+ $logger->debug('Saving image', [
+ 'path' => realpath($path)
+ ]);
$this->image->save($path);
}
diff --git a/src/Utils/InferenceSession.php b/src/Utils/InferenceSession.php
index f83a699..b6da823 100644
--- a/src/Utils/InferenceSession.php
+++ b/src/Utils/InferenceSession.php
@@ -15,6 +15,7 @@
use Exception;
use FFI;
use FFI\CData;
+use Codewithkyrian\Transformers\Transformers;
class InferenceSession
{
@@ -22,6 +23,7 @@ class InferenceSession
private ?CData $allocator;
private array $inputs;
private array $outputs;
+ private OnnxRuntime $ort;
public function __construct(
$path,
@@ -41,79 +43,80 @@ public function __construct(
$profileFilePrefix = null,
$sessionConfigEntries = null,
$providers = []
- )
- {
-// $providers = ['CoreMLExecutionProvider', 'CPUExecutionProvider'];
+ ) {
+ $this->ort = new OnnxRuntime();
+ // $providers = ['CoreMLExecutionProvider', 'CPUExecutionProvider'];
// session options
- $sessionOptions = OnnxRuntime::CreateSessionOptions();
+ $sessionOptions = $this->ort->CreateSessionOptions();
if ($enableCpuMemArena) {
- OnnxRuntime::EnableCpuMemArena($sessionOptions);
+ $this->ort->EnableCpuMemArena($sessionOptions);
} else {
- OnnxRuntime::DisableCpuMemArena($sessionOptions);
+ $this->ort->DisableCpuMemArena($sessionOptions);
}
if ($enableMemPattern) {
- OnnxRuntime::EnableMemPattern($sessionOptions);
+ $this->ort->EnableMemPattern($sessionOptions);
} else {
- OnnxRuntime::DisableMemPattern($sessionOptions);
+ $this->ort->DisableMemPattern($sessionOptions);
}
if ($enableProfiling) {
- OnnxRuntime::EnableProfiling($sessionOptions, $this->ortString($profileFilePrefix ?? 'onnxruntime_profile_'));
+ $this->ort->EnableProfiling($sessionOptions, $this->ortString($profileFilePrefix ?? 'onnxruntime_profile_'));
} else {
- OnnxRuntime::DisableProfiling($sessionOptions);
+ $this->ort->DisableProfiling($sessionOptions);
}
if (!is_null($executionMode)) {
- OnnxRuntime::SetSessionExecutionMode($sessionOptions, $executionMode->value);
+ $this->ort->SetSessionExecutionMode($sessionOptions, $executionMode->value);
}
if (!is_null($freeDimensionOverridesByDenotation)) {
foreach ($freeDimensionOverridesByDenotation as $k => $v) {
- OnnxRuntime::AddFreeDimensionOverride($sessionOptions, $k, $v);
+ $this->ort->AddFreeDimensionOverride($sessionOptions, $k, $v);
}
}
if (!is_null($freeDimensionOverridesByName)) {
foreach ($freeDimensionOverridesByName as $k => $v) {
- OnnxRuntime::AddFreeDimensionOverrideByName($sessionOptions, $k, $v);
+ $this->ort->AddFreeDimensionOverrideByName($sessionOptions, $k, $v);
}
}
if (!is_null($graphOptimizationLevel)) {
- OnnxRuntime::SetSessionGraphOptimizationLevel($sessionOptions, $graphOptimizationLevel->value);
+ $this->ort->SetSessionGraphOptimizationLevel($sessionOptions, $graphOptimizationLevel->value);
}
if (!is_null($interOpNumThreads)) {
- OnnxRuntime::SetInterOpNumThreads($sessionOptions, $interOpNumThreads);
+ $this->ort->SetInterOpNumThreads($sessionOptions, $interOpNumThreads);
}
if (!is_null($intraOpNumThreads)) {
- OnnxRuntime::SetIntraOpNumThreads($sessionOptions, $intraOpNumThreads);
+ $this->ort->SetIntraOpNumThreads($sessionOptions, $intraOpNumThreads);
}
if (!is_null($logSeverityLevel)) {
- OnnxRuntime::SetSessionLogSeverityLevel($sessionOptions, $logSeverityLevel);
+ $this->ort->SetSessionLogSeverityLevel($sessionOptions, $logSeverityLevel);
}
if (!is_null($logVerbosityLevel)) {
- OnnxRuntime::SetSessionLogVerbosityLevel($sessionOptions, $logVerbosityLevel);
+ $this->ort->SetSessionLogVerbosityLevel($sessionOptions, $logVerbosityLevel);
}
if (!is_null($logid)) {
- OnnxRuntime::SetSessionLogId($sessionOptions, $logid);
+ $this->ort->SetSessionLogId($sessionOptions, $logid);
}
if (!is_null($optimizedModelFilepath)) {
- OnnxRuntime::SetOptimizedModelFilePath($sessionOptions, $this->ortString($optimizedModelFilepath));
+ $this->ort->SetOptimizedModelFilePath($sessionOptions, $this->ortString($optimizedModelFilepath));
}
if (!is_null($sessionConfigEntries)) {
foreach ($sessionConfigEntries as $k => $v) {
- OnnxRuntime::AddSessionConfigEntry($sessionOptions, $k, $v);
+ $this->ort->AddSessionConfigEntry($sessionOptions, $k, $v);
}
}
foreach ($providers as $provider) {
if (!in_array($provider, $this->providers())) {
- trigger_error('Provider not available: ' . $provider, E_USER_WARNING);
+ $logger = Transformers::getLogger();
+ $logger->warning('Provider not available: ' . $provider);
continue;
}
if ($provider == 'CUDAExecutionProvider') {
- $cudaOptions = OnnxRuntime::CreateCUDAProviderOptions();
- OnnxRuntime::SessionOptionsAppendExecutionProvider_CUDA_V2($sessionOptions, $cudaOptions);
- OnnxRuntime::ReleaseCUDAProviderOptions($cudaOptions);
+ $cudaOptions = $this->ort->CreateCUDAProviderOptions();
+ $this->ort->SessionOptionsAppendExecutionProvider_CUDA_V2($sessionOptions, $cudaOptions);
+ $this->ort->ReleaseCUDAProviderOptions($cudaOptions);
} elseif ($provider == 'CoreMLExecutionProvider') {
- OnnxRuntime::OrtSessionOptionsAppendExecutionProvider_CoreML($sessionOptions, 1);
+ $this->ort->OrtSessionOptionsAppendExecutionProvider_CoreML($sessionOptions, 0);
} elseif ($provider == 'CPUExecutionProvider') {
break;
} else {
@@ -121,66 +124,77 @@ public function __construct(
}
}
$this->session = $this->loadSession($path, $sessionOptions);
- $this->allocator = OnnxRuntime::GetAllocatorWithDefaultOptions();
+ $this->allocator = $this->ort->GetAllocatorWithDefaultOptions();
$this->inputs = $this->loadInputs();
$this->outputs = $this->loadOutputs();
- OnnxRuntime::ReleaseSessionOptions($sessionOptions);
+ $this->ort->ReleaseSessionOptions($sessionOptions);
}
public function __destruct()
{
- OnnxRuntime::ReleaseSession($this->session);
+ $this->ort->ReleaseSession($this->session);
}
+ /**
+ * Runs the inference session with the provided inputs and outputs.
+ *
+ * @param array $inputFeed
+ * @param array $outputNames
+ * @param string|null $logSeverityLevel
+ * @param string|null $logVerbosityLevel
+ * @param string|null $logid
+ * @param bool|null $terminate
+ * @return array The output tensors.
+ */
public function run($outputNames, $inputFeed, $logSeverityLevel = null, $logVerbosityLevel = null, $logid = null, $terminate = null): array
{
// pointer references
$refs = [];
- $inputTensor = $this->convertInputTensorToOnnxTensor($inputFeed, $refs);
+ $inputTensor = $this->tensorArrayToOrtValueArray($inputFeed, $refs);
$outputNames ??= array_map(fn($v) => $v['name'], $this->outputs);
- $inputNodeNames = $this->createNodeNames(array_keys($inputFeed), $refs);
- $outputNodeNames = $this->createNodeNames($outputNames, $refs);
+ $inputNodeNames = $this->createCStringArray(array_keys($inputFeed), $refs);
+ $outputNodeNames = $this->createCStringArray($outputNames, $refs);
// run options
- $runOptions = OnnxRuntime::CreateRunOptions();
+ $runOptions = $this->ort->CreateRunOptions();
if (!is_null($logVerbosityLevel)) {
- OnnxRuntime::RunOptionsSetRunLogSeverityLevel($runOptions, $logSeverityLevel);
+ $this->ort->RunOptionsSetRunLogSeverityLevel($runOptions, $logSeverityLevel);
}
if (!is_null($logVerbosityLevel)) {
- OnnxRuntime::RunOptionsSetRunLogVerbosityLevel($runOptions, $logVerbosityLevel);
+ $this->ort->RunOptionsSetRunLogVerbosityLevel($runOptions, $logVerbosityLevel);
}
if (!is_null($logid)) {
- OnnxRuntime::RunOptionsSetRunTag($runOptions, $logid);
+ $this->ort->RunOptionsSetRunTag($runOptions, $logid);
}
if (!is_null($terminate)) {
if ($terminate) {
- OnnxRuntime::RunOptionsSetTerminate($runOptions);
+ $this->ort->RunOptionsSetTerminate($runOptions);
} else {
- OnnxRuntime::RunOptionsUnsetTerminate($runOptions);
+ $this->ort->RunOptionsUnsetTerminate($runOptions);
}
}
- $outputTensor = OnnxRuntime::Run($this->session, $runOptions, $inputNodeNames, $inputTensor, count($inputFeed), $outputNodeNames, count($outputNames));
+ $outputTensor = $this->ort->Run($this->session, $runOptions, $inputNodeNames, $inputTensor, count($inputFeed), $outputNodeNames, count($outputNames));
$output = [];
foreach ($outputTensor as $i => $t) {
- $output[$outputNames[$i]] = $this->createFromOnnxValue($t);
+ $output[$outputNames[$i]] = $this->ortValueToTensor($t);
}
// TODO use finally
- OnnxRuntime::ReleaseRunOptions($runOptions);
+ $this->ort->ReleaseRunOptions($runOptions);
if ($inputTensor) {
for ($i = 0; $i < count($inputFeed); $i++) {
- OnnxRuntime::ReleaseValue($inputTensor[$i]);
+ $this->ort->ReleaseValue($inputTensor[$i]);
}
}
- // output values released in createFromOnnxValue
+ // output values released in ortValueToTensor
return $output;
}
@@ -197,36 +211,36 @@ public function outputs(): array
public function modelmeta(): array
{
- $metadata = OnnxRuntime::SessionGetModelMetadata($this->session);
+ $metadata = $this->ort->SessionGetModelMetadata($this->session);
$customMetadataMap = [];
- [$keys, $numKeys] = OnnxRuntime::ModelMetadataGetCustomMetadataMapKeys($metadata, $this->allocator);
+ [$keys, $numKeys] = $this->ort->ModelMetadataGetCustomMetadataMapKeys($metadata, $this->allocator);
for ($i = 0; $i < $numKeys; $i++) {
$key = $keys[$i];
- $value = OnnxRuntime::ModelMetadataLookupCustomMetadataMap($metadata, $this->allocator, $key);
+ $value = $this->ort->ModelMetadataLookupCustomMetadataMap($metadata, $this->allocator, $key);
$customMetadataMap[$key] = $value;
}
- $description = OnnxRuntime::ModelMetadataGetDescription($metadata, $this->allocator);
- $domain = OnnxRuntime::ModelMetadataGetDomain($metadata, $this->allocator);
- $graphName = OnnxRuntime::ModelMetadataGetGraphName($metadata, $this->allocator);
-// $graphDescription = OnnxRuntime::ModelMetadataGetGraphDescription($metadata, $this->allocator);
- $producerName = OnnxRuntime::ModelMetadataGetProducerName($metadata, $this->allocator);
- $version = OnnxRuntime::ModelMetadataGetVersion($metadata);
+ $description = $this->ort->ModelMetadataGetDescription($metadata, $this->allocator);
+ $domain = $this->ort->ModelMetadataGetDomain($metadata, $this->allocator);
+ $graphName = $this->ort->ModelMetadataGetGraphName($metadata, $this->allocator);
+ // $graphDescription = OnnxRuntime::ModelMetadataGetGraphDescription($metadata, $this->allocator);
+ $producerName = $this->ort->ModelMetadataGetProducerName($metadata, $this->allocator);
+ $version = $this->ort->ModelMetadataGetVersion($metadata);
$result = [
'custom_metadata_map' => $customMetadataMap,
'description' => $description,
'domain' => $domain,
'graph_name' => $graphName,
-// 'graph_description' => $graphDescription,
+ // 'graph_description' => $graphDescription,
'producer_name' => $producerName,
'version' => $version
];
// TODO use finally
- OnnxRuntime::ReleaseModelMetadata($metadata);
+ $this->ort->ReleaseModelMetadata($metadata);
return $result;
}
@@ -234,13 +248,13 @@ public function modelmeta(): array
// return value has double underscore like Python
public function endProfiling(): string
{
- return OnnxRuntime::SessionEndProfiling($this->session, $this->allocator);
+ return $this->ort->SessionEndProfiling($this->session, $this->allocator);
}
// No way to set providers with C API yet, so we can return all available providers
public function providers(): array
{
- [$outPtr, $length] = OnnxRuntime::GetAvailableProviders();
+ [$outPtr, $length] = $this->ort->GetAvailableProviders();
$providers = [];
@@ -248,7 +262,7 @@ public function providers(): array
$providers[] = FFI::string($outPtr[$i]);
}
- OnnxRuntime::ReleaseAvailableProviders($outPtr, $length);
+ $this->ort->ReleaseAvailableProviders($outPtr, $length);
return $providers;
}
@@ -257,9 +271,9 @@ private function loadSession($path, $sessionOptions): ?CData
{
if (is_resource($path) && get_resource_type($path) == 'stream') {
$contents = stream_get_contents($path);
- $session = OnnxRuntime::CreateSessionFromArray(self::env(), $contents, strlen($contents), $sessionOptions);
+ $session = $this->ort->CreateSessionFromArray(self::env(), $contents, strlen($contents), $sessionOptions);
} else {
- $session = OnnxRuntime::CreateSession(self::env(), $this->ortString($path), $sessionOptions);
+ $session = $this->ort->CreateSession(self::env(), $this->ortString($path), $sessionOptions);
}
return $session;
}
@@ -267,12 +281,12 @@ private function loadSession($path, $sessionOptions): ?CData
private function loadInputs(): array
{
$inputs = [];
- $numInputNodes = OnnxRuntime::SessionGetInputCount($this->session);
+ $numInputNodes = $this->ort->SessionGetInputCount($this->session);
for ($i = 0; $i < $numInputNodes; $i++) {
- $name = OnnxRuntime::SessionGetInputName($this->session, $i, $this->allocator);
+ $name = $this->ort->SessionGetInputName($this->session, $i, $this->allocator);
- $typeInfo = OnnxRuntime::SessionGetInputTypeInfo($this->session, $i); // freed in nodeInfo
+ $typeInfo = $this->ort->SessionGetInputTypeInfo($this->session, $i); // freed in nodeInfo
$inputs[] = array_merge(['name' => $name], $this->nodeInfo($typeInfo));
}
@@ -283,12 +297,12 @@ private function loadInputs(): array
private function loadOutputs(): array
{
$outputs = [];
- $numOutputNodes = OnnxRuntime::SessionGetOutputCount($this->session);
+ $numOutputNodes = $this->ort->SessionGetOutputCount($this->session);
for ($i = 0; $i < $numOutputNodes; $i++) {
- $name = OnnxRuntime::SessionGetOutputName($this->session, $i, $this->allocator);
+ $name = $this->ort->SessionGetOutputName($this->session, $i, $this->allocator);
- $typeInfo = OnnxRuntime::SessionGetOutputTypeInfo($this->session, $i); // freed in nodeInfo
+ $typeInfo = $this->ort->SessionGetOutputTypeInfo($this->session, $i); // freed in nodeInfo
$outputs[] = array_merge(['name' => $name], $this->nodeInfo($typeInfo));
}
@@ -296,16 +310,23 @@ private function loadOutputs(): array
return $outputs;
}
- private function convertInputTensorToOnnxTensor($inputFeed, &$refs): ?CData
+ /**
+ * Convert internal input tensor to Onnx tensor
+ *
+ * @param array $inputFeed
+ * @param array $refs
+ * @return CData|null
+ */
+ private function tensorArrayToOrtValueArray($inputFeed, &$refs): ?CData
{
- $allocatorInfo = OnnxRuntime::CreateCpuMemoryInfo(1, 0);
+ $allocatorInfo = $this->ort->CreateCpuMemoryInfo(1, 0);
$inputFeedSize = count($inputFeed);
if ($inputFeedSize == 0) {
throw new Exception('No input');
}
- $inputTensor = OnnxRuntime::new("OrtValue*[$inputFeedSize]");
+ $inputTensor = $this->ort->new("OrtValue*[$inputFeedSize]");
$idx = 0;
/* @var $input Tensor */
@@ -325,18 +346,17 @@ private function convertInputTensorToOnnxTensor($inputFeed, &$refs): ?CData
$ndim = $input->ndim();
$size = $input->size();
- $inputNodeShape = OnnxRuntime::new("int64_t[$ndim]");
+ $inputNodeShape = $this->ort->new("int64_t[$ndim]");
for ($i = 0; $i < $ndim; $i++) {
$inputNodeShape[$i] = $shape[$i];
}
if ($inp['type'] == 'tensor(string)') {
- $inputTensorValues = OnnxRuntime::new("char*[$size]");
- $this->fillStringTensorValues($input, $inputTensorValues, $refs);
+ $inputTensorValues = $this->createCStringArray($input->toArray(), $refs);
- $typeEnum = OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING');
- OnnxRuntime::CreateTensorAsOrtValue($this->allocator, $inputNodeShape, $ndim, $typeEnum, FFI::addr($inputTensor[$idx]));
- OnnxRuntime::FillStringTensor($inputTensor[$idx], $inputTensorValues, $size);
+ $typeEnum = $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING');
+ $this->ort->CreateTensorAsOrtValue($this->allocator, $inputNodeShape, $ndim, $typeEnum, FFI::addr($inputTensor[$idx]));
+ $this->ort->FillStringTensor($inputTensor[$idx], $inputTensorValues, $size);
} else {
$inputTypes = array_flip(array_map(fn($v) => "tensor($v)", $this->elementDataTypes()));
@@ -351,15 +371,15 @@ private function convertInputTensorToOnnxTensor($inputFeed, &$refs): ?CData
}
if ($size === 0) {
- $inputTensorValues = OnnxRuntime::new("void *");
+ $inputTensorValues = $this->ort->new("void *");
} else {
- $inputTensorValues = OnnxRuntime::new("{$castType}[$size]");
+ $inputTensorValues = $this->ort->new("{$castType}[$size]");
}
$inputDump = $input->buffer()->dump();
- FFI::memcpy($inputTensorValues, $input->buffer()->dump(), strlen($inputDump));
+ FFI::memcpy($inputTensorValues, $inputDump, strlen($inputDump));
- OnnxRuntime::CreateTensorWithDataAsOrtValue($allocatorInfo, $inputTensorValues, FFI::sizeof($inputTensorValues), $inputNodeShape, $ndim, $typeEnum, FFI::addr($inputTensor[$idx]));
+ $this->ort->CreateTensorWithDataAsOrtValue($allocatorInfo, $inputTensorValues, FFI::sizeof($inputTensorValues), $inputNodeShape, $ndim, $typeEnum, FFI::addr($inputTensor[$idx]));
}
$refs[] = $inputNodeShape;
@@ -369,55 +389,46 @@ private function convertInputTensorToOnnxTensor($inputFeed, &$refs): ?CData
}
// TODO use finally
- OnnxRuntime::ReleaseMemoryInfo($allocatorInfo);
+ $this->ort->ReleaseMemoryInfo($allocatorInfo);
return $inputTensor;
}
- private function fillStringTensorValues(Tensor $input, $ptr, &$refs): void
- {
- foreach ($input->buffer() as $i => $v) {
- $strPtr = Libc::cstring($v);
- $ptr[$i] = $strPtr;
- $refs[] = $strPtr;
- }
- }
-
- private function createNodeNames($names, &$refs): CData
+ private function createCStringArray(array $strings, array &$refs): CData
{
- $namesSize = count($names);
- $ptr = OnnxRuntime::new("char*[$namesSize]");
- foreach ($names as $i => $name) {
- $strPtr = Libc::cstring($name);
+ $arraySize = count($strings);
+ $ptr = $this->ort->new("char*[$arraySize]");
+ foreach ($strings as $i => $str) {
+ $strPtr = Libc::cstring($str);
$ptr[$i] = $strPtr;
$refs[] = $strPtr;
}
return $ptr;
}
- private function createFromOnnxValue($outPtr)
+ private function ortValueToTensor($outPtr)
{
try {
- $outType = OnnxRuntime::GetValueType($outPtr);
+ $outType = $this->ort->GetValueType($outPtr);
- if ($outType->cdata == OnnxRuntime::enum('ONNX_TYPE_TENSOR')) {
- $typeInfo = OnnxRuntime::GetTensorTypeAndShape($outPtr);
+ if ($outType->cdata == $this->ort->enum('ONNX_TYPE_TENSOR')) {
+ $typeInfo = $this->ort->GetTensorTypeAndShape($outPtr);
[$type, $shape] = $this->tensorTypeAndShape($typeInfo);
// TODO skip if string
- $tensorData = OnnxRuntime::GetTensorMutableData($outPtr);
+ $tensorData = $this->ort->GetTensorMutableData($outPtr);
- $outputTensorSize = OnnxRuntime::GetTensorShapeElementCount($typeInfo);
+ $outputTensorSize = $this->ort->GetTensorShapeElementCount($typeInfo);
- OnnxRuntime::ReleaseTensorTypeAndShapeInfo($typeInfo);
+ $this->ort->ReleaseTensorTypeAndShapeInfo($typeInfo);
$castTypes = $this->castTypes();
if (isset($castTypes[$type])) {
- $arr = OnnxRuntime::cast($castTypes[$type] . "[$outputTensorSize]", $tensorData);
- } elseif ($type == OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING')) {
- $arr = $this->createStringsFromOnnxValue($outPtr, $outputTensorSize);
+ $arr = $this->ort->cast($castTypes[$type] . "[$outputTensorSize]", $tensorData);
+ } elseif ($type == $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING')) {
+ $arr = $this->ortValueToStrings($outPtr, $outputTensorSize);
} else {
$this->unsupportedType('element', $type);
}
@@ -431,28 +442,29 @@ private function createFromOnnxValue($outPtr)
$buffer->load($stringPtr);
return new Tensor($buffer, $phpTensorType, $shape, 0);
- } elseif ($outType->cdata == OnnxRuntime::enum('ONNX_TYPE_SEQUENCE')) {
- $out = OnnxRuntime::GetValueCount($outPtr);
+ } elseif ($outType->cdata == $this->ort->enum('ONNX_TYPE_SEQUENCE')) {
+ $out = $this->ort->GetValueCount($outPtr);
$result = [];
for ($i = 0; $i < $out; $i++) {
- $sequence = OnnxRuntime::GetValue($outPtr, $i, $this->allocator);
- $result[] = $this->createFromOnnxValue($sequence);
+ $sequence = $this->ort->GetValue($outPtr, $i, $this->allocator);
+ $result[] = $this->ortValueToTensor($sequence);
}
return $result;
- } elseif ($outType->cdata == OnnxRuntime::enum('ONNX_TYPE_MAP')) {
- $mapKeys = OnnxRuntime::GetValue($outPtr, 0, $this->allocator);
- $mapValues = OnnxRuntime::GetValue($outPtr, 1, $this->allocator);
- $typeShape = OnnxRuntime::GetTensorTypeAndShape($mapKeys);
- $elemType = OnnxRuntime::GetTensorElementType($typeShape);
-
- OnnxRuntime::ReleaseTensorTypeAndShapeInfo($typeShape);
-
- // TODO support more types
- if ($elemType->cdata == OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64')) {
- $keys = $this->createFromOnnxValue($mapKeys);
- $values = $this->createFromOnnxValue($mapValues);
- return array_combine($keys, $values);
+ } elseif ($outType->cdata == $this->ort->enum('ONNX_TYPE_MAP')) {
+ $mapKeys = $this->ort->GetValue($outPtr, 0, $this->allocator);
+ $mapValues = $this->ort->GetValue($outPtr, 1, $this->allocator);
+ $typeShape = $this->ort->GetTensorTypeAndShape($mapKeys);
+ $elemType = $this->ort->GetTensorElementType($typeShape);
+
+ $this->ort->ReleaseTensorTypeAndShapeInfo($typeShape);
+
+ if ($elemType->cdata == $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64')) {
+ $keys = $this->ortValueToTensor($mapKeys);
+ $values = $this->ortValueToTensor($mapValues);
+
+ $pairs = Tensor::stack([$keys->to($values->dtype()), $values], 1);
+ return $pairs;
} else {
$this->unsupportedType('element', $elemType);
}
@@ -461,16 +473,16 @@ private function createFromOnnxValue($outPtr)
}
} finally {
if (!FFI::isNull($outPtr)) {
- OnnxRuntime::ReleaseValue($outPtr);
+ $this->ort->ReleaseValue($outPtr);
}
}
}
- private function createStringsFromOnnxValue($outPtr, $outputTensorSize): array
+ private function ortValueToStrings($outPtr, $outputTensorSize): array
{
- $len = OnnxRuntime::GetStringTensorDataLength($outPtr);
+ $len = $this->ort->GetStringTensorDataLength($outPtr);
- [$s, $offsets] = OnnxRuntime::GetStringTensorContent($outPtr, $len, $outputTensorSize);
+ [$s, $offsets] = $this->ort->GetStringTensorContent($outPtr, $len, $outputTensorSize);
$result = [];
foreach ($offsets as $i => $v) {
@@ -484,32 +496,32 @@ private function createStringsFromOnnxValue($outPtr, $outputTensorSize): array
private function nodeInfo($typeInfo)
{
- $onnxType = OnnxRuntime::GetOnnxTypeFromTypeInfo($typeInfo);
+ $onnxType = $this->ort->GetOnnxTypeFromTypeInfo($typeInfo);
- if ($onnxType->cdata == OnnxRuntime::enum('ONNX_TYPE_TENSOR')) {
+ if ($onnxType->cdata == $this->ort->enum('ONNX_TYPE_TENSOR')) {
// don't free tensor_info
- $tensorInfo = OnnxRuntime::CastTypeInfoToTensorInfo($typeInfo);
+ $tensorInfo = $this->ort->CastTypeInfoToTensorInfo($typeInfo);
[$type, $shape] = $this->tensorTypeAndShape($tensorInfo);
$elementDataType = $this->elementDataTypes()[$type];
return ['type' => "tensor($elementDataType)", 'shape' => $shape];
- } elseif ($onnxType->cdata == OnnxRuntime::enum('ONNX_TYPE_SEQUENCE')) {
- $sequenceTypeInfo = OnnxRuntime::CastTypeInfoToSequenceTypeInfo($typeInfo);
- $nestedTypeInfo = OnnxRuntime::GetSequenceElementType($sequenceTypeInfo);
+ } elseif ($onnxType->cdata == $this->ort->enum('ONNX_TYPE_SEQUENCE')) {
+ $sequenceTypeInfo = $this->ort->CastTypeInfoToSequenceTypeInfo($typeInfo);
+ $nestedTypeInfo = $this->ort->GetSequenceElementType($sequenceTypeInfo);
$v = $this->nodeInfo($nestedTypeInfo)['type'];
return ['type' => "seq($v)", 'shape' => []];
- } elseif ($onnxType->cdata == OnnxRuntime::enum('ONNX_TYPE_MAP')) {
- $mapTypeInfo = OnnxRuntime::CastTypeInfoToMapTypeInfo($typeInfo);
+ } elseif ($onnxType->cdata == $this->ort->enum('ONNX_TYPE_MAP')) {
+ $mapTypeInfo = $this->ort->CastTypeInfoToMapTypeInfo($typeInfo);
// key
- $keyType = OnnxRuntime::GetMapKeyType($mapTypeInfo);
+ $keyType = $this->ort->GetMapKeyType($mapTypeInfo);
$k = $this->elementDataTypes()[$keyType->cdata];
// value
- $valueTypeInfo = OnnxRuntime::GetMapValueType($mapTypeInfo);
+ $valueTypeInfo = $this->ort->GetMapValueType($mapTypeInfo);
$v = $this->nodeInfo($valueTypeInfo)['type'];
return ['type' => "map($k,$v)", 'shape' => []];
@@ -521,69 +533,69 @@ private function nodeInfo($typeInfo)
private function castTypes(): array
{
return [
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT') => 'float',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8') => 'uint8_t',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8') => 'int8_t',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16') => 'uint16_t',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16') => 'int16_t',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32') => 'int32_t',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64') => 'int64_t',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL') => 'bool',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE') => 'double',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32') => 'uint32_t',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64') => 'uint64_t',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT') => 'float',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8') => 'uint8_t',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8') => 'int8_t',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16') => 'uint16_t',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16') => 'int16_t',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32') => 'int32_t',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64') => 'int64_t',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL') => 'bool',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE') => 'double',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32') => 'uint32_t',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64') => 'uint64_t',
];
}
private function elementDataTypes(): array
{
return [
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED') => 'undefined',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT') => 'float',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8') => 'uint8',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8') => 'int8',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16') => 'uint16',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16') => 'int16',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32') => 'int32',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64') => 'int64',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING') => 'string',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL') => 'bool',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16') => 'float16',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE') => 'double',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32') => 'uint32',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64') => 'uint64',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64') => 'complex64',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128') => 'complex128',
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16') => 'bfloat16',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED') => 'undefined',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT') => 'float',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8') => 'uint8',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8') => 'int8',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16') => 'uint16',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16') => 'int16',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32') => 'int32',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64') => 'int64',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING') => 'string',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL') => 'bool',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16') => 'float16',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE') => 'double',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32') => 'uint32',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64') => 'uint64',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64') => 'complex64',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128') => 'complex128',
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16') => 'bfloat16',
];
}
private function phpTensorTypes(): array
{
return [
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT') => Tensor::float32,
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8') => Tensor::uint8,
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8') => Tensor::int8,
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16') => Tensor::uint16,
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16') => Tensor::int16,
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32') => Tensor::int32,
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64') => Tensor::int64,
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL') => Tensor::bool,
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE') => Tensor::float64,
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32') => Tensor::uint32,
- OnnxRuntime::enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64') => Tensor::uint64,
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT') => Tensor::float32,
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8') => Tensor::uint8,
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8') => Tensor::int8,
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16') => Tensor::uint16,
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16') => Tensor::int16,
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32') => Tensor::int32,
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64') => Tensor::int64,
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL') => Tensor::bool,
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE') => Tensor::float64,
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32') => Tensor::uint32,
+ $this->ort->enum('ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64') => Tensor::uint64,
];
}
private function tensorTypeAndShape($tensorInfo): array
{
- $type = OnnxRuntime::GetTensorElementType($tensorInfo);
- $numDims = OnnxRuntime::GetDimensionsCount($tensorInfo);
+ $type = $this->ort->GetTensorElementType($tensorInfo);
+ $numDims = $this->ort->GetDimensionsCount($tensorInfo);
if ($numDims > 0) {
- $dims = OnnxRuntime::GetDimensions($tensorInfo, $numDims);
- $symbolicDims = OnnxRuntime::GetSymbolicDimensions($tensorInfo, $numDims);
+ $dims = $this->ort->GetDimensions($tensorInfo, $numDims);
+ $symbolicDims = $this->ort->GetSymbolicDimensions($tensorInfo, $numDims);
for ($i = 0; $i < $numDims; $i++) {
$namedDim = FFI::string($symbolicDims[$i]);
@@ -623,10 +635,15 @@ private function ortString($str)
}
}
- private static function env()
+ private function env()
{
// TODO use mutex for thread-safety
- // TODO memoize
- return OnnxRuntime::CreateEnv(3, 'Default');
+ $env = $this->ort->CreateEnv(3, 'Default');
+
+ register_shutdown_function(function () use ($env) {
+ $this->ort->ReleaseEnv($env);
+ });
+
+ return $env;
}
-}
\ No newline at end of file
+}
diff --git a/src/Utils/LibsChecker.php b/src/Utils/LibsChecker.php
deleted file mode 100644
index 3052d48..0000000
--- a/src/Utils/LibsChecker.php
+++ /dev/null
@@ -1,161 +0,0 @@
-%message% : [%bar%] %percent:3s%%');
-
- if (!isset(self::$progressBar)) {
- self::$progressBar = new ProgressBar($output, 100);
- self::$progressBar->setFormat('hub');
- self::$progressBar->setBarCharacter('•>');
- self::$progressBar->setEmptyBarCharacter("⚬>");
- self::$progressBar->setProgressCharacter('➤>');
- self::$progressBar->setMessage($filename);
- }
-
- return self::$progressBar;
- }
-
- public static function check($event = null, OutputInterface $output = null): void
- {
- $output ??= new ConsoleOutput();
-
- $vendorDir = $event !== null ?
- $event->getComposer()->getConfig()->get('vendor-dir')
- : 'vendor';
-
- require $vendorDir.'/autoload.php';
-
- $libsDir = basePath('libs');
- $installationNeeded = false;
-
- foreach (Library::cases() as $library) {
- if (!$library->exists($libsDir)) {
- $installationNeeded = true;
- break;
- }
- }
-
- if ($installationNeeded) {
- $output->writeln("Installing TransformersPHP libraries...");
- self::install($output);
- }
- }
-
- private static function install(OutputInterface $output): void
- {
- $version = file_get_contents(basePath('VERSION'));
-
- $os = match (PHP_OS_FAMILY) {
- 'Windows' => 'windows',
- 'Darwin' => 'macosx',
- default => 'linux',
- };
-
- $arch = match (PHP_OS_FAMILY) {
- 'Windows' => 'x86_64',
- 'Darwin' => php_uname('m') == 'x86_64' ? 'x86_64' : 'arm64',
- default => php_uname('m') == 'x86_64' ? 'x86_64' : 'aarch64',
- };
-
- $extension = match ($os) {
- 'windows' => 'zip',
- default => 'tar.gz',
- };
-
- $maxRetries = 10;
- $attempts = 0;
-
-
- do {
- $baseUrl = "https://github.com/CodeWithKyrian/transformers-php/releases/download/$version";
- $filename = "transformersphp-$version-$os-$arch";
- $downloadUrl = "$baseUrl/$filename.$extension";
- $downloadPath = tempnam(sys_get_temp_dir(), 'transformers-php').".$extension";
-
- $onProgress = function ($downloadSize, $downloaded, $uploadSize, $uploaded) use ($output, $filename) {
- $progressBar = self::getProgressBar($filename, $output);
- $percent = round(($downloaded / $downloadSize) * 100, 2);
- $progressBar->setProgress((int)$percent);
- };
-
- $downloadSuccess = false;
-
- try {
- $downloadSuccess = Downloader::download($downloadUrl, $downloadPath, onProgress: $onProgress);
-
- $progressBar = self::getProgressBar($filename, $output);
- $progressBar->finish();
- $progressBar->clear();
- $output->writeln(" - Downloading $filename");
- } catch (\Exception) {
- } finally {
- unset($progressBar);
- }
-
- if ($downloadSuccess) {
- $output->writeln(" - Installing $filename : Extracting archive");
-
- $archive = new \PharData($downloadPath);
- if ($extension != 'zip') {
- $archive = $archive->decompress();
- }
-
- $archive->extractTo(basePath(), overwrite: true);
- @unlink($downloadPath);
-
- $output->writeln("✔ TransformersPHP libraries installed successfully!");
- return;
- } else {
- $output->writeln(" - Failed to download $filename trying a lower version...");
- $version = self::getLowerVersion($version);
- }
-
- $attempts++;
- } while ($version !== null && $attempts < $maxRetries);
-
- throw new \Exception("Could not find the required binaries after $maxRetries attempts.");
- }
-
- private static function getLowerVersion(string $version): ?string
- {
- $parts = explode('.', $version);
-
- if (count($parts) === 3 && $parts[2] > 0) {
- $parts[2]--;
- } elseif (count($parts) === 3) {
- $parts[1]--;
- $parts[2] = 9; // Reset patch version
- } elseif (count($parts) === 2 && $parts[1] > 0) {
- $parts[1]--;
- } else {
- return null; // No lower version possible
- }
-
- return implode('.', $parts);
- }
-
- private static function colorize(string $text, string $color = 'green'): string
- {
- $prefix = match ($color) {
- 'red' => "\033[31m",
- 'green' => "\033[32m",
- 'yellow' => "\033[33m",
- };
-
- return "$prefix$text\033[39m";
- }
-}
\ No newline at end of file
diff --git a/src/Utils/Math.php b/src/Utils/Math.php
index 0fb5a04..5223928 100644
--- a/src/Utils/Math.php
+++ b/src/Utils/Math.php
@@ -34,10 +34,8 @@ public static function sigmoid(array|ArrayAccess $arr): array
*/
public static function logSoftmax(array $arr): array
{
- // Compute the softmax values
$softmaxArr = self::softmax($arr);
- // Apply log formula to each element
return array_map(fn($x) => log($x), $softmaxArr);
}
@@ -49,16 +47,12 @@ public static function logSoftmax(array $arr): array
*/
public static function softmax(array $arr): array
{
- // Compute the maximum value in the array
$maxVal = max($arr);
- // Compute the exponentials of the array values
$exps = array_map(fn($x) => exp($x - $maxVal), $arr);
- // Compute the sum of the exponentials
$sumExps = array_sum($exps);
- // Compute the softmax values
return array_map(fn($x) => $x / $sumExps, $exps);
}
@@ -80,7 +74,6 @@ public static function getTopItems(array $items, int $topK = -1): array
return $b[1] <=> $a[1];
});
- // Get top k items if top_k > 0
if ($topK !== -1 && $topK > 0) {
$indexedItems = array_slice($indexedItems, 0, $topK);
}
@@ -96,9 +89,6 @@ public static function getTopItems(array $items, int $topK = -1): array
*/
public static function product(...$a): array
{
- // Cartesian product of items
- // Adapted from https://stackoverflow.com/a/43053803
-
return array_reduce($a, function ($carry, $array) {
return array_merge(
...array_map(function ($d) use ($array) {
@@ -122,8 +112,6 @@ public static function product(...$a): array
*/
public static function permuteData($array, array $shape, array $axes): array
{
- // Calculate the new shape of the permuted array
- // and the stride of the original array
$newShape = array_fill(0, count($axes), 0);
$stride = array_fill(0, count($axes), 0);
@@ -133,15 +121,12 @@ public static function permuteData($array, array $shape, array $axes): array
$s *= $newShape[$i];
}
- // Precompute inverse mapping of stride
$invStride = array_map(function ($_, $i) use ($stride, $axes) {
return $stride[array_search($i, $axes)];
}, $stride, array_keys($stride));
- // Create the permuted array with the new shape
$permutedData = array_fill(0, count($array), null);
- // Permute the original array to the new array
for ($i = 0; $i < count($array); ++$i) {
$newIndex = 0;
for ($j = count($shape) - 1, $k = $i; $j >= 0; --$j) {
@@ -153,6 +138,4 @@ public static function permuteData($array, array $shape, array $axes): array
return [$permutedData, $newShape];
}
-
-
-}
\ No newline at end of file
+}
diff --git a/src/Utils/StreamLogger.php b/src/Utils/StreamLogger.php
deleted file mode 100644
index 2b05cef..0000000
--- a/src/Utils/StreamLogger.php
+++ /dev/null
@@ -1,276 +0,0 @@
- 0) {
- // use max 10% of allowed memory for the chunk size, and at least 100KB
- $this->streamChunkSize = min(static::MAX_CHUNK_SIZE, max((int) ($phpMemoryLimit / 10), 100 * 1024));
- } else {
- // memory is unlimited, set to the default 10MB
- $this->streamChunkSize = static::DEFAULT_CHUNK_SIZE;
- }
- } else {
- // no memory limit information, set to the default 10MB
- $this->streamChunkSize = static::DEFAULT_CHUNK_SIZE;
- }
-
- if (is_resource($stream)) {
- $this->stream = $stream;
-
- stream_set_chunk_size($this->stream, $this->streamChunkSize);
- } elseif (is_string($stream)) {
- $this->url = self::canonicalizePath($stream);
- } else {
- throw new InvalidArgumentException('A stream must either be a resource or a string.');
- }
-
- $this->fileOpenMode = $fileOpenMode;
- $this->filePermission = $filePermission;
- $this->useLocking = $useLocking;
- }
-
- public function log($level, Stringable|string $message, array $context = []): void
- {
- if (! is_resource($this->stream)) {
- $url = $this->url;
- if ($url === null || $url === '') {
- throw new LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close()');
- }
- $this->createDir($url);
- $this->errorMessage = null;
- set_error_handler($this->customErrorHandler(...));
-
- try {
- $stream = fopen($url, $this->fileOpenMode);
- if ($this->filePermission !== null) {
- @chmod($url, $this->filePermission);
- }
- } finally {
- restore_error_handler();
- }
- if (! is_resource($stream)) {
- $this->stream = null;
-
- throw new UnexpectedValueException('The stream could not be opened in append mode');
- }
- stream_set_chunk_size($stream, $this->streamChunkSize);
- $this->stream = $stream;
- }
-
- $stream = $this->stream;
- if ($this->useLocking) {
- // ignoring errors here, there's not much we can do about them
- flock($stream, LOCK_EX);
- }
-
- $this->errorMessage = null;
- set_error_handler($this->customErrorHandler(...));
- try {
-
- $params = [
- '%datetime%' => date(static::DATE_FORMAT),
- '%level_name%' => $level,
- '%message%' => trim($message),
- '%context%' => json_encode(
- $context,
- JSON_UNESCAPED_SLASHES |
- JSON_UNESCAPED_UNICODE |
- JSON_PRESERVE_ZERO_FRACTION
- ),
- ];
- fwrite($stream, strtr(static::LOG_FORMAT, $params));
- } finally {
- restore_error_handler();
- }
- if ($this->errorMessage !== null) {
- // close the resource if possible to reopen it, and retry the failed write
- if (! $this->retrying && $this->url !== null && $this->url !== 'php://memory') {
- $this->retrying = true;
- $this->close();
- $this->log($level, $message, $context);
-
- return;
- }
-
- throw new UnexpectedValueException('Writing to the log file failed');
- }
-
- $this->retrying = false;
- if ($this->useLocking) {
- flock($stream, LOCK_UN);
- }
- }
-
- public function close(): void
- {
- if ($this->url !== null && is_resource($this->stream)) {
- fclose($this->stream);
- }
- $this->stream = null;
- $this->dirCreated = null;
- }
-
- private function getDirFromStream(string $stream): ?string
- {
- $pos = strpos($stream, '://');
- if ($pos === false) {
- return dirname($stream);
- }
-
- if (str_starts_with($stream, 'file://')) {
- return dirname(substr($stream, 7));
- }
-
- return null;
- }
-
- private function customErrorHandler(int $code, string $msg): bool
- {
- $this->errorMessage = preg_replace('{^(fopen|mkdir|fwrite)\(.*?\): }', '', $msg);
-
- return true;
- }
-
- private function createDir(string $url): void
- {
- // Do not try to create dir if it has already been tried.
- if ($this->dirCreated === true) {
- return;
- }
-
- $dir = $this->getDirFromStream($url);
- if ($dir !== null && ! is_dir($dir)) {
- $this->errorMessage = null;
- set_error_handler(function (...$args) {
- return $this->customErrorHandler(...$args);
- });
- $status = mkdir($dir, 0777, true);
- restore_error_handler();
- if ($status === false && ! is_dir($dir) && ! str_contains((string) $this->errorMessage, 'File exists')) {
- throw new UnexpectedValueException(sprintf('There is no existing directory at "%s" and it could not be created: '.$this->errorMessage, $dir));
- }
- }
- $this->dirCreated = true;
- }
-
- protected static function getMemoryLimitInBytes(): false|int
- {
- $limit = ini_get('memory_limit');
- if (! is_string($limit)) {
- return false;
- }
-
- // support -1
- if ((int) $limit < 0) {
- return (int) $limit;
- }
-
- if (!preg_match('/^\s*(?\d+)(?:\.\d+)?\s*(?[gmk]?)\s*$/i', $limit, $match)) {
- return false;
- }
-
- $limit = (int) $match['limit'];
- switch (strtolower($match['unit'])) {
- case 'g':
- $limit *= 1024;
- // no break
- case 'm':
- $limit *= 1024;
- // no break
- case 'k':
- $limit *= 1024;
- }
-
- return $limit;
- }
-
- /**
- * Makes sure if a relative path is passed in it is turned into an absolute path
- *
- * @param string $streamUrl stream URL or path without protocol
- */
- public static function canonicalizePath(string $streamUrl): string
- {
- $prefix = '';
- if (str_starts_with($streamUrl, 'file://')) {
- $streamUrl = substr($streamUrl, 7);
- $prefix = 'file://';
- }
-
- // other type of stream, not supported
- if (str_contains($streamUrl, '://')) {
- return $streamUrl;
- }
-
- // already absolute
- if (str_starts_with($streamUrl, '/') || substr($streamUrl, 1, 1) === ':' || str_starts_with($streamUrl, '\\\\')) {
- return $prefix.$streamUrl;
- }
-
- $streamUrl = getcwd().'/'.$streamUrl;
-
- return $prefix.$streamUrl;
- }
-
- public function __destruct()
- {
- $this->close();
- }
-}
diff --git a/tests/Utils/HubTest.php b/tests/Utils/HubTest.php
index 53971f9..282b02f 100644
--- a/tests/Utils/HubTest.php
+++ b/tests/Utils/HubTest.php
@@ -20,27 +20,32 @@
it('joins paths correctly', function () {
$result = joinPaths('path', 'to', 'file');
- expect($result)->toBe('path/to/file');
+ $expected = 'path'.DIRECTORY_SEPARATOR.'to'.DIRECTORY_SEPARATOR.'file';
+ expect($result)->toBe($expected);
});
it('joins paths correctly with leading slash', function () {
$result = joinPaths('/path', 'to', 'file');
- expect($result)->toBe('/path/to/file');
+ $expected = '/path'.DIRECTORY_SEPARATOR.'to'.DIRECTORY_SEPARATOR.'file';
+ expect($result)->toBe($expected);
});
it('joins paths correctly with trailing slash', function () {
- $result = joinPaths('path', 'to', 'file/');
- expect($result)->toBe('path/to/file');
+ $result = joinPaths('path', 'to', 'file'.DIRECTORY_SEPARATOR);
+ $expected = 'path'.DIRECTORY_SEPARATOR.'to'.DIRECTORY_SEPARATOR.'file';
+ expect($result)->toBe($expected);
});
it('joins paths correctly with empty string', function () {
$result = joinPaths('path', '', 'file');
- expect($result)->toBe('path/file');
+ $expected = 'path'.DIRECTORY_SEPARATOR.'file';
+ expect($result)->toBe($expected);
});
it('joins paths correctly with empty string and slashes', function () {
- $result = joinPaths('path', '', '/file');
- expect($result)->toBe('path/file');
+ $result = joinPaths('path', '', DIRECTORY_SEPARATOR.'file');
+ $expected = 'path'.DIRECTORY_SEPARATOR.'file';
+ expect($result)->toBe($expected);
});
it('ensures directory creation', function () {
diff --git a/tests/Utils/ImageTest.php b/tests/Utils/ImageTest.php
new file mode 100644
index 0000000..17da86e
--- /dev/null
+++ b/tests/Utils/ImageTest.php
@@ -0,0 +1,75 @@
+setImageDriver(ImageDriver::VIPS);
+ });
+
+ it('can read and get dimensions', function () {
+ $img = Image::read('tests/fixtures/images/sample.jpg');
+ expect($img->width())->toBeInt()->and($img->height())->toBeInt();
+ expect($img->size())->toHaveCount(2);
+ });
+
+ it('can resize and thumbnail', function () {
+ $img = Image::read('tests/fixtures/images/sample.jpg');
+ $resized = $img->resize(64, 32);
+ expect($resized->width())->toBe(64);
+ expect($resized->height())->toBe(32);
+ $thumb = $img->thumbnail(32, 32);
+ expect($thumb->width())->toBeLessThanOrEqual(32);
+ expect($thumb->height())->toBeLessThanOrEqual(32);
+ });
+
+ it('can grayscale, rgb, and rgba', function () {
+ $img = Image::read('tests/fixtures/images/sample.jpg');
+ $gray = $img->grayscale();
+ expect($gray->channels)->toBe(1);
+ $rgb = $img->rgb();
+ expect($rgb->channels)->toBe(3);
+ $rgba = $img->rgba();
+ expect($rgba->channels)->toBe(4);
+ });
+
+ it('can center crop and crop', function () {
+ $img = Image::read('tests/fixtures/images/sample.jpg');
+ $center = $img->centerCrop(32, 32);
+ expect($center->width())->toBe(32);
+ expect($center->height())->toBe(32);
+ $crop = $img->crop(0, 0, 15, 15);
+ expect($crop->width())->toBe(16);
+ expect($crop->height())->toBe(16);
+ });
+
+ it('can pad and invert', function () {
+ $img = Image::read('tests/fixtures/images/sample.jpg');
+ $padded = $img->pad(2, 2, 2, 2);
+ expect($padded->width())->toBe($img->width() + 4);
+ expect($padded->height())->toBe($img->height() + 4);
+ $inverted = $img->invert();
+ expect($inverted)->toBeInstanceOf(Image::class);
+ });
+
+ it('can convert to and from tensor', function () {
+ $img = Image::read('tests/fixtures/images/sample.jpg');
+ $tensor = $img->toTensor('CHW');
+ expect($tensor)->toBeInstanceOf(Tensor::class);
+ $img2 = Image::fromTensor($tensor, 'CHW');
+ expect($img2->width())->toBe($img->width());
+ expect($img2->height())->toBe($img->height());
+ expect($img2->channels)->toBe($img->channels);
+ });
+
+ it('can save an image', function () {
+ $img = Image::read('tests/fixtures/images/sample.jpg');
+ $tmp = tempnam(sys_get_temp_dir(), 'imgtest_') . '.jpg';
+ $img->save($tmp);
+ expect(file_exists($tmp))->toBeTrue();
+ unlink($tmp);
+ });
+});
diff --git a/tests/Utils/InferenceSessionTest.php b/tests/Utils/InferenceSessionTest.php
new file mode 100644
index 0000000..d710d87
--- /dev/null
+++ b/tests/Utils/InferenceSessionTest.php
@@ -0,0 +1,217 @@
+run(['label', 'probabilities'], ['input' => $input]);
+ expect($output)->toBeArray();
+ expect($output['label']->shape())->toBe([1]);
+ expect($output['label']->toArray())->toBe([1]);
+ expect($output['probabilities'])->toBeArray(); // Should be a sequence/map
+});
+
+it('returns available providers', function () {
+ $session = new InferenceSession('tests/fixtures/models/lightgbm.onnx');
+ $providers = $session->providers();
+ expect($providers)->toContain('CPUExecutionProvider');
+});
+
+it('ignores unavailable CUDA provider', function () {
+ $session = new InferenceSession('tests/fixtures/models/lightgbm.onnx', providers: ['CUDAExecutionProvider', 'CPUExecutionProvider']);
+ $providers = $session->providers();
+ expect($providers)->not->toContain('CUDAExecutionProvider');
+});
+
+it('supports profiling and returns a profile file', function () {
+ $session = new InferenceSession('tests/fixtures/models/lightgbm.onnx', enableProfiling: true);
+ $file = $session->endProfiling();
+ expect($file)->toContain('.json');
+ if (file_exists($file)) {
+ unlink($file);
+ }
+});
+
+it('supports custom profile file prefix', function () {
+ $session = new InferenceSession('tests/fixtures/models/lightgbm.onnx', enableProfiling: true, profileFilePrefix: 'hello');
+ $file = $session->endProfiling();
+ expect($file)->toContain('hello');
+ if (file_exists($file)) {
+ unlink($file);
+ }
+});
+
+
+it('returns correct input and output signatures for hello_world.onnx', function () {
+ $session = new InferenceSession('tests/fixtures/models/hello_world.onnx');
+ expect($session->inputs())->toBe([
+ ['name' => 'x', 'type' => 'tensor(float)', 'shape' => [3, 4, 5]]
+ ]);
+ expect($session->outputs())->toBe([
+ ['name' => 'y', 'type' => 'tensor(float)', 'shape' => [3, 4, 5]]
+ ]);
+});
+
+it('predicts correctly for a float tensor input', function () {
+ $session = new InferenceSession('tests/fixtures/models/hello_world.onnx');
+ $x = [
+ [
+ [0.5488135, 0.71518934, 0.60276335, 0.5448832, 0.4236548],
+ [0.6458941, 0.4375872, 0.891773, 0.96366274, 0.3834415],
+ [0.79172504, 0.5288949, 0.56804454, 0.92559665, 0.07103606],
+ [0.0871293, 0.0202184, 0.83261985, 0.77815676, 0.87001216]
+ ],
+
+ [
+ [0.9786183, 0.7991586, 0.46147937, 0.7805292, 0.11827443],
+ [0.639921, 0.14335328, 0.9446689, 0.5218483, 0.41466194],
+ [0.2645556, 0.7742337, 0.45615032, 0.56843394, 0.0187898],
+ [0.6176355, 0.6120957, 0.616934, 0.94374806, 0.6818203]
+ ],
+
+ [
+ [0.3595079, 0.43703195, 0.6976312, 0.06022547, 0.6667667],
+ [0.67063785, 0.21038257, 0.12892629, 0.31542835, 0.36371076],
+ [0.57019675, 0.43860152, 0.9883738, 0.10204481, 0.20887676],
+ [0.16130951, 0.6531083, 0.2532916, 0.46631077, 0.2444256]
+ ]
+ ];
+ $output = $session->run(['y'], ['x' => Tensor::fromArray($x, Tensor::float32)]);
+ expect($output['y'][0][0]->toArray())->toEqualWithDelta([0.6338603, 0.6715468, 0.6462883, 0.6329476, 0.6043575], 0.00001);
+});
+
+it('handles boolean input/output', function () {
+ $session = new InferenceSession('tests/fixtures/models/logical_and.onnx');
+ $x = [[false, false], [true, true]];
+ $x2 = [[true, false], [true, false]];
+ $output = $session->run(['output:0'], [
+ 'input:0' => Tensor::fromArray($x, Tensor::bool),
+ 'input1:0' => Tensor::fromArray($x2, Tensor::bool)
+ ]);
+ expect($output['output:0']->toArray())->toBe([[false, false], [true, false]]);
+});
+
+it('can load a model from a stream', function () {
+ $stream = fopen('tests/fixtures/models/hello_world.onnx', 'rb');
+ $session = new InferenceSession($stream);
+ expect($session->inputs())->toBe([
+ ['name' => 'x', 'type' => 'tensor(float)', 'shape' => [3, 4, 5]]
+ ]);
+});
+
+it('predicts correctly for lightgbm.onnx and checks probabilities', function () {
+ $session = new InferenceSession('tests/fixtures/models/lightgbm.onnx');
+ $x = [[5.8, 2.8]];
+ $output = $session->run(['label', 'probabilities'], ['input' => Tensor::fromArray($x, Tensor::float32)]);
+ expect($output['label']->toArray())->toBe([1]);
+ $probabilities = $output['probabilities'][0];
+ expect(array_column($probabilities->toArray(), 0))->toBe([0.0, 1.0, 2.0]);
+ expect(array_column($probabilities->toArray(), 1))->toEqualWithDelta([0.2593829035758972, 0.409047931432724, 0.3315691649913788], 0.00001);
+});
+
+it('predicts correctly for randomforest.onnx', function () {
+ $session = new InferenceSession('tests/fixtures/models/randomforest.onnx');
+ $x = [[5.8, 2.8, 5.1, 2.4]];
+ $output = $session->run(['output_label', 'output_probability'], ['float_input' => Tensor::fromArray($x, Tensor::float32)]);
+ expect($output['output_label']->toArray())->toBe([2]);
+ $probabilities = $output['output_probability'][0];
+ expect(array_column($probabilities->toArray(), 0))->toBe([0.0, 1.0, 2.0]);
+ expect(array_column($probabilities->toArray(), 1))->toEqualWithDelta([0.0, 0.0, 1.0000001192092896], 0.00001);
+});
+
+it('returns only requested output names', function () {
+ $session = new InferenceSession('tests/fixtures/models/lightgbm.onnx');
+ $output = $session->run(['label'], ['input' => Tensor::fromArray([[5.8, 2.8]], Tensor::float32)]);
+ expect(array_keys($output))->toBe(['label']);
+});
+
+
+
+it('handles session options and optimized model file', function () {
+ $optimizedPath = tempnam(sys_get_temp_dir(), 'optimized');
+ $session = new InferenceSession(
+ 'tests/fixtures/models/lightgbm.onnx',
+ executionMode: null, // Set as needed
+ graphOptimizationLevel: null, // Set as needed
+ interOpNumThreads: 1,
+ intraOpNumThreads: 1,
+ logSeverityLevel: 4,
+ logVerbosityLevel: 4,
+ logid: 'test',
+ optimizedModelFilepath: $optimizedPath
+ );
+ $x = [[5.8, 2.8]];
+ $session->run(['label', 'probabilities'], ['input' => Tensor::fromArray($x, Tensor::float32)]);
+ expect(file_get_contents($optimizedPath))->toContain('onnx');
+});
+
+it('handles free dimension overrides by denotation', function () {
+ $session = new InferenceSession('tests/fixtures/models/abs_free_dimensions.onnx', freeDimensionOverridesByDenotation: ['DATA_BATCH' => 3, 'DATA_CHANNEL' => 5]);
+ expect($session->inputs()[0]['shape'])->toBe([3, 5, 5]);
+});
+
+it('handles free dimension overrides by name', function () {
+ $session = new InferenceSession('tests/fixtures/models/abs_free_dimensions.onnx', freeDimensionOverridesByName: ['Dim1' => 4, 'Dim2' => 6]);
+ expect($session->inputs()[0]['shape'])->toBe([4, 6, 5]);
+});
+
+it('returns input shape names for symbolic dimensions', function () {
+ $session = new InferenceSession('tests/fixtures/models/abs_free_dimensions.onnx');
+ expect($session->inputs()[0]['shape'])->toBe(['Dim1', 'Dim2', 5]);
+});
+
+it('handles session config entries', function () {
+ $session = new InferenceSession('tests/fixtures/models/lightgbm.onnx', sessionConfigEntries: ['key' => 'value']);
+ expect($session)->toBeInstanceOf(InferenceSession::class);
+});
+
+it('handles run options', function () {
+ $session = new InferenceSession('tests/fixtures/models/lightgbm.onnx');
+ $x = [[5.8, 2.8]];
+ $session->run(['label', 'probabilities'], ['input' => Tensor::fromArray($x, Tensor::float32)], logSeverityLevel: 4, logVerbosityLevel: 4, logid: 'test', terminate: false);
+ expect(true)->toBeTrue();
+});
+
+it('throws on invalid rank', function () {
+ $session = new InferenceSession('tests/fixtures/models/hello_world.onnx');
+ expect(fn() => $session->run(['y'], ['x' => Tensor::fromArray([1], Tensor::float32)]))
+ ->toThrow(Exception::class);
+});
+
+it('throws on invalid dimensions', function () {
+ $session = new InferenceSession('tests/fixtures/models/hello_world.onnx');
+ expect(fn() => $session->run(['y'], ['x' => Tensor::fromArray([[[1]],], Tensor::float32)]))
+ ->toThrow(Exception::class);
+});
+
+it('throws on missing input', function () {
+ $session = new InferenceSession('tests/fixtures/models/hello_world.onnx');
+ expect(fn() => $session->run(['y'], []))
+ ->toThrow(Exception::class);
+});
+
+it('throws on extra input', function () {
+ $session = new InferenceSession('tests/fixtures/models/hello_world.onnx');
+ expect(fn() => $session->run(['y'], ['x' => Tensor::fromArray([1], Tensor::float32), 'y' => Tensor::fromArray([1], Tensor::float32)]))
+ ->toThrow(Exception::class);
+});
+
+it('throws on invalid output name', function () {
+ $session = new InferenceSession('tests/fixtures/models/lightgbm.onnx');
+ $x = [[5.8, 2.8]];
+ expect(fn() => $session->run(['bad'], ['input' => Tensor::fromArray($x, Tensor::float32)]))
+ ->toThrow(Exception::class);
+});
+
+it('returns model metadata', function () {
+ $session = new InferenceSession('tests/fixtures/models/hello_world.onnx');
+ $metadata = $session->modelmeta();
+ expect($metadata['custom_metadata_map'])->toEqual(['hello' => 'world', 'test' => 'value']);
+ expect($metadata['description'])->toBe('');
+ expect($metadata['domain'])->toBe('');
+ expect($metadata['graph_name'])->toBe('test_sigmoid');
+ expect($metadata['producer_name'])->toBe('backend-test');
+ expect($metadata['version'])->toBe(9223372036854775807);
+});
diff --git a/tests/Utils/StreamLoggerTest.php b/tests/Utils/StreamLoggerTest.php
deleted file mode 100644
index 1d6c0ad..0000000
--- a/tests/Utils/StreamLoggerTest.php
+++ /dev/null
@@ -1,83 +0,0 @@
-outputBuffer = fopen('php://memory', 'rw');
- $this->logger = new StreamLogger($this->outputBuffer);
-});
-
-afterEach(function () {
- fclose($this->outputBuffer);
-});
-
-it('logs messages with the correct format', function () {
- $this->logger->log('info', 'This is a test message');
-
- rewind($this->outputBuffer);
- $output = stream_get_contents($this->outputBuffer);
-
- expect($output)->toMatch('/\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[\+\-]\d{2}:\d{2}\] info: This is a test message \[\]\n/');
-});
-
-it('handles context correctly in log messages', function () {
- $context = ['user_id' => 123, 'action' => 'login'];
- $this->logger->log('warning', 'User action recorded', $context);
-
- rewind($this->outputBuffer);
- $output = stream_get_contents($this->outputBuffer);
-
- $expectedContext = json_encode($context, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION);
-
- expect($output)->toContain('warning: User action recorded')
- ->and($output)->toContain($expectedContext);
-});
-
-it('handles different log levels correctly', function () {
- $levels = ['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'];
-
- foreach ($levels as $level) {
- $this->logger->log($level, "Message at $level level");
-
- rewind($this->outputBuffer);
- $output = stream_get_contents($this->outputBuffer);
- expect($output)->toContain("$level: Message at $level level");
-
- ftruncate($this->outputBuffer, 0); // Clear buffer
- rewind($this->outputBuffer);
- }
-});
-
-it('handles empty context gracefully', function () {
- $this->logger->log('info', 'Message with no context');
-
- rewind($this->outputBuffer);
- $output = stream_get_contents($this->outputBuffer);
-
- expect($output)->toContain('info: Message with no context []');
-});
-
-it('handles stringable objects in the message', function () {
- $stringable = new class {
- public function __toString(): string
- {
- return 'Stringable message content';
- }
- };
-
- $this->logger->log('info', $stringable);
-
- rewind($this->outputBuffer);
- $output = stream_get_contents($this->outputBuffer);
-
- expect($output)->toContain('info: Stringable message content');
-});
-
-it('outputs log messages to STDOUT', function () {
- $this->logger->log('info', 'Check output redirection');
-
- rewind($this->outputBuffer);
- $output = stream_get_contents($this->outputBuffer);
-
- expect($output)->toContain('info: Check output redirection');
-});
diff --git a/tests/ffi/SamplerateTest.php b/tests/ffi/SamplerateTest.php
new file mode 100644
index 0000000..d5f489d
--- /dev/null
+++ b/tests/ffi/SamplerateTest.php
@@ -0,0 +1,83 @@
+markTestSkipped('FFI extension is not loaded.');
+ }
+ $this->samplerate = new Samplerate();
+});
+
+it('loads the FFI instance', function () {
+ $ffi = $this->samplerate->getFFI();
+ expect($ffi)->toBeInstanceOf(FFI::class);
+});
+
+it('can get the version of the library', function () {
+ $version = $this->samplerate->version();
+ expect($version)->toBeString();
+});
+
+it('can create a new instance of any type from the library', function () {
+ $instance = $this->samplerate->new('SRC_DATA');
+ expect($instance)->toBeInstanceOf(CData::class);
+});
+
+it('can cast a pointer to a different type', function () {
+ $data = $this->samplerate->new("float[2]");
+ $castedInstance = $this->samplerate->cast('float *', $data);
+ expect($castedInstance)->toBeInstanceOf(CData::class);
+});
+
+it('can retrieve the value of an enum constant', function () {
+ $value = $this->samplerate->enum('SRC_SINC_FASTEST');
+ expect($value)->toBeInt();
+});
+
+it('can create a new sample rate converter', function () {
+ $converterType = $this->samplerate->enum('SRC_SINC_FASTEST');
+ $state = $this->samplerate->src_new($converterType, 2);
+
+ expect($state)->toBeInstanceOf(CData::class);
+
+ $this->samplerate->delete($state);
+});
+
+it('can process data using a sample rate converter', function () {
+ $converterType = $this->samplerate->enum('SRC_SINC_FASTEST');
+ $state = $this->samplerate->src_new($converterType, 1);
+
+ $srcRatio = 0.2;
+ $inputFrames = 1024;
+ $outputFrames = 2048;
+
+ $data = array_map(fn ($i) => 0.5 * sin(2 * pi() * 880 * $i / 44100), range(0, $inputFrames - 1));
+ $dataIn = $this->samplerate->new("float[$inputFrames]");
+ for ($i = 0; $i < $inputFrames; $i++) {
+ $dataIn[$i] = $data[$i];
+ }
+ $dataOut = $this->samplerate->new("float[$outputFrames]");
+ for ($i = 0; $i < $outputFrames; $i++) {
+ $dataOut[$i] = 0.0;
+ }
+
+ $data = $this->samplerate->new('SRC_DATA');
+ $data->data_in = $this->samplerate->cast('float *', $dataIn);
+ $data->data_out = $this->samplerate->cast('float *', $dataOut);
+ $data->input_frames = $inputFrames;
+ $data->output_frames = $outputFrames;
+ $data->src_ratio = $srcRatio;
+ $data->end_of_input = 0;
+
+ $this->samplerate->process($state, \FFI::addr($data));
+
+ expect($data->output_frames_gen)
+ ->toBeInt()
+ ->toBeLessThanOrEqual((int)ceil($inputFrames * $srcRatio));
+
+ $this->samplerate->delete($state);
+});
diff --git a/tests/ffi/SndfileTest.php b/tests/ffi/SndfileTest.php
new file mode 100644
index 0000000..b750b6f
--- /dev/null
+++ b/tests/ffi/SndfileTest.php
@@ -0,0 +1,88 @@
+markTestSkipped('FFI extension is not loaded.');
+ }
+
+ $this->testSoundFile = __DIR__ . '/../sounds/jfk.wav';
+ $this->outputSoundFile = __DIR__ . '/../sounds/output.wav';
+
+ $this->sndfile = new Sndfile();
+});
+
+it('loads the FFI instance', function () {
+ $ffi = $this->sndfile->getFFI();
+ expect($ffi)->toBeInstanceOf(FFI::class);
+});
+
+it('can create a new instance of any type from the library', function () {
+ $instance = $this->sndfile->new('SF_INFO');
+ expect($instance)->toBeInstanceOf(CData::class);
+});
+
+it('can cast a pointer to a different type', function () {
+ $data = $this->sndfile->new("float[2]");
+ $float = $this->sndfile->cast("float*", $data);
+ expect($float)->toBeInstanceOf(CData::class);
+});
+
+it('can retrieve the value of an enum constant', function () {
+ $value = $this->sndfile->enum('SF_FORMAT_PCM_16');
+ expect($value)->toBeInt();
+});
+
+it('can open a sound file', function () {
+ $sfinfo = $this->sndfile->new('SF_INFO');
+ $sndfileHandle = $this->sndfile->open($this->testSoundFile, $this->sndfile->enum('SFM_READ'), \FFI::addr($sfinfo));
+
+ expect($sndfileHandle)->toBeInstanceOf(CData::class);
+
+ $this->sndfile->close($sndfileHandle);
+});
+
+it('can read frames from a sound file', function () {
+ $sfinfo = $this->sndfile->new('SF_INFO');
+ $sndfileHandle = $this->sndfile->open($this->testSoundFile, $this->sndfile->enum('SFM_READ'), \FFI::addr($sfinfo));
+
+ $chunkSize = 2048;
+ $bufferSize = $chunkSize * $sfinfo->channels;
+ $buffer = $this->sndfile->new("float[{$bufferSize}]");
+ $framesRead = $this->sndfile->readf_float($sndfileHandle, $buffer, $chunkSize);
+
+ expect($framesRead)->toBe($chunkSize)
+ ->and($buffer[0])->toBeFloat();
+
+ $this->sndfile->close($sndfileHandle);
+});
+
+it('can write frames to a sound file', function () {
+ $sfinfo = $this->sndfile->new('SF_INFO');
+ $sfinfo->channels = 1;
+ $sfinfo->samplerate = 44100;
+ $sfinfo->format = $this->sndfile->enum('SF_FORMAT_WAV') | $this->sndfile->enum('SF_FORMAT_PCM_16');
+
+ $sndfileHandle = $this->sndfile->open($this->outputSoundFile, $this->sndfile->enum('SFM_WRITE'), \FFI::addr($sfinfo));
+
+ $chunkSize = 44100;
+ $bufferSize = $chunkSize * $sfinfo->channels;
+ $buffer = $this->sndfile->new("float[{$bufferSize}]");
+ $data = array_map(fn ($i) => 0.5 * sin(2 * pi() * 880 * $i / 44100), range(0, $bufferSize - 1));
+
+ for ($i = 0; $i < $bufferSize; $i++) {
+ $buffer[$i] = $data[$i];
+ }
+
+ $framesWritten = $this->sndfile->writef_float($sndfileHandle, $buffer, $chunkSize);
+
+ expect($framesWritten)->toBe($chunkSize);
+
+ $this->sndfile->close($sndfileHandle);
+
+ @unlink($this->outputSoundFile);
+});
diff --git a/tests/fixtures/images/sample.jpg b/tests/fixtures/images/sample.jpg
new file mode 100644
index 0000000..cee4aef
Binary files /dev/null and b/tests/fixtures/images/sample.jpg differ
diff --git a/tests/fixtures/models/abs_free_dimensions.onnx b/tests/fixtures/models/abs_free_dimensions.onnx
new file mode 100644
index 0000000..4c3d5ab
--- /dev/null
+++ b/tests/fixtures/models/abs_free_dimensions.onnx
@@ -0,0 +1,14 @@
+backend-test:s
+
+xy"Abstest_absZ9
+x4
+2.
+Dim1
+DATA_BATCH
+Dim2DATA_CHANNEL
+b
+y
+
+Dim1
+Dim2
+B
\ No newline at end of file
diff --git a/tests/fixtures/models/hello_world.onnx b/tests/fixtures/models/hello_world.onnx
new file mode 100644
index 0000000..279a4df
--- /dev/null
+++ b/tests/fixtures/models/hello_world.onnx
@@ -0,0 +1,15 @@
+backend-test:Q
+
+xy"Sigmoidtest_sigmoidZ
+x
+
+
+
+b
+y
+
+
+
+B r
+helloworldr
+testvalue
\ No newline at end of file
diff --git a/tests/fixtures/models/identity_string.onnx b/tests/fixtures/models/identity_string.onnx
new file mode 100644
index 0000000..c33e4f8
--- /dev/null
+++ b/tests/fixtures/models/identity_string.onnx
@@ -0,0 +1,11 @@
+tf2onnx0.0.2.0:m
+%
+input:0output:0output"Identitytf2onnxRtestZ
+input:0
+
+
+b
+output:0
+
+
+B
\ No newline at end of file
diff --git a/tests/fixtures/models/lightgbm.onnx b/tests/fixtures/models/lightgbm.onnx
new file mode 100644
index 0000000..335ad4b
Binary files /dev/null and b/tests/fixtures/models/lightgbm.onnx differ
diff --git a/tests/fixtures/models/logical_and.onnx b/tests/fixtures/models/logical_and.onnx
new file mode 100644
index 0000000..cedb131
--- /dev/null
+++ b/tests/fixtures/models/logical_and.onnx
@@ -0,0 +1,16 @@
+tf2onnx0.0.2.0:Ž
+*
+input:0
+input1:0output:0output"Andtf2onnxRtestZ
+input1:0
+
+
+Z
+input:0
+
+
+b
+output:0
+
+
+B
\ No newline at end of file
diff --git a/tests/fixtures/models/logreg_iris.onnx b/tests/fixtures/models/logreg_iris.onnx
new file mode 100644
index 0000000..0326870
Binary files /dev/null and b/tests/fixtures/models/logreg_iris.onnx differ
diff --git a/tests/fixtures/models/mul_1.onnx b/tests/fixtures/models/mul_1.onnx
new file mode 100644
index 0000000..0b6dc51
Binary files /dev/null and b/tests/fixtures/models/mul_1.onnx differ
diff --git a/tests/fixtures/models/randomforest.onnx b/tests/fixtures/models/randomforest.onnx
new file mode 100644
index 0000000..c8c2d3e
Binary files /dev/null and b/tests/fixtures/models/randomforest.onnx differ
diff --git a/tests/fixtures/models/sigmoid.onnx b/tests/fixtures/models/sigmoid.onnx
new file mode 100644
index 0000000..f03fcd1
--- /dev/null
+++ b/tests/fixtures/models/sigmoid.onnx
@@ -0,0 +1,13 @@
+backend-test:Q
+
+xy"Sigmoidtest_sigmoidZ
+x
+
+
+
+b
+y
+
+
+
+B
\ No newline at end of file
diff --git a/tests/sounds/jfk.wav b/tests/sounds/jfk.wav
new file mode 100644
index 0000000..bd627bf
Binary files /dev/null and b/tests/sounds/jfk.wav differ
diff --git a/tests/tensors/TensorTest.php b/tests/tensors/TensorTest.php
index 4ceb2b6..3c76538 100644
--- a/tests/tensors/TensorTest.php
+++ b/tests/tensors/TensorTest.php
@@ -263,13 +263,13 @@
expect($t->mean())->toBe(3.0);
});
- it('can calculate standard deviation', function () {
- $t = new Tensor([1.0, 2.0, 3.0, 4.0, 5.0]);
- [$std, $mean] = $t->stdMean();
-
- expect($std)->toEqualWithDelta(1.4142, 1e-4)
- ->and($mean)->toEqualWithDelta(3.0, 1e-4);
- })->todo();
+// it('can calculate standard deviation', function () {
+// $t = new Tensor([1.0, 2.0, 3.0, 4.0, 5.0]);
+// [$std, $mean] = $t->stdMean();
+//
+// expect($std)->toEqualWithDelta(1.4142, 1e-4)
+// ->and($mean)->toEqualWithDelta(3.0, 1e-4);
+// })->todo();
it('can calculate cosine similarity', function () {
$t1 = new Tensor([1.0, 2.0, 3.0]);
diff --git a/tests/tokenizers/TokenizersTest.php b/tests/tokenizers/TokenizersTest.php
index 4ee8e25..6a5cd3f 100644
--- a/tests/tokenizers/TokenizersTest.php
+++ b/tests/tokenizers/TokenizersTest.php
@@ -21,12 +21,11 @@
$tokenizer = AutoTokenizer::fromPretrained($tokenizerId);
- if (is_string($test['input']))
- {
+ if (is_string($test['input'])) {
// Tokenize the input text
$encoded = $tokenizer($test['input'], returnTensor: false);
- // Add the input text to the encoded object for easier debugging
+ // Add the input text to the encoded object for easier debugging
$test['encoded']['input'] = $encoded['input'] = $test['input'];
expect($encoded)->toMatchArray($test['encoded']);
@@ -41,7 +40,7 @@
$decodedWithoutSpecial = $tokenizer->decode($encoded['input_ids'], skipSpecialTokens: true);
expect($decodedWithoutSpecial)->toBe($test['decoded_without_special']);
- } else{
+ } else {
['text' => $text, 'text_pair' => $textPair] = $test['input'];
@@ -50,7 +49,7 @@
expect($encoded)->toMatchArray($test['output']);
}
})
- ->with('regular-tokenization');
+ ->with('regular-tokenization');
});
describe('Chat templates', function () {
@@ -70,6 +69,7 @@
$inputIds = $tokenizer->applyChatTemplate($chat, returnTensor: false);
+
expect($inputIds)
->toBe([1, 733, 16289, 28793, 22557, 28725, 910, 460, 368, 28804, 733, 28748, 16289, 28793, 28737, 28742, 28719, 2548, 1598, 28723, 1602, 541, 315, 1316, 368, 3154, 28804, 2, 28705, 733, 16289, 28793, 315, 28742, 28715, 737, 298, 1347, 805, 910, 10706, 5752, 1077, 3791, 28808, 733, 28748, 16289, 28793]);
});
@@ -83,35 +83,35 @@
['role' => 'user', 'content' => "I'd like to show off how chat templating works!"],
];
- $chatTemplate = "{% if messages[0]['role'] == 'system' %}".
- "{% set loop_messages = messages[1:] %}".
- "{% set system_message = messages[0]['content'] %}".
- "{% elif USE_DEFAULT_PROMPT == true and not '<>' in messages[0]['content'] %}".
- "{% set loop_messages = messages %}".
- "{% set system_message = 'DEFAULT_SYSTEM_MESSAGE' %}".
- "{% else %}".
- "{% set loop_messages = messages %}".
- "{% set system_message = false %}".
- "{% endif %}".
- "{% if loop_messages|length == 0 and system_message %}".
- "{{ bos_token + '[INST] <>\\n' + system_message + '\\n<>\\n\\n [/INST]' }}".
- "{% endif %}".
- "{% for message in loop_messages %}".
- "{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}".
- "{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}".
- "{% endif %}".
- "{% if loop.index0 == 0 and system_message != false %}".
- "{% set content = '<>\\n' + system_message + '\\n<>\\n\\n' + message['content'] %}".
- "{% else %}".
- "{% set content = message['content'] %}".
- "{% endif %}".
- "{% if message['role'] == 'user' %}".
- "{{ bos_token + '[INST] ' + content.strip() + ' [/INST]' }}".
- "{% elif message['role'] == 'system' %}".
- "{{ '<>\\n' + content.strip() + '\\n<>\\n\\n' }}".
- "{% elif message['role'] == 'assistant' %}".
- "{{ ' ' + content.strip() + ' ' + eos_token }}".
- "{% endif %}".
+ $chatTemplate = "{% if messages[0]['role'] == 'system' %}" .
+ "{% set loop_messages = messages[1:] %}" .
+ "{% set system_message = messages[0]['content'] %}" .
+ "{% elif USE_DEFAULT_PROMPT == true and not '<>' in messages[0]['content'] %}" .
+ "{% set loop_messages = messages %}" .
+ "{% set system_message = 'DEFAULT_SYSTEM_MESSAGE' %}" .
+ "{% else %}" .
+ "{% set loop_messages = messages %}" .
+ "{% set system_message = false %}" .
+ "{% endif %}" .
+ "{% if loop_messages|length == 0 and system_message %}" .
+ "{{ bos_token + '[INST] <>\\n' + system_message + '\\n<>\\n\\n [/INST]' }}" .
+ "{% endif %}" .
+ "{% for message in loop_messages %}" .
+ "{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}" .
+ "{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}" .
+ "{% endif %}" .
+ "{% if loop.index0 == 0 and system_message != false %}" .
+ "{% set content = '<>\\n' + system_message + '\\n<>\\n\\n' + message['content'] %}" .
+ "{% else %}" .
+ "{% set content = message['content'] %}" .
+ "{% endif %}" .
+ "{% if message['role'] == 'user' %}" .
+ "{{ bos_token + '[INST] ' + content.strip() + ' [/INST]' }}" .
+ "{% elif message['role'] == 'system' %}" .
+ "{{ '<>\\n' + content.strip() + '\\n<>\\n\\n' }}" .
+ "{% elif message['role'] == 'assistant' %}" .
+ "{{ ' ' + content.strip() + ' ' + eos_token }}" .
+ "{% endif %}" .
"{% endfor %}";
$chatTemplate = str_replace('USE_DEFAULT_PROMPT', 'true', $chatTemplate);
@@ -173,7 +173,7 @@
$tokenizer = AutoTokenizer::fromPretrained('Xenova/bert-base-uncased');
// Expected to throw error if jagged array
- expect(fn () => $tokenizer->tokenize($inputs))->toThrow('Unable to create tensor');
+ expect(fn() => $tokenizer->tokenize($inputs))->toThrow('Unable to create tensor');
// Truncation
['input_ids' => $inputIds, 'attention_mask' => $attentionMask, 'token_type_ids' => $tokenTypeIds] = $tokenizer