diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f27772c..c282f6f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,9 +79,6 @@ jobs: - name: Install Dependencies run: composer install - - name: Static Analysis - run: composer analyze - - name: Unit Tests run: composer test diff --git a/AGENTS.md b/AGENTS.md index 2c651ec..f15aab9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -17,8 +17,8 @@ Guidance for AI coding agents contributing to **Tensor** — a scientific-comput ## Environment -- PHP **8.1+** (CI matrix is 8.1 → 8.5). `composer.json` declares `>=1.0`. -- Dev tooling is installed as Composer dev dependencies (PHPStan, php-cs-fixer, phpunit, phpbench, Zephir). +- PHP **8.1+** (CI matrix is 8.1 → 8.5). `composer.json` declares `>=8.1`. +- Dev tooling is installed as Composer dev dependencies (php-cs-fixer, phpunit, phpbench, Zephir). - Compiling the extension additionally needs a C compiler, GFortran, `phpize`, OpenBLAS dev headers, LAPACKE, and re2c (see README for per-OS install commands). ## Commands @@ -29,20 +29,18 @@ All are Composer scripts (see `composer.json`): | --- | --- | | Install deps | `composer install` | | Validate manifest | `composer validate` | -| Static analysis | `composer analyze` (PHPStan level 8 over `tests`, `benchmarks`) | | Run tests | `composer test` (PHPUnit, test suite `Base`; requires the extension to be loaded) | | Check style | `composer check` (php-cs-fixer, dry-run; sets `PHP_CS_FIXER_IGNORE_ENV=1`) | | Fix style | `composer fix` | | Full build | `composer build` = validate → install → analyze → test → check | | Benchmarks | `composer benchmark` (requires the extension to be loaded) | -| Compile extension | `composer compile` = zephir generate → `php build-ext` → zephir compile | +| Compile extension | `composer compile` = zephir generate → zephir compile | | Clean generated extension | `composer clean` (zephir fullclean) | **Recommended loop before submitting a change:** ```sh composer install -composer analyze composer test composer fix ``` @@ -52,12 +50,11 @@ composer fix ## Conventions to follow - **Coding style** is governed by `.php-cs-fixer.dist.php` (extends `@PSR2`). Highlights: single quotes, short array syntax, compact nullable type hints, pre-increment, ordered class elements, trimmed/multi-line phpdoc, `echo` over `print`. Rather than memorize the rule set, run `composer fix`. -- **Static analysis is required.** New code must pass PHPStan level 8 (`composer analyze`). Keep types accurate; the codebase uses docblock generics like `list` and `int<0,max>`. - **Testing guidance** (from `CONTRIBUTING.md`): - New functionality ships with a matching unit test in `tests/`. - Bug fixes ship with a passing test that would have reproduced the bug beforehand. - Tests target public methods and cover edge cases / invalid input. -- **Documentation & changelog:** update docs if behavior changes, and add a `CHANGELOG.md` entry for user-facing changes. +- **Documentation:** update docs if behavior changes. - **PHPDoc:** classes use `@category` / `@package` / `@author` blocks; methods carry param and return annotations. Use `@var list` for element arrays. - **Exceptions** are typed under `Tensor\Exceptions` (e.g. `InvalidArgumentException`, `DimensionalityMismatch`, `RuntimeException`). Use the existing ones rather than `Exception`. - **Math is float-only.** Values stored/computed as `float`; don't introduce integer-only branches. When adding a new operation, mirror it across the `Tensor` sub-interfaces (`Arithmetic`, `Comparable`, `Algebraic`, `Trigonometric`, `Statistical`, `Special`). @@ -70,16 +67,16 @@ Every public method a new `tensor/` class adds typically routes into the C backi 1. Update the Zephir class in `tensor/`. 2. Add/adjust the matching `optimizers/TensorOptimizer.php` if it is a callable that the extension should route into C. 3. Ensure the underlying C implementation exists under `ext/include/*.c` and is linked (already wired in `config.json` `extra-sources`). -4. Bump the version in both `config.json` and `package.xml` if this is a released change, and record it in `CHANGELOG.md`. +4. Bump the version in both `config.json` if this is a released change, and record it in `CHANGELOG.md`. Do **not** hand-edit the generated C in `ext/` (files like `*.dep`, `*.lo`, `*.o`, `Makefile*`, `config.h`). They are produced by `composer compile`. Hand-written logic belongs in `ext/include/*.c`. ## Working verification paths -To run the tests against the locally compiled extension, load the built shared object. For example: +An installed TEnsor extension will override any new changes. To run the tests against the locally compiled extension, load the built shared object. For example: ```sh -php -n -d extension=$PWD/ext/modules/tensor.so vendor/bin/phpunit ... +php -n -d extension=$PWD/ext/modules/tensor_ext.so extension=iconv -d extension=mbstring -d extension=tokenizer -d extension=dom -d extension=xml -d extension=ctype -d extension=xmlwriter vendor/bin/phpunit ... ``` If a system-installed `tensor` extension is already enabled, you can rely on it instead of building locally. diff --git a/CHANGELOG.md b/CHANGELOG.md index 764ede1..14d77b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Change Log -- 3.1.1 - - Just triggering the first Packagist release +- 4.0.0 + - Speed up `Vector::fromArray()` and `Matrix::fromArray()` by eliminating intermediate array copies - 3.1.0 - Implemented the singular value decomposition (SVD) in the extension diff --git a/benchmarks/Arithmetic/ColumnVectorMatrixDivideBench.php b/benchmarks/Arithmetic/ColumnVectorMatrixDivideBench.php new file mode 100644 index 0000000..4a21214 --- /dev/null +++ b/benchmarks/Arithmetic/ColumnVectorMatrixDivideBench.php @@ -0,0 +1,40 @@ +a = ColumnVector::uniform(1000); + + $this->b = Matrix::uniform(1000, 1000); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("seconds", precision=3) + */ + public function divide() : void + { + $this->a->divide($this->b); + } +} diff --git a/benchmarks/Arithmetic/MatrixColumnVectorDivideBench.php b/benchmarks/Arithmetic/MatrixColumnVectorDivideBench.php new file mode 100644 index 0000000..6c2dc2b --- /dev/null +++ b/benchmarks/Arithmetic/MatrixColumnVectorDivideBench.php @@ -0,0 +1,40 @@ +a = Matrix::uniform(1000, 1000); + + $this->b = ColumnVector::uniform(1000); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("seconds", precision=3) + */ + public function divide() : void + { + $this->a->divide($this->b); + } +} diff --git a/benchmarks/Arithmetic/MatrixColumnVectorSubtractBench.php b/benchmarks/Arithmetic/MatrixColumnVectorSubtractBench.php new file mode 100644 index 0000000..21e3b13 --- /dev/null +++ b/benchmarks/Arithmetic/MatrixColumnVectorSubtractBench.php @@ -0,0 +1,40 @@ +a = Matrix::uniform(1000, 1000); + + $this->b = ColumnVector::uniform(1000); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("seconds", precision=3) + */ + public function subtract() : void + { + $this->a->subtract($this->b); + } +} diff --git a/benchmarks/Arithmetic/MatrixVectorAddBench.php b/benchmarks/Arithmetic/MatrixVectorAddBench.php new file mode 100644 index 0000000..21db41b --- /dev/null +++ b/benchmarks/Arithmetic/MatrixVectorAddBench.php @@ -0,0 +1,40 @@ +a = Matrix::uniform(1000, 1000); + + $this->b = Vector::uniform(1000); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("seconds", precision=3) + */ + public function add() : void + { + $this->a->add($this->b); + } +} diff --git a/benchmarks/Arithmetic/MatrixVectorDivideBench.php b/benchmarks/Arithmetic/MatrixVectorDivideBench.php new file mode 100644 index 0000000..9d8e4dc --- /dev/null +++ b/benchmarks/Arithmetic/MatrixVectorDivideBench.php @@ -0,0 +1,40 @@ +a = Matrix::uniform(1000, 1000); + + $this->b = Vector::uniform(1000); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("seconds", precision=3) + */ + public function divide() : void + { + $this->a->divide($this->b); + } +} diff --git a/benchmarks/Arithmetic/VectorMatrixMultiplyBench.php b/benchmarks/Arithmetic/VectorMatrixMultiplyBench.php new file mode 100644 index 0000000..082ccdf --- /dev/null +++ b/benchmarks/Arithmetic/VectorMatrixMultiplyBench.php @@ -0,0 +1,40 @@ +a = Vector::uniform(1000); + + $this->b = Matrix::uniform(1000, 1000); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("seconds", precision=3) + */ + public function multiply() : void + { + $this->a->multiplyMatrix($this->b); + } +} diff --git a/benchmarks/Buffer/TensorBufferBench.php b/benchmarks/Buffer/TensorBufferBench.php new file mode 100644 index 0000000..221eb74 --- /dev/null +++ b/benchmarks/Buffer/TensorBufferBench.php @@ -0,0 +1,214 @@ + + */ + protected $chunkLength; + + /** + * @var int + */ + protected $times; + + /** + * @var TensorBuffer + */ + protected $concatOther; + + public function setUp() : void + { + $a = []; + + for ($i = 0; $i < 10000; ++$i) { + $a[] = ($i * 31) % 10000; + } + + $this->buffer = new TensorBuffer(Buffer::fromArray($a)); + $this->concatOther = new TensorBuffer(Buffer::fromArray($a)); + + $this->offset = 500; + $this->length = 2500; + $this->stride = 3; + $this->chunkLength = 100; + $this->times = 10; + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function sort() : void + { + $this->buffer->sort(); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function sortNative() : void + { + $a = $this->buffer->toArray(); + + sort($a); + + $this->buffer = new TensorBuffer(Buffer::fromArray($a)); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function slice() : void + { + $this->buffer->slice($this->offset, $this->length); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function sliceNative() : void + { + $a = $this->buffer->toArray(); + + $a = array_slice($a, $this->offset, $this->length); + + new TensorBuffer(Buffer::fromArray($a)); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function sliceStrided() : void + { + $this->buffer->sliceStrided($this->offset, $this->length, $this->stride); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function sliceStridedNative() : void + { + $a = $this->buffer->toArray(); + + $b = []; + + for ($i = $this->offset; $i < $this->offset + $this->length * $this->stride; $i += $this->stride) { + $b[] = $a[$i]; + } + + new TensorBuffer(Buffer::fromArray($b)); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function concat() : void + { + $this->buffer->concat([$this->concatOther]); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function concatNative() : void + { + $a = $this->buffer->toArray(); + $b = $this->concatOther->toArray(); + + new TensorBuffer(Buffer::fromArray(array_merge($a, $b))); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function split() : void + { + $this->buffer->split($this->chunkLength); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + * @return array> + */ + public function splitNative() : array + { + return array_chunk($this->buffer->toArray(), $this->chunkLength); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function repeat() : void + { + $this->buffer->repeat($this->times); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function repeatNative() : void + { + $a = $this->buffer->toArray(); + + $b = []; + + for ($i = 0; $i < $this->times; ++$i) { + $b = array_merge($b, $a); + } + + new TensorBuffer(Buffer::fromArray($b)); + } +} diff --git a/benchmarks/Comparison/MatrixColumnVectorEqualBench.php b/benchmarks/Comparison/MatrixColumnVectorEqualBench.php new file mode 100644 index 0000000..1a0d3d6 --- /dev/null +++ b/benchmarks/Comparison/MatrixColumnVectorEqualBench.php @@ -0,0 +1,40 @@ +a = Matrix::uniform(1000, 1000); + + $this->b = ColumnVector::uniform(1000); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("seconds", precision=3) + */ + public function equal() : void + { + $this->a->equal($this->b); + } +} diff --git a/benchmarks/Comparison/MatrixVectorGreaterBench.php b/benchmarks/Comparison/MatrixVectorGreaterBench.php new file mode 100644 index 0000000..61b2d2c --- /dev/null +++ b/benchmarks/Comparison/MatrixVectorGreaterBench.php @@ -0,0 +1,40 @@ +a = Matrix::uniform(1000, 1000); + + $this->b = Vector::uniform(1000); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("seconds", precision=3) + */ + public function greater() : void + { + $this->a->greater($this->b); + } +} diff --git a/benchmarks/Functions/NegateMatrixBench.php b/benchmarks/Functions/NegateMatrixBench.php new file mode 100644 index 0000000..8c5515b --- /dev/null +++ b/benchmarks/Functions/NegateMatrixBench.php @@ -0,0 +1,32 @@ +a = Matrix::uniform(1000, 1000); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("seconds", precision=3) + */ + public function negate() : void + { + $this->a->negate(); + } +} diff --git a/benchmarks/Functions/Rad2DegMatrixBench.php b/benchmarks/Functions/Rad2DegMatrixBench.php new file mode 100644 index 0000000..e8e09d0 --- /dev/null +++ b/benchmarks/Functions/Rad2DegMatrixBench.php @@ -0,0 +1,32 @@ +a = Matrix::uniform(1000, 1000); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("seconds", precision=3) + */ + public function rad2deg() : void + { + $this->a->rad2deg(); + } +} diff --git a/benchmarks/LinearAlgebra/MatrixDotBench.php b/benchmarks/LinearAlgebra/MatrixDotBench.php new file mode 100644 index 0000000..3507831 --- /dev/null +++ b/benchmarks/LinearAlgebra/MatrixDotBench.php @@ -0,0 +1,41 @@ +a = Matrix::uniform(1000, 1000); + + $this->b = Vector::uniform(1000); + } + + /** + * @Subject + * @Iterations(5) + * @Revs(100) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function dot() : void + { + $this->a->dot($this->b); + } +} diff --git a/benchmarks/Random/GaussianVectorBench.php b/benchmarks/Random/GaussianVectorBench.php index d60fe61..2d8e993 100644 --- a/benchmarks/Random/GaussianVectorBench.php +++ b/benchmarks/Random/GaussianVectorBench.php @@ -7,7 +7,7 @@ /** * @Groups({"Random"}) */ -class GaussianMVectorBench +class GaussianVectorBench { /** * @Subject @@ -16,6 +16,6 @@ class GaussianMVectorBench */ public function gaussian() : void { - Vector::gaussian(100000); + Vector::gaussian(250000); } } diff --git a/benchmarks/Statistical/VectorMedianBench.php b/benchmarks/Statistical/VectorMedianBench.php new file mode 100644 index 0000000..c0fd2ae --- /dev/null +++ b/benchmarks/Statistical/VectorMedianBench.php @@ -0,0 +1,32 @@ +a = Vector::uniform(100000); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function median() : void + { + $this->a->median(); + } +} diff --git a/benchmarks/Statistical/VectorPNormBench.php b/benchmarks/Statistical/VectorPNormBench.php new file mode 100644 index 0000000..bdc825e --- /dev/null +++ b/benchmarks/Statistical/VectorPNormBench.php @@ -0,0 +1,52 @@ +a = Vector::uniform(100000); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function p2() : void + { + $this->a->pNorm(2.0); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function p3() : void + { + $this->a->pNorm(3.0); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function p10() : void + { + $this->a->pNorm(10.0); + } +} diff --git a/benchmarks/Statistical/VectorQuantileBench.php b/benchmarks/Statistical/VectorQuantileBench.php new file mode 100644 index 0000000..4852f88 --- /dev/null +++ b/benchmarks/Statistical/VectorQuantileBench.php @@ -0,0 +1,32 @@ +a = Vector::uniform(100000); + } + + /** + * @Subject + * @Iterations(5) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function quantile() : void + { + $this->a->quantile(0.5); + } +} diff --git a/benchmarks/Structural/MatrixFromArrayBench.php b/benchmarks/Structural/MatrixFromArrayBench.php new file mode 100644 index 0000000..29ad375 --- /dev/null +++ b/benchmarks/Structural/MatrixFromArrayBench.php @@ -0,0 +1,54 @@ +a = $a; + } + + /** + * @Subject + * @Iterations(10) + * @OutputTimeUnit("seconds", precision=3) + */ + public function fromArray() : void + { + Matrix::fromArray($this->a); + } + + /** + * @Subject + * @Iterations(10) + * @OutputTimeUnit("seconds", precision=3) + */ + public function fromArrayNoValidate() : void + { + Matrix::fromArray($this->a, false); + } +} diff --git a/benchmarks/Structural/VectorFromArrayBench.php b/benchmarks/Structural/VectorFromArrayBench.php new file mode 100644 index 0000000..4da84fc --- /dev/null +++ b/benchmarks/Structural/VectorFromArrayBench.php @@ -0,0 +1,48 @@ + + */ + protected $a; + + public function setUp() : void + { + $a = []; + + for ($i = 0; $i < 4000000; ++$i) { + $a[] = $i; + } + + $this->a = $a; + } + + /** + * @Subject + * @Iterations(10) + * @OutputTimeUnit("seconds", precision=3) + */ + public function fromArray() : void + { + Vector::fromArray($this->a); + } + + /** + * @Subject + * @Iterations(10) + * @OutputTimeUnit("seconds", precision=3) + */ + public function fromArrayNoValidate() : void + { + Vector::fromArray($this->a, false); + } +} diff --git a/composer.json b/composer.json index d6a855a..8257892 100644 --- a/composer.json +++ b/composer.json @@ -31,11 +31,8 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.0", - "phalcon/zephir": "^1.0", + "phalcon/zephir": "dev-development", "phpbench/phpbench": "^1.0", - "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", "phpunit/phpunit": "^9.0" }, "autoload": { @@ -53,11 +50,9 @@ "build": [ "@composer validate", "@composer install", - "@analyze", "@test", "@check" ], - "analyze": "phpstan analyse -c phpstan.neon --memory-limit=1G", "benchmark": "phpbench run --report=env --report=aggregate", "check": [ "@putenv PHP_CS_FIXER_IGNORE_ENV=1", @@ -68,6 +63,11 @@ "zephir generate", "zephir compile --no-dev" ], + "compile-ci": [ + "zephir generate", + "build-ext", + "zephir compile --no-dev" + ], "install-ext": "zephir install", "fix": "php-cs-fixer fix --config=.php-cs-fixer.dist.php", "test": "phpunit" diff --git a/config.json b/config.json index 4edbf6b..054be19 100644 --- a/config.json +++ b/config.json @@ -4,13 +4,17 @@ "extension-name": "tensor_ext", "description": "Scientific computing for the PHP language.", "author": "The Rubix ML Community", - "version": "3.1.1", + "version": "4.0.0", "verbose": true, "extra-cflags": "-O3", "extra-libs": "-lopenblas -llapacke -lgfortran", "extra-sources": [ "include/arithmetic.c", + "include/buffer.c", "include/comparison.c", + "include/reductions.c", + "include/shape.c", + "include/unary.c", "include/linear_algebra.c", "include/signal_processing.c", "include/settings.c" @@ -20,6 +24,9 @@ { "include": "cblas.h", "code": "openblas_set_num_threads(1)" + }, + { + "code": "extern zend_class_entry *tensor_buffer_ce; extern zend_class_entry *zephir_buffer_ce; tensor_buffer_ce = zephir_buffer_ce;" } ] }, @@ -33,10 +40,7 @@ "constant-folding": true, "static-constant-class-folding": true, "call-gatherer-pass": true, - "check-invalid-reads": false, - "private-internal-methods": false, - "public-internal-methods": false, - "public-internal-functions": true + "check-invalid-reads": false }, "warnings": { "unused-variable": true, @@ -49,5 +53,8 @@ "extra": { "export-classes": false, "indent": "spaces" + }, + "kernel-classes": { + "buffer": true } } diff --git a/docs/ColumnVector.md b/docs/ColumnVector.md index c833145..76795be 100644 --- a/docs/ColumnVector.md +++ b/docs/ColumnVector.md @@ -16,6 +16,7 @@ This page documents only the methods **defined on `ColumnVector`** and how they - Element-wise operations against a `Matrix` broadcast **down the rows** of the matrix (each matrix row is scaled by one vector element), whereas a `Vector` broadcasts **across the columns**. - `transpose()` rotates the column vector into a horizontal `Vector`. - All inherited factory/operators operate on `static`, so they return `ColumnVector` instances where applicable. +- `ColumnVector::fromArray(array $a, bool $validate = true)` is inherited from `Vector` and returns a `ColumnVector` instance directly. ## Dimensionality diff --git a/docs/Matrix.md b/docs/Matrix.md index 9addf5a..3f07235 100644 --- a/docs/Matrix.md +++ b/docs/Matrix.md @@ -17,23 +17,23 @@ Interface methods are implemented by Matrices with **row-wise** semantics: ## Constructors & Factories -### `__construct(array $a, bool $validate = true)` +### `__construct(\Tensor\TensorBuffer $a, int $m, int $n)` -Instantiate a matrix directly. +Instantiate a matrix from a row-major `TensorBuffer` of its elements and its target dimensions. - **Parameters:** - - `$a` — the 2-dimensional element array `array>` - - `$validate` — whether to validate rectangularity and cast elements to floats (default `true`) -- **Throws:** `Tensor\Exceptions\InvalidArgumentException` if rows have unequal column counts -- **Note:** Prefer the factory methods below. + - `$a` — the row-major `TensorBuffer` of elements + - `$m` — number of rows, `$n` — number of columns -### `Matrix::build(array $a = []) : Matrix` +### `Matrix::fromArray(array $a, bool $validate = true) : Matrix` -Factory method to build a new matrix from an array, running validation. +Build a matrix from a PHP array of rows, casting elements to floats. -### `Matrix::quick(array $a = []) : Matrix` - -Build a new matrix foregoing any validation for quicker instantiation. +- **Parameters:** + - `$a` — `array>`, i.e. rows of numeric elements + - `$validate` — whether to validate that every row has the same column count (default `true`) +- **Returns:** `Matrix` +- **Throws:** `Tensor\Exceptions\InvalidArgumentException` if `$a` is not an array of arrays, or (when validating) if rows have unequal column counts ### `Matrix::identity(int $n) : Matrix` @@ -424,6 +424,8 @@ See [Statistical](interfaces/statistical.md) and [Special](interfaces/special.md - `product() : ColumnVector` — calculate the row product of the matrix - `min() : ColumnVector` — minimum of each row - `max() : ColumnVector` — maximum of each row +- `argmin() : ColumnVector` — index of the minimum of each row; ties resolve to the first occurrence +- `argmax() : ColumnVector` — index of the maximum of each row; ties resolve to the first occurrence - `mean() : ColumnVector` — means of each row - `median() : ColumnVector` — median vector of this matrix - `quantile(float $q) : ColumnVector` — q'th quantile of each row (throws `InvalidArgumentException` if `$q` is outside `[0, 1]`) diff --git a/docs/TensorBuffer.md b/docs/TensorBuffer.md new file mode 100644 index 0000000..d9ec500 --- /dev/null +++ b/docs/TensorBuffer.md @@ -0,0 +1,92 @@ +# TensorBuffer + +A decorator that wraps the kernel `Buffer` class and adds higher-level operations such as sorting and slicing. + +- **Namespace:** `Tensor\TensorBuffer` + +## Overview + +The Zephir kernel `Buffer` (`Tensor\Buffer`) is an ordinary refcounted object that stores its elements in one contiguous C array of `double` or `zend_long`. It exposes a minimal PHP API — construction, `fromArray()` / `toArray()`, `count()`, `type()`, `fill()`, and array access — but no sorting or slicing. + +`TensorBuffer` composes a `Buffer` and delegates to it, adding operations that cannot be expressed through the minimal API. Those operations are implemented in C over the buffer's raw element pointers (`qsort`, `memcpy`), so no intermediate PHP array is materialised. + +`sort()` mutates the wrapped buffer in place; `slice()` returns a **new** `TensorBuffer` wrapping a new buffer, leaving the source untouched. + +## Constructors + +### `__construct(Buffer $buffer)` + +Wrap an existing buffer. + +- **Parameters:** `$buffer` — the `Tensor\Buffer` to decorate + +## Methods + +### `asBuffer() : Buffer` + +Return the underlying buffer being decorated. + +### `count() : int` + +Return the number of elements in the buffer. + +### `type() : int` + +Return the element type of the buffer — `Buffer::TYPE_DOUBLE` or `Buffer::TYPE_LONG`. + +### `toArray() : array` + +Return the buffer as a PHP array. + +### `get(int $index) : mixed` + +Return the element at the given index. + +- **Throws:** `Tensor\Exceptions\RuntimeException` (or `OutOfBoundsException` on PHP 8.4+) if the index is out of range + +### `set(int $index, mixed $value) : void` + +Set the element at the given index, cast to the buffer's element type. + +- **Throws:** `Tensor\Exceptions\RuntimeException` (or `OutOfBoundsException` on PHP 8.4+) if the index is out of range + +### `sort(bool $ascending = true) : void` + +Sort the buffer **in place**. + +- **Parameters:** `$ascending` — sort ascending when `true`, descending when `false` (default `true`) + +### `slice(int $offset, int $length) : TensorBuffer` + +Return a new decorator wrapping a new buffer of `$length` elements copied from `buffer[$offset .. $offset + $length - 1]`. The source buffer is left unchanged. + +- **Throws:** `Tensor\Exceptions\InvalidArgumentException` if `$offset` or `$length` is negative, or the requested range exceeds the buffer size + +### `sliceStrided(int $offset, int $length, int $stride) : TensorBuffer` + +Return a new decorator wrapping a new buffer of `$length` elements gathered at `$stride` intervals from `buffer[$offset]` — i.e. `buffer[$offset + i * $stride]` for `i` in `0..length - 1`. The source buffer is left unchanged. Supports gathering rows, columns, and diagonals from a flat matrix layout. + +- **Throws:** `Tensor\Exceptions\InvalidArgumentException` if `$offset` or `$length` is negative, `$stride` is less than 1, or the requested range exceeds the buffer size + +### `concat(TensorBuffer[] $buffers) : TensorBuffer` + +Return a new decorator wrapping a new buffer containing a copy of this buffer followed by the contents of each buffer in `$buffers`, in order. The source buffers are left unchanged. Passing an empty list returns a copy of this buffer. + +- **Throws:** `InvalidArgumentException` if an element of `$buffers` is not a `TensorBuffer` of the same element type + +### `split(int $chunkLength) : TensorBuffer[]` + +Return an array of new decorators splitting this buffer into consecutive chunks of up to `$chunkLength` elements each. The final chunk may be shorter. The source buffer is left unchanged. + +- **Throws:** `Tensor\Exceptions\InvalidArgumentException` if `$chunkLength` is less than 1 + +### `repeat(int $times) : TensorBuffer` + +Return a new decorator wrapping a new buffer containing the elements of this buffer repeated `$times` times. The source buffer is left unchanged. + +- **Throws:** `Tensor\Exceptions\InvalidArgumentException` if `$times` is less than 1 + +## Notes + +- `sort()`, `slice()`, `sliceStrided()`, `concat()`, `split()`, and `repeat()` are implemented in C (`ext/include/buffer.c`) and route through this class's optimizer calls, operating directly on the buffer's raw pointer. +- Both element kinds (`TYPE_DOUBLE` and `TYPE_LONG`) are supported; `slice()`, `sliceStrided()`, `concat()`, `split()`, and `repeat()` preserve the source kind. \ No newline at end of file diff --git a/docs/Vector.md b/docs/Vector.md index 45cd0ef..37b5ce1 100644 --- a/docs/Vector.md +++ b/docs/Vector.md @@ -14,28 +14,21 @@ Interface methods are implemented by Vectors with scalar-level semantics — red ## Constructors & Factories -### `__construct(array $a, bool $validate = true)` +### `__construct(\Tensor\TensorBuffer $a)` -Instantiate a vector directly. +Instantiate a vector from a `TensorBuffer` holding its elements. -- **Parameters:** - - `$a` — the 1-dimensional element array `(int|float)[]` - - `$validate` — whether to validate and cast elements to floats (default `true`) -- **Note:** Prefer the factory methods below. - -### `Vector::build(array $a = [])` - -Factory method to build a new vector from an array, running validation. +- **Parameters:** `$a` — the `TensorBuffer` of elements -- **Parameters:** `$a` — `(int|float)[]` -- **Returns:** `mixed` (a `Vector`/`static`) +### `Vector::fromArray(array $a, bool $validate = true) : Vector` -### `Vector::quick(array $a = [])` +Build a vector from a flat PHP array of numeric elements, casting each value to a float. -Build a vector foregoing any validation for quicker instantiation. - -- **Parameters:** `$a` — `(int|float)[]` -- **Returns:** `mixed` (a `Vector`/`static`) +- **Parameters:** + - `$a` — `list`, a flat array of numeric elements + - `$validate` — whether to reject nested arrays (default `true`) +- **Returns:** `Vector` (or `ColumnVector` when called on `Tensor\ColumnVector`) +- **Throws:** `Tensor\Exceptions\InvalidArgumentException` if `$a` is not a flat array of numeric elements (i.e. contains a nested array, when `$validate` is `true`) ### `Vector::zeros(int $n) : Vector` @@ -335,6 +328,8 @@ See [Statistical](interfaces/statistical.md) and [Special](interfaces/special.md - `product() : float` — the product of the vector - `min() : float` — the minimum element - `max() : float` — the maximum element +- `argmin() : int` — the index of the minimum element; ties resolve to the first occurrence +- `argmax() : int` — the index of the maximum element; ties resolve to the first occurrence - `mean() : float` — the mean of the vector - `median() : float` — the median of the vector - `quantile(float $q) : float` — the q'th quantile (throws `InvalidArgumentException` if `$q` is outside `[0, 1]`) diff --git a/docs/getting-started.md b/docs/getting-started.md index e94f884..2afa6fa 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -42,13 +42,13 @@ use Tensor\Matrix; use Tensor\Vector; // Build a 2 x 3 matrix. -$a = Matrix::build([ +$a = Matrix::fromArray([ [1.0, 2.0, 3.0], [4.0, 5.0, 6.0], ]); // Build a 3 x 2 matrix. -$b = Matrix::build([ +$b = Matrix::fromArray([ [7.0, 8.0], [9.0, 10.0], [11.0, 12.0], diff --git a/docs/index.md b/docs/index.md index bce0b0c..3377001 100644 --- a/docs/index.md +++ b/docs/index.md @@ -10,6 +10,8 @@ Tensor \ ├── Vector ├── ColumnVector (extends Vector) ├── Matrix +├── Buffer (kernel class) +├── TensorBuffer (decorates Buffer) │ ├── ArrayLike (interface) ├── Arithmetic (interface) @@ -36,6 +38,7 @@ Tensor \ | [Vector](Vector.md) | A one dimensional (rank 1) tensor with integer and/or floating point elements. | | [ColumnVector](ColumnVector.md) | A vertical one dimensional tensor; extends `Vector` with matrix-facing operations. | | [Matrix](Matrix.md) | A two dimensional (rank 2) tensor with integer and/or floating point elements. | +| [TensorBuffer](TensorBuffer.md) | A decorator that wraps the kernel `Buffer` class and adds sorting, slicing, reductions, and structural operations. | ## Interfaces diff --git a/docs/interfaces/special.md b/docs/interfaces/special.md index 684e627..89b73e4 100644 --- a/docs/interfaces/special.md +++ b/docs/interfaces/special.md @@ -13,7 +13,7 @@ interface Special ``` - For `Vector`, reductions return a `float` scalar. -- For `Matrix`, the reductions `sum`, `product`, `min`, and `max` operate per-row and return a `ColumnVector`; clipping returns a new `Matrix` of the same shape. +- For `Matrix`, the reductions `sum`, `product`, `min`, `max`, `argmin`, and `argmax` operate per-row and return a `ColumnVector`; clipping returns a new `Matrix` of the same shape. ## Methods @@ -33,6 +33,14 @@ Return the minimum of the tensor. Return the maximum of the tensor. +### `argmin() : mixed` + +Return the index of the minimum of the tensor. For a `Vector`, this is an `int`; for a `Matrix`, this is a `ColumnVector` of the per-row minimum indices. Ties resolve to the first occurrence. + +### `argmax() : mixed` + +Return the index of the maximum of the tensor. For a `Vector`, this is an `int`; for a `Matrix`, this is a `ColumnVector` of the per-row maximum indices. Ties resolve to the first occurrence. + ### `clip(float $min, float $max) : mixed` Clip the tensor to be between the given minimum and maximum. diff --git a/ext/config.m4 b/ext/config.m4 index 92d193c..e77b81a 100644 --- a/ext/config.m4 +++ b/ext/config.m4 @@ -9,7 +9,7 @@ if test "$PHP_TENSOR_EXT" = "yes"; then fi AC_DEFINE(HAVE_TENSOR_EXT, 1, [Whether you have Tensor_ext]) - tensor_ext_sources="tensor_ext.c kernel/main.c kernel/memory.c kernel/exception.c kernel/debug.c kernel/backtrace.c kernel/object.c kernel/array.c kernel/string.c kernel/fcall.c kernel/require.c kernel/file.c kernel/operators.c kernel/math.c kernel/concat.c kernel/variables.c kernel/filter.c kernel/iterator.c kernel/time.c kernel/exit.c kernel/generator.c tensor/algebraic.zep.c + tensor_ext_sources="tensor_ext.c kernel/main.c kernel/memory.c kernel/exception.c kernel/debug.c kernel/backtrace.c kernel/object.c kernel/array.c kernel/string.c kernel/fcall.c kernel/require.c kernel/file.c kernel/operators.c kernel/math.c kernel/concat.c kernel/variables.c kernel/filter.c kernel/iterator.c kernel/time.c kernel/exit.c kernel/generator.c kernel/buffer.c tensor/algebraic.zep.c tensor/arithmetic.zep.c tensor/arraylike.zep.c tensor/comparable.zep.c @@ -31,8 +31,13 @@ if test "$PHP_TENSOR_EXT" = "yes"; then tensor/matrix.zep.c tensor/reductions/ref.zep.c tensor/reductions/rref.zep.c - tensor/settings.zep.c include/arithmetic.c + tensor/settings.zep.c + tensor/tensorbuffer.zep.c include/arithmetic.c + include/buffer.c include/comparison.c + include/reductions.c + include/shape.c + include/unary.c include/linear_algebra.c include/signal_processing.c include/settings.c" @@ -63,21 +68,19 @@ if test "$PHP_TENSOR_EXT" = "yes"; then [[#include "php_config.h"]] ) - AC_CHECK_DECL( - [HAVE_JSON], + dnl php-src stopped declaring HAVE_JSON in php_config.h in 8.4, so probing + dnl for it left ZEPHIR_USE_PHP_JSON undefined on 8.4 and 8.5 even though + dnl ext/json has been built in unconditionally since 8.0 -- which quietly + dnl demoted zephir_json_encode() to calling the userland json_encode() + dnl function. Probe for the header, which is what the code actually needs. + AC_CHECK_HEADERS( + [ext/json/php_json.h], [ - AC_CHECK_HEADERS( - [ext/json/php_json.h], - [ - PHP_ADD_EXTENSION_DEP([tensor_ext], [json]) - AC_DEFINE([ZEPHIR_USE_PHP_JSON], [1], [Whether PHP json extension is present at compile time]) - ], - , - [[#include "main/php.h"]] - ) + PHP_ADD_EXTENSION_DEP([tensor_ext], [json]) + AC_DEFINE([ZEPHIR_USE_PHP_JSON], [1], [Whether PHP json extension is present at compile time]) ], , - [[#include "php_config.h"]] + [[#include "main/php.h"]] ) CPPFLAGS=$old_CPPFLAGS diff --git a/ext/config.w32 b/ext/config.w32 index a5a354d..018e89d 100644 --- a/ext/config.w32 +++ b/ext/config.w32 @@ -2,15 +2,15 @@ ARG_ENABLE("tensor_ext", "enable tensor_ext", "no"); if (PHP_TENSOR_EXT != "no") { EXTENSION("tensor_ext", "tensor_ext.c", null, "-I"+configure_module_dirname); - ADD_SOURCES(configure_module_dirname + "/kernel", "main.c memory.c exception.c debug.c backtrace.c object.c array.c string.c fcall.c require.c file.c operators.c math.c concat.c variables.c filter.c iterator.c exit.c time.c generator.c", "tensor_ext"); + ADD_SOURCES(configure_module_dirname + "/kernel", "main.c memory.c exception.c debug.c backtrace.c object.c array.c string.c fcall.c require.c file.c operators.c math.c concat.c variables.c filter.c iterator.c exit.c time.c generator.c buffer.c", "tensor_ext"); /* PCRE is always included on WIN32 */ AC_DEFINE("ZEPHIR_USE_PHP_PCRE", 1, "Whether PHP pcre extension is present at compile time"); if (PHP_JSON != "no") { ADD_EXTENSION_DEP("tensor_ext", "json"); AC_DEFINE("ZEPHIR_USE_PHP_JSON", 1, "Whether PHP json extension is present at compile time"); } - ADD_SOURCES(configure_module_dirname + "/include", "arithmetic.c comparison.c linear_algebra.c signal_processing.c settings.c", "tensor_ext"); - ADD_SOURCES(configure_module_dirname + "/tensor", "algebraic.zep.c arithmetic.zep.c arraylike.zep.c comparable.zep.c special.zep.c statistical.zep.c trigonometric.zep.c tensor.zep.c vector.zep.c columnvector.zep.c matrix.zep.c settings.zep.c", "tensor_ext"); + ADD_SOURCES(configure_module_dirname + "/include", "arithmetic.c buffer.c comparison.c reductions.c shape.c unary.c linear_algebra.c signal_processing.c settings.c", "tensor_ext"); + ADD_SOURCES(configure_module_dirname + "/tensor", "algebraic.zep.c arithmetic.zep.c arraylike.zep.c comparable.zep.c special.zep.c statistical.zep.c trigonometric.zep.c tensor.zep.c vector.zep.c columnvector.zep.c matrix.zep.c settings.zep.c tensorbuffer.zep.c", "tensor_ext"); ADD_SOURCES(configure_module_dirname + "/tensor/exceptions", "tensorexception.zep.c invalidargumentexception.zep.c runtimeexception.zep.c dimensionalitymismatch.zep.c singularmatrix.zep.c", "tensor_ext"); ADD_SOURCES(configure_module_dirname + "/tensor/decompositions", "cholesky.zep.c eigen.zep.c lu.zep.c svd.zep.c", "tensor_ext"); ADD_SOURCES(configure_module_dirname + "/tensor/reductions", "ref.zep.c rref.zep.c", "tensor_ext"); diff --git a/ext/include/arithmetic.c b/ext/include/arithmetic.c index 39792dc..38eda28 100644 --- a/ext/include/arithmetic.c +++ b/ext/include/arithmetic.c @@ -3,272 +3,509 @@ #endif #include +#include +#include #include "kernel/operators.h" +#include "php_ext.h" +#include "kernel/buffer.h" +#include "include/buffer.h" void tensor_multiply(zval * return_value, zval * a, zval * b) { - unsigned int i; - double product; - zval c; + zend_long i; + zend_long na = 0, nb = 0; + int ok_a = 0, ok_b = 0; + + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); + + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + if (UNEXPECTED(na != nb)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must be the same length.")); + return; + } - unsigned int n = zend_array_count(aa); + zval c; - array_init_size(&c, n); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - for (i = 0; i < n; ++i) { - product = zephir_get_doubleval(zend_hash_index_find(aa, i)) * zephir_get_doubleval(zend_hash_index_find(ab, i)); + double * vc = zephir_buffer_doubles(&c); - add_next_index_double(&c, product); - } + for (i = 0; i < na; ++i) { + vc[i] = va[i] * vb[i]; + } - RETVAL_ARR(Z_ARR(c)); + zval_ptr_dtor(&c); } void tensor_divide(zval * return_value, zval * a, zval * b) { - unsigned int i; - double quotient; - zval c; + zend_long i; + zend_long na = 0, nb = 0; + int ok_a = 0, ok_b = 0; + + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } - unsigned int n = zend_array_count(aa); + if (UNEXPECTED(na != nb)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must be the same length.")); + return; + } - array_init_size(&c, n); + zval c; + + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - for (i = 0; i < n; ++i) { - quotient = zephir_get_doubleval(zend_hash_index_find(aa, i)) / zephir_get_doubleval(zend_hash_index_find(ab, i)); + double * vc = zephir_buffer_doubles(&c); - add_next_index_double(&c, quotient); - } + for (i = 0; i < na; ++i) { + vc[i] = va[i] / vb[i]; + } - RETVAL_ARR(Z_ARR(c)); + zval_ptr_dtor(&c); } void tensor_add(zval * return_value, zval * a, zval * b) { - unsigned int i; - double sum; - zval c; + zend_long i; + zend_long na = 0, nb = 0; + int ok_a = 0, ok_b = 0; - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); - unsigned int n = zend_array_count(aa); + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } + + if (UNEXPECTED(na != nb)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must be the same length.")); + return; + } + + zval c; - array_init_size(&c, n); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - for (i = 0; i < n; ++i) { - sum = zephir_get_doubleval(zend_hash_index_find(aa, i)) + zephir_get_doubleval(zend_hash_index_find(ab, i)); + double * vc = zephir_buffer_doubles(&c); - add_next_index_double(&c, sum); - } + for (i = 0; i < na; ++i) { + vc[i] = va[i] + vb[i]; + } - RETVAL_ARR(Z_ARR(c)); + zval_ptr_dtor(&c); } void tensor_subtract(zval * return_value, zval * a, zval * b) { - unsigned int i; - double difference; - zval c; + zend_long i; + zend_long na = 0, nb = 0; + int ok_a = 0, ok_b = 0; + + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); + + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + if (UNEXPECTED(na != nb)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must be the same length.")); + return; + } - unsigned int n = zend_array_count(aa); + zval c; - array_init_size(&c, n); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - for (i = 0; i < n; ++i) { - difference = zephir_get_doubleval(zend_hash_index_find(aa, i)) - zephir_get_doubleval(zend_hash_index_find(ab, i)); + double * vc = zephir_buffer_doubles(&c); - add_next_index_double(&c, difference); - } + for (i = 0; i < na; ++i) { + vc[i] = va[i] - vb[i]; + } - RETVAL_ARR(Z_ARR(c)); + zval_ptr_dtor(&c); } void tensor_pow(zval * return_value, zval * a, zval * b) { - unsigned int i; - double power; - zval c; + zend_long i; + zend_long na = 0, nb = 0; + int ok_a = 0, ok_b = 0; - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); - unsigned int n = zend_array_count(aa); + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } - array_init_size(&c, n); + if (UNEXPECTED(na != nb)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must be the same length.")); + return; + } - for (i = 0; i < n; ++i) { - power = pow(zephir_get_doubleval(zend_hash_index_find(aa, i)), zephir_get_doubleval(zend_hash_index_find(ab, i))); + zval c; - add_next_index_double(&c, power); - } + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - RETVAL_ARR(Z_ARR(c)); + double * vc = zephir_buffer_doubles(&c); + + for (i = 0; i < na; ++i) { + vc[i] = pow(va[i], vb[i]); + } + + zval_ptr_dtor(&c); } void tensor_mod(zval * return_value, zval * a, zval * b) { - unsigned int i; - zval modulus; - zval c; + zend_long i; + zend_long na = 0, nb = 0; + int ok_a = 0, ok_b = 0; + + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); + + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + if (UNEXPECTED(na != nb)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must be the same length.")); + return; + } - unsigned int n = zend_array_count(aa); + zval c; - array_init_size(&c, n); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - for (i = 0; i < n; ++i) { - mod_function(&modulus, zend_hash_index_find(aa, i), zend_hash_index_find(ab, i)); + double * vc = zephir_buffer_doubles(&c); - add_next_index_zval(&c, &modulus); - } + for (i = 0; i < na; ++i) { + vc[i] = fmod(va[i], vb[i]); + } - RETVAL_ARR(Z_ARR(c)); + zval_ptr_dtor(&c); } void tensor_multiply_scalar(zval * return_value, zval * a, zval * b) { - unsigned int i; - double product; - zval c; + zend_long i; + zend_long na = 0; + int ok_a = 0; + + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); - zend_array * aa = Z_ARR_P(a); + if (UNEXPECTED(!ok_a)) { + return; + } - double ab = zephir_get_doubleval(b); + double ab = zephir_get_doubleval(b); - unsigned int n = zend_array_count(aa); + zval c; - array_init_size(&c, n); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - for (i = 0; i < n; ++i) { - product = zephir_get_doubleval(zend_hash_index_find(aa, i)) * ab; + double * vc = zephir_buffer_doubles(&c); - add_next_index_double(&c, product); - } + for (i = 0; i < na; ++i) { + vc[i] = va[i] * ab; + } - RETVAL_ARR(Z_ARR(c)); + zval_ptr_dtor(&c); } void tensor_divide_scalar(zval * return_value, zval * a, zval * b) { - unsigned int i; - double quotient; - zval c; + zend_long i; + zend_long na = 0; + int ok_a = 0; + + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); - zend_array * aa = Z_ARR_P(a); + if (UNEXPECTED(!ok_a)) { + return; + } - double ab = zephir_get_doubleval(b); + double ab = zephir_get_doubleval(b); - unsigned int n = zend_array_count(aa); + zval c; - array_init_size(&c, n); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - for (i = 0; i < n; ++i) { - quotient = zephir_get_doubleval(zend_hash_index_find(aa, i)) / ab; + double * vc = zephir_buffer_doubles(&c); - add_next_index_double(&c, quotient); - } + for (i = 0; i < na; ++i) { + vc[i] = va[i] / ab; + } - RETVAL_ARR(Z_ARR(c)); + zval_ptr_dtor(&c); } void tensor_add_scalar(zval * return_value, zval * a, zval * b) { - unsigned int i; - double sum; - zval c; + zend_long i; + zend_long na = 0; + int ok_a = 0; + + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); - zend_array * aa = Z_ARR_P(a); + if (UNEXPECTED(!ok_a)) { + return; + } - double ab = zephir_get_doubleval(b); + double ab = zephir_get_doubleval(b); - unsigned int n = zend_array_count(aa); + zval c; - array_init_size(&c, n); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - for (i = 0; i < n; ++i) { - sum = zephir_get_doubleval(zend_hash_index_find(aa, i)) + ab; + double * vc = zephir_buffer_doubles(&c); - add_next_index_double(&c, sum); - } + for (i = 0; i < na; ++i) { + vc[i] = va[i] + ab; + } - RETVAL_ARR(Z_ARR(c)); + zval_ptr_dtor(&c); } void tensor_subtract_scalar(zval * return_value, zval * a, zval * b) { - unsigned int i; - double difference; - zval c; + zend_long i; + zend_long na = 0; + int ok_a = 0; - zend_array * aa = Z_ARR_P(a); + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); - double ab = zephir_get_doubleval(b); + if (UNEXPECTED(!ok_a)) { + return; + } - unsigned int n = zend_array_count(aa); + double ab = zephir_get_doubleval(b); - array_init_size(&c, n); + zval c; - for (i = 0; i < n; ++i) { - difference = zephir_get_doubleval(zend_hash_index_find(aa, i)) - ab; + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - add_next_index_double(&c, difference); - } + double * vc = zephir_buffer_doubles(&c); - RETVAL_ARR(Z_ARR(c)); + for (i = 0; i < na; ++i) { + vc[i] = va[i] - ab; + } + + zval_ptr_dtor(&c); } void tensor_pow_scalar(zval * return_value, zval * a, zval * b) { - unsigned int i; - double power; - zval c; + zend_long i; + zend_long na = 0; + int ok_a = 0; + + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); - zend_array * aa = Z_ARR_P(a); + if (UNEXPECTED(!ok_a)) { + return; + } - double ab = zephir_get_doubleval(b); + double ab = zephir_get_doubleval(b); - unsigned int n = zend_array_count(aa); + zval c; - array_init_size(&c, n); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - for (i = 0; i < n; ++i) { - power = pow(zephir_get_doubleval(zend_hash_index_find(aa, i)), ab); + double * vc = zephir_buffer_doubles(&c); - add_next_index_double(&c, power); - } + for (i = 0; i < na; ++i) { + vc[i] = pow(va[i], ab); + } - RETVAL_ARR(Z_ARR(c)); + zval_ptr_dtor(&c); } void tensor_mod_scalar(zval * return_value, zval * a, zval * b) { - unsigned int i; - zval modulus; + zend_long i; + zend_long na = 0; + int ok_a = 0; + + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + + if (UNEXPECTED(!ok_a)) { + return; + } + + double ab = zephir_get_doubleval(b); + zval c; - zend_array * aa = Z_ARR_P(a); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - unsigned int n = zend_array_count(aa); + double * vc = zephir_buffer_doubles(&c); - array_init_size(&c, n); + for (i = 0; i < na; ++i) { + vc[i] = fmod(va[i], ab); + } - for (i = 0; i < n; ++i) { - mod_function(&modulus, zend_hash_index_find(aa, i), b); + zval_ptr_dtor(&c); +} - add_next_index_zval(&c, &modulus); - } +/* Scalar operation applied to every element of a matrix row. The matrix is + * wrapped up in `a` (m * n doubles in row-major order) and the column vector + * in `b` (m doubles) so that element (i, j) of the result is op(a[i * n + j], + * b[i]). Each operation expands into its own dedicated pair of loops so that + * the optimizer can vectorize the elementwise mapping instead of being blocked + * by an indirect call. */ + +#define TENSOR_COL_APPLY(name, expr) \ +void tensor_##name(zval * return_value, zval * a, zval * b, zval * n_zval) \ +{ \ + zend_long n = 0, m = 0, total = 0; \ + int ok_a = 0, ok_b = 0; \ + \ + double * va = tensor_tensorbuffer_doubles(a, &total, &ok_a); \ + double * vb = tensor_tensorbuffer_doubles(b, &m, &ok_b); \ + \ + if (UNEXPECTED(!ok_a || !ok_b)) { \ + return; \ + } \ + \ + zend_long nHat = zephir_get_intval(n_zval); \ + \ + if (UNEXPECTED(nHat < 1 || total != m * nHat)) { \ + zephir_throw_exception_string(spl_ce_LengthException, \ + SL("Matrix and vector dimensions must agree.")); \ + return; \ + } \ + \ + zval c; \ + \ + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, total, &c) == FAILURE)) { \ + return; \ + } \ + \ + double * vc = zephir_buffer_doubles(&c); \ + \ + zend_long i, j; \ + \ + for (i = 0; i < m; ++i) { \ + for (j = 0; j < nHat; ++j) { \ + vc[i * nHat + j] = expr; \ + } \ + } \ + \ + zval_ptr_dtor(&c); \ +} - RETVAL_ARR(Z_ARR(c)); +TENSOR_COL_APPLY(multiply_col, va[i * nHat + j] * vb[i]) +TENSOR_COL_APPLY(add_col, va[i * nHat + j] + vb[i]) +TENSOR_COL_APPLY(divide_col, va[i * nHat + j] / vb[i]) +TENSOR_COL_APPLY(divide_col_reverse, vb[i] / va[i * nHat + j]) +TENSOR_COL_APPLY(subtract_col, va[i * nHat + j] - vb[i]) +TENSOR_COL_APPLY(subtract_col_reverse, vb[i] - va[i * nHat + j]) +TENSOR_COL_APPLY(pow_col, pow(va[i * nHat + j], vb[i])) +TENSOR_COL_APPLY(pow_col_reverse, pow(vb[i], va[i * nHat + j])) +TENSOR_COL_APPLY(mod_col, fmod(va[i * nHat + j], vb[i])) +TENSOR_COL_APPLY(mod_col_reverse, fmod(vb[i], va[i * nHat + j])) + +#undef TENSOR_COL_APPLY + +/* Binary operation applied to every element of a matrix using a shared + * row vector. The matrix is wrapped up in `a` (m * n doubles in row-major + * order) and the row vector in `b` (n doubles) so that element (i, j) of the + * result is op(a[i * n + j], b[j]). Each operation expands into its own + * dedicated pair of loops so that the optimizer can vectorize the elementwise + * mapping instead of being blocked by an indirect call. */ + +#define TENSOR_ROW_APPLY(name, expr) \ +void tensor_##name(zval * return_value, zval * a, zval * b, zval * n_zval) \ +{ \ + zend_long nHat = 0, m = 0, total = 0, nb = 0; \ + int ok_a = 0, ok_b = 0; \ + \ + double * va = tensor_tensorbuffer_doubles(a, &total, &ok_a); \ + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); \ + \ + if (UNEXPECTED(!ok_a || !ok_b)) { \ + return; \ + } \ + \ + nHat = zephir_get_intval(n_zval); \ + \ + if (UNEXPECTED(nHat < 1 || nb != nHat || total < nHat || total % nHat != 0)) { \ + zephir_throw_exception_string(spl_ce_LengthException, \ + SL("Matrix and vector dimensions must agree.")); \ + return; \ + } \ + \ + m = total / nHat; \ + \ + zval c; \ + \ + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, total, &c) == FAILURE)) { \ + return; \ + } \ + \ + double * vc = zephir_buffer_doubles(&c); \ + \ + zend_long i, j; \ + \ + for (i = 0; i < m; ++i) { \ + for (j = 0; j < nHat; ++j) { \ + vc[i * nHat + j] = expr; \ + } \ + } \ + \ + zval_ptr_dtor(&c); \ } + +TENSOR_ROW_APPLY(multiply_row, va[i * nHat + j] * vb[j]) +TENSOR_ROW_APPLY(add_row, va[i * nHat + j] + vb[j]) +TENSOR_ROW_APPLY(divide_row, va[i * nHat + j] / vb[j]) +TENSOR_ROW_APPLY(divide_row_reverse, vb[j] / va[i * nHat + j]) +TENSOR_ROW_APPLY(subtract_row, va[i * nHat + j] - vb[j]) +TENSOR_ROW_APPLY(subtract_row_reverse, vb[j] - va[i * nHat + j]) +TENSOR_ROW_APPLY(pow_row, pow(va[i * nHat + j], vb[j])) +TENSOR_ROW_APPLY(pow_row_reverse, pow(vb[j], va[i * nHat + j])) +TENSOR_ROW_APPLY(mod_row, fmod(va[i * nHat + j], vb[j])) +TENSOR_ROW_APPLY(mod_row_reverse, fmod(vb[j], va[i * nHat + j])) + +#undef TENSOR_ROW_APPLY \ No newline at end of file diff --git a/ext/include/arithmetic.h b/ext/include/arithmetic.h index 9d459db..c504320 100644 --- a/ext/include/arithmetic.h +++ b/ext/include/arithmetic.h @@ -17,4 +17,26 @@ void tensor_subtract_scalar(zval * return_value, zval * a, zval * b); void tensor_pow_scalar(zval * return_value, zval * a, zval * b); void tensor_mod_scalar(zval * return_value, zval * a, zval * b); +void tensor_multiply_col(zval * return_value, zval * a, zval * b, zval * n); +void tensor_add_col(zval * return_value, zval * a, zval * b, zval * n); +void tensor_divide_col(zval * return_value, zval * a, zval * b, zval * n); +void tensor_divide_col_reverse(zval * return_value, zval * a, zval * b, zval * n); +void tensor_subtract_col(zval * return_value, zval * a, zval * b, zval * n); +void tensor_subtract_col_reverse(zval * return_value, zval * a, zval * b, zval * n); +void tensor_pow_col(zval * return_value, zval * a, zval * b, zval * n); +void tensor_pow_col_reverse(zval * return_value, zval * a, zval * b, zval * n); +void tensor_mod_col(zval * return_value, zval * a, zval * b, zval * n); +void tensor_mod_col_reverse(zval * return_value, zval * a, zval * b, zval * n); + +void tensor_multiply_row(zval * return_value, zval * a, zval * b, zval * n); +void tensor_add_row(zval * return_value, zval * a, zval * b, zval * n); +void tensor_divide_row(zval * return_value, zval * a, zval * b, zval * n); +void tensor_divide_row_reverse(zval * return_value, zval * a, zval * b, zval * n); +void tensor_subtract_row(zval * return_value, zval * a, zval * b, zval * n); +void tensor_subtract_row_reverse(zval * return_value, zval * a, zval * b, zval * n); +void tensor_pow_row(zval * return_value, zval * a, zval * b, zval * n); +void tensor_pow_row_reverse(zval * return_value, zval * a, zval * b, zval * n); +void tensor_mod_row(zval * return_value, zval * a, zval * b, zval * n); +void tensor_mod_row_reverse(zval * return_value, zval * a, zval * b, zval * n); + #endif diff --git a/ext/include/buffer.c b/ext/include/buffer.c new file mode 100644 index 0000000..1fb61d7 --- /dev/null +++ b/ext/include/buffer.c @@ -0,0 +1,511 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include "kernel/main.h" +#include "php_ext.h" +#include "kernel/buffer.h" +#include "kernel/exception.h" +#include "kernel/operators.h" +#include "include/buffer.h" +#include "../tensor/exceptions/invalidargumentexception.zep.h" + +#ifdef ZEPHIR_BUFFER_ENABLED + +zend_class_entry * tensor_buffer_ce; + +/** + * Allocate a new `Tensor\TensorBuffer` wrapping a fresh zero-filled double + * buffer of `len` elements (see include/buffer.h). + */ +int tensor_tensorbuffer_create(zval * ret, zend_long len, zval * buffer) +{ + if (UNEXPECTED(zephir_buffer_create(buffer, len, ZEPHIR_BUFFER_DOUBLE) == FAILURE)) { + ZVAL_UNDEF(buffer); + return FAILURE; + } + + object_init_ex(ret, tensor_tensorbuffer_ce); + + /* zend_update_property() sets the engine's fake scope to the owner class + * so protected property writes from C pass the PHP 8.4 access check. */ + zend_update_property(tensor_tensorbuffer_ce, Z_OBJ_P(ret), "buffer", sizeof("buffer") - 1, buffer); + + if (UNEXPECTED(EG(exception))) { + zval_ptr_dtor(ret); + ZVAL_UNDEF(ret); + zval_ptr_dtor(buffer); + ZVAL_UNDEF(buffer); + return FAILURE; + } + + return SUCCESS; +} + +/** + * Allocate a new `Tensor\TensorBuffer` decorator wrapping a `Tensor\Buffer` + * built from a PHP array of values, casting every element to a double (see + * include/buffer.h). + */ +void tensor_buffer_from_array(zval * ret, zval * arr) +{ + zval buffer; + + if (UNEXPECTED(zephir_buffer_create_from_array(&buffer, arr, ZEPHIR_BUFFER_DOUBLE) == FAILURE)) { + ZVAL_NULL(ret); + return; + } + + object_init_ex(ret, tensor_tensorbuffer_ce); + + zend_update_property(tensor_tensorbuffer_ce, Z_OBJ_P(ret), "buffer", sizeof("buffer") - 1, &buffer); + + if (UNEXPECTED(EG(exception))) { + zval_ptr_dtor(ret); + ZVAL_UNDEF(ret); + zval_ptr_dtor(&buffer); + ZVAL_UNDEF(&buffer); + return; + } + + zval_ptr_dtor(&buffer); +} + +/** + * Unwrap the double buffer hidden inside a `Tensor\TensorBuffer` object + * (see include/buffer.h). + */ +double * tensor_tensorbuffer_doubles(zval * obj, zend_long * len, int * success) +{ + zval rv; + + ZVAL_UNDEF(&rv); + + if (success != NULL) { + *success = 0; + } + + if (len != NULL) { + *len = 0; + } + + if (UNEXPECTED(Z_TYPE_P(obj) != IS_OBJECT || Z_OBJCE_P(obj) != tensor_tensorbuffer_ce)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Argument must be a Tensor\\TensorBuffer object.")); + return NULL; + } + + zval *prop = zend_read_property(tensor_tensorbuffer_ce, Z_OBJ_P(obj), "buffer", sizeof("buffer") - 1, 1, &rv); + + if (prop != NULL && prop != &rv) { + ZVAL_COPY(&rv, prop); + } + + if (UNEXPECTED(!zephir_is_buffer(&rv))) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Argument is not wrapping a Buffer object.")); + goto cleanup; + } + + if (UNEXPECTED(zephir_buffer_kind(&rv) != ZEPHIR_BUFFER_DOUBLE)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Argument must wrap a buffer of type double.")); + goto cleanup; + } + + zend_long n = zephir_buffer_len(&rv); + double * ptr = zephir_buffer_doubles(&rv); + + zval_ptr_dtor(&rv); + + if (len != NULL) { + *len = n; + } + + if (success != NULL) { + *success = 1; + } + + return ptr; + +cleanup: + zval_ptr_dtor(&rv); + + return NULL; +} + +static int tensor_double_cmp(const void * a, const void * b) +{ + double da = *(const double *) a; + double db = *(const double *) b; + + return (da > db) - (da < db); +} + +static int tensor_double_cmp_desc(const void * a, const void * b) +{ + return tensor_double_cmp(b, a); +} + +static int tensor_long_cmp(const void * a, const void * b) +{ + zend_long la = *(const zend_long *) a; + zend_long lb = *(const zend_long *) b; + + return (la > lb) - (la < lb); +} + +static int tensor_long_cmp_desc(const void * a, const void * b) +{ + return tensor_long_cmp(b, a); +} + +/** + * Sort the elements of a Buffer in place. + * + * @param return_value + * @param obj + * @param ascending + */ +void tensor_buffer_sort(zval * return_value, zval * obj, zval * ascending) +{ + uint8_t kind = zephir_buffer_kind(obj); + zend_long len = zephir_buffer_len(obj); + int ascending_order = zend_is_true(ascending); + + if (UNEXPECTED(kind == 0 || len < 2)) { + RETURN_NULL(); + } + + if (kind == ZEPHIR_BUFFER_LONG) { + qsort((void *) zephir_buffer_longs(obj), (size_t) len, sizeof(zend_long), + ascending_order ? tensor_long_cmp : tensor_long_cmp_desc); + } else { + qsort((void *) zephir_buffer_doubles(obj), (size_t) len, sizeof(double), + ascending_order ? tensor_double_cmp : tensor_double_cmp_desc); + } + + RETURN_NULL(); +} + +/** + * Return a new Buffer populated with a slice of the given buffer. + * + * @param return_value + * @param obj + * @param offset + * @param length + */ +void tensor_buffer_slice(zval * return_value, zval * obj, zval * offset, zval * length) +{ + uint8_t kind = zephir_buffer_kind(obj); + zend_long len = zephir_buffer_len(obj); + zend_long offsetHat = zephir_get_intval(offset); + zend_long lengthHat = zephir_get_intval(length); + + if (UNEXPECTED(kind == 0)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Argument must be a Buffer object.")); + return; + } + + if (UNEXPECTED(offsetHat < 0 || lengthHat < 0 || offsetHat > len - lengthHat)) { + zephir_throw_exception_string(spl_ce_OutOfBoundsException, + SL("Slice offset and length must be within the bounds of the buffer.")); + return; + } + + if (UNEXPECTED(zephir_buffer_create(return_value, lengthHat, kind) == FAILURE)) { + return; + } + + if (lengthHat == 0) { + return; + } + + if (kind == ZEPHIR_BUFFER_LONG) { + memcpy(zephir_buffer_longs(return_value), zephir_buffer_longs(obj) + offsetHat, + (size_t) lengthHat * sizeof(zend_long)); + } else { + memcpy(zephir_buffer_doubles(return_value), zephir_buffer_doubles(obj) + offsetHat, + (size_t) lengthHat * sizeof(double)); + } +} + +/** + * Return a new Buffer populated with a strided slice of the given buffer. + * + * @param return_value + * @param obj + * @param offset + * @param length + * @param stride + */ +void tensor_buffer_slice_strided(zval * return_value, zval * obj, zval * offset, zval * length, zval * stride) +{ + uint8_t kind = zephir_buffer_kind(obj); + zend_long len = zephir_buffer_len(obj); + zend_long offsetHat = zephir_get_intval(offset); + zend_long lengthHat = zephir_get_intval(length); + zend_long strideHat = zephir_get_intval(stride); + + if (UNEXPECTED(kind == 0)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Argument must be a Buffer object.")); + return; + } + + if (UNEXPECTED(offsetHat < 0 || lengthHat < 0 || strideHat < 1)) { + zephir_throw_exception_string(spl_ce_OutOfBoundsException, + SL("Slice offset, length, and stride must be within the bounds of the buffer.")); + return; + } + + if (lengthHat > 0) { + zend_long last = len - 1 - offsetHat; + + /* Integer division on non-negative operands is exact and immune to the + * signed overflow of (lengthHat - 1) * strideHat, which wraps for huge + * arguments and previously let the guard pass while the copy below read + * far out of bounds. */ + if (UNEXPECTED(last < 0 || (lengthHat - 1) > last / strideHat)) { + zephir_throw_exception_string(spl_ce_OutOfBoundsException, + SL("Slice offset, length, and stride must be within the bounds of the buffer.")); + return; + } + } + + if (UNEXPECTED(zephir_buffer_create(return_value, lengthHat, kind) == FAILURE)) { + return; + } + + if (lengthHat == 0) { + return; + } + + zend_long i; + + if (kind == ZEPHIR_BUFFER_LONG) { + const zend_long * src = zephir_buffer_longs(obj); + zend_long * dst = zephir_buffer_longs(return_value); + zend_long index = offsetHat; + + for (i = 0; i < lengthHat; ++i) { + dst[i] = src[index]; + + if (i + 1 < lengthHat) { + index += strideHat; + } + } + } else { + const double * src = zephir_buffer_doubles(obj); + double * dst = zephir_buffer_doubles(return_value); + zend_long index = offsetHat; + + for (i = 0; i < lengthHat; ++i) { + dst[i] = src[index]; + + if (i + 1 < lengthHat) { + index += strideHat; + } + } + } +} + +/** + * Return a new Buffer populated with a copy of this buffer concatenated with + * the given buffers. + * + * @param return_value + * @param obj + * @param others + */ +void tensor_buffer_concat(zval * return_value, zval * obj, zval * others) +{ + uint8_t kind = zephir_buffer_kind(obj); + zend_long len = zephir_buffer_len(obj); + + if (UNEXPECTED(kind == 0)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Argument must be a Buffer object.")); + return; + } + + HashTable * ht; + + if (UNEXPECTED((ht = Z_ARRVAL_P(others)) == NULL)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Argument must be an array of Buffer objects.")); + return; + } + + zend_long total = len; + zval * other; + + ZEND_HASH_FOREACH_VAL(ht, other) { + if (UNEXPECTED(!zephir_is_buffer(other) || zephir_buffer_kind(other) != kind)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("All buffers must be the same type as the given buffer.")); + return; + } + + total += zephir_buffer_len(other); + } ZEND_HASH_FOREACH_END(); + + if (UNEXPECTED(zephir_buffer_create(return_value, total, kind) == FAILURE)) { + return; + } + + if (len > 0) { + if (kind == ZEPHIR_BUFFER_LONG) { + memcpy(zephir_buffer_longs(return_value), zephir_buffer_longs(obj), + (size_t) len * sizeof(zend_long)); + } else { + memcpy(zephir_buffer_doubles(return_value), zephir_buffer_doubles(obj), + (size_t) len * sizeof(double)); + } + } + + zend_long pos = len; + + ZEND_HASH_FOREACH_VAL(ht, other) { + zend_long other_len = zephir_buffer_len(other); + + if (other_len > 0) { + if (kind == ZEPHIR_BUFFER_LONG) { + memcpy(zephir_buffer_longs(return_value) + pos, zephir_buffer_longs(other), + (size_t) other_len * sizeof(zend_long)); + } else { + memcpy(zephir_buffer_doubles(return_value) + pos, zephir_buffer_doubles(other), + (size_t) other_len * sizeof(double)); + } + } + + pos += other_len; + } ZEND_HASH_FOREACH_END(); +} + +/** + * Return a new array of Buffers splitting the given buffer into chunks of + * the given length. + * + * @param return_value + * @param obj + * @param chunk_length + */ +void tensor_buffer_split(zval * return_value, zval * obj, zval * chunk_length) +{ + uint8_t kind = zephir_buffer_kind(obj); + zend_long len = zephir_buffer_len(obj); + zend_long chunkHat = zephir_get_intval(chunk_length); + + if (UNEXPECTED(kind == 0)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Argument must be a Buffer object.")); + return; + } + + if (UNEXPECTED(chunkHat < 1)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Chunk length must be greater than 0.")); + return; + } + + zend_long chunks; + + if (UNEXPECTED(len == 0)) { + chunks = 0; + } else if (UNEXPECTED(chunkHat > len)) { + /* The whole buffer fits in one chunk; avoids the overflow of + * len + chunkHat - 1 for a chunk length near LONG_MAX. */ + chunks = 1; + } else { + /* Both operands are at most 2 * len, so the sum cannot overflow. */ + chunks = (len + chunkHat - 1) / chunkHat; + } + + zend_long i; + + array_init_size(return_value, (zend_ulong) chunks); + + for (i = 0; i < chunks; ++i) { + zend_long start = i * chunkHat; + zend_long chunk_len = len - start < chunkHat ? len - start : chunkHat; + zval buffer; + + if (UNEXPECTED(zephir_buffer_create(&buffer, chunk_len, kind) == FAILURE)) { + return; + } + + if (chunk_len > 0) { + if (kind == ZEPHIR_BUFFER_LONG) { + memcpy(zephir_buffer_longs(&buffer), zephir_buffer_longs(obj) + start, + (size_t) chunk_len * sizeof(zend_long)); + } else { + memcpy(zephir_buffer_doubles(&buffer), zephir_buffer_doubles(obj) + start, + (size_t) chunk_len * sizeof(double)); + } + } + + add_next_index_zval(return_value, &buffer); + } +} + +/** + * Return a new Buffer populated with the elements of the given buffer + * repeated the given number of times. + * + * @param return_value + * @param obj + * @param times + */ +void tensor_buffer_repeat(zval * return_value, zval * obj, zval * times) +{ + uint8_t kind = zephir_buffer_kind(obj); + zend_long len = zephir_buffer_len(obj); + zend_long timesHat = zephir_get_intval(times); + + if (UNEXPECTED(kind == 0)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Argument must be a Buffer object.")); + return; + } + + if (UNEXPECTED(timesHat < 1)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Times must be greater than 0.")); + return; + } + + /* Reject before len * timesHat wraps; the product is then guaranteed to + * fit, so every i * len destination offset stays in bounds. */ + if (UNEXPECTED(len > 0 && timesHat > ZEND_LONG_MAX / len)) { + zephir_throw_exception_string(tensor_exceptions_invalidargumentexception_ce, + SL("Repeat count must not overflow the buffer length.")); + return; + } + + zend_long total = len * timesHat; + zend_long i; + + if (UNEXPECTED(zephir_buffer_create(return_value, total, kind) == FAILURE)) { + return; + } + + if (len > 0) { + for (i = 0; i < timesHat; ++i) { + if (kind == ZEPHIR_BUFFER_LONG) { + memcpy(zephir_buffer_longs(return_value) + i * len, zephir_buffer_longs(obj), + (size_t) len * sizeof(zend_long)); + } else { + memcpy(zephir_buffer_doubles(return_value) + i * len, zephir_buffer_doubles(obj), + (size_t) len * sizeof(double)); + } + } + } +} + +#endif \ No newline at end of file diff --git a/ext/include/buffer.h b/ext/include/buffer.h new file mode 100644 index 0000000..b5d0e32 --- /dev/null +++ b/ext/include/buffer.h @@ -0,0 +1,40 @@ +#ifndef TENSOR_BUFFER_H +#define TENSOR_BUFFER_H + +#include + +/* The Zephir compiler emits references to `tensor_buffer_ce` for the kernel + * `Tensor\Buffer` class even though the kernel registers and exports it as + * `zephir_buffer_ce`. Alias the two (see config.json module initializer). */ +extern zend_class_entry * tensor_buffer_ce; + +/* The `Tensor\TensorBuffer` decorator class. */ +extern zend_class_entry * tensor_tensorbuffer_ce; + +/* Allocate a new `Tensor\TensorBuffer` wrapping a fresh zero-filled double + * buffer of `len` elements. The exposed `Buffer` is written to `buffer` so + * callers can fill it through a raw pointer. Returns FAILURE (and throws) on + * allocation failure; on SUCCESS the caller owns a reference to `buffer` and + * must release it with zval_ptr_dtor() when done. */ +int tensor_tensorbuffer_create(zval * ret, zend_long len, zval * buffer); + +/* Unwrap the double buffer hidden inside a `Tensor\TensorBuffer` object, + * returning a raw pointer into it. Sets `*success` to 1 on success and 0 on + * failure (throwing an InvalidArgumentException). An empty buffer yields + * success with a NULL pointer and `*len` of 0. */ +double * tensor_tensorbuffer_doubles(zval * obj, zend_long * len, int * success); + +/* Build a `Tensor\TensorBuffer` decorator from a PHP array of values, casting + * every element to a double. Passed arrays must be 1-d and positionally + * indexed; keys are discarded. On failure `ret` is set to NULL. Used to seed + * tensor classes from arrays in Zephir. */ +void tensor_buffer_from_array(zval * ret, zval * arr); + +void tensor_buffer_sort(zval * return_value, zval * obj, zval * ascending); +void tensor_buffer_slice(zval * return_value, zval * obj, zval * offset, zval * length); +void tensor_buffer_slice_strided(zval * return_value, zval * obj, zval * offset, zval * length, zval * stride); +void tensor_buffer_concat(zval * return_value, zval * obj, zval * others); +void tensor_buffer_split(zval * return_value, zval * obj, zval * chunk_length); +void tensor_buffer_repeat(zval * return_value, zval * obj, zval * times); + +#endif \ No newline at end of file diff --git a/ext/include/comparison.c b/ext/include/comparison.c index 24796fe..2de0d76 100644 --- a/ext/include/comparison.c +++ b/ext/include/comparison.c @@ -3,286 +3,509 @@ #endif #include +#include #include "kernel/operators.h" +#include "php_ext.h" +#include "kernel/buffer.h" +#include "include/buffer.h" void tensor_equal(zval * return_value, zval * a, zval * b) { - unsigned int i; - zval c; + zend_long i; + zend_long na = 0, nb = 0; + int ok_a = 0, ok_b = 0; + + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); + + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } + + if (UNEXPECTED(na != nb)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must be the same length.")); + return; + } - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + zval c; - unsigned int n = zend_array_count(aa); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - array_init_size(&c, n); + double * vc = zephir_buffer_doubles(&c); - for (i = 0; i < n; ++i) { - if (zephir_get_doubleval(zend_hash_index_find(aa, i)) == zephir_get_doubleval(zend_hash_index_find(ab, i))) { - add_next_index_long(&c, 1); - } else { - add_next_index_long(&c, 0); - } - } + for (i = 0; i < na; ++i) { + vc[i] = va[i] == vb[i] ? 1.0 : 0.0; + } - RETVAL_ARR(Z_ARR(c)); + zval_ptr_dtor(&c); } void tensor_not_equal(zval * return_value, zval * a, zval * b) { - unsigned int i; - zval c; + zend_long i; + zend_long na = 0, nb = 0; + int ok_a = 0, ok_b = 0; - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); - unsigned int n = zend_array_count(aa); + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } - array_init_size(&c, n); + if (UNEXPECTED(na != nb)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must be the same length.")); + return; + } + + zval c; - for (i = 0; i < n; ++i) { - if (zephir_get_doubleval(zend_hash_index_find(aa, i)) != zephir_get_doubleval(zend_hash_index_find(ab, i))) { - add_next_index_long(&c, 1); - } else { - add_next_index_long(&c, 0); - } - } + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - RETVAL_ARR(Z_ARR(c)); + double * vc = zephir_buffer_doubles(&c); + + for (i = 0; i < na; ++i) { + vc[i] = va[i] != vb[i] ? 1.0 : 0.0; + } + + zval_ptr_dtor(&c); } void tensor_greater(zval * return_value, zval * a, zval * b) { - unsigned int i; - zval c; + zend_long i; + zend_long na = 0, nb = 0; + int ok_a = 0, ok_b = 0; + + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } + + if (UNEXPECTED(na != nb)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must be the same length.")); + return; + } + + zval c; - unsigned int n = zend_array_count(aa); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - array_init_size(&c, n); + double * vc = zephir_buffer_doubles(&c); - for (i = 0; i < n; ++i) { - if (zephir_get_doubleval(zend_hash_index_find(aa, i)) > zephir_get_doubleval(zend_hash_index_find(ab, i))) { - add_next_index_long(&c, 1); - } else { - add_next_index_long(&c, 0); - } - } + for (i = 0; i < na; ++i) { + vc[i] = va[i] > vb[i] ? 1.0 : 0.0; + } - RETVAL_ARR(Z_ARR(c)); + zval_ptr_dtor(&c); } void tensor_greater_equal(zval * return_value, zval * a, zval * b) { - unsigned int i; - zval c; + zend_long i; + zend_long na = 0, nb = 0; + int ok_a = 0, ok_b = 0; + + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } - unsigned int n = zend_array_count(aa); + if (UNEXPECTED(na != nb)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must be the same length.")); + return; + } + + zval c; - array_init_size(&c, n); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - for (i = 0; i < n; ++i) { - if (zephir_get_doubleval(zend_hash_index_find(aa, i)) >= zephir_get_doubleval(zend_hash_index_find(ab, i))) { - add_next_index_long(&c, 1); - } else { - add_next_index_long(&c, 0); - } - } + double * vc = zephir_buffer_doubles(&c); - RETVAL_ARR(Z_ARR(c)); + for (i = 0; i < na; ++i) { + vc[i] = va[i] >= vb[i] ? 1.0 : 0.0; + } + + zval_ptr_dtor(&c); } void tensor_less(zval * return_value, zval * a, zval * b) { - unsigned int i; - zval c; + zend_long i; + zend_long na = 0, nb = 0; + int ok_a = 0, ok_b = 0; + + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } - unsigned int n = zend_array_count(aa); + if (UNEXPECTED(na != nb)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must be the same length.")); + return; + } - array_init_size(&c, n); + zval c; + + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - for (i = 0; i < n; ++i) { - if (zephir_get_doubleval(zend_hash_index_find(aa, i)) < zephir_get_doubleval(zend_hash_index_find(ab, i))) { - add_next_index_long(&c, 1); - } else { - add_next_index_long(&c, 0); - } - } + double * vc = zephir_buffer_doubles(&c); - RETVAL_ARR(Z_ARR(c)); + for (i = 0; i < na; ++i) { + vc[i] = va[i] < vb[i] ? 1.0 : 0.0; + } + + zval_ptr_dtor(&c); } void tensor_less_equal(zval * return_value, zval * a, zval * b) { - unsigned int i; - zval c; + zend_long i; + zend_long na = 0, nb = 0; + int ok_a = 0, ok_b = 0; - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); - unsigned int n = zend_array_count(aa); + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } + + if (UNEXPECTED(na != nb)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must be the same length.")); + return; + } + + zval c; - array_init_size(&c, n); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - for (i = 0; i < n; ++i) { - if (zephir_get_doubleval(zend_hash_index_find(aa, i)) <= zephir_get_doubleval(zend_hash_index_find(ab, i))) { - add_next_index_long(&c, 1); - } else { - add_next_index_long(&c, 0); - } - } + double * vc = zephir_buffer_doubles(&c); - RETVAL_ARR(Z_ARR(c)); + for (i = 0; i < na; ++i) { + vc[i] = va[i] <= vb[i] ? 1.0 : 0.0; + } + + zval_ptr_dtor(&c); } void tensor_equal_scalar(zval * return_value, zval * a, zval * b) { - unsigned int i; - zval c; + zend_long i; + zend_long na = 0; + int ok_a = 0; - zend_array * aa = Z_ARR_P(a); + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); - double ab = zephir_get_doubleval(b); + if (UNEXPECTED(!ok_a)) { + return; + } - unsigned int n = zend_array_count(aa); + double ab = zephir_get_doubleval(b); + + zval c; - array_init_size(&c, n); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - for (i = 0; i < n; ++i) { - if (zephir_get_doubleval(zend_hash_index_find(aa, i)) == ab) { - add_next_index_long(&c, 1); - } else { - add_next_index_long(&c, 0); - } - } + double * vc = zephir_buffer_doubles(&c); - RETVAL_ARR(Z_ARR(c)); + for (i = 0; i < na; ++i) { + vc[i] = va[i] == ab ? 1.0 : 0.0; + } + + zval_ptr_dtor(&c); } void tensor_not_equal_scalar(zval * return_value, zval * a, zval * b) { - unsigned int i; - zval c; + zend_long i; + zend_long na = 0; + int ok_a = 0; + + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); - zend_array * aa = Z_ARR_P(a); + if (UNEXPECTED(!ok_a)) { + return; + } - double ab = zephir_get_doubleval(b); + double ab = zephir_get_doubleval(b); - unsigned int n = zend_array_count(aa); + zval c; + + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - array_init_size(&c, n); + double * vc = zephir_buffer_doubles(&c); - for (i = 0; i < n; ++i) { - if (zephir_get_doubleval(zend_hash_index_find(aa, i)) != ab) { - add_next_index_long(&c, 1); - } else { - add_next_index_long(&c, 0); - } - } + for (i = 0; i < na; ++i) { + vc[i] = va[i] != ab ? 1.0 : 0.0; + } - RETVAL_ARR(Z_ARR(c)); + zval_ptr_dtor(&c); } void tensor_greater_scalar(zval * return_value, zval * a, zval * b) { - unsigned int i; - zval c; + zend_long i; + zend_long na = 0; + int ok_a = 0; - zend_array * aa = Z_ARR_P(a); + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); - double ab = zephir_get_doubleval(b); + if (UNEXPECTED(!ok_a)) { + return; + } - unsigned int n = zend_array_count(aa); + double ab = zephir_get_doubleval(b); - array_init_size(&c, n); + zval c; - for (i = 0; i < n; ++i) { - if (zephir_get_doubleval(zend_hash_index_find(aa, i)) > ab) { - add_next_index_long(&c, 1); - } else { - add_next_index_long(&c, 0); - } - } + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - RETVAL_ARR(Z_ARR(c)); + double * vc = zephir_buffer_doubles(&c); + + for (i = 0; i < na; ++i) { + vc[i] = va[i] > ab ? 1.0 : 0.0; + } + + zval_ptr_dtor(&c); } void tensor_greater_equal_scalar(zval * return_value, zval * a, zval * b) { - unsigned int i; - zval c; + zend_long i; + zend_long na = 0; + int ok_a = 0; - zend_array * aa = Z_ARR_P(a); + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); - double ab = zephir_get_doubleval(b); + if (UNEXPECTED(!ok_a)) { + return; + } - unsigned int n = zend_array_count(aa); + double ab = zephir_get_doubleval(b); - array_init_size(&c, n); + zval c; + + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - for (i = 0; i < n; ++i) { - if (zephir_get_doubleval(zend_hash_index_find(aa, i)) >= ab) { - add_next_index_long(&c, 1); - } else { - add_next_index_long(&c, 0); - } - } + double * vc = zephir_buffer_doubles(&c); - RETVAL_ARR(Z_ARR(c)); + for (i = 0; i < na; ++i) { + vc[i] = va[i] >= ab ? 1.0 : 0.0; + } + + zval_ptr_dtor(&c); } void tensor_less_scalar(zval * return_value, zval * a, zval * b) { - unsigned int i; - zval c; + zend_long i; + zend_long na = 0; + int ok_a = 0; - zend_array * aa = Z_ARR_P(a); + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); - double ab = zephir_get_doubleval(b); + if (UNEXPECTED(!ok_a)) { + return; + } + + double ab = zephir_get_doubleval(b); + + zval c; - unsigned int n = zend_array_count(aa); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - array_init_size(&c, n); + double * vc = zephir_buffer_doubles(&c); - for (i = 0; i < n; ++i) { - if (zephir_get_doubleval(zend_hash_index_find(aa, i)) < ab) { - add_next_index_long(&c, 1); - } else { - add_next_index_long(&c, 0); - } - } + for (i = 0; i < na; ++i) { + vc[i] = va[i] < ab ? 1.0 : 0.0; + } - RETVAL_ARR(Z_ARR(c)); + zval_ptr_dtor(&c); } void tensor_less_equal_scalar(zval * return_value, zval * a, zval * b) { - unsigned int i; + zend_long i; + zend_long na = 0; + int ok_a = 0; + + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + + if (UNEXPECTED(!ok_a)) { + return; + } + + double ab = zephir_get_doubleval(b); + zval c; - zend_array * aa = Z_ARR_P(a); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + return; + } - double ab = zephir_get_doubleval(b); + double * vc = zephir_buffer_doubles(&c); - unsigned int n = zend_array_count(aa); + for (i = 0; i < na; ++i) { + vc[i] = va[i] <= ab ? 1.0 : 0.0; + } - array_init_size(&c, n); + zval_ptr_dtor(&c); +} - for (i = 0; i < n; ++i) { - if (zephir_get_doubleval(zend_hash_index_find(aa, i)) <= ab) { - add_next_index_long(&c, 1); - } else { - add_next_index_long(&c, 0); - } - } +/* Comparison applied to every element of a matrix row. The matrix is wrapped + * up in `a` (m * n doubles in row-major order) and the column vector in `b` + * (m doubles) so that element (i, j) of the result is 1.0 when the comparison + * op(a[i * n + j], b[i]) holds and 0.0 otherwise. Each operation expands into + * its own dedicated pair of loops so that the optimizer can vectorize the + * elementwise mapping instead of being blocked by an indirect call. */ + +#define TENSOR_COL_APPLY(name, expr) \ +void tensor_##name(zval * return_value, zval * a, zval * b, zval * n_zval) \ +{ \ + zend_long n = 0, m = 0, total = 0; \ + int ok_a = 0, ok_b = 0; \ + \ + double * va = tensor_tensorbuffer_doubles(a, &total, &ok_a); \ + double * vb = tensor_tensorbuffer_doubles(b, &m, &ok_b); \ + \ + if (UNEXPECTED(!ok_a || !ok_b)) { \ + return; \ + } \ + \ + zend_long nHat = zephir_get_intval(n_zval); \ + \ + if (UNEXPECTED(nHat < 1 || total != m * nHat)) { \ + zephir_throw_exception_string(spl_ce_LengthException, \ + SL("Matrix and vector dimensions must agree.")); \ + return; \ + } \ + \ + zval c; \ + \ + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, total, &c) == FAILURE)) { \ + return; \ + } \ + \ + double * vc = zephir_buffer_doubles(&c); \ + \ + zend_long i, j; \ + \ + for (i = 0; i < m; ++i) { \ + for (j = 0; j < nHat; ++j) { \ + vc[i * nHat + j] = expr; \ + } \ + } \ + \ + zval_ptr_dtor(&c); \ +} - RETVAL_ARR(Z_ARR(c)); +TENSOR_COL_APPLY(equal_col, va[i * nHat + j] == vb[i] ? 1.0 : 0.0) +TENSOR_COL_APPLY(not_equal_col, va[i * nHat + j] != vb[i] ? 1.0 : 0.0) +TENSOR_COL_APPLY(greater_col, va[i * nHat + j] > vb[i] ? 1.0 : 0.0) +TENSOR_COL_APPLY(greater_col_reverse, vb[i] > va[i * nHat + j] ? 1.0 : 0.0) +TENSOR_COL_APPLY(greater_equal_col, va[i * nHat + j] >= vb[i] ? 1.0 : 0.0) +TENSOR_COL_APPLY(greater_equal_col_reverse, vb[i] >= va[i * nHat + j] ? 1.0 : 0.0) +TENSOR_COL_APPLY(less_col, va[i * nHat + j] < vb[i] ? 1.0 : 0.0) +TENSOR_COL_APPLY(less_col_reverse, vb[i] < va[i * nHat + j] ? 1.0 : 0.0) +TENSOR_COL_APPLY(less_equal_col, va[i * nHat + j] <= vb[i] ? 1.0 : 0.0) +TENSOR_COL_APPLY(less_equal_col_reverse, vb[i] <= va[i * nHat + j] ? 1.0 : 0.0) + +#undef TENSOR_COL_APPLY + +/* Comparison applied to every element of a matrix using a shared row vector. + * The matrix is wrapped up in `a` (m * n doubles in row-major order) and the + * row vector in `b` (n doubles) so that element (i, j) of the result is 1.0 + * when the comparison op(a[i * n + j], b[j]) holds and 0.0 otherwise. Each + * operation expands into its own dedicated pair of loops so that the optimizer + * can vectorize the elementwise mapping instead of being blocked by an + * indirect call. */ + +#define TENSOR_ROW_APPLY(name, expr) \ +void tensor_##name(zval * return_value, zval * a, zval * b, zval * n_zval) \ +{ \ + zend_long nHat = 0, m = 0, total = 0, nb = 0; \ + int ok_a = 0, ok_b = 0; \ + \ + double * va = tensor_tensorbuffer_doubles(a, &total, &ok_a); \ + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); \ + \ + if (UNEXPECTED(!ok_a || !ok_b)) { \ + return; \ + } \ + \ + nHat = zephir_get_intval(n_zval); \ + \ + if (UNEXPECTED(nHat < 1 || nb != nHat || total < nHat || total % nHat != 0)) { \ + zephir_throw_exception_string(spl_ce_LengthException, \ + SL("Matrix and vector dimensions must agree.")); \ + return; \ + } \ + \ + m = total / nHat; \ + \ + zval c; \ + \ + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, total, &c) == FAILURE)) { \ + return; \ + } \ + \ + double * vc = zephir_buffer_doubles(&c); \ + \ + zend_long i, j; \ + \ + for (i = 0; i < m; ++i) { \ + for (j = 0; j < nHat; ++j) { \ + vc[i * nHat + j] = expr; \ + } \ + } \ + \ + zval_ptr_dtor(&c); \ } + +TENSOR_ROW_APPLY(equal_row, va[i * nHat + j] == vb[j] ? 1.0 : 0.0) +TENSOR_ROW_APPLY(not_equal_row, va[i * nHat + j] != vb[j] ? 1.0 : 0.0) +TENSOR_ROW_APPLY(greater_row, va[i * nHat + j] > vb[j] ? 1.0 : 0.0) +TENSOR_ROW_APPLY(greater_row_reverse, vb[j] > va[i * nHat + j] ? 1.0 : 0.0) +TENSOR_ROW_APPLY(greater_equal_row, va[i * nHat + j] >= vb[j] ? 1.0 : 0.0) +TENSOR_ROW_APPLY(greater_equal_row_reverse, vb[j] >= va[i * nHat + j] ? 1.0 : 0.0) +TENSOR_ROW_APPLY(less_row, va[i * nHat + j] < vb[j] ? 1.0 : 0.0) +TENSOR_ROW_APPLY(less_row_reverse, vb[j] < va[i * nHat + j] ? 1.0 : 0.0) +TENSOR_ROW_APPLY(less_equal_row, va[i * nHat + j] <= vb[j] ? 1.0 : 0.0) +TENSOR_ROW_APPLY(less_equal_row_reverse, vb[j] <= va[i * nHat + j] ? 1.0 : 0.0) + +#undef TENSOR_ROW_APPLY \ No newline at end of file diff --git a/ext/include/comparison.h b/ext/include/comparison.h index 5dadc04..7fd1e06 100644 --- a/ext/include/comparison.h +++ b/ext/include/comparison.h @@ -17,4 +17,26 @@ void tensor_greater_equal_scalar(zval * return_value, zval * a, zval * b); void tensor_less_scalar(zval * return_value, zval * a, zval * b); void tensor_less_equal_scalar(zval * return_value, zval * a, zval * b); +void tensor_equal_col(zval * return_value, zval * a, zval * b, zval * n); +void tensor_not_equal_col(zval * return_value, zval * a, zval * b, zval * n); +void tensor_greater_col(zval * return_value, zval * a, zval * b, zval * n); +void tensor_greater_col_reverse(zval * return_value, zval * a, zval * b, zval * n); +void tensor_greater_equal_col(zval * return_value, zval * a, zval * b, zval * n); +void tensor_greater_equal_col_reverse(zval * return_value, zval * a, zval * b, zval * n); +void tensor_less_col(zval * return_value, zval * a, zval * b, zval * n); +void tensor_less_col_reverse(zval * return_value, zval * a, zval * b, zval * n); +void tensor_less_equal_col(zval * return_value, zval * a, zval * b, zval * n); +void tensor_less_equal_col_reverse(zval * return_value, zval * a, zval * b, zval * n); + +void tensor_equal_row(zval * return_value, zval * a, zval * b, zval * n); +void tensor_not_equal_row(zval * return_value, zval * a, zval * b, zval * n); +void tensor_greater_row(zval * return_value, zval * a, zval * b, zval * n); +void tensor_greater_row_reverse(zval * return_value, zval * a, zval * b, zval * n); +void tensor_greater_equal_row(zval * return_value, zval * a, zval * b, zval * n); +void tensor_greater_equal_row_reverse(zval * return_value, zval * a, zval * b, zval * n); +void tensor_less_row(zval * return_value, zval * a, zval * b, zval * n); +void tensor_less_row_reverse(zval * return_value, zval * a, zval * b, zval * n); +void tensor_less_equal_row(zval * return_value, zval * a, zval * b, zval * n); +void tensor_less_equal_row_reverse(zval * return_value, zval * a, zval * b, zval * n); + #endif \ No newline at end of file diff --git a/ext/include/linear_algebra.c b/ext/include/linear_algebra.c index a65348f..d9ff24c 100644 --- a/ext/include/linear_algebra.c +++ b/ext/include/linear_algebra.c @@ -4,9 +4,13 @@ #include #include +#include #include #include #include "kernel/operators.h" +#include "php_ext.h" +#include "kernel/buffer.h" +#include "include/buffer.h" /** * Matrix-matrix multiplication i.e. linear transformation of matrices A and B. @@ -14,59 +18,85 @@ * @param return_value * @param a * @param b + * @param m + * @param p + * @param n */ -void tensor_matmul(zval * return_value, zval * a, zval * b) +void tensor_matmul(zval * return_value, zval * a, zval * b, zval * m, zval * p, zval * n) { - unsigned int i, j; - zval * row; - zval rowC, c; + zend_long i; + zend_long ma = zephir_get_intval(m); + zend_long pa = zephir_get_intval(p); + zend_long nb = zephir_get_intval(n); + zend_long na = 0, nbb = 0; + int ok_a = 0, ok_b = 0; - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nbb, &ok_b); - unsigned int m = zend_array_count(aa); - unsigned int p = zend_array_count(ab); - unsigned int n = zend_array_count(Z_ARR_P(zend_hash_index_find(ab, 0))); + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } - double * va = emalloc(m * p * sizeof(double)); - double * vb = emalloc(n * p * sizeof(double)); - double * vc = emalloc(m * n * sizeof(double)); + if (UNEXPECTED(na != ma * pa || nbb != pa * nb)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must match the given dimensions.")); + return; + } - for (i = 0; i < m; ++i) { - row = zend_hash_index_find(aa, i); + zval c; - for (j = 0; j < p; ++j) { - va[i * p + j] = zephir_get_doubleval(zend_hash_index_find(Z_ARR_P(row), j)); - } + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, ma * nb, &c) == FAILURE)) { + return; } - for (i = 0; i < p; ++i) { - row = zend_hash_index_find(ab, i); + double * vc = zephir_buffer_doubles(&c); - for (j = 0; j < n; ++j) { - vb[i * n + j] = zephir_get_doubleval(zend_hash_index_find(Z_ARR_P(row), j)); - } - } + cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, ma, nb, pa, 1.0, va, pa, vb, nb, 0.0, vc, nb); + + zval_ptr_dtor(&c); +} + +/** + * Matrix-vector product i.e. the dot product of matrix A and vector B. + * + * @param return_value + * @param a + * @param b + * @param m + * @param p + */ +void tensor_matrix_dot(zval * return_value, zval * a, zval * b, zval * m, zval * p) +{ + zend_long ma = zephir_get_intval(m); + zend_long pc = zephir_get_intval(p); + zend_long na = 0, nb = 0; + int ok_a = 0, ok_b = 0; - cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, m, n, p, 1.0, va, p, vb, n, 0.0, vc, n); + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); - array_init_size(&c, m); + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } - for (i = 0; i < m; ++i) { - array_init_size(&rowC, n); + if (UNEXPECTED(na != ma * pc || nb != pc)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must match the given dimensions.")); + return; + } - for (j = 0; j < n; ++j) { - add_next_index_double(&rowC, vc[i * n + j]); - } + zval c; - add_next_index_zval(&c, &rowC); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, ma, &c) == FAILURE)) { + return; } - RETVAL_ARR(Z_ARR(c)); + double * vc = zephir_buffer_doubles(&c); - efree(va); - efree(vb); - efree(vc); + cblas_dgemv(CblasRowMajor, CblasNoTrans, (blasint) ma, (blasint) pc, 1.0, va, (blasint) pc, vb, 1, 0.0, vc, 1); + + zval_ptr_dtor(&c); } /** @@ -78,20 +108,23 @@ void tensor_matmul(zval * return_value, zval * a, zval * b) */ void tensor_dot(zval * return_value, zval * a, zval * b) { - unsigned int i; - - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + zend_long na = 0, nb = 0; + int ok_a = 0, ok_b = 0; - unsigned int n = zend_array_count(aa); + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); - double sigma = 0.0; + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } - for (i = 0; i < n; ++i) { - sigma += zephir_get_doubleval(zend_hash_index_find(aa, i)) * zephir_get_doubleval(zend_hash_index_find(ab, i)); - } + if (UNEXPECTED(na != nb)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must be the same length.")); + return; + } - RETVAL_DOUBLE(sigma); + RETVAL_DOUBLE(cblas_ddot((blasint) na, va, 1, vb, 1)); } /** @@ -99,63 +132,72 @@ void tensor_dot(zval * return_value, zval * a, zval * b) * * @param return_value * @param a + * @param n */ -void tensor_inverse(zval * return_value, zval * a) +void tensor_inverse(zval * return_value, zval * a, zval * n) { - unsigned int i, j; - zval * row; - zval rowB, b; + zend_long i; + zend_long nn = zephir_get_intval(n); + zend_long na = 0; + int ok_a = 0; - zend_array * aa = Z_ARR_P(a); + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); - unsigned int n = zend_array_count(aa); + if (UNEXPECTED(!ok_a)) { + return; + } - double * va = emalloc(n * n * sizeof(double)); - int * pivots = emalloc(n * sizeof(int)); + if (UNEXPECTED(na != nn * nn)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffer must match the given dimensions.")); + return; + } - for (i = 0; i < n; ++i) { - row = zend_hash_index_find(aa, i); + double * w = emalloc(na * sizeof(double)); + int * pivots = emalloc(nn * sizeof(int)); - for (j = 0; j < n; ++j) { - va[i * n + j] = zephir_get_doubleval(zend_hash_index_find(Z_ARR_P(row), j)); - } + for (i = 0; i < na; ++i) { + w[i] = va[i]; } - + lapack_int status; - status = LAPACKE_dgetrf(LAPACK_ROW_MAJOR, n, n, va, n, pivots); + status = LAPACKE_dgetrf(LAPACK_ROW_MAJOR, nn, nn, w, nn, pivots); if (status != 0) { - efree(va); + efree(w); efree(pivots); RETURN_NULL(); } - status = LAPACKE_dgetri(LAPACK_ROW_MAJOR, n, va, n, pivots); + status = LAPACKE_dgetri(LAPACK_ROW_MAJOR, nn, w, nn, pivots); if (status != 0) { - efree(va); + efree(w); efree(pivots); RETURN_NULL(); } - array_init_size(&b, n); + zval c; - for (i = 0; i < n; ++i) { - array_init_size(&rowB, n); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na, &c) == FAILURE)) { + efree(w); + efree(pivots); - for (j = 0; j < n; ++j) { - add_next_index_double(&rowB, va[i * n + j]); - } + return; + } - add_next_index_zval(&b, &rowB); + double * vc = zephir_buffer_doubles(&c); + + for (i = 0; i < na; ++i) { + vc[i] = w[i]; } - RETVAL_ARR(Z_ARR(b)); + zval_ptr_dtor(&c); - efree(va); + efree(w); efree(pivots); } @@ -164,37 +206,45 @@ void tensor_inverse(zval * return_value, zval * a) * * @param return_value * @param a + * @param m + * @param n */ -void tensor_pseudoinverse(zval * return_value, zval * a) +void tensor_pseudoinverse(zval * return_value, zval * a, zval * m, zval * n) { - unsigned int i, j; - zval * row; - zval b, rowB; + zend_long i; + zend_long ma = zephir_get_intval(m); + zend_long na = zephir_get_intval(n); + zend_long nbuf = 0; + int ok_a = 0; - zend_array * aa = Z_ARR_P(a); + double * va = tensor_tensorbuffer_doubles(a, &nbuf, &ok_a); - unsigned int m = zend_array_count(aa); - unsigned int n = zend_array_count(Z_ARR_P(zend_hash_index_find(aa, 0))); - unsigned int k = MIN(m, n); + if (UNEXPECTED(!ok_a)) { + return; + } - double * va = emalloc(m * n * sizeof(double)); - double * vu = emalloc(m * m * sizeof(double)); - double * vs = emalloc(k * sizeof(double)); - double * vvt = emalloc(n * n * sizeof(double)); - double * vb = emalloc(n * m * sizeof(double)); + if (UNEXPECTED(nbuf != ma * na)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffer must match the given dimensions.")); + return; + } - for (i = 0; i < m; ++i) { - row = zend_hash_index_find(aa, i); + unsigned int k = MIN(ma, na); - for (j = 0; j < n; ++j) { - va[i * n + j] = zephir_get_doubleval(zend_hash_index_find(Z_ARR_P(row), j)); - } + double * w = emalloc(nbuf * sizeof(double)); + double * vu = emalloc(ma * ma * sizeof(double)); + double * vs = emalloc(k * sizeof(double)); + double * vvt = emalloc(na * na * sizeof(double)); + double * vb = emalloc(na * ma * sizeof(double)); + + for (i = 0; i < nbuf; ++i) { + w[i] = va[i]; } - lapack_int status = LAPACKE_dgesdd(LAPACK_ROW_MAJOR, 'A', m, n, va, n, vs, vu, m, vvt, n); + lapack_int status = LAPACKE_dgesdd(LAPACK_ROW_MAJOR, 'A', ma, na, w, na, vs, vu, ma, vvt, na); if (status != 0) { - efree(va); + efree(w); efree(vu); efree(vs); efree(vvt); @@ -204,26 +254,32 @@ void tensor_pseudoinverse(zval * return_value, zval * a) } for (i = 0; i < k; ++i) { - cblas_dscal(m, 1.0 / vs[i], &vu[i], m); + cblas_dscal(ma, 1.0 / vs[i], &vu[i], ma); } - cblas_dgemm(CblasRowMajor, CblasTrans, CblasTrans, n, m, m, 1.0, vvt, n, vu, m, 0.0, vb, m); + cblas_dgemm(CblasRowMajor, CblasTrans, CblasTrans, na, ma, ma, 1.0, vvt, na, vu, ma, 0.0, vb, ma); - array_init_size(&b, n); + zval c; - for (i = 0; i < n; ++i) { - array_init_size(&rowB, m); + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, na * ma, &c) == FAILURE)) { + efree(w); + efree(vu); + efree(vs); + efree(vvt); + efree(vb); - for (j = 0; j < m; ++j) { - add_next_index_double(&rowB, vb[i * m + j]); - } + return; + } + + double * vc = zephir_buffer_doubles(&c); - add_next_index_zval(&b, &rowB); + for (i = 0; i < na * ma; ++i) { + vc[i] = vb[i]; } - RETVAL_ARR(Z_ARR(b)); + zval_ptr_dtor(&c); - efree(va); + efree(w); efree(vu); efree(vs); efree(vvt); @@ -231,21 +287,19 @@ void tensor_pseudoinverse(zval * return_value, zval * a) } /** - * Build the row echelon form of a singular matrix using row reduction, - * mirroring the pure-PHP rowReductionMethod in REF. Pivot rows are not - * normalised so the output matches the non-singular (LAPACK dgetrf) path. - * - * @param return_value - * @param a + * Reduce a (possibly singular) row echelon matrix stored in `w` in place, + * mirroring the pure-PHP row reduction path. Pivot rows are not normalized so + * the output matches the non-singular (LAPACK dgetrf) path. Returns the + * number of row swaps performed. + * + * @param w * @param m * @param n + * @return long */ -static void tensor_ref_singular(zval * return_value, zval * a, unsigned int m, unsigned int n) +static long tensor_ref_singular(double * w, unsigned int m, unsigned int n) { unsigned int i, j; - zval * row; - zval rowB, b; - zval tuple; double epsilon = 0.00000001; double pivot, scale, tmp; @@ -253,18 +307,6 @@ static void tensor_ref_singular(zval * return_value, zval * a, unsigned int m, u unsigned int c = 0; long swaps = 0; - zend_array * aa = Z_ARR_P(a); - - double * w = emalloc(m * n * sizeof(double)); - - for (i = 0; i < m; ++i) { - row = zend_hash_index_find(aa, i); - - for (j = 0; j < n; ++j) { - w[i * n + j] = zephir_get_doubleval(zend_hash_index_find(Z_ARR_P(row), j)); - } - } - while (r < m && c < n) { double * pivotRow = w + r * n; @@ -306,243 +348,242 @@ static void tensor_ref_singular(zval * return_value, zval * a, unsigned int m, u ++c; } - array_init_size(&b, m); - - for (i = 0; i < m; ++i) { - array_init_size(&rowB, n); - - for (j = 0; j < n; ++j) { - add_next_index_double(&rowB, w[i * n + j]); - } - - add_next_index_zval(&b, &rowB); - } - - array_init_size(&tuple, 2); - - add_next_index_zval(&tuple, &b); - add_next_index_long(&tuple, swaps); - - RETVAL_ARR(Z_ARR(tuple)); - - efree(w); + return swaps; } /** - * Compute the row echelon form (REF) of matrix A and return a tuple with the - * reduced matrix and the number of row swaps performed. - * + * Bring a matrix in row-echelon form on a scratch buffer in place, mirroring + * the pure-PHP forward elimination path. Returns the number of row swaps and + * sets `*status` to the LAPACK result (negative on failure). + */ +static long tensor_ref_step(double * w, const double * orig, unsigned int m, unsigned int n, lapack_int * status); + +/** + * Compute the row echelon form (REF) of matrix A, reading A out of a + * TensorBuffer, and return a tuple with the reduced matrix (as a TensorBuffer) + * and the number of row swaps performed. + * * @param return_value * @param a + * @param m + * @param n */ -void tensor_ref(zval * return_value, zval * a) +void tensor_ref(zval * return_value, zval * a, zval * m, zval * n) { - unsigned int i, j; - zval * row; - zval rowB, b; - zval tuple; + zend_long nbuf = 0; + int ok_a = 0; + unsigned int i; - zend_array * aa = Z_ARR_P(a); + unsigned int ma = (unsigned int) zephir_get_intval(m); + unsigned int na = (unsigned int) zephir_get_intval(n); - unsigned int m = zend_array_count(aa); - unsigned int n = zend_array_count(Z_ARR_P(zend_hash_index_find(aa, 0))); + double * va = tensor_tensorbuffer_doubles(a, &nbuf, &ok_a); - double * va = emalloc(m * n * sizeof(double)); - int * pivots = emalloc(MIN(m, n) * sizeof(int)); - - for (i = 0; i < m; ++i) { - row = zend_hash_index_find(aa, i); + if (UNEXPECTED(!ok_a)) { + return; + } - for (j = 0; j < n; ++j) { - va[i * n + j] = zephir_get_doubleval(zend_hash_index_find(Z_ARR_P(row), j)); - } + if (UNEXPECTED(nbuf != (zend_long) ma * na)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffer must match the given dimensions.")); + return; } - lapack_int status = LAPACKE_dgetrf(LAPACK_ROW_MAJOR, m, n, va, n, pivots); + double * w = emalloc(ma * na * sizeof(double)); - if (status > 0) { - efree(va); - efree(pivots); + for (i = 0; i < ma * na; ++i) { + w[i] = va[i]; + } - tensor_ref_singular(return_value, a, m, n); + lapack_int status; - return; - } + long swaps = tensor_ref_step(w, va, ma, na, &status); - if (status != 0) { - efree(va); - efree(pivots); + if (status < 0) { + efree(w); RETURN_NULL(); } - - array_init_size(&b, m); - long swaps = 0; + zval matrix, buf; - for (i = 0; i < m; ++i) { - array_init_size(&rowB, n); + if (UNEXPECTED(tensor_tensorbuffer_create(&matrix, (zend_long) ma * na, &buf) == FAILURE)) { + efree(w); - for (j = 0; j < i; ++j) { - add_next_index_double(&rowB, 0.0); - } - - for (j = i; j < n; ++j) { - add_next_index_double(&rowB, va[i * n + j]); - } + return; + } - add_next_index_zval(&b, &rowB); + { + double * vc = (double *) zephir_buffer_doubles(&buf); - if (i + 1 != pivots[i]) { - ++swaps; + for (i = 0; i < (zend_ulong)(ma * na); ++i) { + vc[i] = w[i]; } } + zval_ptr_dtor(&buf); + + zval tuple; + array_init_size(&tuple, 2); - - add_next_index_zval(&tuple, &b); + + add_next_index_zval(&tuple, &matrix); add_next_index_long(&tuple, swaps); RETVAL_ARR(Z_ARR(tuple)); - efree(va); - efree(pivots); + efree(w); } /** - * Compute the Cholesky decomposition of matrix A and return the lower triangular matrix. - * + * Compute the Cholesky decomposition of matrix A (read from a TensorBuffer) + * and return the lower triangular matrix as a TensorBuffer. + * * @param return_value * @param a + * @param n */ -void tensor_cholesky(zval * return_value, zval * a) +void tensor_cholesky(zval * return_value, zval * a, zval * n) { + zend_long nbuf = 0; + int ok_a = 0; unsigned int i, j; - zval * row; - zval rowB, b; - zend_array * aa = Z_ARR_P(a); + unsigned int na = (unsigned int) zephir_get_intval(n); - unsigned int n = zend_array_count(aa); + double * va = tensor_tensorbuffer_doubles(a, &nbuf, &ok_a); - double * va = emalloc(n * n * sizeof(double)); + if (UNEXPECTED(!ok_a)) { + return; + } + + if (UNEXPECTED(nbuf != (zend_long) na * na)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffer must match the given dimensions.")); + return; + } - for (i = 0; i < n; ++i) { - row = zend_hash_index_find(aa, i); + double * w = emalloc(na * na * sizeof(double)); - for (j = 0; j < n; ++j) { - va[i * n + j] = zephir_get_doubleval(zend_hash_index_find(Z_ARR_P(row), j)); - } + for (i = 0; i < na * na; ++i) { + w[i] = va[i]; } - lapack_int status = LAPACKE_dpotrf(LAPACK_ROW_MAJOR, 'L', n, va, n); + lapack_int status = LAPACKE_dpotrf(LAPACK_ROW_MAJOR, 'L', na, w, na); if (status != 0) { - efree(va); + efree(w); RETURN_NULL(); } - - array_init_size(&b, n); - for (i = 0; i < n; ++i) { - array_init_size(&rowB, n); - - for (j = 0; j <= i; ++j) { - add_next_index_double(&rowB, va[i * n + j]); + /* zero the upper triangle so the result is a proper lower triangular matrix */ + for (i = 0; i < na; ++i) { + for (j = i + 1; j < na; ++j) { + w[i * na + j] = 0.0; } + } - for (j = i + 1; j < n; ++j) { - add_next_index_double(&rowB, 0.0); - } + zval l, buf; + + if (UNEXPECTED(tensor_tensorbuffer_create(&l, (zend_long) na * na, &buf) == FAILURE)) { + efree(w); - add_next_index_zval(&b, &rowB); + return; } - RETVAL_ARR(Z_ARR(b)); + { + double * vc = (double *) zephir_buffer_doubles(&buf); - efree(va); + for (i = 0; i < (zend_ulong)(na * na); ++i) { + vc[i] = w[i]; + } + } + + zval_ptr_dtor(&buf); + + *return_value = l; + + efree(w); } /** - * Compute the LU factorization of matrix A and return a tuple with lower, upper, and permutation matrices. - * + * Compute the LU factorization of matrix A (read from a TensorBuffer) and + * return a tuple with the lower, upper, and permutation matrices (each as a + * TensorBuffer). + * * @param return_value * @param a + * @param n */ -void tensor_lu(zval * return_value, zval * a) +void tensor_lu(zval * return_value, zval * a, zval * n) { + zend_long nbuf = 0; + int ok_a = 0; unsigned int i, j; - zval * row; - zval rowL, l, rowU, u, rowP, p; - zval tuple; - zend_array * aa = Z_ARR_P(a); + unsigned int na = (unsigned int) zephir_get_intval(n); - unsigned int n = zend_array_count(aa); + double * va = tensor_tensorbuffer_doubles(a, &nbuf, &ok_a); - unsigned int * perm; - double * va = emalloc(n * n * sizeof(double)); - int * pivots = emalloc(n * sizeof(int)); + if (UNEXPECTED(!ok_a)) { + return; + } - for (i = 0; i < n; ++i) { - row = zend_hash_index_find(aa, i); + if (UNEXPECTED(nbuf != (zend_long) na * na)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffer must match the given dimensions.")); + return; + } - for (j = 0; j < n; ++j) { - va[i * n + j] = zephir_get_doubleval(zend_hash_index_find(Z_ARR_P(row), j)); - } + unsigned int * perm; + double * va_ = emalloc(na * na * sizeof(double)); + int * pivots = emalloc(na * sizeof(int)); + + for (i = 0; i < na * na; ++i) { + va_[i] = va[i]; } - lapack_int status = LAPACKE_dgetrf(LAPACK_ROW_MAJOR, n, n, va, n, pivots); + lapack_int status = LAPACKE_dgetrf(LAPACK_ROW_MAJOR, na, na, va_, na, pivots); if (status != 0) { - efree(va); + efree(va_); efree(pivots); RETURN_NULL(); } - - array_init_size(&l, n); - array_init_size(&u, n); - array_init_size(&p, n); - for (i = 0; i < n; ++i) { - array_init_size(&rowL, n); + double * lbuf = emalloc(na * na * sizeof(double)); + double * ubuf = emalloc(na * na * sizeof(double)); + double * pbuf = emalloc(na * na * sizeof(double)); + for (i = 0; i < na; ++i) { for (j = 0; j < i; ++j) { - add_next_index_double(&rowL, va[i * n + j]); + lbuf[i * na + j] = va_[i * na + j]; } - add_next_index_double(&rowL, 1.0); + lbuf[i * na + i] = 1.0; - for (j = i + 1; j < n; ++j) { - add_next_index_double(&rowL, 0.0); + for (j = i + 1; j < na; ++j) { + lbuf[i * na + j] = 0.0; } - add_next_index_zval(&l, &rowL); - } - - for (i = 0; i < n; ++i) { - array_init_size(&rowU, n); - for (j = 0; j < i; ++j) { - add_next_index_double(&rowU, 0.0); + ubuf[i * na + j] = 0.0; } - for (j = i; j < n; ++j) { - add_next_index_double(&rowU, va[i * n + j]); + for (j = i; j < na; ++j) { + ubuf[i * na + j] = va_[i * na + j]; } - - add_next_index_zval(&u, &rowU); } - perm = emalloc(n * sizeof(unsigned int)); + perm = emalloc(na * sizeof(unsigned int)); - for (i = 0; i < n; ++i) { + for (i = 0; i < na; ++i) { perm[i] = i; } - for (i = 0; i < n; ++i) { + for (i = 0; i < na; ++i) { unsigned int r = (unsigned int)(pivots[i] - 1); if (r != i) { @@ -553,22 +594,85 @@ void tensor_lu(zval * return_value, zval * a) } } - for (i = 0; i < n; ++i) { - array_init_size(&rowP, n); + for (i = 0; i < na; ++i) { + for (j = 0; j < na; ++j) { + pbuf[i * na + j] = (j == perm[i]) ? 1.0 : 0.0; + } + } + + zval l, u, p, tuple; + zval bufL, bufU, bufP; - for (j = 0; j < n; ++j) { - if (j == perm[i]) { - add_next_index_long(&rowP, 1); - } else { - add_next_index_long(&rowP, 0); - } + if (UNEXPECTED(tensor_tensorbuffer_create(&l, (zend_long) na * na, &bufL) == FAILURE)) { + efree(perm); + efree(lbuf); + efree(ubuf); + efree(pbuf); + efree(va_); + efree(pivots); + + return; + } + + { + double * vc = (double *) zephir_buffer_doubles(&bufL); + + for (i = 0; i < (zend_ulong)(na * na); ++i) { + vc[i] = lbuf[i]; } + } - add_next_index_zval(&p, &rowP); + zval_ptr_dtor(&bufL); + + if (UNEXPECTED(tensor_tensorbuffer_create(&u, (zend_long) na * na, &bufU) == FAILURE)) { + zval_ptr_dtor(&l); + + efree(perm); + efree(lbuf); + efree(ubuf); + efree(pbuf); + efree(va_); + efree(pivots); + + return; } + { + double * vc = (double *) zephir_buffer_doubles(&bufU); + + for (i = 0; i < (zend_ulong)(na * na); ++i) { + vc[i] = ubuf[i]; + } + } + + zval_ptr_dtor(&bufU); + + if (UNEXPECTED(tensor_tensorbuffer_create(&p, (zend_long) na * na, &bufP) == FAILURE)) { + zval_ptr_dtor(&l); + zval_ptr_dtor(&u); + + efree(perm); + efree(lbuf); + efree(ubuf); + efree(pbuf); + efree(va_); + efree(pivots); + + return; + } + + { + double * vc = (double *) zephir_buffer_doubles(&bufP); + + for (i = 0; i < (zend_ulong)(na * na); ++i) { + vc[i] = pbuf[i]; + } + } + + zval_ptr_dtor(&bufP); + array_init_size(&tuple, 3); - + add_next_index_zval(&tuple, &l); add_next_index_zval(&tuple, &u); add_next_index_zval(&tuple, &p); @@ -576,7 +680,10 @@ void tensor_lu(zval * return_value, zval * a) RETVAL_ARR(Z_ARR(tuple)); efree(perm); - efree(va); + efree(lbuf); + efree(ubuf); + efree(pbuf); + efree(va_); efree(pivots); } @@ -586,36 +693,39 @@ void tensor_lu(zval * return_value, zval * a) * @param return_value * @param a */ -void tensor_eig(zval * return_value, zval * a) +void tensor_eig(zval * return_value, zval * a, zval * n) { - unsigned int i, j; - zval * row; - zval eigenvalues; - zval eigenvectors; - zval eigenvector; - zval tuple; + zend_long nbuf = 0; + int ok_a = 0; + unsigned int i; - zend_array * aa = Z_ARR_P(a); + unsigned int na = (unsigned int) zephir_get_intval(n); - unsigned int n = zend_array_count(aa); + double * va = tensor_tensorbuffer_doubles(a, &nbuf, &ok_a); - double * va = emalloc(n * n * sizeof(double)); - double * wr = emalloc(n * sizeof(double)); - double * wi = emalloc(n * sizeof(double)); - double * vr = emalloc(n * n * sizeof(double)); + if (UNEXPECTED(!ok_a)) { + return; + } - for (i = 0; i < n; ++i) { - row = zend_hash_index_find(aa, i); + if (UNEXPECTED(nbuf != (zend_long) na * na)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffer must match the given dimensions.")); + return; + } - for (j = 0; j < n; ++j) { - va[i * n + j] = zephir_get_doubleval(zend_hash_index_find(Z_ARR_P(row), j)); - } + double * w = emalloc(na * na * sizeof(double)); + double * wr = emalloc(na * sizeof(double)); + double * wi = emalloc(na * sizeof(double)); + double * vr = emalloc(na * na * sizeof(double)); + + for (i = 0; i < na * na; ++i) { + w[i] = va[i]; } - lapack_int status = LAPACKE_dgeev(LAPACK_ROW_MAJOR, 'N', 'V', n, va, n, wr, wi, NULL, n, vr, n); + lapack_int status = LAPACKE_dgeev(LAPACK_ROW_MAJOR, 'N', 'V', na, w, na, wr, wi, NULL, na, vr, na); if (status != 0) { - efree(va); + efree(w); efree(wr); efree(wi); efree(vr); @@ -623,29 +733,47 @@ void tensor_eig(zval * return_value, zval * a) RETURN_NULL(); } - array_init_size(&eigenvalues, n); - array_init_size(&eigenvectors, n); + zval eigenvalues; - for (i = 0; i < n; ++i) { + array_init_size(&eigenvalues, na); + + for (i = 0; i < na; ++i) { add_next_index_double(&eigenvalues, wr[i]); + } - array_init_size(&eigenvector, n); + zval eigenvectors, buf; - for (j = 0; j < n; ++j) { - add_next_index_double(&eigenvector, vr[i * n + j]); - } + if (UNEXPECTED(tensor_tensorbuffer_create(&eigenvectors, (zend_long) na * na, &buf) == FAILURE)) { + zval_ptr_dtor(&eigenvalues); - add_next_index_zval(&eigenvectors, &eigenvector); + efree(w); + efree(wr); + efree(wi); + efree(vr); + + return; } + { + double * vc = (double *) zephir_buffer_doubles(&buf); + + for (i = 0; i < (zend_ulong)(na * na); ++i) { + vc[i] = vr[i]; + } + } + + zval_ptr_dtor(&buf); + + zval tuple; + array_init_size(&tuple, 2); - + add_next_index_zval(&tuple, &eigenvalues); add_next_index_zval(&tuple, &eigenvectors); RETVAL_ARR(Z_ARR(tuple)); - efree(va); + efree(w); efree(wr); efree(wi); efree(vr); @@ -657,62 +785,81 @@ void tensor_eig(zval * return_value, zval * a) * @param return_value * @param a */ -void tensor_eig_symmetric(zval * return_value, zval * a) +void tensor_eig_symmetric(zval * return_value, zval * a, zval * n) { - unsigned int i, j; - zval * row; - zval eigenvalues; - zval eigenvectors; - zval eigenvector; - zval tuple; + zend_long nbuf = 0; + int ok_a = 0; + unsigned int i; - zend_array * aa = Z_ARR_P(a); + unsigned int na = (unsigned int) zephir_get_intval(n); - unsigned int n = zend_array_count(aa); + double * va = tensor_tensorbuffer_doubles(a, &nbuf, &ok_a); - double * va = emalloc(n * n * sizeof(double)); - double * wr = emalloc(n * sizeof(double)); + if (UNEXPECTED(!ok_a)) { + return; + } + + if (UNEXPECTED(nbuf != (zend_long) na * na)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffer must match the given dimensions.")); + return; + } - for (i = 0; i < n; ++i) { - row = zend_hash_index_find(aa, i); + double * w = emalloc(na * na * sizeof(double)); + double * wr = emalloc(na * sizeof(double)); - for (j = 0; j < n; ++j) { - va[i * n + j] = zephir_get_doubleval(zend_hash_index_find(Z_ARR_P(row), j)); - } + for (i = 0; i < na * na; ++i) { + w[i] = va[i]; } - lapack_int status = LAPACKE_dsyev(LAPACK_ROW_MAJOR, 'V', 'U', n, va, n, wr); + lapack_int status = LAPACKE_dsyev(LAPACK_ROW_MAJOR, 'V', 'U', na, w, na, wr); if (status != 0) { - efree(va); + efree(w); efree(wr); RETURN_NULL(); } - array_init_size(&eigenvalues, n); - array_init_size(&eigenvectors, n); + zval eigenvalues; + + array_init_size(&eigenvalues, na); - for (i = 0; i < n; ++i) { + for (i = 0; i < na; ++i) { add_next_index_double(&eigenvalues, wr[i]); + } - array_init_size(&eigenvector, n); + zval eigenvectors, buf; - for (j = 0; j < n; ++j) { - add_next_index_double(&eigenvector, va[i * n + j]); - } + if (UNEXPECTED(tensor_tensorbuffer_create(&eigenvectors, (zend_long) na * na, &buf) == FAILURE)) { + zval_ptr_dtor(&eigenvalues); + + efree(w); + efree(wr); + + return; + } - add_next_index_zval(&eigenvectors, &eigenvector); + { + double * vc = (double *) zephir_buffer_doubles(&buf); + + for (i = 0; i < (zend_ulong)(na * na); ++i) { + vc[i] = w[i]; + } } + zval_ptr_dtor(&buf); + + zval tuple; + array_init_size(&tuple, 2); - + add_next_index_zval(&tuple, &eigenvalues); add_next_index_zval(&tuple, &eigenvectors); RETVAL_ARR(Z_ARR(tuple)); - efree(va); + efree(w); efree(wr); } @@ -722,38 +869,41 @@ void tensor_eig_symmetric(zval * return_value, zval * a) * @param return_value * @param a */ -void tensor_svd(zval * return_value, zval * a) +void tensor_svd(zval * return_value, zval * a, zval * m, zval * n) { - unsigned int i, j; - zval * row; - zval u, rowU; - zval s; - zval vt, rowVt; - zval tuple; + zend_long nbuf = 0; + int ok_a = 0; + unsigned int i; - zend_array * aa = Z_ARR_P(a); + unsigned int ma = (unsigned int) zephir_get_intval(m); + unsigned int na = (unsigned int) zephir_get_intval(n); + unsigned int k = MIN(ma, na); - unsigned int m = zend_array_count(aa); - unsigned int n = zend_array_count(Z_ARR_P(zend_hash_index_find(aa, 0))); - unsigned int k = MIN(m, n); + double * va = tensor_tensorbuffer_doubles(a, &nbuf, &ok_a); - double * va = emalloc(m * n * sizeof(double)); - double * vu = emalloc(m * m * sizeof(double)); - double * vs = emalloc(k * sizeof(double)); - double * vvt = emalloc(n * n * sizeof(double)); + if (UNEXPECTED(!ok_a)) { + return; + } + + if (UNEXPECTED(nbuf != (zend_long) ma * na)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffer must match the given dimensions.")); + return; + } - for (i = 0; i < m; ++i) { - row = zend_hash_index_find(aa, i); + double * w = emalloc(ma * na * sizeof(double)); + double * vu = emalloc(ma * ma * sizeof(double)); + double * vs = emalloc(k * sizeof(double)); + double * vvt = emalloc(na * na * sizeof(double)); - for (j = 0; j < n; ++j) { - va[i * n + j] = zephir_get_doubleval(zend_hash_index_find(Z_ARR_P(row), j)); - } + for (i = 0; i < ma * na; ++i) { + w[i] = va[i]; } - lapack_int status = LAPACKE_dgesdd(LAPACK_ROW_MAJOR, 'A', m, n, va, n, vs, vu, m, vvt, n); + lapack_int status = LAPACKE_dgesdd(LAPACK_ROW_MAJOR, 'A', ma, na, w, na, vs, vu, ma, vvt, na); if (status != 0) { - efree(va); + efree(w); efree(vu); efree(vs); efree(vvt); @@ -761,44 +911,397 @@ void tensor_svd(zval * return_value, zval * a) RETURN_NULL(); } - array_init_size(&u, m); - array_init_size(&s, k); - array_init_size(&vt, n); + zval u, bufU; - for (i = 0; i < m; ++i) { - array_init_size(&rowU, m); + if (UNEXPECTED(tensor_tensorbuffer_create(&u, (zend_long) ma * ma, &bufU) == FAILURE)) { + efree(w); + efree(vu); + efree(vs); + efree(vvt); - for (j = 0; j < m; ++j) { - add_next_index_double(&rowU, vu[i * m + j]); - } + return; + } - add_next_index_zval(&u, &rowU); + { + double * vc = (double *) zephir_buffer_doubles(&bufU); + + for (i = 0; i < (zend_ulong)(ma * ma); ++i) { + vc[i] = vu[i]; + } } - + + zval_ptr_dtor(&bufU); + + zval s; + + array_init_size(&s, k); + for (i = 0; i < k; ++i) { add_next_index_double(&s, vs[i]); } - for (i = 0; i < n; ++i) { - array_init_size(&rowVt, n); + zval vt, bufVt; - for (j = 0; j < n; ++j) { - add_next_index_double(&rowVt, vvt[i * n + j]); - } + if (UNEXPECTED(tensor_tensorbuffer_create(&vt, (zend_long) na * na, &bufVt) == FAILURE)) { + zval_ptr_dtor(&u); + zval_ptr_dtor(&s); + + efree(w); + efree(vu); + efree(vs); + efree(vvt); + + return; + } + + { + double * vc = (double *) zephir_buffer_doubles(&bufVt); - add_next_index_zval(&vt, &rowVt); + for (i = 0; i < (zend_ulong)(na * na); ++i) { + vc[i] = vvt[i]; + } } + zval_ptr_dtor(&bufVt); + + zval tuple; + array_init_size(&tuple, 3); - + add_next_index_zval(&tuple, &u); add_next_index_zval(&tuple, &s); add_next_index_zval(&tuple, &vt); RETVAL_ARR(Z_ARR(tuple)); - efree(va); + efree(w); efree(vu); efree(vs); efree(vvt); } + +/** + * Run the forward elimination + singular row reduction used by both + * `tensor_ref` and `tensor_rref`. On failure (LAPACK error) sets *status to a + * large negative value. On success returns the number of row swaps. + */ +static long tensor_ref_step(double * w, const double * orig, unsigned int m, unsigned int n, lapack_int * status) +{ + unsigned int i, j; + + int * pivots = emalloc(MIN(m, n) * sizeof(int)); + + *status = LAPACKE_dgetrf(LAPACK_ROW_MAJOR, m, n, w, n, pivots); + + long swaps = 0; + + if (*status > 0) { + /* Singular: `dgetrf` left `w` partially eliminated. The pure-PHP REF + * fallback must operate on the original (unmodified) matrix to match + * the previous behaviour, so restore `w` from `orig` first. */ + for (i = 0; i < m * n; ++i) { + w[i] = orig[i]; + } + + swaps = tensor_ref_singular(w, m, n); + } else if (*status != 0) { + efree(pivots); + + return 0; + } else { + for (i = 0; i < m; ++i) { + if (i + 1 != (unsigned int) pivots[i]) { + ++swaps; + } + } + + /* `dgetrf` returns the `L + U` factor in `w`. Extract the upper + * triangular `U` (row-echelon form) by clearing the strictly-lower + * triangle, matching the original `tensor_ref` output shape. */ + for (i = 0; i < m; ++i) { + unsigned int lim = i < n ? i : n; + + for (j = 0; j < lim; ++j) { + w[i * n + j] = 0.0; + } + } + } + + efree(pivots); + + return swaps; +} + +/** + * Compute the reduced row echelon form (RREF) of matrix A (read from a + * TensorBuffer). The matrix is first brought to row-echelon form via LAPACK + * `dgetrf` (with a singular-matrix fallback), and then Gauss-Jordan + * normalization and elimination are applied to produce unit pivots, matching + * the pure-PHP `Rref::reduce` path. + * + * @param return_value + * @param a + * @param m + * @param n + */ +void tensor_rref(zval * return_value, zval * a, zval * m, zval * n) +{ + zend_long nbuf = 0; + int ok_a = 0; + unsigned int i, j; + + double epsilon = 0.00000001; + + unsigned int ma = (unsigned int) zephir_get_intval(m); + unsigned int na = (unsigned int) zephir_get_intval(n); + + double * va = tensor_tensorbuffer_doubles(a, &nbuf, &ok_a); + + if (UNEXPECTED(!ok_a)) { + return; + } + + if (UNEXPECTED(nbuf != (zend_long) ma * na)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffer must match the given dimensions.")); + return; + } + + double * w = emalloc(ma * na * sizeof(double)); + + for (i = 0; i < ma * na; ++i) { + w[i] = va[i]; + } + + lapack_int status; + + (void) tensor_ref_step(w, va, ma, na, &status); + + if (status < 0) { + efree(w); + + RETURN_NULL(); + } + + /* Normalize each pivot to 1 and eliminate the entries above it, matching + * the pure-PHP `Rref::reduce` path. */ + unsigned int r = 0, c = 0; + + while (r < ma && c < na) { + double pivot = w[r * na + c]; + + if (fabs(pivot) < epsilon) { + int found = 0; + + for (i = c; i < na; ++i) { + if (fabs(w[r * na + i]) >= epsilon) { + found = 1; + break; + } + } + + if (!found) { + for (j = c; j < na; ++j) { + w[r * na + j] = 0.0; + } + + ++r; + + continue; + } + + ++c; + + continue; + } + + if (pivot != 1.0) { + for (j = 0; j < na; ++j) { + w[r * na + j] /= pivot; + } + } + + for (i = 0; i < r; ++i) { + double scale = w[i * na + c]; + + if (fabs(scale) >= epsilon) { + for (j = 0; j < na; ++j) { + w[i * na + j] -= scale * w[r * na + j]; + } + } + } + + ++r; + ++c; + } + + zval result, buf; + + if (UNEXPECTED(tensor_tensorbuffer_create(&result, (zend_long) ma * na, &buf) == FAILURE)) { + efree(w); + + return; + } + + { + double * vc = (double *) zephir_buffer_doubles(&buf); + + for (i = 0; i < (zend_ulong)(ma * na); ++i) { + vc[i] = w[i]; + } + } + + zval_ptr_dtor(&buf); + + *return_value = result; + + efree(w); +} + +/** + * Return the rank of an already-reduced matrix stored in a TensorBuffer, i.e. + * the number of rows containing at least one non-zero element. + * + * @param return_value + * @param a + * @param m + * @param n + */ +void tensor_rank(zval * return_value, zval * a, zval * m, zval * n) +{ + zend_long nbuf = 0; + int ok_a = 0; + unsigned int i, j; + + double epsilon = 0.00000001; + + unsigned int ma = (unsigned int) zephir_get_intval(m); + unsigned int na = (unsigned int) zephir_get_intval(n); + + double * va = tensor_tensorbuffer_doubles(a, &nbuf, &ok_a); + + if (UNEXPECTED(!ok_a)) { + return; + } + + if (UNEXPECTED(nbuf != (zend_long) ma * na)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffer must match the given dimensions.")); + return; + } + + unsigned int rank = 0; + + for (i = 0; i < ma; ++i) { + for (j = 0; j < na; ++j) { + if (fabs(va[i * na + j]) >= epsilon) { + ++rank; + + break; + } + } + } + + RETVAL_LONG((zend_long) rank); +} + +/** + * Return whether the square matrix A (read from a TensorBuffer) is symmetric + * with respect to a strict element-wise equality (matching PHP `!=`). + * + * @param return_value + * @param a + * @param n + */ +void tensor_is_symmetric(zval * return_value, zval * a, zval * n) +{ + zend_long nbuf = 0; + int ok_a = 0; + + unsigned int i, j; + + unsigned int na = (unsigned int) zephir_get_intval(n); + + double * va = tensor_tensorbuffer_doubles(a, &nbuf, &ok_a); + + if (UNEXPECTED(!ok_a)) { + return; + } + + if (UNEXPECTED(nbuf != (zend_long) na * na)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffer must be square.")); + return; + } + + if (na < 2) { + RETVAL_TRUE; + + return; + } + + for (i = 0; i < na - 1; ++i) { + for (j = i + 1; j < na; ++j) { + if (va[i * na + j] != va[j * na + i]) { + RETVAL_FALSE; + + return; + } + } + } + + RETVAL_TRUE; +} + +/** + * Compute the outer product of two vectors (read from TensorBuffers) and + * return the resulting matrix as a TensorBuffer. + * + * @param return_value + * @param a + * @param b + * @param na + * @param nb + */ +void tensor_outer(zval * return_value, zval * a, zval * b, zval * na, zval * nb) +{ + zend_long nbufa = 0, nbufb = 0; + int ok_a = 0, ok_b = 0; + + unsigned int naHat = (unsigned int) zephir_get_intval(na); + unsigned int nbHat = (unsigned int) zephir_get_intval(nb); + + double * va = tensor_tensorbuffer_doubles(a, &nbufa, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nbufb, &ok_b); + + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } + + if (UNEXPECTED(nbufa != (zend_long) naHat || nbufb != (zend_long) nbHat)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Buffer lengths must match the given dimensions.")); + return; + } + + zval product, buf; + + if (UNEXPECTED(tensor_tensorbuffer_create(&product, (zend_long) naHat * nbHat, &buf) == FAILURE)) { + return; + } + + { + double * vc = (double *) zephir_buffer_doubles(&buf); + unsigned int i, j; + + for (i = 0; i < naHat; ++i) { + for (j = 0; j < nbHat; ++j) { + vc[i * nbHat + j] = va[i] * vb[j]; + } + } + } + + zval_ptr_dtor(&buf); + + *return_value = product; +} diff --git a/ext/include/linear_algebra.h b/ext/include/linear_algebra.h index 10a9d86..143b233 100644 --- a/ext/include/linear_algebra.h +++ b/ext/include/linear_algebra.h @@ -3,17 +3,22 @@ #include -void tensor_matmul(zval * return_value, zval * a, zval * b); +void tensor_matmul(zval * return_value, zval * a, zval * b, zval * m, zval * p, zval * n); +void tensor_matrix_dot(zval * return_value, zval * a, zval * b, zval * m, zval * p); void tensor_dot(zval * return_value, zval * a, zval * b); -void tensor_inverse(zval * return_value, zval * a); -void tensor_pseudoinverse(zval * return_value, zval * a); +void tensor_inverse(zval * return_value, zval * a, zval * n); +void tensor_pseudoinverse(zval * return_value, zval * a, zval * m, zval * n); -void tensor_ref(zval * return_value, zval * a); -void tensor_cholesky(zval * return_value, zval * a); -void tensor_lu(zval * return_value, zval * a); -void tensor_eig(zval * return_value, zval * a); -void tensor_eig_symmetric(zval * return_value, zval * a); -void tensor_svd(zval * return_value, zval * a); +void tensor_ref(zval * return_value, zval * a, zval * m, zval * n); +void tensor_rref(zval * return_value, zval * a, zval * m, zval * n); +void tensor_rank(zval * return_value, zval * a, zval * m, zval * n); +void tensor_is_symmetric(zval * return_value, zval * a, zval * n); +void tensor_cholesky(zval * return_value, zval * a, zval * n); +void tensor_lu(zval * return_value, zval * a, zval * n); +void tensor_eig(zval * return_value, zval * a, zval * n); +void tensor_eig_symmetric(zval * return_value, zval * a, zval * n); +void tensor_svd(zval * return_value, zval * a, zval * m, zval * n); +void tensor_outer(zval * return_value, zval * a, zval * b, zval * na, zval * nb); #endif \ No newline at end of file diff --git a/ext/include/reductions.c b/ext/include/reductions.c new file mode 100644 index 0000000..530b77f --- /dev/null +++ b/ext/include/reductions.c @@ -0,0 +1,667 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include "kernel/main.h" +#include "php_ext.h" +#include "kernel/buffer.h" +#include "kernel/exception.h" +#include "kernel/operators.h" +#include "include/buffer.h" +#include "include/reductions.h" + +#ifdef ZEPHIR_BUFFER_ENABLED + +/** + * Resolve the underlying raw buffer for the reduction operations, accepting + * either a `TensorBuffer` decorator (returns a reference to its wrapped + * buffer) or a raw `Buffer` object as-is (returns a reference to it). The + * caller owns the reference written to `buf` and must release it with + * `zval_ptr_dtor()`. + * + * @return 1 on success, 0 on failure (throwing). + */ +static int tensor_resolve_underlying_buffer(zval * obj, zval * buf) +{ + if (Z_TYPE_P(obj) == IS_OBJECT && Z_OBJCE_P(obj) == tensor_tensorbuffer_ce) { + zval rv; + zval *prop; + + ZVAL_UNDEF(&rv); + + prop = zend_read_property(tensor_tensorbuffer_ce, Z_OBJ_P(obj), "buffer", sizeof("buffer") - 1, 1, &rv); + + if (prop != NULL && prop != &rv) { + ZVAL_COPY(buf, prop); + } else { + ZVAL_UNDEF(buf); + } + + zval_ptr_dtor(&rv); + } else { + ZVAL_COPY(buf, obj); + } + + if (UNEXPECTED(!zephir_is_buffer(buf))) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Argument must be a Buffer or TensorBuffer object.")); + zval_ptr_dtor(buf); + ZVAL_UNDEF(buf); + return 0; + } + + return 1; +} + +/* The tensor_reduce_* operations reduce a flat buffer viewed as `groups` + * contiguous chunks of `length` elements, mirroring TensorBuffer::split(). A + * single group (groups == 1) reduces the whole buffer to a scalar, which is + * exactly the Vector and ColumnVector case, while multiple groups yield the + * per-row Matrix case. `mode` selects the reduction applied to each chunk. */ + +typedef enum { + TENSOR_REDUCE_SUM = 0, + TENSOR_REDUCE_PRODUCT, + TENSOR_REDUCE_MIN, + TENSOR_REDUCE_MAX, + TENSOR_REDUCE_ARGMIN, + TENSOR_REDUCE_ARGMAX +} tensor_reduce_mode; + +/* Reduce a single contiguous run of `len` elements down to a scalar. For the + * sum and product modes a zero-length run yields the identity, mirroring the + * previous whole-buffer behaviour on empty buffers. The arg- modes write the + * index of the extreme into `*index`; the min/max- modes do too, which is + * ignored by their callers. */ +static double tensor_group_reduce(const uint8_t kind, const void * data, const zend_long len, const int mode, zend_long * index) +{ + zend_long i; + zend_long best_index = 0; + + if (mode == TENSOR_REDUCE_SUM) { + double acc = 0.0; + double u0 = 0.0, u1 = 0.0, u2 = 0.0, u3 = 0.0; + double u4 = 0.0, u5 = 0.0, u6 = 0.0, u7 = 0.0; + + /* Accumulate into eight independent partial sums so the floating + * point dependency chain no longer serializes the iterations, and + * merge the partials in a small tree on the way out. The pairwise + * merge also keeps the accumulated rounding error a fraction of the + * naive serial sum. */ + i = 0; + + if (kind == ZEPHIR_BUFFER_LONG) { + const zend_long * ptr = (const zend_long *) data; + + for (; i + 7 < len; i += 8) { + u0 += (double) ptr[i]; + u1 += (double) ptr[i + 1]; + u2 += (double) ptr[i + 2]; + u3 += (double) ptr[i + 3]; + u4 += (double) ptr[i + 4]; + u5 += (double) ptr[i + 5]; + u6 += (double) ptr[i + 6]; + u7 += (double) ptr[i + 7]; + } + + for (; i < len; ++i) { + acc += (double) ptr[i]; + } + } else { + const double * ptr = (const double *) data; + + for (; i + 7 < len; i += 8) { + u0 += ptr[i]; + u1 += ptr[i + 1]; + u2 += ptr[i + 2]; + u3 += ptr[i + 3]; + u4 += ptr[i + 4]; + u5 += ptr[i + 5]; + u6 += ptr[i + 6]; + u7 += ptr[i + 7]; + } + + for (; i < len; ++i) { + acc += ptr[i]; + } + } + + return ((u0 + u1) + (u2 + u3)) + ((u4 + u5) + (u6 + u7)) + acc; + } + + if (mode == TENSOR_REDUCE_PRODUCT) { + double acc = 1.0; + double u0 = 1.0, u1 = 1.0, u2 = 1.0, u3 = 1.0; + double u4 = 1.0, u5 = 1.0, u6 = 1.0, u7 = 1.0; + + i = 0; + + if (kind == ZEPHIR_BUFFER_LONG) { + const zend_long * ptr = (const zend_long *) data; + + for (; i + 7 < len; i += 8) { + u0 *= (double) ptr[i]; + u1 *= (double) ptr[i + 1]; + u2 *= (double) ptr[i + 2]; + u3 *= (double) ptr[i + 3]; + u4 *= (double) ptr[i + 4]; + u5 *= (double) ptr[i + 5]; + u6 *= (double) ptr[i + 6]; + u7 *= (double) ptr[i + 7]; + } + + for (; i < len; ++i) { + acc *= (double) ptr[i]; + } + } else { + const double * ptr = (const double *) data; + + for (; i + 7 < len; i += 8) { + u0 *= ptr[i]; + u1 *= ptr[i + 1]; + u2 *= ptr[i + 2]; + u3 *= ptr[i + 3]; + u4 *= ptr[i + 4]; + u5 *= ptr[i + 5]; + u6 *= ptr[i + 6]; + u7 *= ptr[i + 7]; + } + + for (; i < len; ++i) { + acc *= ptr[i]; + } + } + + return ((u0 * u1) * (u2 * u3)) * ((u4 * u5) * (u6 * u7)) * acc; + } + + int find_min = mode == TENSOR_REDUCE_MIN || mode == TENSOR_REDUCE_ARGMIN; + + if (kind == ZEPHIR_BUFFER_LONG) { + const zend_long * ptr = (const zend_long *) data; + zend_long best = ptr[0]; + + for (i = 1; i < len; ++i) { + if (find_min ? ptr[i] < best : ptr[i] > best) { + best = ptr[i]; + best_index = i; + } + } + + if (index != NULL) { + *index = best_index; + } + + return (double) best; + } else { + const double * ptr = (const double *) data; + double best = ptr[0]; + + for (i = 1; i < len; ++i) { + if (find_min ? ptr[i] < best : ptr[i] > best) { + best = ptr[i]; + best_index = i; + } + } + + if (index != NULL) { + *index = best_index; + } + + return best; + } +} + +/* Shared implementation backing all tensor_reduce_* operations. Unwraps the + * underlying buffer and validates it against a `groups` x `length` logical + * shape before writing one reduced value per group into a new TensorBuffer. */ +static void tensor_reduce_apply(zval * return_value, zval * obj, zval * groups_zval, zval * length_zval, int mode) +{ + zval buffer; + uint8_t kind; + zend_long total = 0, groupsHat = 0, lengthHat = 0, i; + + if (!tensor_resolve_underlying_buffer(obj, &buffer)) { + return; + } + + kind = zephir_buffer_kind(&buffer); + total = zephir_buffer_len(&buffer); + + if (UNEXPECTED(kind == 0)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Argument must be a Buffer object.")); + zval_ptr_dtor(&buffer); + return; + } + + groupsHat = zephir_get_intval(groups_zval); + lengthHat = zephir_get_intval(length_zval); + + if (UNEXPECTED(groupsHat < 1)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Number of groups must be greater than 0.")); + zval_ptr_dtor(&buffer); + return; + } + + if (UNEXPECTED(lengthHat < 0)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Group length must be non-negative.")); + zval_ptr_dtor(&buffer); + return; + } + + if (lengthHat > 0) { + if (UNEXPECTED(total % lengthHat != 0 || groupsHat != total / lengthHat)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Matrix and row dimensions must agree.")); + zval_ptr_dtor(&buffer); + return; + } + } else if (UNEXPECTED(total != 0)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Group length must not be zero for a non-empty buffer.")); + zval_ptr_dtor(&buffer); + return; + } + + /* Extrema need at least one element in every group. */ + if (UNEXPECTED(lengthHat == 0 && (mode == TENSOR_REDUCE_MIN || mode == TENSOR_REDUCE_MAX + || mode == TENSOR_REDUCE_ARGMIN || mode == TENSOR_REDUCE_ARGMAX))) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Cannot compute the reduction of an empty group.")); + zval_ptr_dtor(&buffer); + return; + } + + zval c; + + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, groupsHat, &c) == FAILURE)) { + zval_ptr_dtor(&buffer); + return; + } + + double * vc = zephir_buffer_doubles(&c); + + if (kind == ZEPHIR_BUFFER_LONG) { + const zend_long * ptr = zephir_buffer_longs(&buffer); + + for (i = 0; i < groupsHat; ++i) { + zend_long index = 0; + + double value = tensor_group_reduce(kind, ptr + i * lengthHat, lengthHat, mode, &index); + + vc[i] = (mode == TENSOR_REDUCE_ARGMIN || mode == TENSOR_REDUCE_ARGMAX) + ? (double) index : value; + } + } else { + const double * ptr = zephir_buffer_doubles(&buffer); + + for (i = 0; i < groupsHat; ++i) { + zend_long index = 0; + + double value = tensor_group_reduce(kind, ptr + i * lengthHat, lengthHat, mode, &index); + + vc[i] = (mode == TENSOR_REDUCE_ARGMIN || mode == TENSOR_REDUCE_ARGMAX) + ? (double) index : value; + } + } + + zval_ptr_dtor(&buffer); + zval_ptr_dtor(&c); +} + + +/** + * Row-wise operations work directly on the flat row-major buffer that backs a + * Matrix (m * n doubles) instead of materializing per-row Buffers. This + * helper unwraps the buffer and validates that it can be divided into whole + * rows of length n, mirroring the semantics of `TensorBuffer::split()`. The + * derived row count `*m` and the raw data pointer are written on success. + * + * @return 1 on success, 0 on failure (throwing). + */ +static int tensor_matrix_doubles(zval * obj, zval * n_zval, double ** ptr, zend_long * m, zend_long * n) +{ + zend_long total = 0; + int ok = 0; + + double * va = tensor_tensorbuffer_doubles(obj, &total, &ok); + + if (UNEXPECTED(!ok)) { + return 0; + } + + zend_long n_hat = zephir_get_intval(n_zval); + + if (UNEXPECTED(n_hat < 1)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Chunk length must be greater than 0.")); + return 0; + } + + if (UNEXPECTED(total % n_hat != 0)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Matrix and row dimensions must agree.")); + return 0; + } + + *ptr = va; + *n = n_hat; + *m = total / n_hat; + + return 1; +} + +static int tensor_matrix_double_cmp(const void * a, const void * b) +{ + double da = *(const double *) a; + double db = *(const double *) b; + + return (da > db) - (da < db); +} + +/** + * Return the sum of each group of the buffer as a TensorBuffer. A single + * group covers the whole-buffer (Vector / ColumnVector) case. + * + * @param return_value + * @param obj + * @param groups + * @param length + */ +void tensor_reduce_sum(zval * return_value, zval * obj, zval * groups, zval * length) +{ + tensor_reduce_apply(return_value, obj, groups, length, TENSOR_REDUCE_SUM); +} + +/** + * Return the product of each group of the buffer as a TensorBuffer. A single + * group covers the whole-buffer (Vector / ColumnVector) case. + * + * @param return_value + * @param obj + * @param groups + * @param length + */ +void tensor_reduce_product(zval * return_value, zval * obj, zval * groups, zval * length) +{ + tensor_reduce_apply(return_value, obj, groups, length, TENSOR_REDUCE_PRODUCT); +} + +/** + * Return the minimum of each group of the buffer as a TensorBuffer. A single + * group covers the whole-buffer (Vector / ColumnVector) case. + * + * @param return_value + * @param obj + * @param groups + * @param length + */ +void tensor_reduce_min(zval * return_value, zval * obj, zval * groups, zval * length) +{ + tensor_reduce_apply(return_value, obj, groups, length, TENSOR_REDUCE_MIN); +} + +/** + * Return the maximum of each group of the buffer as a TensorBuffer. A single + * group covers the whole-buffer (Vector / ColumnVector) case. + * + * @param return_value + * @param obj + * @param groups + * @param length + */ +void tensor_reduce_max(zval * return_value, zval * obj, zval * groups, zval * length) +{ + tensor_reduce_apply(return_value, obj, groups, length, TENSOR_REDUCE_MAX); +} + +/** + * Return the index of the minimum of each group of the buffer as a + * TensorBuffer. A single group covers the whole-buffer (Vector / + * ColumnVector) case. + * + * @param return_value + * @param obj + * @param groups + * @param length + */ +void tensor_reduce_argmin(zval * return_value, zval * obj, zval * groups, zval * length) +{ + tensor_reduce_apply(return_value, obj, groups, length, TENSOR_REDUCE_ARGMIN); +} + +/** + * Return the index of the maximum of each group of the buffer as a + * TensorBuffer. A single group covers the whole-buffer (Vector / + * ColumnVector) case. + * + * @param return_value + * @param obj + * @param groups + * @param length + */ +void tensor_reduce_argmax(zval * return_value, zval * obj, zval * groups, zval * length) +{ + tensor_reduce_apply(return_value, obj, groups, length, TENSOR_REDUCE_ARGMAX); +} + +/** + * Return the median of each row of a matrix as a column buffer, or of a + * vector as a single element. The buffer itself is never modified; the rows + * are copied once and sorted. A Vector is simply a 1 x n matrix. + * + * @param return_value + * @param obj + * @param n + */ +void tensor_median(zval * return_value, zval * obj, zval * n) +{ + double * va = NULL; + zend_long m = 0, n_hat = 0; + zend_long i; + + if (UNEXPECTED(!tensor_matrix_doubles(obj, n, &va, &m, &n_hat))) { + return; + } + + double * copy = NULL; + + if (UNEXPECTED(m > 0 && n_hat > 0)) { + copy = safe_emalloc((size_t) m * (size_t) n_hat, sizeof(double), 0); + + memcpy(copy, va, (size_t) m * (size_t) n_hat * sizeof(double)); + } + + zval c; + + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, m, &c) == FAILURE)) { + efree(copy); + + return; + } + + double * vc = zephir_buffer_doubles(&c); + + zend_long mid = n_hat / 2; + int odd = n_hat % 2 == 1; + + for (i = 0; i < m; ++i) { + double * row = copy + i * n_hat; + + qsort(row, (size_t) n_hat, sizeof(double), tensor_matrix_double_cmp); + + if (odd) { + vc[i] = row[mid]; + } else { + vc[i] = (row[mid - 1] + row[mid]) / 2.0; + } + } + + efree(copy); + + zval_ptr_dtor(&c); +} + +/** + * Return the q'th quantile of each row of a matrix as a column buffer, or of + * a vector as a single element. The buffer itself is never modified; the rows + * are copied once and sorted. A Vector is simply a 1 x n matrix. + * + * @param return_value + * @param obj + * @param n + * @param q + */ +void tensor_quantile(zval * return_value, zval * obj, zval * n, zval * q) +{ + double * va = NULL; + zend_long m = 0, n_hat = 0; + zend_long i; + + if (UNEXPECTED(!tensor_matrix_doubles(obj, n, &va, &m, &n_hat))) { + return; + } + + double * copy = NULL; + + if (UNEXPECTED(m > 0 && n_hat > 0)) { + copy = safe_emalloc((size_t) m * (size_t) n_hat, sizeof(double), 0); + + memcpy(copy, va, (size_t) m * (size_t) n_hat * sizeof(double)); + } + + zval c; + + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, m, &c) == FAILURE)) { + efree(copy); + + return; + } + + double * vc = zephir_buffer_doubles(&c); + + double q_hat = zephir_get_doubleval(q); + + double x = q_hat * (n_hat - 1) + 1; + + zend_long x_hat = (zend_long) x; + double remainder = x - (double) x_hat; + + for (i = 0; i < m; ++i) { + double * row = copy + i * n_hat; + double value; + + qsort(row, (size_t) n_hat, sizeof(double), tensor_matrix_double_cmp); + + if (x_hat >= n_hat) { + value = row[n_hat - 1]; + } else { + double t = row[x_hat - 1]; + + value = t + remainder * (row[x_hat] - t); + } + + vc[i] = value; + } + + efree(copy); + + zval_ptr_dtor(&c); +} + +/** + * Return a new matrix buffer with rows and columns repeated the given number + * of times. Result element (r, c) is element (r % m, c % n) of the input, + * yielding (m * (times_m + 1)) rows and (n * (times_n + 1)) columns. + * + * @param return_value + * @param obj + * @param n + * @param times_m + * @param times_n + */ +void tensor_matrix_repeat(zval * return_value, zval * obj, zval * n, zval * times_m, zval * times_n) +{ + double * va = NULL; + zend_long m = 0, n_hat = 0; + zend_long t_m = 0, t_n = 0; + + if (UNEXPECTED(!tensor_matrix_doubles(obj, n, &va, &m, &n_hat))) { + return; + } + + t_m = zephir_get_intval(times_m); + t_n = zephir_get_intval(times_n); + + if (UNEXPECTED(t_m < 0 || t_n < 0)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Times must be non-negative.")); + return; + } + + zend_long rows = m * (t_m + 1); + zend_long cols = n_hat * (t_n + 1); + + zval c; + + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, rows * cols, &c) == FAILURE)) { + return; + } + + double * vc = zephir_buffer_doubles(&c); + + zend_long i, k; + + for (i = 0; i < rows; ++i) { + const double * src = va + (i % m) * n_hat; + double * dst = vc + i * cols; + + for (k = 0; k <= t_n; ++k) { + memcpy(dst + k * n_hat, src, (size_t) n_hat * sizeof(double)); + } + } + + zval_ptr_dtor(&c); +} + +/** + * Return the matrix as an array of arrays, built directly from the flat + * row-major buffer. + * + * @param return_value + * @param obj + * @param n + */ +void tensor_matrix_to_array(zval * return_value, zval * obj, zval * n) +{ + double * va = NULL; + zend_long m = 0, n_hat = 0; + zend_long i, j; + + if (UNEXPECTED(!tensor_matrix_doubles(obj, n, &va, &m, &n_hat))) { + return; + } + + array_init_size(return_value, (zend_ulong) m); + + for (i = 0; i < m; ++i) { + const double * row = va + i * n_hat; + zval row_value; + + array_init_size(&row_value, (zend_ulong) n_hat); + + for (j = 0; j < n_hat; ++j) { + add_next_index_double(&row_value, row[j]); + } + + add_next_index_zval(return_value, &row_value); + } +} + +#endif \ No newline at end of file diff --git a/ext/include/reductions.h b/ext/include/reductions.h new file mode 100644 index 0000000..521469f --- /dev/null +++ b/ext/include/reductions.h @@ -0,0 +1,18 @@ +#ifndef TENSOR_REDUCTIONS_H +#define TENSOR_REDUCTIONS_H + +#include + +void tensor_reduce_sum(zval * return_value, zval * obj, zval * groups, zval * length); +void tensor_reduce_product(zval * return_value, zval * obj, zval * groups, zval * length); +void tensor_reduce_min(zval * return_value, zval * obj, zval * groups, zval * length); +void tensor_reduce_max(zval * return_value, zval * obj, zval * groups, zval * length); +void tensor_reduce_argmin(zval * return_value, zval * obj, zval * groups, zval * length); +void tensor_reduce_argmax(zval * return_value, zval * obj, zval * groups, zval * length); + +void tensor_median(zval * return_value, zval * obj, zval * n); +void tensor_quantile(zval * return_value, zval * obj, zval * n, zval * q); +void tensor_matrix_repeat(zval * return_value, zval * obj, zval * n, zval * times_m, zval * times_n); +void tensor_matrix_to_array(zval * return_value, zval * obj, zval * n); + +#endif \ No newline at end of file diff --git a/ext/include/shape.c b/ext/include/shape.c new file mode 100644 index 0000000..f16fac6 --- /dev/null +++ b/ext/include/shape.c @@ -0,0 +1,73 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include "kernel/main.h" +#include "php_ext.h" +#include "kernel/buffer.h" +#include "kernel/exception.h" +#include "kernel/operators.h" +#include "include/buffer.h" + +/** + * Return the transpose of the matrix as a new matrix buffer, i.e. row i of the + * output holds column i of the input. Eliminates the strided per-column slices + * and concatenation used by the previous pure-Zephir path. + * + * @param return_value + * @param a + * @param m + * @param n + */ +void tensor_matrix_transpose(zval * return_value, zval * a, zval * m, zval * n) +{ + zend_long total = 0; + int ok = 0; + + double * va = tensor_tensorbuffer_doubles(a, &total, &ok); + + if (UNEXPECTED(!ok)) { + return; + } + + zend_long ma = zephir_get_intval(m); + zend_long na = zephir_get_intval(n); + + if (UNEXPECTED(ma < 0 || na < 0)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, + SL("Dimensions must be non-negative.")); + return; + } + + if (UNEXPECTED(total != ma * na)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffer must match the given dimensions.")); + return; + } + + zval c; + + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, total, &c) == FAILURE)) { + return; + } + + double * vc = zephir_buffer_doubles(&c); + + if (total > 0) { + zend_long i, j; + + for (i = 0; i < ma; ++i) { + const double * src = va + i * na; + double * dst = vc + i; + + for (j = 0; j < na; ++j) { + dst[j * ma] = src[j]; + } + } + } + + zval_ptr_dtor(&c); +} \ No newline at end of file diff --git a/ext/include/shape.h b/ext/include/shape.h new file mode 100644 index 0000000..268673a --- /dev/null +++ b/ext/include/shape.h @@ -0,0 +1,8 @@ +#ifndef TENSOR_SHAPE_H +#define TENSOR_SHAPE_H + +#include + +void tensor_matrix_transpose(zval * return_value, zval * a, zval * m, zval * n); + +#endif \ No newline at end of file diff --git a/ext/include/signal_processing.c b/ext/include/signal_processing.c index d974ff9..59c592c 100644 --- a/ext/include/signal_processing.c +++ b/ext/include/signal_processing.c @@ -3,7 +3,11 @@ #endif #include +#include #include "kernel/operators.h" +#include "php_ext.h" +#include "kernel/buffer.h" +#include "include/buffer.h" /** * 1D convolution between a vector A and B (kernel) with a given stride. @@ -15,50 +19,48 @@ */ void tensor_convolve_1d(zval * return_value, zval * a, zval * b, zval * stride) { - unsigned int i, j; - unsigned int jmin, jmax; - double sigma; - zval c; + zend_long i, j; + zend_long jmin, jmax; + double sigma; + zend_long na = 0, nb = 0; + int ok_a = 0, ok_b = 0; - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + double * va = tensor_tensorbuffer_doubles(a, &na, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nb, &ok_b); - unsigned int s = zephir_get_intval(stride); + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } - unsigned int na = zend_array_count(aa); - unsigned int nb = zend_array_count(ab); - unsigned int nc = na + nb - 1; + zend_long s = zephir_get_intval(stride); - double * va = emalloc(na * sizeof(double)); - double * vb = emalloc(nb * sizeof(double)); + zend_long nc = na + nb - 1; + zend_long nout = (nc + s - 1) / s; - for (i = 0; i < na; ++i) { - va[i] = zephir_get_doubleval(zend_hash_index_find(aa, i)); - } + zval c; - for (i = 0; i < nb; ++i) { - vb[i] = zephir_get_doubleval(zend_hash_index_find(ab, i)); - } + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, nout, &c) == FAILURE)) { + return; + } - array_init_size(&c, (nc + s - 1) / s); + double * vc = zephir_buffer_doubles(&c); - for (i = 0; i < nc; i += s) { - jmin = i >= nb - 1 ? i - (nb - 1) : 0; - jmax = i < na ? i : na - 1; + zend_long idx = 0; - sigma = 0.0; + for (i = 0; i < nc; i += s) { + jmin = i >= nb - 1 ? i - (nb - 1) : 0; + jmax = i < na ? i : na - 1; - for (j = jmin; j <= jmax; ++j) { - sigma += va[j] * vb[i - j]; - } + sigma = 0.0; - add_next_index_double(&c, sigma); - } + for (j = jmin; j <= jmax; ++j) { + sigma += va[j] * vb[i - j]; + } - RETVAL_ARR(Z_ARR(c)); + vc[idx++] = sigma; + } - efree(va); - efree(vb); + zval_ptr_dtor(&c); } /** @@ -68,79 +70,77 @@ void tensor_convolve_1d(zval * return_value, zval * a, zval * b, zval * stride) * @param a * @param b * @param stride + * @param ma + * @param na + * @param mb + * @param nb */ -void tensor_convolve_2d(zval * return_value, zval * a, zval * b, zval * stride) +void tensor_convolve_2d(zval * return_value, zval * a, zval * b, zval * stride, zval * ma, zval * na, zval * mb, zval * nb) { - unsigned int i, j, k, l; - int x, y; + zend_long i, j, k, l; + zend_long x, y; double sigma; - zval * row; - zval rowC, c; + zend_long nbufa = 0, nbufb = 0; + int ok_a = 0, ok_b = 0; - zend_array * aa = Z_ARR_P(a); - zend_array * ab = Z_ARR_P(b); + zend_long s = zephir_get_intval(stride); + zend_long ma_ = zephir_get_intval(ma); + zend_long na_ = zephir_get_intval(na); + zend_long mb_ = zephir_get_intval(mb); + zend_long nb_ = zephir_get_intval(nb); - unsigned int s = zephir_get_intval(stride); + double * va = tensor_tensorbuffer_doubles(a, &nbufa, &ok_a); + double * vb = tensor_tensorbuffer_doubles(b, &nbufb, &ok_b); - unsigned int ma = zend_array_count(aa); - unsigned int na = zend_array_count(Z_ARR_P(zend_hash_index_find(aa, 0))); - unsigned int mb = zend_array_count(ab); - unsigned int nb = zend_array_count(Z_ARR_P(zend_hash_index_find(ab, 0))); + if (UNEXPECTED(!ok_a || !ok_b)) { + return; + } - double * va = emalloc(ma * na * sizeof(double)); - double * vb = emalloc(mb * nb * sizeof(double)); + if (UNEXPECTED(nbufa != ma_ * na_ || nbufb != mb_ * nb_)) { + zephir_throw_exception_string(spl_ce_LengthException, + SL("Input buffers must match the given dimensions.")); + return; + } - for (i = 0; i < ma; ++i) { - row = zend_hash_index_find(aa, i); + zend_long p = mb_ / 2; + zend_long q = nb_ / 2; - for (j = 0; j < na; ++j) { - va[i * na + j] = zephir_get_doubleval(zend_hash_index_find(Z_ARR_P(row), j)); - } - } + zend_long om = (ma_ + s - 1) / s; + zend_long on = (na_ + s - 1) / s; - for (i = 0; i < mb; ++i) { - row = zend_hash_index_find(ab, i); + zval c; - for (j = 0; j < nb; ++j) { - vb[i * nb + j] = zephir_get_doubleval(zend_hash_index_find(Z_ARR_P(row), j)); - } + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, om * on, &c) == FAILURE)) { + return; } - unsigned int p = mb / 2; - unsigned int q = nb / 2; + double * vc = zephir_buffer_doubles(&c); - array_init_size(&c, (ma + s - 1) / s); + zend_long idx = 0; - for (i = 0; i < ma; i += s) { - array_init_size(&rowC, (na + s - 1) / s); - - for (j = 0; j < na; j += s) { + for (i = 0; i < ma_; i += s) { + for (j = 0; j < na_; j += s) { sigma = 0.0; - for (k = 0; k < mb; ++k) { + for (k = 0; k < mb_; ++k) { x = i + p - k; - if (x < 0 || x >= ma) { + if (x < 0 || x >= ma_) { continue; } - for (l = 0; l < nb; ++l) { + for (l = 0; l < nb_; ++l) { y = j + q - l; - if (y >= 0 && y < na) { - sigma += va[x * na + y] * vb[k * nb + l]; + if (y >= 0 && y < na_) { + sigma += va[x * na_ + y] * vb[k * nb_ + l]; } } } - add_next_index_double(&rowC, sigma); + vc[idx++] = sigma; } - - add_next_index_zval(&c, &rowC); } - RETVAL_ARR(Z_ARR(c)); - - efree(va); - efree(vb); + zval_ptr_dtor(&c); } diff --git a/ext/include/signal_processing.h b/ext/include/signal_processing.h index 22f1b66..e64e39a 100644 --- a/ext/include/signal_processing.h +++ b/ext/include/signal_processing.h @@ -4,6 +4,6 @@ #include void tensor_convolve_1d(zval * return_value, zval * a, zval * b, zval * stride); -void tensor_convolve_2d(zval * return_value, zval * a, zval * b, zval * stride); +void tensor_convolve_2d(zval * return_value, zval * a, zval * b, zval * stride, zval * ma, zval * na, zval * mb, zval * nb); #endif diff --git a/ext/include/unary.c b/ext/include/unary.c new file mode 100644 index 0000000..1af9709 --- /dev/null +++ b/ext/include/unary.c @@ -0,0 +1,361 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include "kernel/operators.h" +#include "php_ext.h" +#include "kernel/buffer.h" +#include "include/buffer.h" + +/* Values wrapped up by the kernel Buffer used in the unary operations below. + * Returns a reference to a newly created `Tensor\TensorBuffer` holding the + * mapped doubles. Each operation expands into its own dedicated loop so the + * optimizer can vectorize the elementwise mapping instead of being blocked by + * an indirect call. */ + +#define TENSOR_UNARY(name, expr) \ +void tensor_##name(zval * return_value, zval * a) \ +{ \ + zend_long n = 0; \ + int ok = 0; \ + \ + double * va = tensor_tensorbuffer_doubles(a, &n, &ok); \ + \ + if (UNEXPECTED(!ok)) { \ + return; \ + } \ + \ + zval b; \ + \ + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, n, &b) == FAILURE)) { \ + return; \ + } \ + \ + double * vb = zephir_buffer_doubles(&b); \ + \ + zend_long i; \ + \ + for (i = 0; i < n; ++i) { \ + vb[i] = expr; \ + } \ + \ + zval_ptr_dtor(&b); \ +} + +TENSOR_UNARY(abs, fabs(va[i])) +TENSOR_UNARY(sqrt, sqrt(va[i])) +TENSOR_UNARY(exp, exp(va[i])) +TENSOR_UNARY(expm1, expm1(va[i])) +TENSOR_UNARY(log, log(va[i])) +TENSOR_UNARY(log1p, log1p(va[i])) +TENSOR_UNARY(sin, sin(va[i])) +TENSOR_UNARY(asin, asin(va[i])) +TENSOR_UNARY(cos, cos(va[i])) +TENSOR_UNARY(acos, acos(va[i])) +TENSOR_UNARY(tan, tan(va[i])) +TENSOR_UNARY(atan, atan(va[i])) +TENSOR_UNARY(rad2deg, (va[i] / M_PI) * 180.0) +TENSOR_UNARY(deg2rad, (va[i] / 180.0) * M_PI) +TENSOR_UNARY(floor, floor(va[i])) +TENSOR_UNARY(ceil, ceil(va[i])) +TENSOR_UNARY(negate, -va[i]) +TENSOR_UNARY(sign, va[i] > 0.0 ? 1.0 : (va[i] < 0.0 ? -1.0 : 0.0)) + +#undef TENSOR_UNARY + +void tensor_log_base(zval * return_value, zval * a, zval * b) +{ + zend_long i; + zend_long n = 0; + int ok = 0; + + double * va = tensor_tensorbuffer_doubles(a, &n, &ok); + + if (UNEXPECTED(!ok)) { + return; + } + + double base = zephir_get_doubleval(b); + + zval c; + + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, n, &c) == FAILURE)) { + return; + } + + double * vc = zephir_buffer_doubles(&c); + + for (i = 0; i < n; ++i) { + vc[i] = log(va[i]) / log(base); + } + + zval_ptr_dtor(&c); +} + +/* The following mirror the rounding implementation in ext/standard/math.c so + * that results match PHP's round() exactly. */ +static int tensor_intlog10abs(double value) +{ + value = fabs(value); + + if (value < 1e-8 || value > 1e22) { + return (int) floor(log10(value)); + } else { + int result = 15; + static const double values[] = { + 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0, 1e1, 1e2, + 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, + 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22}; + + if (value < values[result]) { + result -= 8; + } else { + result += 8; + } + + if (value < values[result]) { + result -= 4; + } else { + result += 4; + } + + if (value < values[result]) { + result -= 2; + } else { + result += 2; + } + + if (value < values[result]) { + result -= 1; + } else { + result += 1; + } + + if (value < values[result]) { + result -= 1; + } + + result -= 8; + + return result; + } +} + +static double tensor_intpow10(int power) +{ + if (power < 0 || power > 22) { + return pow(10.0, (double) power); + } + + static const double powers[] = { + 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, + 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22}; + + return powers[power]; +} + +static double tensor_round_half_up(double value) +{ + return value >= 0.0 ? floor(value + 0.5) : ceil(value - 0.5); +} + +static double tensor_math_round(double value, int places) +{ + double f1, f2; + double tmp_value; + int precision_places; + + if (!isfinite(value) || value == 0.0) { + return value; + } + + places = places < INT_MIN + 1 ? INT_MIN + 1 : places; + + precision_places = 14 - tensor_intlog10abs(value); + + f1 = tensor_intpow10(abs(places)); + + if (precision_places > places && precision_places - 15 < places) { + int64_t use_precision = precision_places < INT_MIN + 1 ? INT_MIN + 1 : precision_places; + + f2 = tensor_intpow10(abs((int) use_precision)); + + if (use_precision >= 0) { + tmp_value = value * f2; + } else { + tmp_value = value / f2; + } + + tmp_value = tensor_round_half_up(tmp_value); + + use_precision = places - precision_places; + + if (use_precision < INT_MIN + 1) { + use_precision = INT_MIN + 1; + } + + f2 = tensor_intpow10(abs((int) use_precision)); + + tmp_value = tmp_value / f2; + } else { + if (places >= 0) { + tmp_value = value * f1; + } else { + tmp_value = value / f1; + } + + if (fabs(tmp_value) >= 1e15) { + return value; + } + } + + tmp_value = tensor_round_half_up(tmp_value); + + if (abs(places) < 23) { + if (places > 0) { + tmp_value = tmp_value / f1; + } else { + tmp_value = tmp_value * f1; + } + } else { + char buf[40]; + + snprintf(buf, 39, "%15fe%d", tmp_value, -places); + + buf[39] = '\0'; + + double parsed = zend_strtod(buf, NULL); + + if (!isfinite(parsed) || isnan(parsed)) { + parsed = value; + } + + tmp_value = parsed; + } + + return tmp_value; +} + +void tensor_round(zval * return_value, zval * a, zval * precision) +{ + zend_long i; + zend_long n = 0; + int ok = 0; + + double * va = tensor_tensorbuffer_doubles(a, &n, &ok); + + if (UNEXPECTED(!ok)) { + return; + } + + zend_long p = zephir_get_intval(precision); + + int places = p > INT_MAX ? INT_MAX : (int) p; + + zval c; + + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, n, &c) == FAILURE)) { + return; + } + + double * vc = zephir_buffer_doubles(&c); + + for (i = 0; i < n; ++i) { + vc[i] = tensor_math_round(va[i], places); + } + + zval_ptr_dtor(&c); +} + +void tensor_clip(zval * return_value, zval * a, zval * min, zval * max) +{ + zend_long i; + zend_long n = 0; + int ok = 0; + + double * va = tensor_tensorbuffer_doubles(a, &n, &ok); + + if (UNEXPECTED(!ok)) { + return; + } + + double lo = zephir_get_doubleval(min); + double hi = zephir_get_doubleval(max); + + zval c; + + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, n, &c) == FAILURE)) { + return; + } + + double * vc = zephir_buffer_doubles(&c); + + for (i = 0; i < n; ++i) { + vc[i] = va[i] > hi ? hi : (va[i] < lo ? lo : va[i]); + } + + zval_ptr_dtor(&c); +} + +void tensor_clip_lower(zval * return_value, zval * a, zval * min) +{ + zend_long i; + zend_long n = 0; + int ok = 0; + + double * va = tensor_tensorbuffer_doubles(a, &n, &ok); + + if (UNEXPECTED(!ok)) { + return; + } + + double lo = zephir_get_doubleval(min); + + zval c; + + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, n, &c) == FAILURE)) { + return; + } + + double * vc = zephir_buffer_doubles(&c); + + for (i = 0; i < n; ++i) { + vc[i] = va[i] < lo ? lo : va[i]; + } + + zval_ptr_dtor(&c); +} + +void tensor_clip_upper(zval * return_value, zval * a, zval * max) +{ + zend_long i; + zend_long n = 0; + int ok = 0; + + double * va = tensor_tensorbuffer_doubles(a, &n, &ok); + + if (UNEXPECTED(!ok)) { + return; + } + + double hi = zephir_get_doubleval(max); + + zval c; + + if (UNEXPECTED(tensor_tensorbuffer_create(return_value, n, &c) == FAILURE)) { + return; + } + + double * vc = zephir_buffer_doubles(&c); + + for (i = 0; i < n; ++i) { + vc[i] = va[i] > hi ? hi : va[i]; + } + + zval_ptr_dtor(&c); +} \ No newline at end of file diff --git a/ext/include/unary.h b/ext/include/unary.h new file mode 100644 index 0000000..5a8b39a --- /dev/null +++ b/ext/include/unary.h @@ -0,0 +1,30 @@ +#ifndef TENSOR_ELEMENTWISE_H +#define TENSOR_ELEMENTWISE_H + +#include + +void tensor_abs(zval * return_value, zval * a); +void tensor_sqrt(zval * return_value, zval * a); +void tensor_exp(zval * return_value, zval * a); +void tensor_expm1(zval * return_value, zval * a); +void tensor_log(zval * return_value, zval * a); +void tensor_log_base(zval * return_value, zval * a, zval * b); +void tensor_log1p(zval * return_value, zval * a); +void tensor_sin(zval * return_value, zval * a); +void tensor_asin(zval * return_value, zval * a); +void tensor_cos(zval * return_value, zval * a); +void tensor_acos(zval * return_value, zval * a); +void tensor_tan(zval * return_value, zval * a); +void tensor_atan(zval * return_value, zval * a); +void tensor_rad2deg(zval * return_value, zval * a); +void tensor_deg2rad(zval * return_value, zval * a); +void tensor_floor(zval * return_value, zval * a); +void tensor_ceil(zval * return_value, zval * a); +void tensor_round(zval * return_value, zval * a, zval * precision); +void tensor_negate(zval * return_value, zval * a); +void tensor_sign(zval * return_value, zval * a); +void tensor_clip(zval * return_value, zval * a, zval * min, zval * max); +void tensor_clip_lower(zval * return_value, zval * a, zval * min); +void tensor_clip_upper(zval * return_value, zval * a, zval * max); + +#endif \ No newline at end of file diff --git a/ext/kernel/array.c b/ext/kernel/array.c index bac163a..9ac93ff 100644 --- a/ext/kernel/array.c +++ b/ext/kernel/array.c @@ -24,6 +24,7 @@ #include "kernel/memory.h" #include "kernel/debug.h" #include "kernel/array.h" +#include "kernel/buffer.h" #include "kernel/operators.h" #include "kernel/backtrace.h" #include "kernel/object.h" @@ -464,6 +465,12 @@ int ZEPHIR_FASTCALL zephir_array_isset(const zval *arr, zval *index) return 0; } +#ifdef ZEPHIR_BUFFER_ENABLED + if (UNEXPECTED(zephir_is_buffer(arr))) { + return zephir_buffer_dim_isset(arr, index); + } +#endif + if (UNEXPECTED(Z_TYPE_P(arr) == IS_OBJECT && zephir_instance_of_ev((zval *)arr, (const zend_class_entry *)zend_ce_arrayaccess))) { zend_long ZEPHIR_LAST_CALL_STATUS; zval container, exist; @@ -555,6 +562,12 @@ int ZEPHIR_FASTCALL zephir_array_isset_string(const zval *arr, const char *index int ZEPHIR_FASTCALL zephir_array_isset_long(const zval *arr, zend_long index) { +#ifdef ZEPHIR_BUFFER_ENABLED + if (UNEXPECTED(zephir_is_buffer(arr))) { + return zephir_buffer_dim_isset_long(arr, index); + } +#endif + if (UNEXPECTED(Z_TYPE_P(arr) == IS_OBJECT && zephir_instance_of_ev((zval *)arr, (const zend_class_entry *)zend_ce_arrayaccess))) { zend_long ZEPHIR_LAST_CALL_STATUS; zval container, exist, offset; @@ -938,6 +951,12 @@ int zephir_array_fetch(zval *return_value, zval *arr, zval *index, int flags ZEP arr = zephir_array_write_container(arr); } +#ifdef ZEPHIR_BUFFER_ENABLED + if (UNEXPECTED(zephir_is_buffer(arr)) && (flags & PH_WRITE) != PH_WRITE) { + return zephir_buffer_dim_read(return_value, arr, index); + } +#endif + if (UNEXPECTED(Z_TYPE_P(arr) == IS_OBJECT && zephir_instance_of_ev(arr, (const zend_class_entry *)zend_ce_arrayaccess))) { zend_long ZEPHIR_LAST_CALL_STATUS; ZEPHIR_CALL_METHOD_WITHOUT_OBSERVE(return_value, arr, "offsetget", NULL, 0, index); @@ -1097,6 +1116,16 @@ int zephir_array_fetch_long(zval *return_value, zval *arr, zend_long index, int arr = zephir_array_write_container(arr); } +#ifdef ZEPHIR_BUFFER_ENABLED + /* A \Buffer element is a raw C scalar: one class-entry pointer compare + * and a direct load, instead of an offsetGet() call. A write-context fetch + * deliberately falls through to the ArrayAccess path below, so the engine + * still reports the element as unmodifiable. */ + if (UNEXPECTED(zephir_is_buffer(arr)) && (flags & PH_WRITE) != PH_WRITE) { + return zephir_buffer_dim_read_long(return_value, arr, index); + } +#endif + if (UNEXPECTED(Z_TYPE_P(arr) == IS_OBJECT && zephir_instance_of_ev(arr, (const zend_class_entry *)zend_ce_arrayaccess))) { zend_long ZEPHIR_LAST_CALL_STATUS; zval offset; @@ -1179,6 +1208,12 @@ int zephir_array_update_zval(zval *arr, zval *index, zval *value, int flags) HashTable *ht; zval *ret = NULL; +#ifdef ZEPHIR_BUFFER_ENABLED + if (UNEXPECTED(zephir_is_buffer(arr))) { + return zephir_buffer_dim_write(arr, index, value); + } +#endif + if (UNEXPECTED(Z_TYPE_P(arr) == IS_OBJECT && zephir_instance_of_ev(arr, (const zend_class_entry *)zend_ce_arrayaccess))) { zend_long ZEPHIR_LAST_CALL_STATUS; ZEPHIR_CALL_METHOD_WITHOUT_OBSERVE(NULL, arr, "offsetset", NULL, 0, index, value); @@ -1287,6 +1322,12 @@ int zephir_array_update_string(zval *arr, const char *index, uint32_t index_leng int zephir_array_update_long(zval *arr, zend_long index, zval *value, int flags ZEPHIR_DEBUG_PARAMS) { +#ifdef ZEPHIR_BUFFER_ENABLED + if (UNEXPECTED(zephir_is_buffer(arr))) { + return zephir_buffer_dim_write_long(arr, index, value); + } +#endif + if (UNEXPECTED(Z_TYPE_P(arr) == IS_OBJECT && zephir_instance_of_ev(arr, (const zend_class_entry *)zend_ce_arrayaccess))) { zend_long ZEPHIR_LAST_CALL_STATUS; zval offset; diff --git a/ext/kernel/buffer.c b/ext/kernel/buffer.c new file mode 100644 index 0000000..df5e05e --- /dev/null +++ b/ext/kernel/buffer.c @@ -0,0 +1,910 @@ +/** + * This file is part of the Zephir. + * + * (c) Phalcon Team + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. If you did not receive + * a copy of the license it is available through the world-wide-web at the + * following url: https://docs.zephir-lang.com/en/latest/license + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php_ext.h" +#include "kernel/buffer.h" + +#ifndef ZEPHIR_BUFFER_ENABLED + +/* The project did not opt in: the class is compiled out and MINIT + * registration is a no-op. */ +void zephir_buffer_module_init(void) {} + +#else + +#ifndef ZEPHIR_BUFFER_NAMESPACE +#error "ZEPHIR_BUFFER_NAMESPACE must be defined together with ZEPHIR_BUFFER_ENABLED" +#endif + +#include +#include +#include +#include + +/* Unconditional on purpose. ext/json cannot be disabled in PHP 8, and gating + * JsonSerializable on a build-time probe would mean json_encode() silently + * emitting `{}` and dropping every element wherever the probe happened to + * fail. kernel/string.c's ZEPHIR_USE_PHP_JSON gate is about an optional + * *optimisation*; this is about not losing data. */ +#include + +/* zend_object_count_elements_t returned `int` up to PHP 8.1 and `zend_result` + * from 8.2. The two are different types, so the handler has to be declared + * with whichever one this build expects. */ +#if PHP_VERSION_ID >= 80200 +# define ZEPHIR_BUFFER_COUNT_RESULT zend_result +#else +# define ZEPHIR_BUFFER_COUNT_RESULT int +#endif + +zend_class_entry *zephir_buffer_ce; + +static zend_object_handlers zephir_buffer_object_handlers; + +/* ---------------------------------------------------------------- storage */ + +static zend_always_inline size_t zephir_buffer_elem_size(uint8_t kind) +{ + return kind == ZEPHIR_BUFFER_LONG ? sizeof(zend_long) : sizeof(double); +} + +static zend_always_inline int zephir_buffer_kind_is_valid(uint8_t kind) +{ + return kind == ZEPHIR_BUFFER_DOUBLE || kind == ZEPHIR_BUFFER_LONG; +} + +/** + * (Re)allocates the element array, zero-filled. + * + * All-bits-zero is 0.0 for an IEEE 754 double and 0 for a zend_long, so one + * ecalloc covers both kinds. + */ +static int zephir_buffer_alloc(zephir_buffer_object *b, zend_long len, uint8_t kind) +{ + if (b->data.raw) { + efree(b->data.raw); + b->data.raw = NULL; + } + + b->kind = kind; + b->len = len; + + if (len > 0) { + b->data.raw = ecalloc((size_t) len, zephir_buffer_elem_size(kind)); + } + + return SUCCESS; +} + +static zend_always_inline void zephir_buffer_get(const zephir_buffer_object *b, zend_long index, zval *rv) +{ + if (b->kind == ZEPHIR_BUFFER_LONG) { + ZVAL_LONG(rv, b->data.l[index]); + } else { + ZVAL_DOUBLE(rv, b->data.d[index]); + } +} + +/** + * Stores `value` at `index`, converted with the engine's own cast, so an + * element ends up holding exactly what `(float)` / `(int)` would have produced. + */ +static zend_always_inline void zephir_buffer_put(zephir_buffer_object *b, zend_long index, zval *value) +{ + if (b->kind == ZEPHIR_BUFFER_LONG) { + b->data.l[index] = zval_get_long(value); + } else { + b->data.d[index] = zval_get_double(value); + } +} + +static zend_always_inline int zephir_buffer_in_range(const zephir_buffer_object *b, zend_long index) +{ + /* One compare: a negative index wraps to a huge unsigned value. */ + return (zend_ulong) index < (zend_ulong) b->len; +} + +/* ------------------------------------------------------------- diagnostics */ + +/** + * php-src moved this from RuntimeException to OutOfBoundsException in 8.4 + * (OutOfBoundsException extends RuntimeException, so catching the older one + * still works). Follow it, so a Buffer raises on each version whatever + * SplFixedArray raises there. + */ +static ZEND_COLD void zephir_buffer_throw_out_of_range(void) +{ +#if PHP_VERSION_ID >= 80400 + zend_throw_exception(spl_ce_OutOfBoundsException, "Index invalid or out of range", 0); +#else + zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0); +#endif +} + +/** + * Converts an arbitrary offset zval to an index, following php-src's own + * spl_offset_convert_to_long() -- including the three regimes its failure + * branch went through: + * + * 8.0 no type check at all; an unusable offset became -1 and was + * reported by the range check + * 8.1, 8.2 TypeError, "Illegal offset type" + * 8.3+ TypeError naming the container and the offset type + * + * On failure from 8.1 up an exception is pending, so callers must check + * EG(exception) before using the result. php-src reports BP_VAR_R here even + * from isset(), so do the same rather than varying the message by context. + */ +static zend_long zephir_buffer_offset_to_long(zval *offset) +{ + zend_ulong idx; + +try_again: + switch (Z_TYPE_P(offset)) { + case IS_STRING: + if (ZEND_HANDLE_NUMERIC(Z_STR_P(offset), idx)) { + return (zend_long) idx; + } + break; + + case IS_DOUBLE: +#if PHP_VERSION_ID >= 80100 + return zend_dval_to_lval_safe(Z_DVAL_P(offset)); +#else + return zend_dval_to_lval(Z_DVAL_P(offset)); +#endif + + case IS_LONG: + return Z_LVAL_P(offset); + + case IS_FALSE: + return 0; + + case IS_TRUE: + return 1; + + case IS_REFERENCE: + offset = Z_REFVAL_P(offset); + goto try_again; + + case IS_RESOURCE: +#if PHP_VERSION_ID >= 80100 + zend_use_resource_as_offset(offset); +#endif + return Z_RES_HANDLE_P(offset); + } + +#if PHP_VERSION_ID >= 80300 + zend_illegal_container_offset(zephir_buffer_ce->name, offset, BP_VAR_R); + return 0; +#elif PHP_VERSION_ID >= 80100 + zend_type_error("Illegal offset type"); + return 0; +#else + return -1; +#endif +} + +/** + * Resolves an offset to an in-range index, or returns FAILURE with an + * exception pending. + */ +static int zephir_buffer_resolve(const zephir_buffer_object *b, zval *offset, zend_long *index) +{ + zend_long resolved = zephir_buffer_offset_to_long(offset); + + if (EG(exception)) { + return FAILURE; + } + + if (!zephir_buffer_in_range(b, resolved)) { + zephir_buffer_throw_out_of_range(); + return FAILURE; + } + + *index = resolved; + + return SUCCESS; +} + +/* ----------------------------------------------------------------- object */ + +static zend_object *zephir_buffer_create_object(zend_class_entry *ce) +{ + zephir_buffer_object *b = zend_object_alloc(sizeof(zephir_buffer_object), ce); + + b->data.raw = NULL; + b->len = 0; + b->kind = ZEPHIR_BUFFER_DOUBLE; + + zend_object_std_init(&b->std, ce); + object_properties_init(&b->std, ce); + b->std.handlers = &zephir_buffer_object_handlers; + + return &b->std; +} + +static void zephir_buffer_free_object(zend_object *object) +{ + zephir_buffer_object *b = zephir_buffer_fetch(object); + + if (b->data.raw) { + efree(b->data.raw); + b->data.raw = NULL; + } + + zend_object_std_dtor(&b->std); +} + +static zend_object *zephir_buffer_clone_object(zend_object *object) +{ + zephir_buffer_object *source = zephir_buffer_fetch(object); + zend_object *cloned = zephir_buffer_create_object(object->ce); + zephir_buffer_object *copy = zephir_buffer_fetch(cloned); + + copy->kind = source->kind; + copy->len = source->len; + + if (source->len > 0) { + size_t bytes = (size_t) source->len * zephir_buffer_elem_size(source->kind); + + copy->data.raw = emalloc(bytes); + memcpy(copy->data.raw, source->data.raw, bytes); + } + + zend_objects_clone_members(cloned, object); + + return cloned; +} + +/* Without this var_dump()/print_r() would show an object with no state at all, + * because the elements are not properties. */ +static HashTable *zephir_buffer_get_debug_info(zend_object *object, int *is_temp) +{ + zephir_buffer_object *b = zephir_buffer_fetch(object); + HashTable *info; + zend_long i; + + ALLOC_HASHTABLE(info); + zend_hash_init(info, (uint32_t) (b->len > 0 ? b->len : 0), NULL, ZVAL_PTR_DTOR, 0); + + for (i = 0; i < b->len; ++i) { + zval element; + + zephir_buffer_get(b, i, &element); + zend_hash_index_update(info, (zend_ulong) i, &element); + } + + *is_temp = 1; + + return info; +} + +static ZEPHIR_BUFFER_COUNT_RESULT zephir_buffer_count_elements(zend_object *object, zend_long *count) +{ + *count = zephir_buffer_fetch(object)->len; + + return SUCCESS; +} + +/* ------------------------------------------------------------- dimensions */ + +static int zephir_buffer_has_dimension(zend_object *object, zval *offset, int check_empty); + +/** + * `$buffer[$i]`. + * + * The value is returned in `rv`, never as a pointer into the buffer -- the + * elements are raw C scalars, not zvals, so there is nothing to point at. + * + * That does not stop compound assignment. The engine implements `$buffer[0] + * += 1` on an object as a read followed by a write, so it arrives here and + * then at zephir_buffer_write_dimension() and behaves normally. What cannot + * work is anything needing a reference to the element -- `$buffer[0]++`, + * `$r =& $buffer[0]`, passing it to a by-reference parameter. The engine + * raises its standard "Indirect modification of overloaded element" notice for + * those and the write has no effect, exactly as it does for any ArrayAccess + * object that does not hand back a reference. + */ +static zval *zephir_buffer_read_dimension(zend_object *object, zval *offset, int type, zval *rv) +{ + zephir_buffer_object *b = zephir_buffer_fetch(object); + zend_long index; + + /* `$buffer[$i] ?? $default` must not raise for a merely absent index -- + * but an offset of an unusable *type* still does, as it does for + * SplFixedArray. */ + if (type == BP_VAR_IS && !zephir_buffer_has_dimension(object, offset, 0)) { + return &EG(uninitialized_zval); + } + + if (!offset) { + zend_throw_error(NULL, "Cannot use [] for reading"); + return NULL; + } + + if (zephir_buffer_resolve(b, offset, &index) == FAILURE) { + return NULL; + } + + zephir_buffer_get(b, index, rv); + + return rv; +} + +static void zephir_buffer_write_dimension(zend_object *object, zval *offset, zval *value) +{ + zephir_buffer_object *b = zephir_buffer_fetch(object); + zend_long index; + + if (!offset) { + /* `$buffer[] = v`. A Buffer is fixed-size, so there is nothing to + * append to. php-src changed SplFixedArray's report here in 8.1. */ +#if PHP_VERSION_ID >= 80100 + zend_throw_error(NULL, "[] operator not supported for %s", ZSTR_VAL(object->ce->name)); +#else + zephir_buffer_throw_out_of_range(); +#endif + return; + } + + if (zephir_buffer_resolve(b, offset, &index) == FAILURE) { + return; + } + + zephir_buffer_put(b, index, value); +} + +static int zephir_buffer_has_dimension(zend_object *object, zval *offset, int check_empty) +{ + zephir_buffer_object *b = zephir_buffer_fetch(object); + zend_long index; + zval element; + + index = zephir_buffer_offset_to_long(offset); + + if (EG(exception)) { + return 0; + } + + if (!zephir_buffer_in_range(b, index)) { + return 0; + } + + /* Every in-range element is set. A Buffer holds numbers, so unlike + * SplFixedArray -- whose slots start out null, and where isset() is + * therefore false on a freshly constructed one -- there is no element + * value that isset() reports as absent. */ + if (!check_empty) { + return 1; + } + + zephir_buffer_get(b, index, &element); + + return zend_is_true(&element); +} + +/* A numeric buffer cannot hold null, so unset() writes the zero element. */ +static void zephir_buffer_unset_dimension(zend_object *object, zval *offset) +{ + zephir_buffer_object *b = zephir_buffer_fetch(object); + zend_long index; + + if (zephir_buffer_resolve(b, offset, &index) == FAILURE) { + return; + } + + if (b->kind == ZEPHIR_BUFFER_LONG) { + b->data.l[index] = 0; + } else { + b->data.d[index] = 0.0; + } +} + +/* -------------------------------------------------------------- C-side API */ + +int zephir_buffer_create(zval *ret, zend_long len, uint8_t kind) +{ + zephir_buffer_object *b; + + if (!zephir_buffer_kind_is_valid(kind) || len < 0) { + ZVAL_NULL(ret); + + return FAILURE; + } + + object_init_ex(ret, zephir_buffer_ce); + b = ZEPHIR_BUFFER_P(ret); + + return zephir_buffer_alloc(b, len, kind); +} + +int zephir_buffer_create_from_array(zval *ret, zval *arr, uint8_t kind) +{ + zephir_buffer_object *b; + zval *value; + zend_long i = 0; + + if (Z_TYPE_P(arr) != IS_ARRAY) { + ZVAL_NULL(ret); + + return FAILURE; + } + + if (zephir_buffer_create(ret, (zend_long) zend_hash_num_elements(Z_ARRVAL_P(arr)), kind) == FAILURE) { + return FAILURE; + } + + b = ZEPHIR_BUFFER_P(ret); + + /* Positional: the keys of the source array are discarded, the values are + * taken in iteration order. */ + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arr), value) { + zephir_buffer_put(b, i++, value); + } ZEND_HASH_FOREACH_END(); + + return SUCCESS; +} + +int zephir_buffer_to_array(zval *ret, const zval *obj) +{ + zephir_buffer_object *b; + zend_long i; + + if (!zephir_is_buffer(obj)) { + ZVAL_NULL(ret); + + return FAILURE; + } + + b = ZEPHIR_BUFFER_P((zval *) obj); + + array_init_size(ret, (uint32_t) (b->len > 0 ? b->len : 0)); + + for (i = 0; i < b->len; ++i) { + if (b->kind == ZEPHIR_BUFFER_LONG) { + add_next_index_long(ret, b->data.l[i]); + } else { + add_next_index_double(ret, b->data.d[i]); + } + } + + return SUCCESS; +} + +uint8_t zephir_buffer_kind(const zval *obj) +{ + return zephir_is_buffer(obj) ? ZEPHIR_BUFFER_P((zval *) obj)->kind : 0; +} + +zend_long zephir_buffer_len(const zval *obj) +{ + return zephir_is_buffer(obj) ? ZEPHIR_BUFFER_P((zval *) obj)->len : 0; +} + +double *zephir_buffer_doubles(const zval *obj) +{ + zephir_buffer_object *b; + + if (!zephir_is_buffer(obj)) { + return NULL; + } + + b = ZEPHIR_BUFFER_P((zval *) obj); + + return b->kind == ZEPHIR_BUFFER_DOUBLE ? b->data.d : NULL; +} + +zend_long *zephir_buffer_longs(const zval *obj) +{ + zephir_buffer_object *b; + + if (!zephir_is_buffer(obj)) { + return NULL; + } + + b = ZEPHIR_BUFFER_P((zval *) obj); + + return b->kind == ZEPHIR_BUFFER_LONG ? b->data.l : NULL; +} + +/* ------------------------------------------------ kernel/array.c fast paths */ + +int zephir_buffer_dim_read_long(zval *return_value, zval *obj, zend_long index) +{ + zephir_buffer_object *b = ZEPHIR_BUFFER_P(obj); + + if (UNEXPECTED(!zephir_buffer_in_range(b, index))) { + zephir_buffer_throw_out_of_range(); + ZVAL_NULL(return_value); + + return FAILURE; + } + + zephir_buffer_get(b, index, return_value); + + return SUCCESS; +} + +int zephir_buffer_dim_read(zval *return_value, zval *obj, zval *offset) +{ + zephir_buffer_object *b = ZEPHIR_BUFFER_P(obj); + zend_long index; + + if (UNEXPECTED(zephir_buffer_resolve(b, offset, &index) == FAILURE)) { + ZVAL_NULL(return_value); + + return FAILURE; + } + + zephir_buffer_get(b, index, return_value); + + return SUCCESS; +} + +int zephir_buffer_dim_write_long(zval *obj, zend_long index, zval *value) +{ + zephir_buffer_object *b = ZEPHIR_BUFFER_P(obj); + + if (UNEXPECTED(!zephir_buffer_in_range(b, index))) { + zephir_buffer_throw_out_of_range(); + + return FAILURE; + } + + zephir_buffer_put(b, index, value); + + return SUCCESS; +} + +int zephir_buffer_dim_write(zval *obj, zval *offset, zval *value) +{ + zephir_buffer_object *b = ZEPHIR_BUFFER_P(obj); + zend_long index; + + if (UNEXPECTED(zephir_buffer_resolve(b, offset, &index) == FAILURE)) { + return FAILURE; + } + + zephir_buffer_put(b, index, value); + + return SUCCESS; +} + +int zephir_buffer_dim_isset_long(const zval *obj, zend_long index) +{ + return zephir_buffer_in_range(ZEPHIR_BUFFER_P((zval *) obj), index); +} + +int zephir_buffer_dim_isset(const zval *obj, zval *offset) +{ + return zephir_buffer_has_dimension(Z_OBJ_P((zval *) obj), offset, 0); +} + +/* ---------------------------------------------------------------- methods */ + +PHP_METHOD(ZephirBuffer, __construct) +{ + zephir_buffer_object *b = ZEPHIR_BUFFER_P(getThis()); + zend_long size; + zend_long type = ZEPHIR_BUFFER_DOUBLE; + + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_LONG(size) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(type) + ZEND_PARSE_PARAMETERS_END(); + + if (size < 0) { + zend_argument_value_error(1, "must be greater than or equal to 0"); + RETURN_THROWS(); + } + + if (!zephir_buffer_kind_is_valid((uint8_t) type)) { + zend_argument_value_error(2, "must be Buffer::TYPE_DOUBLE or Buffer::TYPE_LONG"); + RETURN_THROWS(); + } + + zephir_buffer_alloc(b, size, (uint8_t) type); +} + +PHP_METHOD(ZephirBuffer, fromArray) +{ + zval *values; + zend_long type = ZEPHIR_BUFFER_DOUBLE; + + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(values) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(type) + ZEND_PARSE_PARAMETERS_END(); + + if (!zephir_buffer_kind_is_valid((uint8_t) type)) { + zend_argument_value_error(2, "must be Buffer::TYPE_DOUBLE or Buffer::TYPE_LONG"); + RETURN_THROWS(); + } + + zephir_buffer_create_from_array(return_value, values, (uint8_t) type); +} + +PHP_METHOD(ZephirBuffer, toArray) +{ + ZEND_PARSE_PARAMETERS_NONE(); + + zephir_buffer_to_array(return_value, getThis()); +} + +PHP_METHOD(ZephirBuffer, type) +{ + ZEND_PARSE_PARAMETERS_NONE(); + + RETURN_LONG(ZEPHIR_BUFFER_P(getThis())->kind); +} + +PHP_METHOD(ZephirBuffer, count) +{ + ZEND_PARSE_PARAMETERS_NONE(); + + RETURN_LONG(ZEPHIR_BUFFER_P(getThis())->len); +} + +PHP_METHOD(ZephirBuffer, fill) +{ + zephir_buffer_object *b = ZEPHIR_BUFFER_P(getThis()); + zval *value; + zend_long i; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(value) + ZEND_PARSE_PARAMETERS_END(); + + if (b->kind == ZEPHIR_BUFFER_LONG) { + zend_long converted = zval_get_long(value); + + for (i = 0; i < b->len; ++i) { + b->data.l[i] = converted; + } + } else { + double converted = zval_get_double(value); + + for (i = 0; i < b->len; ++i) { + b->data.d[i] = converted; + } + } +} + +PHP_METHOD(ZephirBuffer, offsetExists) +{ + zval *offset; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(offset) + ZEND_PARSE_PARAMETERS_END(); + + RETURN_BOOL(zephir_buffer_has_dimension(Z_OBJ_P(getThis()), offset, 0)); +} + +PHP_METHOD(ZephirBuffer, offsetGet) +{ + zephir_buffer_object *b = ZEPHIR_BUFFER_P(getThis()); + zval *offset; + zend_long index; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(offset) + ZEND_PARSE_PARAMETERS_END(); + + if (zephir_buffer_resolve(b, offset, &index) == FAILURE) { + RETURN_THROWS(); + } + + zephir_buffer_get(b, index, return_value); +} + +PHP_METHOD(ZephirBuffer, offsetSet) +{ + zval *offset; + zval *value; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(offset) + Z_PARAM_ZVAL(value) + ZEND_PARSE_PARAMETERS_END(); + + zephir_buffer_write_dimension(Z_OBJ_P(getThis()), offset, value); +} + +PHP_METHOD(ZephirBuffer, offsetUnset) +{ + zval *offset; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(offset) + ZEND_PARSE_PARAMETERS_END(); + + zephir_buffer_unset_dimension(Z_OBJ_P(getThis()), offset); +} + +/** + * foreach materialises the elements. A Buffer exists so that hot loops happen + * in C over the raw pointer; iterating one element at a time through the VM is + * the slow path by definition, so it is not worth a lazy iterator. + */ +PHP_METHOD(ZephirBuffer, getIterator) +{ + zval elements; + + ZEND_PARSE_PARAMETERS_NONE(); + + zephir_buffer_to_array(&elements, getThis()); + + object_init_ex(return_value, spl_ce_ArrayIterator); + zend_call_method_with_1_params( + Z_OBJ_P(return_value), spl_ce_ArrayIterator, NULL, "__construct", NULL, &elements); + + zval_ptr_dtor(&elements); +} + +/* Without this json_encode() would serialise an object with no properties as + * `{}` and drop every element. */ +PHP_METHOD(ZephirBuffer, jsonSerialize) +{ + ZEND_PARSE_PARAMETERS_NONE(); + + zephir_buffer_to_array(return_value, getThis()); +} + +PHP_METHOD(ZephirBuffer, __serialize) +{ + zval elements; + + ZEND_PARSE_PARAMETERS_NONE(); + + zephir_buffer_to_array(&elements, getThis()); + + array_init_size(return_value, 2); + add_next_index_long(return_value, ZEPHIR_BUFFER_P(getThis())->kind); + add_next_index_zval(return_value, &elements); +} + +PHP_METHOD(ZephirBuffer, __unserialize) +{ + zephir_buffer_object *b = ZEPHIR_BUFFER_P(getThis()); + zval *payload; + zval *kind; + zval *elements; + zval *value; + zend_long i = 0; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(payload) + ZEND_PARSE_PARAMETERS_END(); + + kind = zend_hash_index_find(Z_ARRVAL_P(payload), 0); + elements = zend_hash_index_find(Z_ARRVAL_P(payload), 1); + + if (!kind || Z_TYPE_P(kind) != IS_LONG || !elements || Z_TYPE_P(elements) != IS_ARRAY + || !zephir_buffer_kind_is_valid((uint8_t) Z_LVAL_P(kind))) { + zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", + ZSTR_VAL(zephir_buffer_ce->name)); + RETURN_THROWS(); + } + + zephir_buffer_alloc(b, (zend_long) zend_hash_num_elements(Z_ARRVAL_P(elements)), + (uint8_t) Z_LVAL_P(kind)); + + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(elements), value) { + zephir_buffer_put(b, i++, value); + } ZEND_HASH_FOREACH_END(); +} + +/* ------------------------------------------------------------- class init */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_zephir_buffer_construct, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_zephir_buffer_from_array, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, values, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zephir_buffer_to_array, 0, 0, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zephir_buffer_long, 0, 0, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zephir_buffer_fill, 0, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zephir_buffer_offset_exists, 0, 1, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, offset, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zephir_buffer_offset_get, 0, 1, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO(0, offset, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zephir_buffer_offset_set, 0, 2, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, offset, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zephir_buffer_offset_unset, 0, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, offset, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_zephir_buffer_get_iterator, 0, 0, Traversable, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zephir_buffer_json_serialize, 0, 0, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zephir_buffer_serialize, 0, 0, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zephir_buffer_unserialize, 0, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +static const zend_function_entry zephir_buffer_methods[] = { + PHP_ME(ZephirBuffer, __construct, arginfo_zephir_buffer_construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) + PHP_ME(ZephirBuffer, fromArray, arginfo_zephir_buffer_from_array, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(ZephirBuffer, toArray, arginfo_zephir_buffer_to_array, ZEND_ACC_PUBLIC) + PHP_ME(ZephirBuffer, type, arginfo_zephir_buffer_long, ZEND_ACC_PUBLIC) + PHP_ME(ZephirBuffer, count, arginfo_zephir_buffer_long, ZEND_ACC_PUBLIC) + PHP_ME(ZephirBuffer, fill, arginfo_zephir_buffer_fill, ZEND_ACC_PUBLIC) + PHP_ME(ZephirBuffer, offsetExists, arginfo_zephir_buffer_offset_exists, ZEND_ACC_PUBLIC) + PHP_ME(ZephirBuffer, offsetGet, arginfo_zephir_buffer_offset_get, ZEND_ACC_PUBLIC) + PHP_ME(ZephirBuffer, offsetSet, arginfo_zephir_buffer_offset_set, ZEND_ACC_PUBLIC) + PHP_ME(ZephirBuffer, offsetUnset, arginfo_zephir_buffer_offset_unset, ZEND_ACC_PUBLIC) + PHP_ME(ZephirBuffer, getIterator, arginfo_zephir_buffer_get_iterator, ZEND_ACC_PUBLIC) + PHP_ME(ZephirBuffer, jsonSerialize, arginfo_zephir_buffer_json_serialize, ZEND_ACC_PUBLIC) + PHP_ME(ZephirBuffer, __serialize, arginfo_zephir_buffer_serialize, ZEND_ACC_PUBLIC) + PHP_ME(ZephirBuffer, __unserialize, arginfo_zephir_buffer_unserialize, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +void zephir_buffer_module_init(void) +{ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, ZEPHIR_BUFFER_NAMESPACE, "Buffer", zephir_buffer_methods); + zephir_buffer_ce = zend_register_internal_class(&ce); + zephir_buffer_ce->ce_flags |= ZEND_ACC_FINAL | ZEND_ACC_NO_DYNAMIC_PROPERTIES; + zephir_buffer_ce->create_object = zephir_buffer_create_object; + + zend_declare_class_constant_long(zephir_buffer_ce, ZEND_STRL("TYPE_DOUBLE"), ZEPHIR_BUFFER_DOUBLE); + zend_declare_class_constant_long(zephir_buffer_ce, ZEND_STRL("TYPE_LONG"), ZEPHIR_BUFFER_LONG); + + memcpy(&zephir_buffer_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); + zephir_buffer_object_handlers.offset = XtOffsetOf(zephir_buffer_object, std); + zephir_buffer_object_handlers.free_obj = zephir_buffer_free_object; + zephir_buffer_object_handlers.clone_obj = zephir_buffer_clone_object; + zephir_buffer_object_handlers.get_debug_info = zephir_buffer_get_debug_info; + zephir_buffer_object_handlers.count_elements = zephir_buffer_count_elements; + zephir_buffer_object_handlers.read_dimension = zephir_buffer_read_dimension; + zephir_buffer_object_handlers.write_dimension = zephir_buffer_write_dimension; + zephir_buffer_object_handlers.has_dimension = zephir_buffer_has_dimension; + zephir_buffer_object_handlers.unset_dimension = zephir_buffer_unset_dimension; + + zend_class_implements(zephir_buffer_ce, 4, + zend_ce_arrayaccess, zend_ce_countable, zend_ce_aggregate, php_json_serializable_ce); +} + +#endif /* ZEPHIR_BUFFER_ENABLED */ diff --git a/ext/kernel/buffer.h b/ext/kernel/buffer.h new file mode 100644 index 0000000..4c4ca1c --- /dev/null +++ b/ext/kernel/buffer.h @@ -0,0 +1,134 @@ +/** + * This file is part of the Zephir. + * + * (c) Phalcon Team + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. If you did not receive + * a copy of the license it is available through the world-wide-web at the + * following url: https://docs.zephir-lang.com/en/latest/license + */ + +#ifndef ZEPHIR_KERNEL_BUFFER_H +#define ZEPHIR_KERNEL_BUFFER_H + +#include +#include + +/** + * \Buffer -- a fixed-size, contiguous, C-typed numeric buffer, + * issue #2721. + * + * A PHP array of floats costs a zval plus a hash slot per element and can only + * be handed to a C numeric library by walking it into a scratch buffer and + * walking the result back out again. Where that pack/unpack happens once per + * operation it dominates the operation. This class is the place to keep the + * data between operations instead: the elements live in one `emalloc`'d C + * array, hand-written C reads and writes them through a raw pointer, and the + * PHP array is materialised only at the boundary, by toArray(). + * + * It is an ordinary refcounted zend_object, so it can be held in a Zephir + * property, passed between methods and garbage collected like anything else. + * + * The whole class is compiled out unless the project opts in + * (ZEPHIR_BUFFER_ENABLED is defined in php_.h by the compiler when + * `kernel-classes.buffer` is true in config.json). + */ + +/* Element kinds. Fixed at construction; a buffer never changes kind. */ +#define ZEPHIR_BUFFER_DOUBLE 1 +#define ZEPHIR_BUFFER_LONG 2 + +typedef struct _zephir_buffer_object { + /* `len` contiguous elements of the kind named by `kind`, or NULL when + * len == 0. Never a zval: this is the whole point of the class. */ + union { + double *d; + zend_long *l; + void *raw; + } data; + + zend_long len; + uint8_t kind; + + /* MUST stay last: handlers.offset is XtOffsetOf(..., std). */ + zend_object std; +} zephir_buffer_object; + +#ifdef ZEPHIR_BUFFER_ENABLED +extern zend_class_entry *zephir_buffer_ce; +#endif + +/* Registered in every extension's MINIT (no-op when compiled out). */ +void zephir_buffer_module_init(void); + +#ifdef ZEPHIR_BUFFER_ENABLED + +static inline zephir_buffer_object *zephir_buffer_fetch(zend_object *obj) +{ + return (zephir_buffer_object *) ((char *) obj - XtOffsetOf(zephir_buffer_object, std)); +} + +#define ZEPHIR_BUFFER_P(zv) zephir_buffer_fetch(Z_OBJ_P(zv)) + +/* True when `zv` is a Buffer object. The check is a class-entry pointer + * compare, so it is cheap enough for the kernel array fast paths. */ +static inline int zephir_is_buffer(const zval *zv) +{ + return Z_TYPE_P(zv) == IS_OBJECT && Z_OBJCE_P((zval *) zv) == zephir_buffer_ce; +} + +/** + * Creates a zero-filled buffer of `len` elements into `ret`. + * Returns FAILURE (and throws) for a negative length or an unknown kind. + */ +int zephir_buffer_create(zval *ret, zend_long len, uint8_t kind); + +/** + * Creates a buffer holding the values of `arr` in iteration order. Keys are + * discarded -- a Buffer is positional. Each value is converted with PHP's own + * cast, so the result matches `(float)` / `(int)` element for element. + */ +int zephir_buffer_create_from_array(zval *ret, zval *arr, uint8_t kind); + +/** Materialises the elements as a packed PHP list into `ret`. */ +int zephir_buffer_to_array(zval *ret, const zval *obj); + +/** The element kind, or 0 when `obj` is not a Buffer. */ +uint8_t zephir_buffer_kind(const zval *obj); + +/** The element count, or 0 when `obj` is not a Buffer. */ +zend_long zephir_buffer_len(const zval *obj); + +/** + * The raw element pointers. Each returns NULL unless `obj` is a Buffer of + * that kind -- asking for the wrong one is a NULL, never a silently + * reinterpreted buffer. NULL is also returned for an empty buffer. + * + * This is the extension author's entry point: pass the result straight to + * cblas_daxpy(), a hand-written loop, or anything else expecting a contiguous + * array. The pointer stays valid until the buffer is destroyed; buffers are + * fixed-size, so it is never reallocated. + */ +double *zephir_buffer_doubles(const zval *obj); +zend_long *zephir_buffer_longs(const zval *obj); + +/** + * Fast paths for kernel/array.c. + * + * `buf[i]` in Zephir source compiles to a zephir_array_* call, which would + * otherwise see an ordinary ArrayAccess object and dispatch a full + * offsetGet()/offsetSet() method call per element. These do the same work + * without leaving C, and raise the same diagnostics when the offset is + * unusable. + */ +int zephir_buffer_dim_read_long(zval *return_value, zval *obj, zend_long index); +int zephir_buffer_dim_read(zval *return_value, zval *obj, zval *offset); +int zephir_buffer_dim_write_long(zval *obj, zend_long index, zval *value); +int zephir_buffer_dim_write(zval *obj, zval *offset, zval *value); +int zephir_buffer_dim_isset_long(const zval *obj, zend_long index); +int zephir_buffer_dim_isset(const zval *obj, zval *offset); + +#endif /* ZEPHIR_BUFFER_ENABLED */ + +#endif /* ZEPHIR_KERNEL_BUFFER_H */ diff --git a/ext/kernel/concat.c b/ext/kernel/concat.c index e34f2ca..a820634 100644 --- a/ext/kernel/concat.c +++ b/ext/kernel/concat.c @@ -223,124 +223,6 @@ void zephir_concat_ssvsvs(zval *result, const char *op1, uint32_t op1_len, const } -void zephir_concat_ssvsvssvs(zval *result, const char *op1, uint32_t op1_len, const char *op2, uint32_t op2_len, zval *op3, const char *op4, uint32_t op4_len, zval *op5, const char *op6, uint32_t op6_len, const char *op7, uint32_t op7_len, zval *op8, const char *op9, uint32_t op9_len, int self_var){ - - zval result_copy, op3_copy, op5_copy, op8_copy; - int use_copy = 0, use_copy3 = 0, use_copy5 = 0, use_copy8 = 0; - size_t offset = 0, length; - - if (Z_TYPE_P(op3) != IS_STRING) { - use_copy3 = zend_make_printable_zval(op3, &op3_copy); - if (use_copy3) { - op3 = &op3_copy; - } - } - - if (Z_TYPE_P(op5) != IS_STRING) { - use_copy5 = zend_make_printable_zval(op5, &op5_copy); - if (use_copy5) { - op5 = &op5_copy; - } - } - - if (Z_TYPE_P(op8) != IS_STRING) { - use_copy8 = zend_make_printable_zval(op8, &op8_copy); - if (use_copy8) { - op8 = &op8_copy; - } - } - - length = op1_len; - if (UNEXPECTED(op2_len > ZSTR_MAX_LEN - length)) { - goto zephir_concat_overflow; - } - length += op2_len; - if (UNEXPECTED(Z_STRLEN_P(op3) > ZSTR_MAX_LEN - length)) { - goto zephir_concat_overflow; - } - length += Z_STRLEN_P(op3); - if (UNEXPECTED(op4_len > ZSTR_MAX_LEN - length)) { - goto zephir_concat_overflow; - } - length += op4_len; - if (UNEXPECTED(Z_STRLEN_P(op5) > ZSTR_MAX_LEN - length)) { - goto zephir_concat_overflow; - } - length += Z_STRLEN_P(op5); - if (UNEXPECTED(op6_len > ZSTR_MAX_LEN - length)) { - goto zephir_concat_overflow; - } - length += op6_len; - if (UNEXPECTED(op7_len > ZSTR_MAX_LEN - length)) { - goto zephir_concat_overflow; - } - length += op7_len; - if (UNEXPECTED(Z_STRLEN_P(op8) > ZSTR_MAX_LEN - length)) { - goto zephir_concat_overflow; - } - length += Z_STRLEN_P(op8); - if (UNEXPECTED(op9_len > ZSTR_MAX_LEN - length)) { - goto zephir_concat_overflow; - } - length += op9_len; - if (self_var) { - - if (Z_TYPE_P(result) != IS_STRING) { - use_copy = zend_make_printable_zval(result, &result_copy); - if (use_copy) { - ZEPHIR_CPY_WRT_CTOR(result, (&result_copy)); - } - } - - offset = Z_STRLEN_P(result); - if (UNEXPECTED(offset > ZSTR_MAX_LEN - length)) { - goto zephir_concat_overflow; - } - length += offset; - Z_STR_P(result) = zend_string_realloc(Z_STR_P(result), length, 0); - - } else { - ZVAL_STR(result, zend_string_alloc(length, 0)); - } - - memcpy(Z_STRVAL_P(result) + offset, op1, op1_len); - memcpy(Z_STRVAL_P(result) + offset + op1_len, op2, op2_len); - memcpy(Z_STRVAL_P(result) + offset + op1_len + op2_len, Z_STRVAL_P(op3), Z_STRLEN_P(op3)); - memcpy(Z_STRVAL_P(result) + offset + op1_len + op2_len + Z_STRLEN_P(op3), op4, op4_len); - memcpy(Z_STRVAL_P(result) + offset + op1_len + op2_len + Z_STRLEN_P(op3) + op4_len, Z_STRVAL_P(op5), Z_STRLEN_P(op5)); - memcpy(Z_STRVAL_P(result) + offset + op1_len + op2_len + Z_STRLEN_P(op3) + op4_len + Z_STRLEN_P(op5), op6, op6_len); - memcpy(Z_STRVAL_P(result) + offset + op1_len + op2_len + Z_STRLEN_P(op3) + op4_len + Z_STRLEN_P(op5) + op6_len, op7, op7_len); - memcpy(Z_STRVAL_P(result) + offset + op1_len + op2_len + Z_STRLEN_P(op3) + op4_len + Z_STRLEN_P(op5) + op6_len + op7_len, Z_STRVAL_P(op8), Z_STRLEN_P(op8)); - memcpy(Z_STRVAL_P(result) + offset + op1_len + op2_len + Z_STRLEN_P(op3) + op4_len + Z_STRLEN_P(op5) + op6_len + op7_len + Z_STRLEN_P(op8), op9, op9_len); - Z_STRVAL_P(result)[length] = 0; - zend_string_forget_hash_val(Z_STR_P(result)); - goto zephir_concat_cleanup; - -zephir_concat_overflow: - zend_throw_error(NULL, "String size overflow"); - if (!self_var) { - ZVAL_UNDEF(result); - } - -zephir_concat_cleanup: - if (use_copy3) { - zval_dtor(op3); - } - - if (use_copy5) { - zval_dtor(op5); - } - - if (use_copy8) { - zval_dtor(op8); - } - - if (use_copy) { - zval_dtor(&result_copy); - } - -} - void zephir_concat_sv(zval *result, const char *op1, uint32_t op1_len, zval *op2, int self_var){ zval result_copy, op2_copy; diff --git a/ext/kernel/concat.h b/ext/kernel/concat.h index 97d81ee..d14d71c 100644 --- a/ext/kernel/concat.h +++ b/ext/kernel/concat.h @@ -19,11 +19,6 @@ #define ZEPHIR_SCONCAT_SSVSVS(result, op1, op2, op3, op4, op5, op6) \ zephir_concat_ssvsvs(result, op1, sizeof(op1)-1, op2, sizeof(op2)-1, op3, op4, sizeof(op4)-1, op5, op6, sizeof(op6)-1, 1); -#define ZEPHIR_CONCAT_SSVSVSSVS(result, op1, op2, op3, op4, op5, op6, op7, op8, op9) \ - zephir_concat_ssvsvssvs(result, op1, sizeof(op1)-1, op2, sizeof(op2)-1, op3, op4, sizeof(op4)-1, op5, op6, sizeof(op6)-1, op7, sizeof(op7)-1, op8, op9, sizeof(op9)-1, 0); -#define ZEPHIR_SCONCAT_SSVSVSSVS(result, op1, op2, op3, op4, op5, op6, op7, op8, op9) \ - zephir_concat_ssvsvssvs(result, op1, sizeof(op1)-1, op2, sizeof(op2)-1, op3, op4, sizeof(op4)-1, op5, op6, sizeof(op6)-1, op7, sizeof(op7)-1, op8, op9, sizeof(op9)-1, 1); - #define ZEPHIR_CONCAT_SV(result, op1, op2) \ zephir_concat_sv(result, op1, sizeof(op1)-1, op2, 0); #define ZEPHIR_SCONCAT_SV(result, op1, op2) \ @@ -63,7 +58,6 @@ void zephir_concat_ss(zval *result, const char *op1, uint32_t op1_len, const char *op2, uint32_t op2_len, int self_var); void zephir_concat_ssvs(zval *result, const char *op1, uint32_t op1_len, const char *op2, uint32_t op2_len, zval *op3, const char *op4, uint32_t op4_len, int self_var); void zephir_concat_ssvsvs(zval *result, const char *op1, uint32_t op1_len, const char *op2, uint32_t op2_len, zval *op3, const char *op4, uint32_t op4_len, zval *op5, const char *op6, uint32_t op6_len, int self_var); -void zephir_concat_ssvsvssvs(zval *result, const char *op1, uint32_t op1_len, const char *op2, uint32_t op2_len, zval *op3, const char *op4, uint32_t op4_len, zval *op5, const char *op6, uint32_t op6_len, const char *op7, uint32_t op7_len, zval *op8, const char *op9, uint32_t op9_len, int self_var); void zephir_concat_sv(zval *result, const char *op1, uint32_t op1_len, zval *op2, int self_var); void zephir_concat_svsvs(zval *result, const char *op1, uint32_t op1_len, zval *op2, const char *op3, uint32_t op3_len, zval *op4, const char *op5, uint32_t op5_len, int self_var); void zephir_concat_vs(zval *result, zval *op1, const char *op2, uint32_t op2_len, int self_var); diff --git a/ext/kernel/fcall.c b/ext/kernel/fcall.c index c16a985..11c3406 100644 --- a/ext/kernel/fcall.c +++ b/ext/kernel/fcall.c @@ -232,6 +232,21 @@ static void resolve_callable(zval* retval, zephir_call_type type, zend_class_ent * scope assignments are unchanged, only the redundant resolution is skipped. * See the FastCall investigation: https://github.com/zephir-lang/zephir/issues/1510 */ +/** + * Resolves the handler a call will use, so the engine can skip its own lookup. + * + * `func` carries the method name as it was written at the call site, while + * `function_table` is keyed by the lower-cased name, so every lookup here has + * to fold the case the way PHP folds it: `zend_std_get_method()` lower-cases + * for the table and keeps the original only for the `__call()` trampoline, and + * `zend_is_callable_check_method()` uses this very function. + * + * At most one of the lookups below runs per call, and none of them runs once a + * handler has been cached, so the fold costs one `zend_string_tolower()` per + * cache miss. + * + * @see https://github.com/zephir-lang/zephir/issues/2715 + */ static void populate_fcic(zend_fcall_info_cache* fcic, zephir_call_type type, zend_class_entry* ce, zval *this_ptr, zval *func, zend_class_entry* called_scope, zend_function* cached_handler) { zend_class_entry* calling_scope; @@ -251,11 +266,11 @@ static void populate_fcic(zend_fcall_info_cache* fcic, zephir_call_type type, ze switch (type) { case zephir_fcall_parent: if (ce && Z_TYPE_P(func) == IS_STRING) { - fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr(&ce->parent->function_table, Z_STR_P(func)); + fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr_lc(&ce->parent->function_table, Z_STR_P(func)); fcic->calling_scope = ce->parent; } else if (EXPECTED(calling_scope && calling_scope->parent)) { if (Z_TYPE_P(func) == IS_STRING) { - fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr(&calling_scope->parent->function_table, Z_STR_P(func)); + fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr_lc(&calling_scope->parent->function_table, Z_STR_P(func)); } fcic->calling_scope = calling_scope->parent; } else { @@ -271,10 +286,10 @@ static void populate_fcic(zend_fcall_info_cache* fcic, zephir_call_type type, ze case zephir_fcall_static: if (ce && Z_TYPE_P(func) == IS_STRING) { - fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr(&ce->function_table, Z_STR_P(func)); + fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr_lc(&ce->function_table, Z_STR_P(func)); fcic->calling_scope = ce; } else if (calling_scope && Z_TYPE_P(func) == IS_STRING) { - fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr(&calling_scope->function_table, Z_STR_P(func)); + fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr_lc(&calling_scope->function_table, Z_STR_P(func)); fcic->calling_scope = called_scope; } @@ -282,10 +297,10 @@ static void populate_fcic(zend_fcall_info_cache* fcic, zephir_call_type type, ze case zephir_fcall_self: if (ce && Z_TYPE_P(func) == IS_STRING) { - fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr(&ce->function_table, Z_STR_P(func)); + fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr_lc(&ce->function_table, Z_STR_P(func)); fcic->calling_scope = ce; } else if (calling_scope && Z_TYPE_P(func) == IS_STRING) { - fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr(&calling_scope->function_table, Z_STR_P(func)); + fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr_lc(&calling_scope->function_table, Z_STR_P(func)); // TODO: Review when error will be enabled in zend_is_callable_ex() calls //fcic->object = zend_get_this_object(EG(current_execute_data)); //fcic->called_scope = zend_get_called_scope(EG(current_execute_data)); @@ -306,9 +321,9 @@ static void populate_fcic(zend_fcall_info_cache* fcic, zephir_call_type type, ze #if PHP_VERSION_ID >= 80000 if (Z_TYPE_P(func) == IS_STRING) { if (ce) { - fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr(&ce->function_table, Z_STR_P(func)); + fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr_lc(&ce->function_table, Z_STR_P(func)); } else if (calling_scope) { - fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr(&calling_scope->function_table, Z_STR_P(func)); + fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr_lc(&calling_scope->function_table, Z_STR_P(func)); fcic->calling_scope = calling_scope; } } @@ -362,7 +377,7 @@ static void populate_fcic(zend_fcall_info_cache* fcic, zephir_call_type type, ze fcic->calling_scope = ce; #if PHP_VERSION_ID >= 80000 - fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr(&ce->function_table, Z_STR_P(func)); + fcic->function_handler = cached_handler ? cached_handler : zend_hash_find_ptr_lc(&ce->function_table, Z_STR_P(func)); #endif } else { fcic->calling_scope = this_ptr ? Z_OBJCE_P(this_ptr) : NULL; diff --git a/ext/kernel/fcall.h b/ext/kernel/fcall.h index 91e121b..4dfba18 100644 --- a/ext/kernel/fcall.h +++ b/ext/kernel/fcall.h @@ -150,37 +150,43 @@ extern zend_internal_function zephir_internal_call_frame_func; ZEPHIR_LAST_CALL_STATUS = zephir_call_class_method_aparams(return_value_ptr, Z_TYPE_P(object) == IS_OBJECT ? Z_OBJCE_P(object) : NULL, zephir_fcall_method, object, method, strlen(method), cache, cache_slot, ZEPHIR_CALL_NUM_PARAMS(params_), ZEPHIR_PASS_CALL_PARAMS(params_)); \ } while (0) +/** + * The `_ZVAL` macros take the method name from a variable, and pass it on as it + * was spelled: `__call()` is defined to receive the name as written, and the + * lookup that dispatches the call folds the case itself (see populate_fcic() + * in kernel/fcall.c). They used to lower-case it into a copy on every call. + * + * @see https://github.com/zephir-lang/zephir/issues/2715 + */ #define ZEPHIR_RETURN_CALL_METHOD_ZVAL(object, method, cache, cache_slot, ...) \ do { \ - char *method_name; \ - int method_len; \ + const char *method_name; \ + uint32_t method_len; \ zval *params_[] = {ZEPHIR_FETCH_VA_ARGS __VA_ARGS__}; \ if (Z_TYPE_P(method) == IS_STRING) { \ method_len = Z_STRLEN_P(method); \ - method_name = zend_str_tolower_dup(Z_STRVAL_P(method), method_len); \ + method_name = Z_STRVAL_P(method); \ } else { \ method_len = 0; \ - method_name = zend_str_tolower_dup("", 0); \ + method_name = ""; \ } \ ZEPHIR_LAST_CALL_STATUS = zephir_return_call_class_method(return_value, Z_TYPE_P(object) == IS_OBJECT ? Z_OBJCE_P(object) : NULL, zephir_fcall_method, object, method_name, method_len, cache, cache_slot, ZEPHIR_CALL_NUM_PARAMS(params_), ZEPHIR_PASS_CALL_PARAMS(params_)); \ - efree(method_name); \ } while (0) #define ZEPHIR_CALL_METHOD_ZVAL(return_value_ptr, object, method, cache, cache_slot, ...) \ do { \ - char *method_name; \ - int method_len; \ + const char *method_name; \ + uint32_t method_len; \ zval *params_[] = {ZEPHIR_FETCH_VA_ARGS __VA_ARGS__}; \ if (Z_TYPE_P(method) == IS_STRING) { \ method_len = Z_STRLEN_P(method); \ - method_name = zend_str_tolower_dup(Z_STRVAL_P(method), method_len); \ + method_name = Z_STRVAL_P(method); \ } else { \ method_len = 0; \ - method_name = zend_str_tolower_dup("", 0); \ + method_name = ""; \ } \ ZEPHIR_OBSERVE_OR_NULLIFY_PPZV(return_value_ptr); \ ZEPHIR_LAST_CALL_STATUS = zephir_call_class_method_aparams(return_value_ptr, Z_TYPE_P(object) == IS_OBJECT ? Z_OBJCE_P(object) : NULL, zephir_fcall_method, object, method_name, method_len, cache, cache_slot, ZEPHIR_CALL_NUM_PARAMS(params_), ZEPHIR_PASS_CALL_PARAMS(params_)); \ - efree(method_name); \ } while (0) #define ZEPHIR_CALL_PARENT(return_value_ptr, class_entry, this_ptr, method, cache, cache_slot, ...) \ @@ -243,35 +249,33 @@ extern zend_internal_function zephir_internal_call_frame_func; #define ZEPHIR_CALL_CE_STATIC_ZVAL(return_value_ptr, class_entry, method, cache, cache_slot, ...) \ do { \ - char *method_name; \ - int method_len; \ + const char *method_name; \ + uint32_t method_len; \ zval *params_[] = {ZEPHIR_FETCH_VA_ARGS __VA_ARGS__}; \ if (Z_TYPE(method) == IS_STRING) { \ method_len = Z_STRLEN(method); \ - method_name = zend_str_tolower_dup(Z_STRVAL(method), method_len); \ + method_name = Z_STRVAL(method); \ } else { \ method_len = 0; \ - method_name = zend_str_tolower_dup("", 0); \ + method_name = ""; \ } \ ZEPHIR_OBSERVE_OR_NULLIFY_PPZV(return_value_ptr); \ ZEPHIR_LAST_CALL_STATUS = zephir_call_class_method_aparams(return_value_ptr, class_entry, zephir_fcall_ce, NULL, method_name, method_len, cache, cache_slot, ZEPHIR_CALL_NUM_PARAMS(params_), ZEPHIR_PASS_CALL_PARAMS(params_)); \ - efree(method_name); \ } while (0) #define ZEPHIR_RETURN_CALL_CE_STATIC_ZVAL(class_entry, method, cache, cache_slot, ...) \ do { \ - char *method_name; \ - int method_len; \ + const char *method_name; \ + uint32_t method_len; \ zval *params_[] = { ZEPHIR_FETCH_VA_ARGS __VA_ARGS__ }; \ if (Z_TYPE(method) == IS_STRING) { \ method_len = Z_STRLEN(method); \ - method_name = zend_str_tolower_dup(Z_STRVAL(method), method_len); \ + method_name = Z_STRVAL(method); \ } else { \ method_len = 0; \ - method_name = zend_str_tolower_dup("", 0); \ + method_name = ""; \ } \ ZEPHIR_LAST_CALL_STATUS = zephir_return_call_class_method(return_value, class_entry, zephir_fcall_ce, NULL, method_name, method_len, cache, cache_slot, ZEPHIR_CALL_NUM_PARAMS(params_), ZEPHIR_PASS_CALL_PARAMS(params_)); \ - efree(method_name); \ } while (0) /** Use these functions to call functions in the PHP userland using an arbitrary zval as callable */ diff --git a/ext/kernel/main.c b/ext/kernel/main.c index 80776c6..1744c56 100644 --- a/ext/kernel/main.c +++ b/ext/kernel/main.c @@ -26,6 +26,7 @@ #include "kernel/fcall.h" #include "kernel/object.h" #include "kernel/exception.h" +#include "kernel/buffer.h" #include "kernel/generator.h" @@ -1184,6 +1185,7 @@ void zephir_module_init() i_static = zend_new_interned_string(zend_string_init(ZEND_STRL("static"), 1)); i_self = zend_new_interned_string(zend_string_init(ZEND_STRL("self"), 1)); + zephir_buffer_module_init(); zephir_generator_module_init(); zephir_closure_module_init(); } @@ -1199,3 +1201,33 @@ void zephir_module_shutdown(void) { zephir_closure_module_shutdown(); } + +ZEND_INI_MH(zephir_OnUpdateChar) +{ + char *p = (char *) ZEND_INI_GET_ADDR(); + + *p = (new_value && ZSTR_LEN(new_value)) ? ZSTR_VAL(new_value)[0] : '\0'; + + return SUCCESS; +} + +void zephir_ini_activate_globals(const char *const *names) +{ + for (; *names; names++) { + zend_ini_entry *entry = zend_hash_str_find_ptr(EG(ini_directives), *names, strlen(*names)); + + /* An entry the engine refused to register (a duplicate name) leaves + * its global at whatever MINIT left behind, which is the same + * outcome as before this call existed. */ + if (entry && entry->on_modify) { + entry->on_modify( + entry, + entry->value, + entry->mh_arg1, + entry->mh_arg2, + entry->mh_arg3, + ZEND_INI_STAGE_ACTIVATE + ); + } + } +} diff --git a/ext/kernel/main.h b/ext/kernel/main.h index 7892c3a..dcc48c5 100644 --- a/ext/kernel/main.h +++ b/ext/kernel/main.h @@ -19,6 +19,8 @@ #include #include #include +/* ZEND_INI_MH and ZEND_INI_GET_ADDR; does not pull this in. */ +#include extern zend_string* i_parent; extern zend_string* i_static; @@ -605,6 +607,34 @@ void zephir_get_args_from(zval* return_value, uint32_t skip); void zephir_module_init(); void zephir_module_shutdown(void); +/** + * Update handler for an extension global declared as `char` or `uchar`. + * + * The engine exports no handler writing a single character: the stock set + * covers bool, zend_long, double, char* and zend_string* only. ext/soap's + * OnUpdateCacheMode is the same four lines for the same reason. + */ +ZEND_INI_MH(zephir_OnUpdateChar); + +/** + * Re-applies the current value of each named ini directive to the global it + * backs, at the start of a request. + * + * REGISTER_INI_ENTRIES() already seeds every INI-backed global at MINIT, and + * the engine restores anything ini_set() touched at request shutdown. What it + * cannot see is globals_set(), which writes the struct member directly; that + * value would otherwise survive into the next request. Re-running each + * entry's own on_modify handler resets exactly those, for every type, without + * the generated code having to know which type each global is. + * + * Mirrors zend_ini_refresh_caches(), which the engine runs for the same + * reason when a new thread starts. + * + * @param names NULL-terminated list of directive names + * @see https://github.com/zephir-lang/zephir/issues/2449 + */ +void zephir_ini_activate_globals(const char *const *names); + /** * Z_PARAM_ARRAY(dest) expands to a call to zend_parse_arg_array(_arg, &dest, ...). * The inline function has taken `zval **dest` since at least PHP 7.0, so the diff --git a/ext/kernel/operators.c b/ext/kernel/operators.c index bb36f33..5666aaf 100644 --- a/ext/kernel/operators.c +++ b/ext/kernel/operators.c @@ -208,6 +208,41 @@ void zephir_concat_self_long(zval *left, const zend_long right) zend_string_release(right_str); } +/** + * Appends the string form of the right operator to the left operator. + * + * Mirrors what PHP does for `$s .= $d` with an `IS_DOUBLE` right operand: + * `concat_function()` renders it through `zval_get_string()`, which reads + * `EG(precision)` at run time. Rendering the value here with `printf()` would + * freeze that precision at build time, and `zend_double_to_str()` reaches the + * conversion directly but only exists on PHP 8.1 and later. Boxing the operand + * and letting `zephir_concat_self()` call `zephir_make_printable_zval()` is the + * same conversion on every supported version. + */ +void zephir_concat_self_double(zval *left, const double right) +{ + zval right_zv; + + ZVAL_DOUBLE(&right_zv, right); + zephir_concat_self(left, &right_zv); +} + +/** + * Appends the string form of a boolean right operator to the left operator. + * + * PHP renders `true` as "1" and `false` as the empty string. Appending nothing + * is not the same as doing nothing: `$v = 5; $v .= false;` leaves PHP holding + * the *string* "5", so `false` goes through the same conversion rather than + * returning early. + */ +void zephir_concat_self_bool(zval *left, const zend_bool right) +{ + zval right_zv; + + ZVAL_BOOL(&right_zv, right); + zephir_concat_self(left, &right_zv); +} + /** * Natural compare with long operandus on right */ diff --git a/ext/kernel/operators.h b/ext/kernel/operators.h index d2dcd15..b3648f9 100644 --- a/ext/kernel/operators.h +++ b/ext/kernel/operators.h @@ -85,6 +85,8 @@ void zephir_concat_self(zval *left, zval *right); void zephir_concat_self_str(zval *left, const char *right, int right_length); void zephir_concat_self_long(zval *left, const zend_long right); void zephir_concat_self_char(zval *left, unsigned char right); +void zephir_concat_self_double(zval *left, const double right); +void zephir_concat_self_bool(zval *left, const zend_bool right); /** Strict comparing */ int zephir_compare_strict_string(zval *op1, const char *op2, int op2_length); diff --git a/ext/php_tensor.h b/ext/php_tensor.h index d788231..b9ddfd0 100644 --- a/ext/php_tensor.h +++ b/ext/php_tensor.h @@ -19,6 +19,9 @@ +#define ZEPHIR_BUFFER_ENABLED 1 +#define ZEPHIR_BUFFER_NAMESPACE "Tensor" + ZEND_BEGIN_MODULE_GLOBALS(tensor) diff --git a/ext/php_tensor_ext.h b/ext/php_tensor_ext.h index 7c2722c..50ab57c 100644 --- a/ext/php_tensor_ext.h +++ b/ext/php_tensor_ext.h @@ -11,7 +11,7 @@ #include "kernel/globals.h" #define PHP_TENSOR_EXT_NAME "tensor" -#define PHP_TENSOR_EXT_VERSION "3.1.1" +#define PHP_TENSOR_EXT_VERSION "4.0.0" #define PHP_TENSOR_EXT_EXTNAME "tensor_ext" #define PHP_TENSOR_EXT_AUTHOR "The Rubix ML Community" #define PHP_TENSOR_EXT_ZEPVERSION "1.5.0-$Id$" @@ -19,6 +19,9 @@ +#define ZEPHIR_BUFFER_ENABLED 1 +#define ZEPHIR_BUFFER_NAMESPACE "Tensor" + ZEND_BEGIN_MODULE_GLOBALS(tensor_ext) diff --git a/ext/tensor/columnvector.zep.c b/ext/tensor/columnvector.zep.c index b398508..985535e 100644 --- a/ext/tensor/columnvector.zep.c +++ b/ext/tensor/columnvector.zep.c @@ -12,14 +12,15 @@ #include #include "kernel/main.h" +#include "kernel/object.h" #include "kernel/fcall.h" #include "kernel/memory.h" #include "kernel/operators.h" -#include "kernel/object.h" #include "kernel/exception.h" #include "kernel/concat.h" -#include "kernel/string.h" -#include "kernel/array.h" +#include "include/linear_algebra.h" +#include "include/arithmetic.h" +#include "include/comparison.h" /** @@ -38,76 +39,6 @@ ZEPHIR_INIT_CLASS(Tensor_ColumnVector) return SUCCESS; } -/** - * Factory method to build a new vector from an array. - * - * @param (int|float)[] a - * @return self - */ -PHP_METHOD(Tensor_ColumnVector, build) -{ - zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS; - zval *a_param = NULL, _0; - zval a; - - ZVAL_UNDEF(&a); - ZVAL_UNDEF(&_0); - ZEND_PARSE_PARAMETERS_START(0, 1) - Z_PARAM_OPTIONAL - ZEPHIR_Z_PARAM_ARRAY(a, a_param) - ZEND_PARSE_PARAMETERS_END(); - ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); - zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_fetch_params(1, 0, 1, &a_param); - if (!a_param) { - ZEPHIR_INIT_VAR(&a); - array_init(&a); - } else { - zephir_get_arrval(&a, a_param); - } - object_init_ex(return_value, tensor_columnvector_ce); - ZVAL_BOOL(&_0, 1); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 1, &a, &_0); - zephir_check_call_status(); - RETURN_MM(); -} - -/** - * Build a vector foregoing any validation for quicker instantiation. - * - * @param (int|float)[] a - * @return self - */ -PHP_METHOD(Tensor_ColumnVector, quick) -{ - zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS; - zval *a_param = NULL, _0; - zval a; - - ZVAL_UNDEF(&a); - ZVAL_UNDEF(&_0); - ZEND_PARSE_PARAMETERS_START(0, 1) - Z_PARAM_OPTIONAL - ZEPHIR_Z_PARAM_ARRAY(a, a_param) - ZEND_PARSE_PARAMETERS_END(); - ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); - zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_fetch_params(1, 0, 1, &a_param); - if (!a_param) { - ZEPHIR_INIT_VAR(&a); - array_init(&a); - } else { - zephir_get_arrval(&a, a_param); - } - object_init_ex(return_value, tensor_columnvector_ce); - ZVAL_BOOL(&_0, 0); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 1, &a, &_0); - zephir_check_call_status(); - RETURN_MM(); -} - /** * Return the number of rows in the vector. * @@ -150,8 +81,9 @@ PHP_METHOD(Tensor_ColumnVector, transpose) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_vector_ce); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_vector_ce, "quick", NULL, 0, &_0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -164,22 +96,67 @@ PHP_METHOD(Tensor_ColumnVector, transpose) */ PHP_METHOD(Tensor_ColumnVector, matmul) { + zval _3$$3, _4$$3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0; + zval *b, b_sub, _0, product, _5, _6, _7, _8, _9, _10, _1$$3, _2$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&product); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); + ZVAL_UNDEF(&_10); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); + ZVAL_UNDEF(&_3$$3); + ZVAL_UNDEF(&_4$$3); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) ZEND_PARSE_PARAMETERS_END(); ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "ascolumnmatrix", NULL, 0); + ZEPHIR_CALL_METHOD(&_0, b, "m", NULL, 0); + zephir_check_call_status(); + if (UNEXPECTED(!ZEPHIR_IS_LONG_IDENTICAL(&_0, 1))) { + ZEPHIR_INIT_VAR(&_1$$3); + object_init_ex(&_1$$3, tensor_exceptions_dimensionalitymismatch_ce); + ZEPHIR_CALL_METHOD(&_2$$3, b, "m", NULL, 0); + zephir_check_call_status(); + zephir_cast_to_string(&_3$$3, &_2$$3); + ZEPHIR_INIT_VAR(&_4$$3); + ZEPHIR_CONCAT_SSVS(&_4$$3, "Matrix A requires", " 1 rows but Matrix B has ", &_3$$3, "."); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_4$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_1$$3, "tensor/columnvector.zep", 57); + ZEPHIR_MM_RESTORE(); + return; + } + ZEPHIR_INIT_VAR(&product); + zephir_read_property_cached(&_5, this_ptr, _zephir_prop_0, 3, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_6, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_7, this_ptr, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_8, b, "n", NULL, 0); + zephir_check_call_status(); + tensor_outer(&product, &_5, &_6, &_7, &_8); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_9, this_ptr, "m", NULL, 0); zephir_check_call_status(); - ZEPHIR_RETURN_CALL_METHOD(&_0, "matmul", NULL, 0, b); + ZEPHIR_CALL_METHOD(&_10, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &product, &_9, &_10); zephir_check_call_status(); RETURN_MM(); } @@ -194,40 +171,23 @@ PHP_METHOD(Tensor_ColumnVector, matmul) PHP_METHOD(Tensor_ColumnVector, multiplyMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _23, _20$$4, _30$$7; - zend_string *_13; - zend_ulong _12; - zval c, rowC; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, valueB, valueA, _8, *_9, _10, *_11, _22, _2$$3, _3$$3, _5$$3, _14$$4, *_15$$4, _16$$4, *_17$$4, _19$$4, _18$$5, _21$$6, _24$$7, *_25$$7, _26$$7, *_27$$7, _29$$7, _28$$8, _31$$9; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); - ZVAL_UNDEF(&valueB); - ZVAL_UNDEF(&valueA); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_22); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$4); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_21$$6); - ZVAL_UNDEF(&_24$$7); - ZVAL_UNDEF(&_26$$7); - ZVAL_UNDEF(&_29$$7); - ZVAL_UNDEF(&_28$$8); - ZVAL_UNDEF(&_31$$9); - ZVAL_UNDEF(&c); - ZVAL_UNDEF(&rowC); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -260,157 +220,25 @@ PHP_METHOD(Tensor_ColumnVector, multiplyMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " rows but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 92); + zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 77); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_INIT_VAR(&rowC); - array_init(&rowC); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/columnvector.zep", 112); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - zephir_read_property_cached(&_14$$4, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_14$$4, &i, PH_NOISY, "tensor/columnvector.zep", 101); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_16$$4); - zephir_string_to_char_array(&_16$$4, &rowB); - _15$$4 = &_16$$4; - } else { - _15$$4 = &rowB; - } - zephir_is_iterable(_15$$4, 0, "tensor/columnvector.zep", 109); - if (Z_TYPE_P(_15$$4) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_15$$4), _17$$4) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _17$$4); - ZEPHIR_INIT_NVAR(&_18$$5); - mul_function(&_18$$5, &valueA, &valueB); - zephir_array_append(&rowC, &_18$$5, PH_SEPARATE, "tensor/columnvector.zep", 106); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "rewind", NULL, 0); - zephir_check_call_status(); - _20$$4 = 1; - while (1) { - if (_20$$4) { - _20$$4 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_19$$4, _15$$4, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_19$$4)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _15$$4, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_21$$6); - mul_function(&_21$$6, &valueA, &valueB); - zephir_array_append(&rowC, &_21$$6, PH_SEPARATE, "tensor/columnvector.zep", 106); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 109); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _23 = 1; - while (1) { - if (_23) { - _23 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_22, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_22)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - zephir_read_property_cached(&_24$$7, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_24$$7, &i, PH_NOISY, "tensor/columnvector.zep", 101); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_26$$7); - zephir_string_to_char_array(&_26$$7, &rowB); - _25$$7 = &_26$$7; - } else { - _25$$7 = &rowB; - } - zephir_is_iterable(_25$$7, 0, "tensor/columnvector.zep", 109); - if (Z_TYPE_P(_25$$7) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_25$$7), _27$$7) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _27$$7); - ZEPHIR_INIT_NVAR(&_28$$8); - mul_function(&_28$$8, &valueA, &valueB); - zephir_array_append(&rowC, &_28$$8, PH_SEPARATE, "tensor/columnvector.zep", 106); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "rewind", NULL, 0); - zephir_check_call_status(); - _30$$7 = 1; - while (1) { - if (_30$$7) { - _30$$7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_29$$7, _25$$7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_29$$7)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _25$$7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_31$$9); - mul_function(&_31$$9, &valueA, &valueB); - zephir_array_append(&rowC, &_31$$9, PH_SEPARATE, "tensor/columnvector.zep", 106); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 109); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_9, b, "n", NULL, 0); + zephir_check_call_status(); + tensor_multiply_col(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -425,40 +253,23 @@ PHP_METHOD(Tensor_ColumnVector, multiplyMatrix) PHP_METHOD(Tensor_ColumnVector, divideMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _23, _20$$4, _30$$7; - zend_string *_13; - zend_ulong _12; - zval c, rowC; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, valueB, valueA, _8, *_9, _10, *_11, _22, _2$$3, _3$$3, _5$$3, _14$$4, *_15$$4, _16$$4, *_17$$4, _19$$4, _18$$5, _21$$6, _24$$7, *_25$$7, _26$$7, *_27$$7, _29$$7, _28$$8, _31$$9; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); - ZVAL_UNDEF(&valueB); - ZVAL_UNDEF(&valueA); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_22); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$4); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_21$$6); - ZVAL_UNDEF(&_24$$7); - ZVAL_UNDEF(&_26$$7); - ZVAL_UNDEF(&_29$$7); - ZVAL_UNDEF(&_28$$8); - ZVAL_UNDEF(&_31$$9); - ZVAL_UNDEF(&c); - ZVAL_UNDEF(&rowC); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -491,157 +302,25 @@ PHP_METHOD(Tensor_ColumnVector, divideMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " rows but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 127); + zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 101); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_INIT_VAR(&rowC); - array_init(&rowC); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/columnvector.zep", 147); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - zephir_read_property_cached(&_14$$4, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_14$$4, &i, PH_NOISY, "tensor/columnvector.zep", 136); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_16$$4); - zephir_string_to_char_array(&_16$$4, &rowB); - _15$$4 = &_16$$4; - } else { - _15$$4 = &rowB; - } - zephir_is_iterable(_15$$4, 0, "tensor/columnvector.zep", 144); - if (Z_TYPE_P(_15$$4) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_15$$4), _17$$4) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _17$$4); - ZEPHIR_INIT_NVAR(&_18$$5); - div_function(&_18$$5, &valueA, &valueB); - zephir_array_append(&rowC, &_18$$5, PH_SEPARATE, "tensor/columnvector.zep", 141); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "rewind", NULL, 0); - zephir_check_call_status(); - _20$$4 = 1; - while (1) { - if (_20$$4) { - _20$$4 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_19$$4, _15$$4, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_19$$4)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _15$$4, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_21$$6); - div_function(&_21$$6, &valueA, &valueB); - zephir_array_append(&rowC, &_21$$6, PH_SEPARATE, "tensor/columnvector.zep", 141); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 144); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _23 = 1; - while (1) { - if (_23) { - _23 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_22, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_22)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - zephir_read_property_cached(&_24$$7, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_24$$7, &i, PH_NOISY, "tensor/columnvector.zep", 136); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_26$$7); - zephir_string_to_char_array(&_26$$7, &rowB); - _25$$7 = &_26$$7; - } else { - _25$$7 = &rowB; - } - zephir_is_iterable(_25$$7, 0, "tensor/columnvector.zep", 144); - if (Z_TYPE_P(_25$$7) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_25$$7), _27$$7) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _27$$7); - ZEPHIR_INIT_NVAR(&_28$$8); - div_function(&_28$$8, &valueA, &valueB); - zephir_array_append(&rowC, &_28$$8, PH_SEPARATE, "tensor/columnvector.zep", 141); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "rewind", NULL, 0); - zephir_check_call_status(); - _30$$7 = 1; - while (1) { - if (_30$$7) { - _30$$7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_29$$7, _25$$7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_29$$7)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _25$$7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_31$$9); - div_function(&_31$$9, &valueA, &valueB); - zephir_array_append(&rowC, &_31$$9, PH_SEPARATE, "tensor/columnvector.zep", 141); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 144); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_9, b, "n", NULL, 0); + zephir_check_call_status(); + tensor_divide_col_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -656,40 +335,23 @@ PHP_METHOD(Tensor_ColumnVector, divideMatrix) PHP_METHOD(Tensor_ColumnVector, addMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _23, _20$$4, _30$$7; - zend_string *_13; - zend_ulong _12; - zval c, rowC; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, valueB, valueA, _8, *_9, _10, *_11, _22, _2$$3, _3$$3, _5$$3, _14$$4, *_15$$4, _16$$4, *_17$$4, _19$$4, _18$$5, _21$$6, _24$$7, *_25$$7, _26$$7, *_27$$7, _29$$7, _28$$8, _31$$9; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); - ZVAL_UNDEF(&valueB); - ZVAL_UNDEF(&valueA); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_22); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$4); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_21$$6); - ZVAL_UNDEF(&_24$$7); - ZVAL_UNDEF(&_26$$7); - ZVAL_UNDEF(&_29$$7); - ZVAL_UNDEF(&_28$$8); - ZVAL_UNDEF(&_31$$9); - ZVAL_UNDEF(&c); - ZVAL_UNDEF(&rowC); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -722,157 +384,25 @@ PHP_METHOD(Tensor_ColumnVector, addMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " rows but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 162); + zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 125); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_INIT_VAR(&rowC); - array_init(&rowC); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/columnvector.zep", 182); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - zephir_read_property_cached(&_14$$4, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_14$$4, &i, PH_NOISY, "tensor/columnvector.zep", 171); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_16$$4); - zephir_string_to_char_array(&_16$$4, &rowB); - _15$$4 = &_16$$4; - } else { - _15$$4 = &rowB; - } - zephir_is_iterable(_15$$4, 0, "tensor/columnvector.zep", 179); - if (Z_TYPE_P(_15$$4) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_15$$4), _17$$4) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _17$$4); - ZEPHIR_INIT_NVAR(&_18$$5); - zephir_add_function(&_18$$5, &valueA, &valueB); - zephir_array_append(&rowC, &_18$$5, PH_SEPARATE, "tensor/columnvector.zep", 176); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "rewind", NULL, 0); - zephir_check_call_status(); - _20$$4 = 1; - while (1) { - if (_20$$4) { - _20$$4 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_19$$4, _15$$4, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_19$$4)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _15$$4, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_21$$6); - zephir_add_function(&_21$$6, &valueA, &valueB); - zephir_array_append(&rowC, &_21$$6, PH_SEPARATE, "tensor/columnvector.zep", 176); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 179); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _23 = 1; - while (1) { - if (_23) { - _23 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_22, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_22)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - zephir_read_property_cached(&_24$$7, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_24$$7, &i, PH_NOISY, "tensor/columnvector.zep", 171); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_26$$7); - zephir_string_to_char_array(&_26$$7, &rowB); - _25$$7 = &_26$$7; - } else { - _25$$7 = &rowB; - } - zephir_is_iterable(_25$$7, 0, "tensor/columnvector.zep", 179); - if (Z_TYPE_P(_25$$7) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_25$$7), _27$$7) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _27$$7); - ZEPHIR_INIT_NVAR(&_28$$8); - zephir_add_function(&_28$$8, &valueA, &valueB); - zephir_array_append(&rowC, &_28$$8, PH_SEPARATE, "tensor/columnvector.zep", 176); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "rewind", NULL, 0); - zephir_check_call_status(); - _30$$7 = 1; - while (1) { - if (_30$$7) { - _30$$7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_29$$7, _25$$7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_29$$7)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _25$$7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_31$$9); - zephir_add_function(&_31$$9, &valueA, &valueB); - zephir_array_append(&rowC, &_31$$9, PH_SEPARATE, "tensor/columnvector.zep", 176); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 179); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_9, b, "n", NULL, 0); + zephir_check_call_status(); + tensor_add_col(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -887,40 +417,23 @@ PHP_METHOD(Tensor_ColumnVector, addMatrix) PHP_METHOD(Tensor_ColumnVector, subtractMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _23, _20$$4, _30$$7; - zend_string *_13; - zend_ulong _12; - zval c, rowC; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, valueB, valueA, _8, *_9, _10, *_11, _22, _2$$3, _3$$3, _5$$3, _14$$4, *_15$$4, _16$$4, *_17$$4, _19$$4, _18$$5, _21$$6, _24$$7, *_25$$7, _26$$7, *_27$$7, _29$$7, _28$$8, _31$$9; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); - ZVAL_UNDEF(&valueB); - ZVAL_UNDEF(&valueA); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_22); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$4); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_21$$6); - ZVAL_UNDEF(&_24$$7); - ZVAL_UNDEF(&_26$$7); - ZVAL_UNDEF(&_29$$7); - ZVAL_UNDEF(&_28$$8); - ZVAL_UNDEF(&_31$$9); - ZVAL_UNDEF(&c); - ZVAL_UNDEF(&rowC); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -953,157 +466,25 @@ PHP_METHOD(Tensor_ColumnVector, subtractMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " rows but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 197); + zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 149); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_INIT_VAR(&rowC); - array_init(&rowC); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/columnvector.zep", 217); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - zephir_read_property_cached(&_14$$4, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_14$$4, &i, PH_NOISY, "tensor/columnvector.zep", 206); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_16$$4); - zephir_string_to_char_array(&_16$$4, &rowB); - _15$$4 = &_16$$4; - } else { - _15$$4 = &rowB; - } - zephir_is_iterable(_15$$4, 0, "tensor/columnvector.zep", 214); - if (Z_TYPE_P(_15$$4) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_15$$4), _17$$4) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _17$$4); - ZEPHIR_INIT_NVAR(&_18$$5); - zephir_sub_function(&_18$$5, &valueA, &valueB); - zephir_array_append(&rowC, &_18$$5, PH_SEPARATE, "tensor/columnvector.zep", 211); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "rewind", NULL, 0); - zephir_check_call_status(); - _20$$4 = 1; - while (1) { - if (_20$$4) { - _20$$4 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_19$$4, _15$$4, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_19$$4)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _15$$4, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_21$$6); - zephir_sub_function(&_21$$6, &valueA, &valueB); - zephir_array_append(&rowC, &_21$$6, PH_SEPARATE, "tensor/columnvector.zep", 211); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 214); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _23 = 1; - while (1) { - if (_23) { - _23 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_22, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_22)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - zephir_read_property_cached(&_24$$7, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_24$$7, &i, PH_NOISY, "tensor/columnvector.zep", 206); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_26$$7); - zephir_string_to_char_array(&_26$$7, &rowB); - _25$$7 = &_26$$7; - } else { - _25$$7 = &rowB; - } - zephir_is_iterable(_25$$7, 0, "tensor/columnvector.zep", 214); - if (Z_TYPE_P(_25$$7) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_25$$7), _27$$7) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _27$$7); - ZEPHIR_INIT_NVAR(&_28$$8); - zephir_sub_function(&_28$$8, &valueA, &valueB); - zephir_array_append(&rowC, &_28$$8, PH_SEPARATE, "tensor/columnvector.zep", 211); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "rewind", NULL, 0); - zephir_check_call_status(); - _30$$7 = 1; - while (1) { - if (_30$$7) { - _30$$7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_29$$7, _25$$7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_29$$7)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _25$$7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_31$$9); - zephir_sub_function(&_31$$9, &valueA, &valueB); - zephir_array_append(&rowC, &_31$$9, PH_SEPARATE, "tensor/columnvector.zep", 211); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 214); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_9, b, "n", NULL, 0); + zephir_check_call_status(); + tensor_subtract_col_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -1118,41 +499,23 @@ PHP_METHOD(Tensor_ColumnVector, subtractMatrix) PHP_METHOD(Tensor_ColumnVector, powMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _24, _21$$4, _31$$7; - zend_string *_13; - zend_ulong _12; - zval c, rowC; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zephir_fcall_cache_entry *_19 = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, valueB, valueA, _8, *_9, _10, *_11, _23, _2$$3, _3$$3, _5$$3, _14$$4, *_15$$4, _16$$4, *_17$$4, _20$$4, _18$$5, _22$$6, _25$$7, *_26$$7, _27$$7, *_28$$7, _30$$7, _29$$8, _32$$9; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); - ZVAL_UNDEF(&valueB); - ZVAL_UNDEF(&valueA); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_23); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_20$$4); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_22$$6); - ZVAL_UNDEF(&_25$$7); - ZVAL_UNDEF(&_27$$7); - ZVAL_UNDEF(&_30$$7); - ZVAL_UNDEF(&_29$$8); - ZVAL_UNDEF(&_32$$9); - ZVAL_UNDEF(&c); - ZVAL_UNDEF(&rowC); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -1185,157 +548,25 @@ PHP_METHOD(Tensor_ColumnVector, powMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " rows but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 232); + zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 173); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_INIT_VAR(&rowC); - array_init(&rowC); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/columnvector.zep", 252); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - zephir_read_property_cached(&_14$$4, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_14$$4, &i, PH_NOISY, "tensor/columnvector.zep", 241); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_16$$4); - zephir_string_to_char_array(&_16$$4, &rowB); - _15$$4 = &_16$$4; - } else { - _15$$4 = &rowB; - } - zephir_is_iterable(_15$$4, 0, "tensor/columnvector.zep", 249); - if (Z_TYPE_P(_15$$4) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_15$$4), _17$$4) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _17$$4); - ZEPHIR_CALL_FUNCTION(&_18$$5, "pow", &_19, 16, &valueA, &valueB); - zephir_check_call_status(); - zephir_array_append(&rowC, &_18$$5, PH_SEPARATE, "tensor/columnvector.zep", 246); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "rewind", NULL, 0); - zephir_check_call_status(); - _21$$4 = 1; - while (1) { - if (_21$$4) { - _21$$4 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_20$$4, _15$$4, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_20$$4)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _15$$4, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_FUNCTION(&_22$$6, "pow", &_19, 16, &valueA, &valueB); - zephir_check_call_status(); - zephir_array_append(&rowC, &_22$$6, PH_SEPARATE, "tensor/columnvector.zep", 246); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 249); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _24 = 1; - while (1) { - if (_24) { - _24 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_23, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_23)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - zephir_read_property_cached(&_25$$7, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_25$$7, &i, PH_NOISY, "tensor/columnvector.zep", 241); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_27$$7); - zephir_string_to_char_array(&_27$$7, &rowB); - _26$$7 = &_27$$7; - } else { - _26$$7 = &rowB; - } - zephir_is_iterable(_26$$7, 0, "tensor/columnvector.zep", 249); - if (Z_TYPE_P(_26$$7) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_26$$7), _28$$7) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _28$$7); - ZEPHIR_CALL_FUNCTION(&_29$$8, "pow", &_19, 16, &valueA, &valueB); - zephir_check_call_status(); - zephir_array_append(&rowC, &_29$$8, PH_SEPARATE, "tensor/columnvector.zep", 246); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _26$$7, "rewind", NULL, 0); - zephir_check_call_status(); - _31$$7 = 1; - while (1) { - if (_31$$7) { - _31$$7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _26$$7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_30$$7, _26$$7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_30$$7)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _26$$7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_FUNCTION(&_32$$9, "pow", &_19, 16, &valueA, &valueB); - zephir_check_call_status(); - zephir_array_append(&rowC, &_32$$9, PH_SEPARATE, "tensor/columnvector.zep", 246); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 249); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_9, b, "n", NULL, 0); + zephir_check_call_status(); + tensor_pow_col_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -1350,40 +581,23 @@ PHP_METHOD(Tensor_ColumnVector, powMatrix) PHP_METHOD(Tensor_ColumnVector, modMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _23, _20$$4, _30$$7; - zend_string *_13; - zend_ulong _12; - zval c, rowC; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, valueB, valueA, _8, *_9, _10, *_11, _22, _2$$3, _3$$3, _5$$3, _14$$4, *_15$$4, _16$$4, *_17$$4, _19$$4, _18$$5, _21$$6, _24$$7, *_25$$7, _26$$7, *_27$$7, _29$$7, _28$$8, _31$$9; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); - ZVAL_UNDEF(&valueB); - ZVAL_UNDEF(&valueA); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_22); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$4); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_21$$6); - ZVAL_UNDEF(&_24$$7); - ZVAL_UNDEF(&_26$$7); - ZVAL_UNDEF(&_29$$7); - ZVAL_UNDEF(&_28$$8); - ZVAL_UNDEF(&_31$$9); - ZVAL_UNDEF(&c); - ZVAL_UNDEF(&rowC); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -1416,157 +630,25 @@ PHP_METHOD(Tensor_ColumnVector, modMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " rows but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 267); + zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 197); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_INIT_VAR(&rowC); - array_init(&rowC); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/columnvector.zep", 287); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - zephir_read_property_cached(&_14$$4, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_14$$4, &i, PH_NOISY, "tensor/columnvector.zep", 276); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_16$$4); - zephir_string_to_char_array(&_16$$4, &rowB); - _15$$4 = &_16$$4; - } else { - _15$$4 = &rowB; - } - zephir_is_iterable(_15$$4, 0, "tensor/columnvector.zep", 284); - if (Z_TYPE_P(_15$$4) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_15$$4), _17$$4) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _17$$4); - ZEPHIR_INIT_NVAR(&_18$$5); - mod_function(&_18$$5, &valueA, &valueB); - zephir_array_append(&rowC, &_18$$5, PH_SEPARATE, "tensor/columnvector.zep", 281); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "rewind", NULL, 0); - zephir_check_call_status(); - _20$$4 = 1; - while (1) { - if (_20$$4) { - _20$$4 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_19$$4, _15$$4, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_19$$4)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _15$$4, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_21$$6); - mod_function(&_21$$6, &valueA, &valueB); - zephir_array_append(&rowC, &_21$$6, PH_SEPARATE, "tensor/columnvector.zep", 281); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 284); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _23 = 1; - while (1) { - if (_23) { - _23 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_22, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_22)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - zephir_read_property_cached(&_24$$7, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_24$$7, &i, PH_NOISY, "tensor/columnvector.zep", 276); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_26$$7); - zephir_string_to_char_array(&_26$$7, &rowB); - _25$$7 = &_26$$7; - } else { - _25$$7 = &rowB; - } - zephir_is_iterable(_25$$7, 0, "tensor/columnvector.zep", 284); - if (Z_TYPE_P(_25$$7) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_25$$7), _27$$7) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _27$$7); - ZEPHIR_INIT_NVAR(&_28$$8); - mod_function(&_28$$8, &valueA, &valueB); - zephir_array_append(&rowC, &_28$$8, PH_SEPARATE, "tensor/columnvector.zep", 281); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "rewind", NULL, 0); - zephir_check_call_status(); - _30$$7 = 1; - while (1) { - if (_30$$7) { - _30$$7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_29$$7, _25$$7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_29$$7)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _25$$7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_31$$9); - mod_function(&_31$$9, &valueA, &valueB); - zephir_array_append(&rowC, &_31$$9, PH_SEPARATE, "tensor/columnvector.zep", 281); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 284); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_9, b, "n", NULL, 0); + zephir_check_call_status(); + tensor_mod_col_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -1581,40 +663,23 @@ PHP_METHOD(Tensor_ColumnVector, modMatrix) PHP_METHOD(Tensor_ColumnVector, equalMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _23, _20$$4, _30$$7; - zend_string *_13; - zend_ulong _12; - zval c, rowC; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, valueB, valueA, _8, *_9, _10, *_11, _22, _2$$3, _3$$3, _5$$3, _14$$4, *_15$$4, _16$$4, *_17$$4, _19$$4, _18$$5, _21$$6, _24$$7, *_25$$7, _26$$7, *_27$$7, _29$$7, _28$$8, _31$$9; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); - ZVAL_UNDEF(&valueB); - ZVAL_UNDEF(&valueA); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_22); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$4); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_21$$6); - ZVAL_UNDEF(&_24$$7); - ZVAL_UNDEF(&_26$$7); - ZVAL_UNDEF(&_29$$7); - ZVAL_UNDEF(&_28$$8); - ZVAL_UNDEF(&_31$$9); - ZVAL_UNDEF(&c); - ZVAL_UNDEF(&rowC); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -1647,181 +712,25 @@ PHP_METHOD(Tensor_ColumnVector, equalMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " rows but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 302); + zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 221); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_INIT_VAR(&rowC); - array_init(&rowC); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/columnvector.zep", 322); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - zephir_read_property_cached(&_14$$4, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_14$$4, &i, PH_NOISY, "tensor/columnvector.zep", 311); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_16$$4); - zephir_string_to_char_array(&_16$$4, &rowB); - _15$$4 = &_16$$4; - } else { - _15$$4 = &rowB; - } - zephir_is_iterable(_15$$4, 0, "tensor/columnvector.zep", 319); - if (Z_TYPE_P(_15$$4) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_15$$4), _17$$4) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _17$$4); - ZEPHIR_INIT_NVAR(&_18$$5); - if (ZEPHIR_IS_EQUAL(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_18$$5); - ZVAL_LONG(&_18$$5, 1); - } else { - ZEPHIR_INIT_NVAR(&_18$$5); - ZVAL_LONG(&_18$$5, 0); - } - zephir_array_append(&rowC, &_18$$5, PH_SEPARATE, "tensor/columnvector.zep", 316); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "rewind", NULL, 0); - zephir_check_call_status(); - _20$$4 = 1; - while (1) { - if (_20$$4) { - _20$$4 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_19$$4, _15$$4, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_19$$4)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _15$$4, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_21$$6); - if (ZEPHIR_IS_EQUAL(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_21$$6); - ZVAL_LONG(&_21$$6, 1); - } else { - ZEPHIR_INIT_NVAR(&_21$$6); - ZVAL_LONG(&_21$$6, 0); - } - zephir_array_append(&rowC, &_21$$6, PH_SEPARATE, "tensor/columnvector.zep", 316); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 319); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _23 = 1; - while (1) { - if (_23) { - _23 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_22, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_22)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - zephir_read_property_cached(&_24$$7, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_24$$7, &i, PH_NOISY, "tensor/columnvector.zep", 311); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_26$$7); - zephir_string_to_char_array(&_26$$7, &rowB); - _25$$7 = &_26$$7; - } else { - _25$$7 = &rowB; - } - zephir_is_iterable(_25$$7, 0, "tensor/columnvector.zep", 319); - if (Z_TYPE_P(_25$$7) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_25$$7), _27$$7) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _27$$7); - ZEPHIR_INIT_NVAR(&_28$$8); - if (ZEPHIR_IS_EQUAL(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_28$$8); - ZVAL_LONG(&_28$$8, 1); - } else { - ZEPHIR_INIT_NVAR(&_28$$8); - ZVAL_LONG(&_28$$8, 0); - } - zephir_array_append(&rowC, &_28$$8, PH_SEPARATE, "tensor/columnvector.zep", 316); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "rewind", NULL, 0); - zephir_check_call_status(); - _30$$7 = 1; - while (1) { - if (_30$$7) { - _30$$7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_29$$7, _25$$7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_29$$7)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _25$$7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_31$$9); - if (ZEPHIR_IS_EQUAL(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_31$$9); - ZVAL_LONG(&_31$$9, 1); - } else { - ZEPHIR_INIT_NVAR(&_31$$9); - ZVAL_LONG(&_31$$9, 0); - } - zephir_array_append(&rowC, &_31$$9, PH_SEPARATE, "tensor/columnvector.zep", 316); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 319); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_9, b, "n", NULL, 0); + zephir_check_call_status(); + tensor_equal_col(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -1836,40 +745,23 @@ PHP_METHOD(Tensor_ColumnVector, equalMatrix) PHP_METHOD(Tensor_ColumnVector, notEqualMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _23, _20$$4, _30$$7; - zend_string *_13; - zend_ulong _12; - zval c, rowC; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, valueB, valueA, _8, *_9, _10, *_11, _22, _2$$3, _3$$3, _5$$3, _14$$4, *_15$$4, _16$$4, *_17$$4, _19$$4, _18$$5, _21$$6, _24$$7, *_25$$7, _26$$7, *_27$$7, _29$$7, _28$$8, _31$$9; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); - ZVAL_UNDEF(&valueB); - ZVAL_UNDEF(&valueA); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_22); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$4); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_21$$6); - ZVAL_UNDEF(&_24$$7); - ZVAL_UNDEF(&_26$$7); - ZVAL_UNDEF(&_29$$7); - ZVAL_UNDEF(&_28$$8); - ZVAL_UNDEF(&_31$$9); - ZVAL_UNDEF(&c); - ZVAL_UNDEF(&rowC); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -1902,181 +794,25 @@ PHP_METHOD(Tensor_ColumnVector, notEqualMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " rows but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 337); + zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 245); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_INIT_VAR(&rowC); - array_init(&rowC); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/columnvector.zep", 357); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - zephir_read_property_cached(&_14$$4, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_14$$4, &i, PH_NOISY, "tensor/columnvector.zep", 346); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_16$$4); - zephir_string_to_char_array(&_16$$4, &rowB); - _15$$4 = &_16$$4; - } else { - _15$$4 = &rowB; - } - zephir_is_iterable(_15$$4, 0, "tensor/columnvector.zep", 354); - if (Z_TYPE_P(_15$$4) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_15$$4), _17$$4) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _17$$4); - ZEPHIR_INIT_NVAR(&_18$$5); - if (!ZEPHIR_IS_EQUAL(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_18$$5); - ZVAL_LONG(&_18$$5, 1); - } else { - ZEPHIR_INIT_NVAR(&_18$$5); - ZVAL_LONG(&_18$$5, 0); - } - zephir_array_append(&rowC, &_18$$5, PH_SEPARATE, "tensor/columnvector.zep", 351); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "rewind", NULL, 0); - zephir_check_call_status(); - _20$$4 = 1; - while (1) { - if (_20$$4) { - _20$$4 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_19$$4, _15$$4, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_19$$4)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _15$$4, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_21$$6); - if (!ZEPHIR_IS_EQUAL(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_21$$6); - ZVAL_LONG(&_21$$6, 1); - } else { - ZEPHIR_INIT_NVAR(&_21$$6); - ZVAL_LONG(&_21$$6, 0); - } - zephir_array_append(&rowC, &_21$$6, PH_SEPARATE, "tensor/columnvector.zep", 351); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 354); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _23 = 1; - while (1) { - if (_23) { - _23 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_22, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_22)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - zephir_read_property_cached(&_24$$7, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_24$$7, &i, PH_NOISY, "tensor/columnvector.zep", 346); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_26$$7); - zephir_string_to_char_array(&_26$$7, &rowB); - _25$$7 = &_26$$7; - } else { - _25$$7 = &rowB; - } - zephir_is_iterable(_25$$7, 0, "tensor/columnvector.zep", 354); - if (Z_TYPE_P(_25$$7) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_25$$7), _27$$7) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _27$$7); - ZEPHIR_INIT_NVAR(&_28$$8); - if (!ZEPHIR_IS_EQUAL(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_28$$8); - ZVAL_LONG(&_28$$8, 1); - } else { - ZEPHIR_INIT_NVAR(&_28$$8); - ZVAL_LONG(&_28$$8, 0); - } - zephir_array_append(&rowC, &_28$$8, PH_SEPARATE, "tensor/columnvector.zep", 351); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "rewind", NULL, 0); - zephir_check_call_status(); - _30$$7 = 1; - while (1) { - if (_30$$7) { - _30$$7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_29$$7, _25$$7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_29$$7)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _25$$7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_31$$9); - if (!ZEPHIR_IS_EQUAL(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_31$$9); - ZVAL_LONG(&_31$$9, 1); - } else { - ZEPHIR_INIT_NVAR(&_31$$9); - ZVAL_LONG(&_31$$9, 0); - } - zephir_array_append(&rowC, &_31$$9, PH_SEPARATE, "tensor/columnvector.zep", 351); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 354); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_9, b, "n", NULL, 0); + zephir_check_call_status(); + tensor_not_equal_col(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -2091,40 +827,23 @@ PHP_METHOD(Tensor_ColumnVector, notEqualMatrix) PHP_METHOD(Tensor_ColumnVector, greaterMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _23, _20$$4, _30$$7; - zend_string *_13; - zend_ulong _12; - zval c, rowC; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, valueB, valueA, _8, *_9, _10, *_11, _22, _2$$3, _3$$3, _5$$3, _14$$4, *_15$$4, _16$$4, *_17$$4, _19$$4, _18$$5, _21$$6, _24$$7, *_25$$7, _26$$7, *_27$$7, _29$$7, _28$$8, _31$$9; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); - ZVAL_UNDEF(&valueB); - ZVAL_UNDEF(&valueA); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_22); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$4); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_21$$6); - ZVAL_UNDEF(&_24$$7); - ZVAL_UNDEF(&_26$$7); - ZVAL_UNDEF(&_29$$7); - ZVAL_UNDEF(&_28$$8); - ZVAL_UNDEF(&_31$$9); - ZVAL_UNDEF(&c); - ZVAL_UNDEF(&rowC); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -2157,181 +876,25 @@ PHP_METHOD(Tensor_ColumnVector, greaterMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " rows but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 372); + zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 269); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_INIT_VAR(&rowC); - array_init(&rowC); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/columnvector.zep", 392); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - zephir_read_property_cached(&_14$$4, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_14$$4, &i, PH_NOISY, "tensor/columnvector.zep", 381); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_16$$4); - zephir_string_to_char_array(&_16$$4, &rowB); - _15$$4 = &_16$$4; - } else { - _15$$4 = &rowB; - } - zephir_is_iterable(_15$$4, 0, "tensor/columnvector.zep", 389); - if (Z_TYPE_P(_15$$4) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_15$$4), _17$$4) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _17$$4); - ZEPHIR_INIT_NVAR(&_18$$5); - if (ZEPHIR_GT(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_18$$5); - ZVAL_LONG(&_18$$5, 1); - } else { - ZEPHIR_INIT_NVAR(&_18$$5); - ZVAL_LONG(&_18$$5, 0); - } - zephir_array_append(&rowC, &_18$$5, PH_SEPARATE, "tensor/columnvector.zep", 386); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "rewind", NULL, 0); - zephir_check_call_status(); - _20$$4 = 1; - while (1) { - if (_20$$4) { - _20$$4 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_19$$4, _15$$4, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_19$$4)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _15$$4, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_21$$6); - if (ZEPHIR_GT(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_21$$6); - ZVAL_LONG(&_21$$6, 1); - } else { - ZEPHIR_INIT_NVAR(&_21$$6); - ZVAL_LONG(&_21$$6, 0); - } - zephir_array_append(&rowC, &_21$$6, PH_SEPARATE, "tensor/columnvector.zep", 386); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 389); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _23 = 1; - while (1) { - if (_23) { - _23 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_22, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_22)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - zephir_read_property_cached(&_24$$7, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_24$$7, &i, PH_NOISY, "tensor/columnvector.zep", 381); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_26$$7); - zephir_string_to_char_array(&_26$$7, &rowB); - _25$$7 = &_26$$7; - } else { - _25$$7 = &rowB; - } - zephir_is_iterable(_25$$7, 0, "tensor/columnvector.zep", 389); - if (Z_TYPE_P(_25$$7) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_25$$7), _27$$7) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _27$$7); - ZEPHIR_INIT_NVAR(&_28$$8); - if (ZEPHIR_GT(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_28$$8); - ZVAL_LONG(&_28$$8, 1); - } else { - ZEPHIR_INIT_NVAR(&_28$$8); - ZVAL_LONG(&_28$$8, 0); - } - zephir_array_append(&rowC, &_28$$8, PH_SEPARATE, "tensor/columnvector.zep", 386); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "rewind", NULL, 0); - zephir_check_call_status(); - _30$$7 = 1; - while (1) { - if (_30$$7) { - _30$$7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_29$$7, _25$$7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_29$$7)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _25$$7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_31$$9); - if (ZEPHIR_GT(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_31$$9); - ZVAL_LONG(&_31$$9, 1); - } else { - ZEPHIR_INIT_NVAR(&_31$$9); - ZVAL_LONG(&_31$$9, 0); - } - zephir_array_append(&rowC, &_31$$9, PH_SEPARATE, "tensor/columnvector.zep", 386); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 389); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_9, b, "n", NULL, 0); + zephir_check_call_status(); + tensor_greater_col_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -2346,40 +909,23 @@ PHP_METHOD(Tensor_ColumnVector, greaterMatrix) PHP_METHOD(Tensor_ColumnVector, greaterEqualMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _23, _20$$4, _30$$7; - zend_string *_13; - zend_ulong _12; - zval c, rowC; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, valueB, valueA, _8, *_9, _10, *_11, _22, _2$$3, _3$$3, _5$$3, _14$$4, *_15$$4, _16$$4, *_17$$4, _19$$4, _18$$5, _21$$6, _24$$7, *_25$$7, _26$$7, *_27$$7, _29$$7, _28$$8, _31$$9; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); - ZVAL_UNDEF(&valueB); - ZVAL_UNDEF(&valueA); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_22); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$4); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_21$$6); - ZVAL_UNDEF(&_24$$7); - ZVAL_UNDEF(&_26$$7); - ZVAL_UNDEF(&_29$$7); - ZVAL_UNDEF(&_28$$8); - ZVAL_UNDEF(&_31$$9); - ZVAL_UNDEF(&c); - ZVAL_UNDEF(&rowC); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -2412,181 +958,25 @@ PHP_METHOD(Tensor_ColumnVector, greaterEqualMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " rows but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 407); + zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 293); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_INIT_VAR(&rowC); - array_init(&rowC); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/columnvector.zep", 427); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - zephir_read_property_cached(&_14$$4, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_14$$4, &i, PH_NOISY, "tensor/columnvector.zep", 416); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_16$$4); - zephir_string_to_char_array(&_16$$4, &rowB); - _15$$4 = &_16$$4; - } else { - _15$$4 = &rowB; - } - zephir_is_iterable(_15$$4, 0, "tensor/columnvector.zep", 424); - if (Z_TYPE_P(_15$$4) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_15$$4), _17$$4) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _17$$4); - ZEPHIR_INIT_NVAR(&_18$$5); - if (ZEPHIR_GE(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_18$$5); - ZVAL_LONG(&_18$$5, 1); - } else { - ZEPHIR_INIT_NVAR(&_18$$5); - ZVAL_LONG(&_18$$5, 0); - } - zephir_array_append(&rowC, &_18$$5, PH_SEPARATE, "tensor/columnvector.zep", 421); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "rewind", NULL, 0); - zephir_check_call_status(); - _20$$4 = 1; - while (1) { - if (_20$$4) { - _20$$4 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_19$$4, _15$$4, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_19$$4)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _15$$4, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_21$$6); - if (ZEPHIR_GE(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_21$$6); - ZVAL_LONG(&_21$$6, 1); - } else { - ZEPHIR_INIT_NVAR(&_21$$6); - ZVAL_LONG(&_21$$6, 0); - } - zephir_array_append(&rowC, &_21$$6, PH_SEPARATE, "tensor/columnvector.zep", 421); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 424); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _23 = 1; - while (1) { - if (_23) { - _23 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_22, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_22)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - zephir_read_property_cached(&_24$$7, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_24$$7, &i, PH_NOISY, "tensor/columnvector.zep", 416); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_26$$7); - zephir_string_to_char_array(&_26$$7, &rowB); - _25$$7 = &_26$$7; - } else { - _25$$7 = &rowB; - } - zephir_is_iterable(_25$$7, 0, "tensor/columnvector.zep", 424); - if (Z_TYPE_P(_25$$7) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_25$$7), _27$$7) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _27$$7); - ZEPHIR_INIT_NVAR(&_28$$8); - if (ZEPHIR_GE(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_28$$8); - ZVAL_LONG(&_28$$8, 1); - } else { - ZEPHIR_INIT_NVAR(&_28$$8); - ZVAL_LONG(&_28$$8, 0); - } - zephir_array_append(&rowC, &_28$$8, PH_SEPARATE, "tensor/columnvector.zep", 421); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "rewind", NULL, 0); - zephir_check_call_status(); - _30$$7 = 1; - while (1) { - if (_30$$7) { - _30$$7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_29$$7, _25$$7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_29$$7)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _25$$7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_31$$9); - if (ZEPHIR_GE(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_31$$9); - ZVAL_LONG(&_31$$9, 1); - } else { - ZEPHIR_INIT_NVAR(&_31$$9); - ZVAL_LONG(&_31$$9, 0); - } - zephir_array_append(&rowC, &_31$$9, PH_SEPARATE, "tensor/columnvector.zep", 421); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 424); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_9, b, "n", NULL, 0); + zephir_check_call_status(); + tensor_greater_equal_col_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -2601,40 +991,23 @@ PHP_METHOD(Tensor_ColumnVector, greaterEqualMatrix) PHP_METHOD(Tensor_ColumnVector, lessMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _23, _20$$4, _30$$7; - zend_string *_13; - zend_ulong _12; - zval c, rowC; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, valueB, valueA, _8, *_9, _10, *_11, _22, _2$$3, _3$$3, _5$$3, _14$$4, *_15$$4, _16$$4, *_17$$4, _19$$4, _18$$5, _21$$6, _24$$7, *_25$$7, _26$$7, *_27$$7, _29$$7, _28$$8, _31$$9; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); - ZVAL_UNDEF(&valueB); - ZVAL_UNDEF(&valueA); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_22); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$4); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_21$$6); - ZVAL_UNDEF(&_24$$7); - ZVAL_UNDEF(&_26$$7); - ZVAL_UNDEF(&_29$$7); - ZVAL_UNDEF(&_28$$8); - ZVAL_UNDEF(&_31$$9); - ZVAL_UNDEF(&c); - ZVAL_UNDEF(&rowC); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -2667,181 +1040,25 @@ PHP_METHOD(Tensor_ColumnVector, lessMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " rows but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 442); + zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 317); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_INIT_VAR(&rowC); - array_init(&rowC); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/columnvector.zep", 462); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - zephir_read_property_cached(&_14$$4, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_14$$4, &i, PH_NOISY, "tensor/columnvector.zep", 451); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_16$$4); - zephir_string_to_char_array(&_16$$4, &rowB); - _15$$4 = &_16$$4; - } else { - _15$$4 = &rowB; - } - zephir_is_iterable(_15$$4, 0, "tensor/columnvector.zep", 459); - if (Z_TYPE_P(_15$$4) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_15$$4), _17$$4) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _17$$4); - ZEPHIR_INIT_NVAR(&_18$$5); - if (ZEPHIR_LT(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_18$$5); - ZVAL_LONG(&_18$$5, 1); - } else { - ZEPHIR_INIT_NVAR(&_18$$5); - ZVAL_LONG(&_18$$5, 0); - } - zephir_array_append(&rowC, &_18$$5, PH_SEPARATE, "tensor/columnvector.zep", 456); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "rewind", NULL, 0); - zephir_check_call_status(); - _20$$4 = 1; - while (1) { - if (_20$$4) { - _20$$4 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_19$$4, _15$$4, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_19$$4)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _15$$4, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_21$$6); - if (ZEPHIR_LT(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_21$$6); - ZVAL_LONG(&_21$$6, 1); - } else { - ZEPHIR_INIT_NVAR(&_21$$6); - ZVAL_LONG(&_21$$6, 0); - } - zephir_array_append(&rowC, &_21$$6, PH_SEPARATE, "tensor/columnvector.zep", 456); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 459); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _23 = 1; - while (1) { - if (_23) { - _23 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_22, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_22)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - zephir_read_property_cached(&_24$$7, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_24$$7, &i, PH_NOISY, "tensor/columnvector.zep", 451); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_26$$7); - zephir_string_to_char_array(&_26$$7, &rowB); - _25$$7 = &_26$$7; - } else { - _25$$7 = &rowB; - } - zephir_is_iterable(_25$$7, 0, "tensor/columnvector.zep", 459); - if (Z_TYPE_P(_25$$7) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_25$$7), _27$$7) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _27$$7); - ZEPHIR_INIT_NVAR(&_28$$8); - if (ZEPHIR_LT(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_28$$8); - ZVAL_LONG(&_28$$8, 1); - } else { - ZEPHIR_INIT_NVAR(&_28$$8); - ZVAL_LONG(&_28$$8, 0); - } - zephir_array_append(&rowC, &_28$$8, PH_SEPARATE, "tensor/columnvector.zep", 456); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "rewind", NULL, 0); - zephir_check_call_status(); - _30$$7 = 1; - while (1) { - if (_30$$7) { - _30$$7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_29$$7, _25$$7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_29$$7)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _25$$7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_31$$9); - if (ZEPHIR_LT(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_31$$9); - ZVAL_LONG(&_31$$9, 1); - } else { - ZEPHIR_INIT_NVAR(&_31$$9); - ZVAL_LONG(&_31$$9, 0); - } - zephir_array_append(&rowC, &_31$$9, PH_SEPARATE, "tensor/columnvector.zep", 456); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 459); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_9, b, "n", NULL, 0); + zephir_check_call_status(); + tensor_less_col_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -2856,40 +1073,23 @@ PHP_METHOD(Tensor_ColumnVector, lessMatrix) PHP_METHOD(Tensor_ColumnVector, lessEqualMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _23, _20$$4, _30$$7; - zend_string *_13; - zend_ulong _12; - zval c, rowC; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, valueB, valueA, _8, *_9, _10, *_11, _22, _2$$3, _3$$3, _5$$3, _14$$4, *_15$$4, _16$$4, *_17$$4, _19$$4, _18$$5, _21$$6, _24$$7, *_25$$7, _26$$7, *_27$$7, _29$$7, _28$$8, _31$$9; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); - ZVAL_UNDEF(&valueB); - ZVAL_UNDEF(&valueA); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_22); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$4); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_21$$6); - ZVAL_UNDEF(&_24$$7); - ZVAL_UNDEF(&_26$$7); - ZVAL_UNDEF(&_29$$7); - ZVAL_UNDEF(&_28$$8); - ZVAL_UNDEF(&_31$$9); - ZVAL_UNDEF(&c); - ZVAL_UNDEF(&rowC); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -2922,181 +1122,25 @@ PHP_METHOD(Tensor_ColumnVector, lessEqualMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " rows but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 477); + zephir_throw_exception_debug(&_2$$3, "tensor/columnvector.zep", 341); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_INIT_VAR(&rowC); - array_init(&rowC); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/columnvector.zep", 497); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - zephir_read_property_cached(&_14$$4, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_14$$4, &i, PH_NOISY, "tensor/columnvector.zep", 486); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_16$$4); - zephir_string_to_char_array(&_16$$4, &rowB); - _15$$4 = &_16$$4; - } else { - _15$$4 = &rowB; - } - zephir_is_iterable(_15$$4, 0, "tensor/columnvector.zep", 494); - if (Z_TYPE_P(_15$$4) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_15$$4), _17$$4) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _17$$4); - ZEPHIR_INIT_NVAR(&_18$$5); - if (ZEPHIR_LE(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_18$$5); - ZVAL_LONG(&_18$$5, 1); - } else { - ZEPHIR_INIT_NVAR(&_18$$5); - ZVAL_LONG(&_18$$5, 0); - } - zephir_array_append(&rowC, &_18$$5, PH_SEPARATE, "tensor/columnvector.zep", 491); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "rewind", NULL, 0); - zephir_check_call_status(); - _20$$4 = 1; - while (1) { - if (_20$$4) { - _20$$4 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _15$$4, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_19$$4, _15$$4, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_19$$4)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _15$$4, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_21$$6); - if (ZEPHIR_LE(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_21$$6); - ZVAL_LONG(&_21$$6, 1); - } else { - ZEPHIR_INIT_NVAR(&_21$$6); - ZVAL_LONG(&_21$$6, 0); - } - zephir_array_append(&rowC, &_21$$6, PH_SEPARATE, "tensor/columnvector.zep", 491); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 494); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _23 = 1; - while (1) { - if (_23) { - _23 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_22, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_22)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - zephir_read_property_cached(&_24$$7, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&valueA); - zephir_array_fetch(&valueA, &_24$$7, &i, PH_NOISY, "tensor/columnvector.zep", 486); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - if (Z_TYPE_P(&rowB) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_26$$7); - zephir_string_to_char_array(&_26$$7, &rowB); - _25$$7 = &_26$$7; - } else { - _25$$7 = &rowB; - } - zephir_is_iterable(_25$$7, 0, "tensor/columnvector.zep", 494); - if (Z_TYPE_P(_25$$7) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_25$$7), _27$$7) - { - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _27$$7); - ZEPHIR_INIT_NVAR(&_28$$8); - if (ZEPHIR_LE(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_28$$8); - ZVAL_LONG(&_28$$8, 1); - } else { - ZEPHIR_INIT_NVAR(&_28$$8); - ZVAL_LONG(&_28$$8, 0); - } - zephir_array_append(&rowC, &_28$$8, PH_SEPARATE, "tensor/columnvector.zep", 491); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "rewind", NULL, 0); - zephir_check_call_status(); - _30$$7 = 1; - while (1) { - if (_30$$7) { - _30$$7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _25$$7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_29$$7, _25$$7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_29$$7)) { - break; - } - ZEPHIR_CALL_METHOD(&valueB, _25$$7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_31$$9); - if (ZEPHIR_LE(&valueA, &valueB)) { - ZEPHIR_INIT_NVAR(&_31$$9); - ZVAL_LONG(&_31$$9, 1); - } else { - ZEPHIR_INIT_NVAR(&_31$$9); - ZVAL_LONG(&_31$$9, 0); - } - zephir_array_append(&rowC, &_31$$9, PH_SEPARATE, "tensor/columnvector.zep", 491); - } - } - ZEPHIR_INIT_NVAR(&valueB); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/columnvector.zep", 494); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 3, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_9, b, "n", NULL, 0); + zephir_check_call_status(); + tensor_less_equal_col_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } diff --git a/ext/tensor/columnvector.zep.h b/ext/tensor/columnvector.zep.h index 889a56c..2cb3521 100644 --- a/ext/tensor/columnvector.zep.h +++ b/ext/tensor/columnvector.zep.h @@ -3,8 +3,6 @@ extern zend_class_entry *tensor_columnvector_ce; ZEPHIR_INIT_CLASS(Tensor_ColumnVector); -PHP_METHOD(Tensor_ColumnVector, build); -PHP_METHOD(Tensor_ColumnVector, quick); PHP_METHOD(Tensor_ColumnVector, m); PHP_METHOD(Tensor_ColumnVector, n); PHP_METHOD(Tensor_ColumnVector, transpose); @@ -22,14 +20,6 @@ PHP_METHOD(Tensor_ColumnVector, greaterEqualMatrix); PHP_METHOD(Tensor_ColumnVector, lessMatrix); PHP_METHOD(Tensor_ColumnVector, lessEqualMatrix); -ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_columnvector_build, 0, 0, 0) -ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, a, IS_ARRAY, 0, "[]") -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_columnvector_quick, 0, 0, 0) -ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, a, IS_ARRAY, 0, "[]") -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_columnvector_m, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -92,8 +82,6 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_columnvector_lessequalmatr ZEND_END_ARG_INFO() ZEPHIR_INIT_FUNCS(tensor_columnvector_method_entry) { - PHP_ME(Tensor_ColumnVector, build, arginfo_tensor_columnvector_build, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME(Tensor_ColumnVector, quick, arginfo_tensor_columnvector_quick, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Tensor_ColumnVector, m, arginfo_tensor_columnvector_m, ZEND_ACC_PUBLIC) PHP_ME(Tensor_ColumnVector, n, arginfo_tensor_columnvector_n, ZEND_ACC_PUBLIC) PHP_ME(Tensor_ColumnVector, transpose, arginfo_tensor_columnvector_transpose, ZEND_ACC_PUBLIC) diff --git a/ext/tensor/decompositions/cholesky.zep.c b/ext/tensor/decompositions/cholesky.zep.c index 4d64f2a..8c962ed 100644 --- a/ext/tensor/decompositions/cholesky.zep.c +++ b/ext/tensor/decompositions/cholesky.zep.c @@ -55,13 +55,16 @@ PHP_METHOD(Tensor_Decompositions_Cholesky, decompose) { zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *a, a_sub, _0, l, _4, _5, _1$$3, _2$$3, _3$$3; + zval *a, a_sub, _0, l, _4, _5, _6, _7, _8, _1$$3, _2$$3, _3$$3; ZVAL_UNDEF(&a_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&l); ZVAL_UNDEF(&_4); ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_8); ZVAL_UNDEF(&_1$$3); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); @@ -71,33 +74,41 @@ PHP_METHOD(Tensor_Decompositions_Cholesky, decompose) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &a); - ZEPHIR_CALL_METHOD(&_0, a, "issquare", NULL, 0); + ZEPHIR_CALL_METHOD(&_0, a, "isSquare", NULL, 0); zephir_check_call_status(); if (!(zephir_is_true(&_0))) { ZEPHIR_INIT_VAR(&_1$$3); object_init_ex(&_1$$3, tensor_exceptions_invalidargumentexception_ce); - ZEPHIR_CALL_METHOD(&_2$$3, a, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_2$$3, a, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3$$3); ZEPHIR_CONCAT_SSVS(&_3$$3, "Matrix must be", " square, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 3, &_3$$3); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); zephir_throw_exception_debug(&_1$$3, "tensor/decompositions/cholesky.zep", 37); ZEPHIR_MM_RESTORE(); return; } ZEPHIR_INIT_VAR(&l); - ZEPHIR_CALL_METHOD(&_4, a, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&_4, a, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - tensor_cholesky(&l, &_4); + ZEPHIR_CALL_METHOD(&_5, a, "n", NULL, 0); + zephir_check_call_status(); + tensor_cholesky(&l, &_4, &_5); if (Z_TYPE_P(&l) == IS_NULL) { ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Failed to decompose matrix.", "tensor/decompositions/cholesky.zep", 43); return; } object_init_ex(return_value, tensor_decompositions_cholesky_ce); - ZEPHIR_CALL_CE_STATIC(&_5, tensor_matrix_ce, "quick", NULL, 0, &l); + ZEPHIR_INIT_VAR(&_6); + object_init_ex(&_6, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_7, a, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_8, a, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, &_6, "__construct", NULL, 14, &l, &_7, &_8); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 24, &_5); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 19, &_6); zephir_check_call_status(); RETURN_MM(); } diff --git a/ext/tensor/decompositions/eigen.zep.c b/ext/tensor/decompositions/eigen.zep.c index 0ef0304..f36739d 100644 --- a/ext/tensor/decompositions/eigen.zep.c +++ b/ext/tensor/decompositions/eigen.zep.c @@ -62,27 +62,33 @@ ZEPHIR_INIT_CLASS(Tensor_Decompositions_Eigen) */ PHP_METHOD(Tensor_Decompositions_Eigen, decompose) { - zval eig, _7; + zval eig, _9, _11; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zend_bool symmetric; - zval *a, a_sub, *symmetric_param = NULL, _0, result, _6, eigenvalues, eigenvectors, _8, _9, _1$$3, _2$$3, _3$$3, _4$$4, _5$$5; + zval *a, a_sub, *symmetric_param = NULL, _0, result, _8, eigenvalues, _10, eigenvectors, _12, _13, _14, _15, _1$$3, _2$$3, _3$$3, _4$$4, _5$$4, _6$$5, _7$$5; ZVAL_UNDEF(&a_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&result); - ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_8); ZVAL_UNDEF(&eigenvalues); + ZVAL_UNDEF(&_10); ZVAL_UNDEF(&eigenvectors); - ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_9); + ZVAL_UNDEF(&_12); + ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_15); ZVAL_UNDEF(&_1$$3); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$4); - ZVAL_UNDEF(&_5$$5); + ZVAL_UNDEF(&_5$$4); + ZVAL_UNDEF(&_6$$5); + ZVAL_UNDEF(&_7$$5); ZVAL_UNDEF(&eig); - ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_9); + ZVAL_UNDEF(&_11); ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_OBJECT_OF_CLASS(a, zephir_get_internal_ce(SL("tensor\\matrix"))) Z_PARAM_OPTIONAL @@ -95,16 +101,16 @@ PHP_METHOD(Tensor_Decompositions_Eigen, decompose) symmetric = 0; } else { } - ZEPHIR_CALL_METHOD(&_0, a, "issquare", NULL, 0); + ZEPHIR_CALL_METHOD(&_0, a, "isSquare", NULL, 0); zephir_check_call_status(); if (UNEXPECTED(!zephir_is_true(&_0))) { ZEPHIR_INIT_VAR(&_1$$3); object_init_ex(&_1$$3, tensor_exceptions_invalidargumentexception_ce); - ZEPHIR_CALL_METHOD(&_2$$3, a, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_2$$3, a, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3$$3); ZEPHIR_CONCAT_SSVS(&_3$$3, "Matrix must be", " square, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 3, &_3$$3); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); zephir_throw_exception_debug(&_1$$3, "tensor/decompositions/eigen.zep", 48); ZEPHIR_MM_RESTORE(); @@ -112,14 +118,18 @@ PHP_METHOD(Tensor_Decompositions_Eigen, decompose) } if (symmetric) { ZEPHIR_INIT_VAR(&result); - ZEPHIR_CALL_METHOD(&_4$$4, a, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&_4$$4, a, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - tensor_eig_symmetric(&result, &_4$$4); + ZEPHIR_CALL_METHOD(&_5$$4, a, "n", NULL, 0); + zephir_check_call_status(); + tensor_eig_symmetric(&result, &_4$$4, &_5$$4); } else { ZEPHIR_INIT_NVAR(&result); - ZEPHIR_CALL_METHOD(&_5$$5, a, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&_6$$5, a, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_7$$5, a, "n", NULL, 0); zephir_check_call_status(); - tensor_eig(&result, &_5$$5); + tensor_eig(&result, &_6$$5, &_7$$5); } if (Z_TYPE_P(&result) == IS_NULL) { ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Failed to decompose matrix.", "tensor/decompositions/eigen.zep", 60); @@ -127,18 +137,26 @@ PHP_METHOD(Tensor_Decompositions_Eigen, decompose) } ZEPHIR_INIT_VAR(&eig); array_init(&eig); - ZEPHIR_CPY_WRT(&_6, &result); - zephir_get_arrval(&_7, &_6); - ZEPHIR_CPY_WRT(&eig, &_7); - zephir_memory_observe(&eigenvalues); - zephir_array_fetch_long(&eigenvalues, &eig, 0, PH_NOISY, "tensor/decompositions/eigen.zep", 67); - zephir_array_fetch_long(&_9, &eig, 1, PH_NOISY | PH_READONLY, "tensor/decompositions/eigen.zep", 68); - ZEPHIR_CALL_CE_STATIC(&_8, tensor_matrix_ce, "quick", NULL, 0, &_9); + ZEPHIR_CPY_WRT(&_8, &result); + zephir_get_arrval(&_9, &_8); + ZEPHIR_CPY_WRT(&eig, &_9); + zephir_memory_observe(&_10); + zephir_array_fetch_long(&_10, &eig, 0, PH_NOISY, "tensor/decompositions/eigen.zep", 67); + zephir_get_arrval(&_11, &_10); + ZEPHIR_CPY_WRT(&eigenvalues, &_11); + ZEPHIR_INIT_VAR(&_12); + object_init_ex(&_12, tensor_matrix_ce); + zephir_array_fetch_long(&_13, &eig, 1, PH_NOISY | PH_READONLY, "tensor/decompositions/eigen.zep", 68); + ZEPHIR_CALL_METHOD(&_14, a, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_15, a, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, &_12, "__construct", NULL, 14, &_13, &_14, &_15); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&eigenvectors, &_8, "transpose", NULL, 0); + ZEPHIR_CALL_METHOD(&eigenvectors, &_12, "transpose", NULL, 20); zephir_check_call_status(); object_init_ex(return_value, tensor_decompositions_eigen_ce); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 25, &eigenvalues, &eigenvectors); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 21, &eigenvalues, &eigenvectors); zephir_check_call_status(); RETURN_MM(); } diff --git a/ext/tensor/decompositions/lu.zep.c b/ext/tensor/decompositions/lu.zep.c index 85aecdf..f5607ef 100644 --- a/ext/tensor/decompositions/lu.zep.c +++ b/ext/tensor/decompositions/lu.zep.c @@ -67,72 +67,99 @@ ZEPHIR_INIT_CLASS(Tensor_Decompositions_Lu) */ PHP_METHOD(Tensor_Decompositions_Lu, decompose) { - zval lup, _6; + zval lup, _7; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *a, a_sub, _0, result, _4, _5, l, _7, u, _8, p, _9, _1$$3, _2$$3, _3$$3; + zval *a, a_sub, _0, result, _4, _5, _6, l, _8, _9, _10, u, _11, _12, _13, p, _14, _15, _16, _1$$3, _2$$3, _3$$3; ZVAL_UNDEF(&a_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&result); ZVAL_UNDEF(&_4); ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); ZVAL_UNDEF(&l); - ZVAL_UNDEF(&_7); - ZVAL_UNDEF(&u); ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&p); ZVAL_UNDEF(&_9); + ZVAL_UNDEF(&_10); + ZVAL_UNDEF(&u); + ZVAL_UNDEF(&_11); + ZVAL_UNDEF(&_12); + ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&p); + ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_15); + ZVAL_UNDEF(&_16); ZVAL_UNDEF(&_1$$3); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&lup); - ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(a, zephir_get_internal_ce(SL("tensor\\matrix"))) ZEND_PARSE_PARAMETERS_END(); ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &a); - ZEPHIR_CALL_METHOD(&_0, a, "issquare", NULL, 0); + ZEPHIR_CALL_METHOD(&_0, a, "isSquare", NULL, 0); zephir_check_call_status(); if (UNEXPECTED(!zephir_is_true(&_0))) { ZEPHIR_INIT_VAR(&_1$$3); object_init_ex(&_1$$3, tensor_exceptions_invalidargumentexception_ce); - ZEPHIR_CALL_METHOD(&_2$$3, a, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_2$$3, a, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3$$3); ZEPHIR_CONCAT_SSVS(&_3$$3, "Matrix must be", " square, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 3, &_3$$3); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); zephir_throw_exception_debug(&_1$$3, "tensor/decompositions/lu.zep", 52); ZEPHIR_MM_RESTORE(); return; } ZEPHIR_INIT_VAR(&result); - ZEPHIR_CALL_METHOD(&_4, a, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&_4, a, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - tensor_lu(&result, &_4); + ZEPHIR_CALL_METHOD(&_5, a, "n", NULL, 0); + zephir_check_call_status(); + tensor_lu(&result, &_4, &_5); if (Z_TYPE_P(&result) == IS_NULL) { ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Failed to decompose matrix.", "tensor/decompositions/lu.zep", 58); return; } ZEPHIR_INIT_VAR(&lup); array_init(&lup); - ZEPHIR_CPY_WRT(&_5, &result); - zephir_get_arrval(&_6, &_5); - ZEPHIR_CPY_WRT(&lup, &_6); - zephir_array_fetch_long(&_7, &lup, 0, PH_NOISY | PH_READONLY, "tensor/decompositions/lu.zep", 65); - ZEPHIR_CALL_CE_STATIC(&l, tensor_matrix_ce, "quick", NULL, 0, &_7); + ZEPHIR_CPY_WRT(&_6, &result); + zephir_get_arrval(&_7, &_6); + ZEPHIR_CPY_WRT(&lup, &_7); + ZEPHIR_INIT_VAR(&l); + object_init_ex(&l, tensor_matrix_ce); + zephir_array_fetch_long(&_8, &lup, 0, PH_NOISY | PH_READONLY, "tensor/decompositions/lu.zep", 65); + ZEPHIR_CALL_METHOD(&_9, a, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_10, a, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, &l, "__construct", NULL, 14, &_8, &_9, &_10); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&u); + object_init_ex(&u, tensor_matrix_ce); + zephir_array_fetch_long(&_11, &lup, 1, PH_NOISY | PH_READONLY, "tensor/decompositions/lu.zep", 66); + ZEPHIR_CALL_METHOD(&_12, a, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_13, a, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, &u, "__construct", NULL, 14, &_11, &_12, &_13); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&p); + object_init_ex(&p, tensor_matrix_ce); + zephir_array_fetch_long(&_14, &lup, 2, PH_NOISY | PH_READONLY, "tensor/decompositions/lu.zep", 67); + ZEPHIR_CALL_METHOD(&_15, a, "n", NULL, 0); zephir_check_call_status(); - zephir_array_fetch_long(&_8, &lup, 1, PH_NOISY | PH_READONLY, "tensor/decompositions/lu.zep", 66); - ZEPHIR_CALL_CE_STATIC(&u, tensor_matrix_ce, "quick", NULL, 0, &_8); + ZEPHIR_CALL_METHOD(&_16, a, "n", NULL, 0); zephir_check_call_status(); - zephir_array_fetch_long(&_9, &lup, 2, PH_NOISY | PH_READONLY, "tensor/decompositions/lu.zep", 67); - ZEPHIR_CALL_CE_STATIC(&p, tensor_matrix_ce, "quick", NULL, 0, &_9); + ZEPHIR_CALL_METHOD(NULL, &p, "__construct", NULL, 14, &_14, &_15, &_16); zephir_check_call_status(); object_init_ex(return_value, tensor_decompositions_lu_ce); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 26, &l, &u, &p); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 22, &l, &u, &p); zephir_check_call_status(); RETURN_MM(); } diff --git a/ext/tensor/decompositions/svd.zep.c b/ext/tensor/decompositions/svd.zep.c index 324a545..0e58c42 100644 --- a/ext/tensor/decompositions/svd.zep.c +++ b/ext/tensor/decompositions/svd.zep.c @@ -62,22 +62,30 @@ ZEPHIR_INIT_CLASS(Tensor_Decompositions_Svd) */ PHP_METHOD(Tensor_Decompositions_Svd, decompose) { - zval usvT, _2; + zval usvT, _4, _9; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *a, a_sub, result, _0, _1, u, _3, singularValues, vT, _4; + zval *a, a_sub, result, _0, _1, _2, _3, u, _5, _6, _7, singularValues, _8, vT, _10, _11, _12; ZVAL_UNDEF(&a_sub); ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&u); + ZVAL_UNDEF(&_2); ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&u); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZVAL_UNDEF(&singularValues); + ZVAL_UNDEF(&_8); ZVAL_UNDEF(&vT); - ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_10); + ZVAL_UNDEF(&_11); + ZVAL_UNDEF(&_12); ZVAL_UNDEF(&usvT); - ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_9); ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(a, zephir_get_internal_ce(SL("tensor\\matrix"))) ZEND_PARSE_PARAMETERS_END(); @@ -85,28 +93,46 @@ PHP_METHOD(Tensor_Decompositions_Svd, decompose) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &a); ZEPHIR_INIT_VAR(&result); - ZEPHIR_CALL_METHOD(&_0, a, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&_0, a, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - tensor_svd(&result, &_0); + ZEPHIR_CALL_METHOD(&_1, a, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_2, a, "n", NULL, 0); + zephir_check_call_status(); + tensor_svd(&result, &_0, &_1, &_2); if (Z_TYPE_P(&result) == IS_NULL) { ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Failed to decompose matrix.", "tensor/decompositions/svd.zep", 48); return; } ZEPHIR_INIT_VAR(&usvT); array_init(&usvT); - ZEPHIR_CPY_WRT(&_1, &result); - zephir_get_arrval(&_2, &_1); - ZEPHIR_CPY_WRT(&usvT, &_2); - zephir_array_fetch_long(&_3, &usvT, 0, PH_NOISY | PH_READONLY, "tensor/decompositions/svd.zep", 55); - ZEPHIR_CALL_CE_STATIC(&u, tensor_matrix_ce, "quick", NULL, 0, &_3); + ZEPHIR_CPY_WRT(&_3, &result); + zephir_get_arrval(&_4, &_3); + ZEPHIR_CPY_WRT(&usvT, &_4); + ZEPHIR_INIT_VAR(&u); + object_init_ex(&u, tensor_matrix_ce); + zephir_array_fetch_long(&_5, &usvT, 0, PH_NOISY | PH_READONLY, "tensor/decompositions/svd.zep", 55); + ZEPHIR_CALL_METHOD(&_6, a, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_7, a, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, &u, "__construct", NULL, 14, &_5, &_6, &_7); + zephir_check_call_status(); + zephir_memory_observe(&_8); + zephir_array_fetch_long(&_8, &usvT, 1, PH_NOISY, "tensor/decompositions/svd.zep", 56); + zephir_get_arrval(&_9, &_8); + ZEPHIR_CPY_WRT(&singularValues, &_9); + ZEPHIR_INIT_VAR(&vT); + object_init_ex(&vT, tensor_matrix_ce); + zephir_array_fetch_long(&_10, &usvT, 2, PH_NOISY | PH_READONLY, "tensor/decompositions/svd.zep", 57); + ZEPHIR_CALL_METHOD(&_11, a, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_12, a, "n", NULL, 0); zephir_check_call_status(); - zephir_memory_observe(&singularValues); - zephir_array_fetch_long(&singularValues, &usvT, 1, PH_NOISY, "tensor/decompositions/svd.zep", 56); - zephir_array_fetch_long(&_4, &usvT, 2, PH_NOISY | PH_READONLY, "tensor/decompositions/svd.zep", 57); - ZEPHIR_CALL_CE_STATIC(&vT, tensor_matrix_ce, "quick", NULL, 0, &_4); + ZEPHIR_CALL_METHOD(NULL, &vT, "__construct", NULL, 14, &_10, &_11, &_12); zephir_check_call_status(); object_init_ex(return_value, tensor_decompositions_svd_ce); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 27, &u, &singularValues, &vT); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 23, &u, &singularValues, &vT); zephir_check_call_status(); RETURN_MM(); } diff --git a/ext/tensor/matrix.zep.c b/ext/tensor/matrix.zep.c index c55d70e..2804da6 100644 --- a/ext/tensor/matrix.zep.c +++ b/ext/tensor/matrix.zep.c @@ -12,19 +12,23 @@ #include #include "kernel/main.h" -#include "kernel/fcall.h" -#include "kernel/memory.h" -#include "kernel/operators.h" -#include "kernel/object.h" #include "kernel/exception.h" +#include "kernel/memory.h" +#include "kernel/fcall.h" #include "kernel/concat.h" #include "kernel/array.h" +#include "kernel/operators.h" +#include "kernel/object.h" #include "math.h" #include "kernel/string.h" #include "kernel/math.h" #include "ext/spl/spl_array.h" +#include "include/buffer.h" +#include "include/reductions.h" +#include "include/shape.h" #include "include/linear_algebra.h" #include "include/signal_processing.h" +#include "include/unary.h" #include "include/arithmetic.h" #include "include/comparison.h" @@ -43,9 +47,9 @@ ZEPHIR_INIT_CLASS(Tensor_Matrix) ZEPHIR_REGISTER_CLASS(Tensor, Matrix, tensor, matrix, tensor_matrix_method_entry, 0); /** - * A 2-dimensional sequential array that holds the values of the matrix. + * A contiguous row-major buffer holding the elements of the matrix. * - * @var list> + * @var \Tensor\TensorBuffer */ zend_declare_property_null(tensor_matrix_ce, SL("a"), ZEND_ACC_PROTECTED); /** @@ -64,76 +68,6 @@ ZEPHIR_INIT_CLASS(Tensor_Matrix) return SUCCESS; } -/** - * Factory method to build a new matrix from an array. - * - * @param array[] a - * @return self - */ -PHP_METHOD(Tensor_Matrix, build) -{ - zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS; - zval *a_param = NULL, _0; - zval a; - - ZVAL_UNDEF(&a); - ZVAL_UNDEF(&_0); - ZEND_PARSE_PARAMETERS_START(0, 1) - Z_PARAM_OPTIONAL - ZEPHIR_Z_PARAM_ARRAY(a, a_param) - ZEND_PARSE_PARAMETERS_END(); - ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); - zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_fetch_params(1, 0, 1, &a_param); - if (!a_param) { - ZEPHIR_INIT_VAR(&a); - array_init(&a); - } else { - zephir_get_arrval(&a, a_param); - } - object_init_ex(return_value, tensor_matrix_ce); - ZVAL_BOOL(&_0, 1); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 28, &a, &_0); - zephir_check_call_status(); - RETURN_MM(); -} - -/** - * Build a new matrix foregoing any validation for quicker instantiation. - * - * @param array[] a - * @return self - */ -PHP_METHOD(Tensor_Matrix, quick) -{ - zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS; - zval *a_param = NULL, _0; - zval a; - - ZVAL_UNDEF(&a); - ZVAL_UNDEF(&_0); - ZEND_PARSE_PARAMETERS_START(0, 1) - Z_PARAM_OPTIONAL - ZEPHIR_Z_PARAM_ARRAY(a, a_param) - ZEND_PARSE_PARAMETERS_END(); - ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); - zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_fetch_params(1, 0, 1, &a_param); - if (!a_param) { - ZEPHIR_INIT_VAR(&a); - array_init(&a); - } else { - zephir_get_arrval(&a, a_param); - } - object_init_ex(return_value, tensor_matrix_ce); - ZVAL_BOOL(&_0, 0); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 28, &a, &_0); - zephir_check_call_status(); - RETURN_MM(); -} - /** * Return an identity matrix with dimensionality n x n. * @@ -146,13 +80,14 @@ PHP_METHOD(Tensor_Matrix, identity) zend_bool _4, _7$$4; zval a, rowA; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zval *n_param = NULL, _0$$3, _1$$3, _2$$3, _3$$3, _10$$5; + zval *n_param = NULL, _0$$3, _1$$3, _2$$3, _3$$3, _11, _10$$5; zend_long n, ZEPHIR_LAST_CALL_STATUS, i = 0, j = 0, _5, _6, _8$$4, _9$$4; ZVAL_UNDEF(&_0$$3); ZVAL_UNDEF(&_1$$3); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_10$$5); ZVAL_UNDEF(&a); ZVAL_UNDEF(&rowA); @@ -166,13 +101,13 @@ PHP_METHOD(Tensor_Matrix, identity) ZEPHIR_INIT_VAR(&_0$$3); object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_1$$3, n); - ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 4, &_1$$3); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 3, &_1$$3); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3$$3); ZEPHIR_CONCAT_SSVS(&_3$$3, "N must be", " greater than 0, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 3, &_3$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 79); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 57); ZEPHIR_MM_RESTORE(); return; } @@ -218,13 +153,14 @@ PHP_METHOD(Tensor_Matrix, identity) ZEPHIR_INIT_NVAR(&_10$$5); ZVAL_DOUBLE(&_10$$5, 0.0); } - zephir_array_append(&rowA, &_10$$5, PH_SEPARATE, "tensor/matrix.zep", 91); + zephir_array_append(&rowA, &_10$$5, PH_SEPARATE, "tensor/matrix.zep", 69); } } - zephir_array_append(&a, &rowA, PH_SEPARATE, "tensor/matrix.zep", 94); + zephir_array_append(&a, &rowA, PH_SEPARATE, "tensor/matrix.zep", 72); } } - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &a); + ZVAL_BOOL(&_11, 0); + ZEPHIR_RETURN_CALL_SELF("fromArray", NULL, 0, &a, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -305,13 +241,14 @@ PHP_METHOD(Tensor_Matrix, diagonal) zend_bool _1, _4$$3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS, n, i = 0, j = 0, _2, _3, _5$$3, _6$$3; - zval *elements_param = NULL, _0, _7$$4; + zval *elements_param = NULL, _0, _8, _7$$4; zval elements, a, rowA; ZVAL_UNDEF(&elements); ZVAL_UNDEF(&a); ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_8); ZVAL_UNDEF(&_7$$4); ZEND_PARSE_PARAMETERS_START(1, 1) ZEPHIR_Z_PARAM_ARRAY(elements, elements_param) @@ -321,7 +258,7 @@ PHP_METHOD(Tensor_Matrix, diagonal) zephir_fetch_params(1, 1, 0, &elements_param); zephir_get_arrval(&elements, elements_param); n = zephir_fast_count_int(&elements); - ZEPHIR_CALL_FUNCTION(&_0, "array_values", NULL, 29, &elements); + ZEPHIR_CALL_FUNCTION(&_0, "array_values", NULL, 24, &elements); zephir_check_call_status(); ZEPHIR_CPY_WRT(&elements, &_0); ZEPHIR_INIT_VAR(&a); @@ -361,18 +298,19 @@ PHP_METHOD(Tensor_Matrix, diagonal) ZEPHIR_INIT_NVAR(&_7$$4); if (i == j) { ZEPHIR_OBS_NVAR(&_7$$4); - zephir_array_fetch_long(&_7$$4, &elements, i, PH_NOISY, "tensor/matrix.zep", 148); + zephir_array_fetch_long(&_7$$4, &elements, i, PH_NOISY, "tensor/matrix.zep", 126); } else { ZEPHIR_INIT_NVAR(&_7$$4); ZVAL_DOUBLE(&_7$$4, 0.0); } - zephir_array_append(&rowA, &_7$$4, PH_SEPARATE, "tensor/matrix.zep", 148); + zephir_array_append(&rowA, &_7$$4, PH_SEPARATE, "tensor/matrix.zep", 126); } } - zephir_array_append(&a, &rowA, PH_SEPARATE, "tensor/matrix.zep", 151); + zephir_array_append(&a, &rowA, PH_SEPARATE, "tensor/matrix.zep", 129); } } - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &a); + ZVAL_BOOL(&_8, 0); + ZEPHIR_RETURN_CALL_SELF("fromArray", NULL, 0, &a, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -420,13 +358,13 @@ PHP_METHOD(Tensor_Matrix, fill) ZEPHIR_INIT_VAR(&_0$$3); object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_1$$3, m); - ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", &_3, 4, &_1$$3); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", &_3, 3, &_1$$3); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_4$$3); ZEPHIR_CONCAT_SSVS(&_4$$3, "M must be", " greater than 0, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 3, &_4$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_4$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 170); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 148); ZEPHIR_MM_RESTORE(); return; } @@ -434,26 +372,27 @@ PHP_METHOD(Tensor_Matrix, fill) ZEPHIR_INIT_VAR(&_5$$4); object_init_ex(&_5$$4, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_6$$4, n); - ZEPHIR_CALL_FUNCTION(&_7$$4, "strval", &_3, 4, &_6$$4); + ZEPHIR_CALL_FUNCTION(&_7$$4, "strval", &_3, 3, &_6$$4); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_8$$4); ZEPHIR_CONCAT_SSVS(&_8$$4, "N must be", " greater than 0, ", &_7$$4, " given."); - ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 3, &_8$$4); + ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_8$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 175); + zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 153); ZEPHIR_MM_RESTORE(); return; } ZVAL_LONG(&_9, 0); ZVAL_LONG(&_10, n); ZVAL_DOUBLE(&_11, value); - ZEPHIR_CALL_FUNCTION(&_12, "array_fill", &_13, 5, &_9, &_10, &_11); + ZEPHIR_CALL_FUNCTION(&_12, "array_fill", &_13, 4, &_9, &_10, &_11); zephir_check_call_status(); ZVAL_LONG(&_9, 0); ZVAL_LONG(&_10, m); - ZEPHIR_CALL_FUNCTION(&_14, "array_fill", &_13, 5, &_9, &_10, &_12); + ZEPHIR_CALL_FUNCTION(&_14, "array_fill", &_13, 4, &_9, &_10, &_12); zephir_check_call_status(); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &_14); + ZVAL_BOOL(&_9, 0); + ZEPHIR_RETURN_CALL_SELF("fromArray", NULL, 0, &_14, &_9); zephir_check_call_status(); RETURN_MM(); } @@ -471,7 +410,7 @@ PHP_METHOD(Tensor_Matrix, rand) zval a, rowA; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zephir_fcall_cache_entry *_3 = NULL, *_11 = NULL; - zval *m_param = NULL, *n_param = NULL, _0$$3, _1$$3, _2$$3, _4$$3, _5$$4, _6$$4, _7$$4, _8$$4, _9, _10$$6, _12$$6; + zval *m_param = NULL, *n_param = NULL, _0$$3, _1$$3, _2$$3, _4$$3, _5$$4, _6$$4, _7$$4, _8$$4, _9, _13, _10$$6, _12$$6; zend_long m, n, ZEPHIR_LAST_CALL_STATUS, max; ZVAL_UNDEF(&_0$$3); @@ -483,6 +422,7 @@ PHP_METHOD(Tensor_Matrix, rand) ZVAL_UNDEF(&_7$$4); ZVAL_UNDEF(&_8$$4); ZVAL_UNDEF(&_9); + ZVAL_UNDEF(&_13); ZVAL_UNDEF(&_10$$6); ZVAL_UNDEF(&_12$$6); ZVAL_UNDEF(&a); @@ -498,13 +438,13 @@ PHP_METHOD(Tensor_Matrix, rand) ZEPHIR_INIT_VAR(&_0$$3); object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_1$$3, m); - ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", &_3, 4, &_1$$3); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", &_3, 3, &_1$$3); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_4$$3); ZEPHIR_CONCAT_SSVS(&_4$$3, "M must be", " greater than 0, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 3, &_4$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_4$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 193); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 171); ZEPHIR_MM_RESTORE(); return; } @@ -512,13 +452,13 @@ PHP_METHOD(Tensor_Matrix, rand) ZEPHIR_INIT_VAR(&_5$$4); object_init_ex(&_5$$4, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_6$$4, n); - ZEPHIR_CALL_FUNCTION(&_7$$4, "strval", &_3, 4, &_6$$4); + ZEPHIR_CALL_FUNCTION(&_7$$4, "strval", &_3, 3, &_6$$4); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_8$$4); ZEPHIR_CONCAT_SSVS(&_8$$4, "N must be", " greater than 0, ", &_7$$4, " given."); - ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 3, &_8$$4); + ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_8$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 198); + zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 176); ZEPHIR_MM_RESTORE(); return; } @@ -526,7 +466,7 @@ PHP_METHOD(Tensor_Matrix, rand) array_init(&a); ZEPHIR_INIT_VAR(&rowA); array_init(&rowA); - ZEPHIR_CALL_FUNCTION(&_9, "getrandmax", NULL, 6); + ZEPHIR_CALL_FUNCTION(&_9, "getrandmax", NULL, 5); zephir_check_call_status(); max = zephir_get_intval(&_9); while (1) { @@ -539,15 +479,16 @@ PHP_METHOD(Tensor_Matrix, rand) if (!(zephir_fast_count_int(&rowA) < n)) { break; } - ZEPHIR_CALL_FUNCTION(&_10$$6, "rand", &_11, 7); + ZEPHIR_CALL_FUNCTION(&_10$$6, "rand", &_11, 6); zephir_check_call_status(); ZEPHIR_INIT_NVAR(&_12$$6); ZVAL_DOUBLE(&_12$$6, zephir_safe_div_zval_long(&_10$$6, max)); - zephir_array_append(&rowA, &_12$$6, PH_SEPARATE, "tensor/matrix.zep", 210); + zephir_array_append(&rowA, &_12$$6, PH_SEPARATE, "tensor/matrix.zep", 188); } - zephir_array_append(&a, &rowA, PH_SEPARATE, "tensor/matrix.zep", 213); + zephir_array_append(&a, &rowA, PH_SEPARATE, "tensor/matrix.zep", 191); } - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &a); + ZVAL_BOOL(&_13, 0); + ZEPHIR_RETURN_CALL_SELF("fromArray", NULL, 0, &a, &_13); zephir_check_call_status(); RETURN_MM(); } @@ -566,7 +507,7 @@ PHP_METHOD(Tensor_Matrix, gaussian) double r = 0, phi = 0; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zephir_fcall_cache_entry *_3 = NULL, *_11 = NULL, *_13 = NULL, *_16 = NULL; - zval *m_param = NULL, *n_param = NULL, _0$$3, _1$$3, _2$$3, _4$$3, _5$$4, _6$$4, _7$$4, _8$$4, _9, _10$$6, _12$$7, _14$$7, _15$$7, _17$$7, _18$$7, _19$$7, _20$$7, _21$$8; + zval *m_param = NULL, *n_param = NULL, _0$$3, _1$$3, _2$$3, _4$$3, _5$$4, _6$$4, _7$$4, _8$$4, _9, _22, _10$$6, _12$$7, _14$$7, _15$$7, _17$$7, _18$$7, _19$$7, _20$$7, _21$$8; zend_long m, n, ZEPHIR_LAST_CALL_STATUS, max; ZVAL_UNDEF(&_0$$3); @@ -578,6 +519,7 @@ PHP_METHOD(Tensor_Matrix, gaussian) ZVAL_UNDEF(&_7$$4); ZVAL_UNDEF(&_8$$4); ZVAL_UNDEF(&_9); + ZVAL_UNDEF(&_22); ZVAL_UNDEF(&_10$$6); ZVAL_UNDEF(&_12$$7); ZVAL_UNDEF(&_14$$7); @@ -601,13 +543,13 @@ PHP_METHOD(Tensor_Matrix, gaussian) ZEPHIR_INIT_VAR(&_0$$3); object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_1$$3, m); - ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", &_3, 4, &_1$$3); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", &_3, 3, &_1$$3); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_4$$3); ZEPHIR_CONCAT_SSVS(&_4$$3, "M must be", " greater than 0, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 3, &_4$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_4$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 231); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 209); ZEPHIR_MM_RESTORE(); return; } @@ -615,13 +557,13 @@ PHP_METHOD(Tensor_Matrix, gaussian) ZEPHIR_INIT_VAR(&_5$$4); object_init_ex(&_5$$4, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_6$$4, n); - ZEPHIR_CALL_FUNCTION(&_7$$4, "strval", &_3, 4, &_6$$4); + ZEPHIR_CALL_FUNCTION(&_7$$4, "strval", &_3, 3, &_6$$4); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_8$$4); ZEPHIR_CONCAT_SSVS(&_8$$4, "N must be", " greater than 0, ", &_7$$4, " given."); - ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 3, &_8$$4); + ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_8$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 236); + zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 214); ZEPHIR_MM_RESTORE(); return; } @@ -631,7 +573,7 @@ PHP_METHOD(Tensor_Matrix, gaussian) array_init(&rowA); ZEPHIR_INIT_VAR(&extras); array_init(&extras); - ZEPHIR_CALL_FUNCTION(&_9, "getrandmax", NULL, 6); + ZEPHIR_CALL_FUNCTION(&_9, "getrandmax", NULL, 5); zephir_check_call_status(); max = zephir_get_intval(&_9); while (1) { @@ -642,44 +584,45 @@ PHP_METHOD(Tensor_Matrix, gaussian) array_init(&rowA); if (!(ZEPHIR_IS_EMPTY(&extras))) { ZEPHIR_MAKE_REF(&extras); - ZEPHIR_CALL_FUNCTION(&_10$$6, "array_pop", &_11, 9, &extras); + ZEPHIR_CALL_FUNCTION(&_10$$6, "array_pop", &_11, 8, &extras); ZEPHIR_UNREF(&extras); zephir_check_call_status(); - zephir_array_append(&rowA, &_10$$6, PH_SEPARATE, "tensor/matrix.zep", 251); + zephir_array_append(&rowA, &_10$$6, PH_SEPARATE, "tensor/matrix.zep", 229); } while (1) { if (!(zephir_fast_count_int(&rowA) < n)) { break; } - ZEPHIR_CALL_FUNCTION(&_12$$7, "rand", &_13, 7); + ZEPHIR_CALL_FUNCTION(&_12$$7, "rand", &_13, 6); zephir_check_call_status(); ZVAL_DOUBLE(&_14$$7, zephir_safe_div_zval_long(&_12$$7, max)); - ZEPHIR_CALL_FUNCTION(&_15$$7, "log", &_16, 8, &_14$$7); + ZEPHIR_CALL_FUNCTION(&_15$$7, "log", &_16, 7, &_14$$7); zephir_check_call_status(); ZVAL_DOUBLE(&_14$$7, (-2.0 * zephir_get_numberval(&_15$$7))); r = (sqrt((-2.0 * zephir_get_numberval(&_15$$7)))); - ZEPHIR_CALL_FUNCTION(&_17$$7, "rand", &_13, 7); + ZEPHIR_CALL_FUNCTION(&_17$$7, "rand", &_13, 6); zephir_check_call_status(); phi = ((zephir_safe_div_zval_long(&_17$$7, max) * 6.28318530718)); ZVAL_DOUBLE(&_18$$7, phi); ZEPHIR_INIT_NVAR(&_19$$7); ZVAL_DOUBLE(&_19$$7, (r * sin(phi))); - zephir_array_append(&rowA, &_19$$7, PH_SEPARATE, "tensor/matrix.zep", 259); + zephir_array_append(&rowA, &_19$$7, PH_SEPARATE, "tensor/matrix.zep", 237); ZVAL_DOUBLE(&_20$$7, phi); ZEPHIR_INIT_NVAR(&_19$$7); ZVAL_DOUBLE(&_19$$7, (r * cos(phi))); - zephir_array_append(&rowA, &_19$$7, PH_SEPARATE, "tensor/matrix.zep", 260); + zephir_array_append(&rowA, &_19$$7, PH_SEPARATE, "tensor/matrix.zep", 238); } if (zephir_fast_count_int(&rowA) > n) { ZEPHIR_MAKE_REF(&rowA); - ZEPHIR_CALL_FUNCTION(&_21$$8, "array_pop", &_11, 9, &rowA); + ZEPHIR_CALL_FUNCTION(&_21$$8, "array_pop", &_11, 8, &rowA); ZEPHIR_UNREF(&rowA); zephir_check_call_status(); - zephir_array_append(&extras, &_21$$8, PH_SEPARATE, "tensor/matrix.zep", 264); + zephir_array_append(&extras, &_21$$8, PH_SEPARATE, "tensor/matrix.zep", 242); } - zephir_array_append(&a, &rowA, PH_SEPARATE, "tensor/matrix.zep", 267); + zephir_array_append(&a, &rowA, PH_SEPARATE, "tensor/matrix.zep", 245); } - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &a); + ZVAL_BOOL(&_22, 0); + ZEPHIR_RETURN_CALL_SELF("fromArray", NULL, 0, &a, &_22); zephir_check_call_status(); RETURN_MM(); } @@ -742,13 +685,13 @@ PHP_METHOD(Tensor_Matrix, poisson) ZEPHIR_INIT_VAR(&_0$$3); object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_1$$3, m); - ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", &_3, 4, &_1$$3); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", &_3, 3, &_1$$3); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_4$$3); ZEPHIR_CONCAT_SSVS(&_4$$3, "M must be", " greater than 0, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 3, &_4$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_4$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 286); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 264); ZEPHIR_MM_RESTORE(); return; } @@ -756,13 +699,13 @@ PHP_METHOD(Tensor_Matrix, poisson) ZEPHIR_INIT_VAR(&_5$$4); object_init_ex(&_5$$4, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_6$$4, n); - ZEPHIR_CALL_FUNCTION(&_7$$4, "strval", &_3, 4, &_6$$4); + ZEPHIR_CALL_FUNCTION(&_7$$4, "strval", &_3, 3, &_6$$4); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_8$$4); ZEPHIR_CONCAT_SSVS(&_8$$4, "N must be", " greater than 0, ", &_7$$4, " given."); - ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 3, &_8$$4); + ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_8$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 291); + zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 269); ZEPHIR_MM_RESTORE(); return; } @@ -770,13 +713,13 @@ PHP_METHOD(Tensor_Matrix, poisson) ZEPHIR_INIT_VAR(&_9$$5); object_init_ex(&_9$$5, tensor_exceptions_invalidargumentexception_ce); ZVAL_DOUBLE(&_10$$5, lambda); - ZEPHIR_CALL_FUNCTION(&_11$$5, "strval", &_3, 4, &_10$$5); + ZEPHIR_CALL_FUNCTION(&_11$$5, "strval", &_3, 3, &_10$$5); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_12$$5); ZEPHIR_CONCAT_SSVS(&_12$$5, "Lambda must be", " greater than or equal to 0, ", &_11$$5, " given."); - ZEPHIR_CALL_METHOD(NULL, &_9$$5, "__construct", NULL, 3, &_12$$5); + ZEPHIR_CALL_METHOD(NULL, &_9$$5, "__construct", NULL, 2, &_12$$5); zephir_check_call_status(); - zephir_throw_exception_debug(&_9$$5, "tensor/matrix.zep", 296); + zephir_throw_exception_debug(&_9$$5, "tensor/matrix.zep", 274); ZEPHIR_MM_RESTORE(); return; } @@ -793,10 +736,10 @@ PHP_METHOD(Tensor_Matrix, poisson) ZEPHIR_INIT_VAR(&rowA); array_init(&rowA); ZVAL_DOUBLE(&_16, -lambda); - ZEPHIR_CALL_FUNCTION(&_17, "exp", NULL, 10, &_16); + ZEPHIR_CALL_FUNCTION(&_17, "exp", NULL, 9, &_16); zephir_check_call_status(); l = (zephir_get_doubleval(&_17)); - ZEPHIR_CALL_FUNCTION(&_18, "getrandmax", NULL, 6); + ZEPHIR_CALL_FUNCTION(&_18, "getrandmax", NULL, 5); zephir_check_call_status(); max = zephir_get_intval(&_18); while (1) { @@ -816,17 +759,18 @@ PHP_METHOD(Tensor_Matrix, poisson) break; } k++; - ZEPHIR_CALL_FUNCTION(&_19$$9, "rand", &_20, 7); + ZEPHIR_CALL_FUNCTION(&_19$$9, "rand", &_20, 6); zephir_check_call_status(); p *= (zephir_safe_div_zval_long(&_19$$9, max)); } ZEPHIR_INIT_NVAR(&_21$$8); ZVAL_DOUBLE(&_21$$8, (k - 1.0)); - zephir_array_append(&rowA, &_21$$8, PH_SEPARATE, "tensor/matrix.zep", 325); + zephir_array_append(&rowA, &_21$$8, PH_SEPARATE, "tensor/matrix.zep", 303); } - zephir_array_append(&a, &rowA, PH_SEPARATE, "tensor/matrix.zep", 328); + zephir_array_append(&a, &rowA, PH_SEPARATE, "tensor/matrix.zep", 306); } - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &a); + ZVAL_BOOL(&_16, 0); + ZEPHIR_RETURN_CALL_SELF("fromArray", NULL, 0, &a, &_16); zephir_check_call_status(); RETURN_MM(); } @@ -844,7 +788,7 @@ PHP_METHOD(Tensor_Matrix, uniform) zval a, rowA; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zephir_fcall_cache_entry *_3 = NULL, *_13 = NULL; - zval *m_param = NULL, *n_param = NULL, _0$$3, _1$$3, _2$$3, _4$$3, _5$$4, _6$$4, _7$$4, _8$$4, _9, _10$$6, _11$$6, _12$$6, _14$$6; + zval *m_param = NULL, *n_param = NULL, _0$$3, _1$$3, _2$$3, _4$$3, _5$$4, _6$$4, _7$$4, _8$$4, _9, _15, _10$$6, _11$$6, _12$$6, _14$$6; zend_long m, n, ZEPHIR_LAST_CALL_STATUS, max; ZVAL_UNDEF(&_0$$3); @@ -856,6 +800,7 @@ PHP_METHOD(Tensor_Matrix, uniform) ZVAL_UNDEF(&_7$$4); ZVAL_UNDEF(&_8$$4); ZVAL_UNDEF(&_9); + ZVAL_UNDEF(&_15); ZVAL_UNDEF(&_10$$6); ZVAL_UNDEF(&_11$$6); ZVAL_UNDEF(&_12$$6); @@ -873,13 +818,13 @@ PHP_METHOD(Tensor_Matrix, uniform) ZEPHIR_INIT_VAR(&_0$$3); object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_1$$3, m); - ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", &_3, 4, &_1$$3); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", &_3, 3, &_1$$3); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_4$$3); ZEPHIR_CONCAT_SSVS(&_4$$3, "M must be", " greater than 0, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 3, &_4$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_4$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 346); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 324); ZEPHIR_MM_RESTORE(); return; } @@ -887,13 +832,13 @@ PHP_METHOD(Tensor_Matrix, uniform) ZEPHIR_INIT_VAR(&_5$$4); object_init_ex(&_5$$4, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_6$$4, n); - ZEPHIR_CALL_FUNCTION(&_7$$4, "strval", &_3, 4, &_6$$4); + ZEPHIR_CALL_FUNCTION(&_7$$4, "strval", &_3, 3, &_6$$4); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_8$$4); ZEPHIR_CONCAT_SSVS(&_8$$4, "N must be", " greater than 0, ", &_7$$4, " given."); - ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 3, &_8$$4); + ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_8$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 351); + zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 329); ZEPHIR_MM_RESTORE(); return; } @@ -901,7 +846,7 @@ PHP_METHOD(Tensor_Matrix, uniform) array_init(&a); ZEPHIR_INIT_VAR(&rowA); array_init(&rowA); - ZEPHIR_CALL_FUNCTION(&_9, "getrandmax", NULL, 6); + ZEPHIR_CALL_FUNCTION(&_9, "getrandmax", NULL, 5); zephir_check_call_status(); max = zephir_get_intval(&_9); while (1) { @@ -916,70 +861,73 @@ PHP_METHOD(Tensor_Matrix, uniform) } ZVAL_LONG(&_10$$6, -max); ZVAL_LONG(&_11$$6, max); - ZEPHIR_CALL_FUNCTION(&_12$$6, "rand", &_13, 7, &_10$$6, &_11$$6); + ZEPHIR_CALL_FUNCTION(&_12$$6, "rand", &_13, 6, &_10$$6, &_11$$6); zephir_check_call_status(); ZEPHIR_INIT_NVAR(&_14$$6); ZVAL_DOUBLE(&_14$$6, zephir_safe_div_zval_long(&_12$$6, max)); - zephir_array_append(&rowA, &_14$$6, PH_SEPARATE, "tensor/matrix.zep", 363); + zephir_array_append(&rowA, &_14$$6, PH_SEPARATE, "tensor/matrix.zep", 341); } - zephir_array_append(&a, &rowA, PH_SEPARATE, "tensor/matrix.zep", 366); + zephir_array_append(&a, &rowA, PH_SEPARATE, "tensor/matrix.zep", 344); } - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &a); + ZVAL_BOOL(&_15, 0); + ZEPHIR_RETURN_CALL_SELF("fromArray", NULL, 0, &a, &_15); zephir_check_call_status(); RETURN_MM(); } /** + * Build a new matrix from a PHP array of rows, each row being a PHP array + * of numeric elements. + * * @param array[] a * @param bool validate * @throws \Tensor\Exceptions\InvalidArgumentException + * @return self */ -PHP_METHOD(Tensor_Matrix, __construct) +PHP_METHOD(Tensor_Matrix, fromArray) { - zend_string *_5$$5; - zend_ulong _4$$5; + zval _5$$6, _9$$8, _25$$14, _28$$16; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zephir_fcall_cache_entry *_9 = NULL, *_12 = NULL, *_18 = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS, m, n; - zend_bool validate, _20$$6; - zval *a_param = NULL, *validate_param = NULL, i, rowA, valueA, _0, _1, _23, _2$$5, *_3$$5, _6$$7, _7$$7, _8$$7, _10$$7, _11$$7, *_13$$6, _14$$6, *_15$$6, _19$$6, _16$$8, _17$$8, _21$$9, _22$$9; - zval a, b$$5, rowB$$5; - zval *this_ptr = getThis(); + zephir_fcall_cache_entry *_6 = NULL, *_14 = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS, rows, n; + zend_bool validate, found, _23, _7$$7, _10$$7, _21$$4, _26$$15, _29$$15, _39$$12; + zval *a_param = NULL, *validate_param = NULL, rowA, valueA, *_3, _22, buffer, _40, _41, buffer$$3, _0$$3, _1$$3, _2$$3, _4$$6, _8$$8, _11$$9, _12$$9, _13$$9, _15$$9, _16$$9, *_17$$4, _18$$4, *_19$$4, _20$$4, _24$$14, _27$$16, _30$$17, _31$$17, _32$$17, _33$$17, _34$$17, *_35$$12, _36$$12, *_37$$12, _38$$12; + zval a, flat; ZVAL_UNDEF(&a); - ZVAL_UNDEF(&b$$5); - ZVAL_UNDEF(&rowB$$5); - ZVAL_UNDEF(&i); + ZVAL_UNDEF(&flat); ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&valueA); - ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&_23); - ZVAL_UNDEF(&_2$$5); - ZVAL_UNDEF(&_6$$7); - ZVAL_UNDEF(&_7$$7); - ZVAL_UNDEF(&_8$$7); - ZVAL_UNDEF(&_10$$7); - ZVAL_UNDEF(&_11$$7); - ZVAL_UNDEF(&_14$$6); - ZVAL_UNDEF(&_19$$6); - ZVAL_UNDEF(&_16$$8); - ZVAL_UNDEF(&_17$$8); - ZVAL_UNDEF(&_21$$9); - ZVAL_UNDEF(&_22$$9); - static zend_string *_zephir_prop_0 = NULL; - static zend_string *_zephir_prop_1 = NULL; - static zend_string *_zephir_prop_2 = NULL; - if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); - } - if (UNEXPECTED(!_zephir_prop_1)) { - _zephir_prop_1 = zend_string_init("m", 1, 1); - } - if (UNEXPECTED(!_zephir_prop_2)) { - _zephir_prop_2 = zend_string_init("n", 1, 1); - } - + ZVAL_UNDEF(&_22); + ZVAL_UNDEF(&buffer); + ZVAL_UNDEF(&_40); + ZVAL_UNDEF(&_41); + ZVAL_UNDEF(&buffer$$3); + ZVAL_UNDEF(&_0$$3); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); + ZVAL_UNDEF(&_4$$6); + ZVAL_UNDEF(&_8$$8); + ZVAL_UNDEF(&_11$$9); + ZVAL_UNDEF(&_12$$9); + ZVAL_UNDEF(&_13$$9); + ZVAL_UNDEF(&_15$$9); + ZVAL_UNDEF(&_16$$9); + ZVAL_UNDEF(&_18$$4); + ZVAL_UNDEF(&_20$$4); + ZVAL_UNDEF(&_24$$14); + ZVAL_UNDEF(&_27$$16); + ZVAL_UNDEF(&_30$$17); + ZVAL_UNDEF(&_31$$17); + ZVAL_UNDEF(&_32$$17); + ZVAL_UNDEF(&_33$$17); + ZVAL_UNDEF(&_34$$17); + ZVAL_UNDEF(&_36$$12); + ZVAL_UNDEF(&_38$$12); + ZVAL_UNDEF(&_5$$6); + ZVAL_UNDEF(&_9$$8); + ZVAL_UNDEF(&_25$$14); + ZVAL_UNDEF(&_28$$16); ZEND_PARSE_PARAMETERS_START(1, 2) ZEPHIR_Z_PARAM_ARRAY(a, a_param) Z_PARAM_OPTIONAL @@ -993,124 +941,301 @@ PHP_METHOD(Tensor_Matrix, __construct) validate = 1; } else { } - m = zephir_fast_count_int(&a); - ZEPHIR_INIT_VAR(&_0); - ZEPHIR_CALL_FUNCTION(&_1, "current", NULL, 30, &a); - zephir_check_call_status(); - if (!(zephir_is_true(&_1))) { - ZEPHIR_INIT_NVAR(&_0); - array_init(&_0); - } else { - ZEPHIR_CALL_FUNCTION(&_0, "current", NULL, 30, &a); + rows = zephir_fast_count_int(&a); + if (UNEXPECTED(rows < 1)) { + ZEPHIR_INIT_VAR(&buffer$$3); + ZEPHIR_INIT_VAR(&_0$$3); + array_init(&_0$$3); + tensor_buffer_from_array(&buffer$$3, &_0$$3); + object_init_ex(return_value, tensor_matrix_ce); + ZVAL_LONG(&_1$$3, 0); + ZVAL_LONG(&_2$$3, 0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &buffer$$3, &_1$$3, &_2$$3); zephir_check_call_status(); + RETURN_MM(); } - n = zephir_fast_count_int(&_0); - if (validate) { - ZEPHIR_INIT_VAR(&b$$5); - array_init(&b$$5); - ZEPHIR_INIT_VAR(&rowB$$5); - array_init(&rowB$$5); - ZEPHIR_CALL_FUNCTION(&_2$$5, "array_values", NULL, 29, &a); - zephir_check_call_status(); - ZEPHIR_CPY_WRT(&a, &_2$$5); - zephir_is_iterable(&a, 0, "tensor/matrix.zep", 407); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(&a), _4$$5, _5$$5, _3$$5) + ZEPHIR_INIT_VAR(&flat); + array_init(&flat); + n = 0; + found = 0; + zephir_is_iterable(&a, 0, "tensor/matrix.zep", 404); + if (Z_TYPE_P(&a) == IS_ARRAY) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&a), _3) { - ZEPHIR_INIT_NVAR(&i); - if (_5$$5 != NULL) { - ZVAL_STR_COPY(&i, _5$$5); - } else { - ZVAL_LONG(&i, _4$$5); - } ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3$$5); - if (UNEXPECTED(zephir_fast_count_int(&rowA) != n)) { - ZEPHIR_INIT_NVAR(&_6$$7); - object_init_ex(&_6$$7, tensor_exceptions_invalidargumentexception_ce); - ZVAL_LONG(&_7$$7, n); - ZEPHIR_CALL_FUNCTION(&_8$$7, "strval", &_9, 4, &_7$$7); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_10$$7); - ZVAL_LONG(&_10$$7, zephir_fast_count_int(&rowA)); - ZEPHIR_INIT_NVAR(&_11$$7); - ZEPHIR_CONCAT_SSVSVSSVS(&_11$$7, "The number of columns", " must be equal for all rows, ", &_8$$7, " needed but ", &_10$$7, " given", " at row offset ", &i, "."); - ZEPHIR_CALL_METHOD(NULL, &_6$$7, "__construct", &_12, 3, &_11$$7); - zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$7, "tensor/matrix.zep", 395); - ZEPHIR_MM_RESTORE(); - return; + ZVAL_COPY(&rowA, _3); + if (UNEXPECTED(!found)) { + if (UNEXPECTED(!(Z_TYPE_P(&rowA) == IS_ARRAY))) { + ZEPHIR_INIT_NVAR(&_4$$6); + object_init_ex(&_4$$6, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_NVAR(&_5$$6); + ZEPHIR_CONCAT_SS(&_5$$6, "Matrix requires an", " array of arrays."); + ZEPHIR_CALL_METHOD(NULL, &_4$$6, "__construct", &_6, 2, &_5$$6); + zephir_check_call_status(); + zephir_throw_exception_debug(&_4$$6, "tensor/matrix.zep", 380); + ZEPHIR_MM_RESTORE(); + return; + } + n = zephir_fast_count_int(&rowA); + found = 1; + } else { + _7$$7 = validate; + if (_7$$7) { + _7$$7 = !(Z_TYPE_P(&rowA) == IS_ARRAY); + } + if (UNEXPECTED(_7$$7)) { + ZEPHIR_INIT_NVAR(&_8$$8); + object_init_ex(&_8$$8, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_NVAR(&_9$$8); + ZEPHIR_CONCAT_SS(&_9$$8, "Matrix requires an", " array of arrays."); + ZEPHIR_CALL_METHOD(NULL, &_8$$8, "__construct", &_6, 2, &_9$$8); + zephir_check_call_status(); + zephir_throw_exception_debug(&_8$$8, "tensor/matrix.zep", 389); + ZEPHIR_MM_RESTORE(); + return; + } + _10$$7 = validate; + if (_10$$7) { + _10$$7 = zephir_fast_count_int(&rowA) != n; + } + if (UNEXPECTED(_10$$7)) { + ZEPHIR_INIT_NVAR(&_11$$9); + object_init_ex(&_11$$9, tensor_exceptions_invalidargumentexception_ce); + ZVAL_LONG(&_12$$9, n); + ZEPHIR_CALL_FUNCTION(&_13$$9, "strval", &_14, 3, &_12$$9); + zephir_check_call_status(); + ZEPHIR_INIT_NVAR(&_15$$9); + ZVAL_LONG(&_15$$9, zephir_fast_count_int(&rowA)); + ZEPHIR_INIT_NVAR(&_16$$9); + ZEPHIR_CONCAT_SSVSVS(&_16$$9, "The number of", " columns must be equal for all rows, ", &_13$$9, " needed but ", &_15$$9, " given."); + ZEPHIR_CALL_METHOD(NULL, &_11$$9, "__construct", &_6, 2, &_16$$9); + zephir_check_call_status(); + zephir_throw_exception_debug(&_11$$9, "tensor/matrix.zep", 395); + ZEPHIR_MM_RESTORE(); + return; + } } - ZEPHIR_INIT_NVAR(&rowB$$5); - array_init(&rowB$$5); - ZEPHIR_CPY_WRT(&rowB$$5, &rowB$$5); if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_14$$6); - zephir_string_to_char_array(&_14$$6, &rowA); - _13$$6 = &_14$$6; + ZEPHIR_INIT_NVAR(&_18$$4); + zephir_string_to_char_array(&_18$$4, &rowA); + _17$$4 = &_18$$4; } else { - _13$$6 = &rowA; + _17$$4 = &rowA; } - zephir_is_iterable(_13$$6, 0, "tensor/matrix.zep", 404); - if (Z_TYPE_P(_13$$6) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_13$$6), _15$$6) + zephir_is_iterable(_17$$4, 0, "tensor/matrix.zep", 402); + if (Z_TYPE_P(_17$$4) == IS_ARRAY) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_17$$4), _19$$4) { ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _15$$6); - ZEPHIR_INIT_NVAR(&_16$$8); - ZEPHIR_CALL_FUNCTION(&_17$$8, "is_float", &_18, 2, &valueA); - zephir_check_call_status(); - if (zephir_is_true(&_17$$8)) { - ZEPHIR_CPY_WRT(&_16$$8, &valueA); - } else { - ZEPHIR_INIT_NVAR(&_16$$8); - ZVAL_DOUBLE(&_16$$8, zephir_get_doubleval(&valueA)); - } - zephir_array_append(&rowB$$5, &_16$$8, PH_SEPARATE, "tensor/matrix.zep", 401); + ZVAL_COPY(&valueA, _19$$4); + zephir_array_append(&flat, &valueA, PH_SEPARATE, "tensor/matrix.zep", 400); } ZEND_HASH_FOREACH_END(); } else { - ZEPHIR_CALL_METHOD(NULL, _13$$6, "rewind", NULL, 0); + ZEPHIR_CALL_METHOD(NULL, _17$$4, "rewind", NULL, 0); zephir_check_call_status(); - _20$$6 = 1; + _21$$4 = 1; while (1) { - if (_20$$6) { - _20$$6 = 0; + if (_21$$4) { + _21$$4 = 0; } else { - ZEPHIR_CALL_METHOD(NULL, _13$$6, "next", NULL, 0); + ZEPHIR_CALL_METHOD(NULL, _17$$4, "next", NULL, 0); zephir_check_call_status(); } - ZEPHIR_CALL_METHOD(&_19$$6, _13$$6, "valid", NULL, 0); + ZEPHIR_CALL_METHOD(&_20$$4, _17$$4, "valid", NULL, 0); zephir_check_call_status(); - if (!zend_is_true(&_19$$6)) { + if (!zend_is_true(&_20$$4)) { break; } - ZEPHIR_CALL_METHOD(&valueA, _13$$6, "current", NULL, 0); + ZEPHIR_CALL_METHOD(&valueA, _17$$4, "current", NULL, 0); zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_21$$9); - ZEPHIR_CALL_FUNCTION(&_22$$9, "is_float", &_18, 2, &valueA); - zephir_check_call_status(); - if (zephir_is_true(&_22$$9)) { - ZEPHIR_CPY_WRT(&_21$$9, &valueA); - } else { - ZEPHIR_INIT_NVAR(&_21$$9); - ZVAL_DOUBLE(&_21$$9, zephir_get_doubleval(&valueA)); - } - zephir_array_append(&rowB$$5, &_21$$9, PH_SEPARATE, "tensor/matrix.zep", 401); + zephir_array_append(&flat, &valueA, PH_SEPARATE, "tensor/matrix.zep", 400); } } ZEPHIR_INIT_NVAR(&valueA); - zephir_array_append(&b$$5, &rowB$$5, PH_SEPARATE, "tensor/matrix.zep", 404); } ZEND_HASH_FOREACH_END(); - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_CPY_WRT(&a, &b$$5); + } else { + ZEPHIR_CALL_METHOD(NULL, &a, "rewind", NULL, 0); + zephir_check_call_status(); + _23 = 1; + while (1) { + if (_23) { + _23 = 0; + } else { + ZEPHIR_CALL_METHOD(NULL, &a, "next", NULL, 0); + zephir_check_call_status(); + } + ZEPHIR_CALL_METHOD(&_22, &a, "valid", NULL, 0); + zephir_check_call_status(); + if (!zend_is_true(&_22)) { + break; + } + ZEPHIR_CALL_METHOD(&rowA, &a, "current", NULL, 0); + zephir_check_call_status(); + if (UNEXPECTED(!found)) { + if (UNEXPECTED(!(Z_TYPE_P(&rowA) == IS_ARRAY))) { + ZEPHIR_INIT_NVAR(&_24$$14); + object_init_ex(&_24$$14, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_NVAR(&_25$$14); + ZEPHIR_CONCAT_SS(&_25$$14, "Matrix requires an", " array of arrays."); + ZEPHIR_CALL_METHOD(NULL, &_24$$14, "__construct", &_6, 2, &_25$$14); + zephir_check_call_status(); + zephir_throw_exception_debug(&_24$$14, "tensor/matrix.zep", 380); + ZEPHIR_MM_RESTORE(); + return; + } + n = zephir_fast_count_int(&rowA); + found = 1; + } else { + _26$$15 = validate; + if (_26$$15) { + _26$$15 = !(Z_TYPE_P(&rowA) == IS_ARRAY); + } + if (UNEXPECTED(_26$$15)) { + ZEPHIR_INIT_NVAR(&_27$$16); + object_init_ex(&_27$$16, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_NVAR(&_28$$16); + ZEPHIR_CONCAT_SS(&_28$$16, "Matrix requires an", " array of arrays."); + ZEPHIR_CALL_METHOD(NULL, &_27$$16, "__construct", &_6, 2, &_28$$16); + zephir_check_call_status(); + zephir_throw_exception_debug(&_27$$16, "tensor/matrix.zep", 389); + ZEPHIR_MM_RESTORE(); + return; + } + _29$$15 = validate; + if (_29$$15) { + _29$$15 = zephir_fast_count_int(&rowA) != n; + } + if (UNEXPECTED(_29$$15)) { + ZEPHIR_INIT_NVAR(&_30$$17); + object_init_ex(&_30$$17, tensor_exceptions_invalidargumentexception_ce); + ZVAL_LONG(&_31$$17, n); + ZEPHIR_CALL_FUNCTION(&_32$$17, "strval", &_14, 3, &_31$$17); + zephir_check_call_status(); + ZEPHIR_INIT_NVAR(&_33$$17); + ZVAL_LONG(&_33$$17, zephir_fast_count_int(&rowA)); + ZEPHIR_INIT_NVAR(&_34$$17); + ZEPHIR_CONCAT_SSVSVS(&_34$$17, "The number of", " columns must be equal for all rows, ", &_32$$17, " needed but ", &_33$$17, " given."); + ZEPHIR_CALL_METHOD(NULL, &_30$$17, "__construct", &_6, 2, &_34$$17); + zephir_check_call_status(); + zephir_throw_exception_debug(&_30$$17, "tensor/matrix.zep", 395); + ZEPHIR_MM_RESTORE(); + return; + } + } + if (Z_TYPE_P(&rowA) == IS_STRING) { + ZEPHIR_INIT_NVAR(&_36$$12); + zephir_string_to_char_array(&_36$$12, &rowA); + _35$$12 = &_36$$12; + } else { + _35$$12 = &rowA; + } + zephir_is_iterable(_35$$12, 0, "tensor/matrix.zep", 402); + if (Z_TYPE_P(_35$$12) == IS_ARRAY) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_35$$12), _37$$12) + { + ZEPHIR_INIT_NVAR(&valueA); + ZVAL_COPY(&valueA, _37$$12); + zephir_array_append(&flat, &valueA, PH_SEPARATE, "tensor/matrix.zep", 400); + } ZEND_HASH_FOREACH_END(); + } else { + ZEPHIR_CALL_METHOD(NULL, _35$$12, "rewind", NULL, 0); + zephir_check_call_status(); + _39$$12 = 1; + while (1) { + if (_39$$12) { + _39$$12 = 0; + } else { + ZEPHIR_CALL_METHOD(NULL, _35$$12, "next", NULL, 0); + zephir_check_call_status(); + } + ZEPHIR_CALL_METHOD(&_38$$12, _35$$12, "valid", NULL, 0); + zephir_check_call_status(); + if (!zend_is_true(&_38$$12)) { + break; + } + ZEPHIR_CALL_METHOD(&valueA, _35$$12, "current", NULL, 0); + zephir_check_call_status(); + zephir_array_append(&flat, &valueA, PH_SEPARATE, "tensor/matrix.zep", 400); + } + } + ZEPHIR_INIT_NVAR(&valueA); + } } - zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 14, &a); - ZVAL_UNDEF(&_23); - ZVAL_LONG(&_23, m); - zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 15, &_23); - ZVAL_UNDEF(&_23); - ZVAL_LONG(&_23, n); - zephir_update_property_zval_cached(this_ptr, _zephir_prop_2, 16, &_23); + ZEPHIR_INIT_NVAR(&rowA); + ZEPHIR_INIT_VAR(&buffer); + tensor_buffer_from_array(&buffer, &flat); + object_init_ex(return_value, tensor_matrix_ce); + ZVAL_LONG(&_40, rows); + ZVAL_LONG(&_41, n); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &buffer, &_40, &_41); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Construct a matrix from a single TensorBuffer holding the elements in + * row-major order together with the target dimensionality. + * + * @param \Tensor\TensorBuffer a + * @param int m + * @param int n + */ +PHP_METHOD(Tensor_Matrix, __construct) +{ + zval _2$$3; + zend_bool _0; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long m, n, ZEPHIR_LAST_CALL_STATUS; + zval *a, a_sub, *m_param = NULL, *n_param = NULL, _3, _1$$3; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&a_sub); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } + + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_OBJECT_OF_CLASS(a, zephir_get_internal_ce(SL("tensor\\tensorbuffer"))) + Z_PARAM_LONG(m) + Z_PARAM_LONG(n) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 3, 0, &a, &m_param, &n_param); + _0 = m < 0; + if (!(_0)) { + _0 = n < 0; + } + if (UNEXPECTED(_0)) { + ZEPHIR_INIT_VAR(&_1$$3); + object_init_ex(&_1$$3, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_VAR(&_2$$3); + ZEPHIR_CONCAT_SS(&_2$$3, "Matrix dimensions must be", " non-negative."); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_1$$3, "tensor/matrix.zep", 421); + ZEPHIR_MM_RESTORE(); + return; + } + zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 14, a); + ZVAL_UNDEF(&_3); + ZVAL_LONG(&_3, m); + zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 15, &_3); + ZVAL_UNDEF(&_3); + ZVAL_LONG(&_3, n); + zephir_update_property_zval_cached(this_ptr, _zephir_prop_2, 16, &_3); ZEPHIR_MM_RESTORE(); } @@ -1262,23 +1387,68 @@ PHP_METHOD(Tensor_Matrix, n) * * @param int index * @return \Tensor\Vector + * @throws \InvalidArgumentException */ PHP_METHOD(Tensor_Matrix, rowAsVector) { + zval _3$$3; + zend_bool _0; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zval *index_param = NULL, _0; + zval *index_param = NULL, _1, _4, _5, _6, _7, _8, _2$$3; zend_long index, ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); - ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_2$$3); + ZVAL_UNDEF(&_3$$3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } + ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_LONG(index) ZEND_PARSE_PARAMETERS_END(); ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &index_param); - ZVAL_LONG(&_0, index); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "offsetget", NULL, 0, &_0); + _0 = index < 0; + if (!(_0)) { + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + _0 = ZEPHIR_LE_LONG(&_1, index); + } + if (UNEXPECTED(_0)) { + ZEPHIR_INIT_VAR(&_2$$3); + object_init_ex(&_2$$3, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_VAR(&_3$$3); + ZEPHIR_CONCAT_SS(&_3$$3, "Row offset out of", " bounds."); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_3$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 500); + ZEPHIR_MM_RESTORE(); + return; + } + object_init_ex(return_value, tensor_vector_ce); + zephir_read_property_cached(&_4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_8, (index * (zend_long) zephir_get_numberval(&_6))); + ZEPHIR_CALL_METHOD(&_5, &_4, "slice", NULL, 0, &_8, &_7); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_5); zephir_check_call_status(); RETURN_MM(); } @@ -1288,20 +1458,36 @@ PHP_METHOD(Tensor_Matrix, rowAsVector) * * @param int index * @return \Tensor\ColumnVector + * @throws \InvalidArgumentException */ PHP_METHOD(Tensor_Matrix, columnAsVector) { + zval _3$$3; + zend_bool _0; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zval *index_param = NULL, _0, _1, _2; + zval *index_param = NULL, _1, _4, _5, _6, _7, _8, _2$$3; zend_long index, ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); - ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_2$$3); + ZVAL_UNDEF(&_3$$3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); + _zephir_prop_0 = zend_string_init("n", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); } ZEND_PARSE_PARAMETERS_START(1, 1) @@ -1310,11 +1496,30 @@ PHP_METHOD(Tensor_Matrix, columnAsVector) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &index_param); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZVAL_LONG(&_1, index); - ZEPHIR_CALL_FUNCTION(&_2, "array_column", NULL, 31, &_0, &_1); + _0 = index < 0; + if (!(_0)) { + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + _0 = ZEPHIR_LE_LONG(&_1, index); + } + if (UNEXPECTED(_0)) { + ZEPHIR_INIT_VAR(&_2$$3); + object_init_ex(&_2$$3, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_VAR(&_3$$3); + ZEPHIR_CONCAT_SS(&_3$$3, "Column offset out of", " bounds."); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_3$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 517); + ZEPHIR_MM_RESTORE(); + return; + } + object_init_ex(return_value, tensor_columnvector_ce); + zephir_read_property_cached(&_4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_8, index); + ZEPHIR_CALL_METHOD(&_5, &_4, "sliceStrided", NULL, 0, &_8, &_6, &_7); zephir_check_call_status(); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_columnvector_ce, "quick", NULL, 0, &_2); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_5); zephir_check_call_status(); RETURN_MM(); } @@ -1322,139 +1527,264 @@ PHP_METHOD(Tensor_Matrix, columnAsVector) /** * Return the diagonal elements of a square matrix as a vector. * - * @throws \Tensor\Exceptions\InvalidArgumentException * @return \Tensor\Vector + * @throws \Tensor\Exceptions\InvalidArgumentException */ PHP_METHOD(Tensor_Matrix, diagonalAsVector) { - zend_bool _12; - zend_string *_9; - zend_ulong _8; - zval b; - zval _0, i, rowA, _4, *_5, _6, *_7, _11, _1$$3, _2$$3, _3$$3, _10$$4, _13$$5; + zval _0, _4, _5, _6, _7, _8, _9, _1$$3, _2$$3, _3$$3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_5); ZVAL_UNDEF(&_6); - ZVAL_UNDEF(&_11); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_1$$3); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); - ZVAL_UNDEF(&_10$$4); - ZVAL_UNDEF(&_13$$5); - ZVAL_UNDEF(&b); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "issquare", NULL, 0); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "isSquare", NULL, 0); zephir_check_call_status(); if (UNEXPECTED(!zephir_is_true(&_0))) { ZEPHIR_INIT_VAR(&_1$$3); object_init_ex(&_1$$3, tensor_exceptions_invalidargumentexception_ce); - ZEPHIR_CALL_METHOD(&_2$$3, this_ptr, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_2$$3, this_ptr, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3$$3); ZEPHIR_CONCAT_SSVS(&_3$$3, "Matrix must be", " square, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 3, &_3$$3); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/matrix.zep", 507); + zephir_throw_exception_debug(&_1$$3, "tensor/matrix.zep", 533); ZEPHIR_MM_RESTORE(); return; } + object_init_ex(return_value, tensor_vector_ce); + zephir_read_property_cached(&_4, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_8, 0); + ZVAL_LONG(&_9, (zephir_get_numberval(&_7) + 1)); + ZEPHIR_CALL_METHOD(&_5, &_4, "sliceStrided", NULL, 0, &_8, &_6, &_9); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_5); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return the rows of the matrix as an array of Vector objects. + * + * @return \Tensor\Vector[] + */ +PHP_METHOD(Tensor_Matrix, asVectors) +{ + zend_bool _10; + zval b; + zval rowBuffer, _0, _1, _2, _3, *_4, _5, *_6, _9, _7$$4, _11$$5; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zephir_fcall_cache_entry *_8 = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&rowBuffer); + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_9); + ZVAL_UNDEF(&_7$$4); + ZVAL_UNDEF(&_11$$5); + ZVAL_UNDEF(&b); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("n", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("a", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + ZEPHIR_INIT_VAR(&b); array_init(&b); - zephir_read_property_cached(&_4, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_4) == IS_STRING) { - ZEPHIR_INIT_VAR(&_6); - zephir_string_to_char_array(&_6, &_4); - _5 = &_6; + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + if (UNEXPECTED(ZEPHIR_LT_LONG(&_0, 1))) { + array_init(return_value); + RETURN_MM(); + } + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_2, &_1, "split", NULL, 0, &_3); + zephir_check_call_status(); + if (Z_TYPE_P(&_2) == IS_STRING) { + ZEPHIR_INIT_VAR(&_5); + zephir_string_to_char_array(&_5, &_2); + _4 = &_5; } else { - _5 = &_4; + _4 = &_2; } - zephir_is_iterable(_5, 0, "tensor/matrix.zep", 518); - if (Z_TYPE_P(_5) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_5), _8, _9, _7) + zephir_is_iterable(_4, 0, "tensor/matrix.zep", 558); + if (Z_TYPE_P(_4) == IS_ARRAY) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_4), _6) { - ZEPHIR_INIT_NVAR(&i); - if (_9 != NULL) { - ZVAL_STR_COPY(&i, _9); - } else { - ZVAL_LONG(&i, _8); - } - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _7); - ZEPHIR_OBS_NVAR(&_10$$4); - zephir_array_fetch(&_10$$4, &rowA, &i, PH_NOISY, "tensor/matrix.zep", 515); - zephir_array_append(&b, &_10$$4, PH_SEPARATE, "tensor/matrix.zep", 515); + ZEPHIR_INIT_NVAR(&rowBuffer); + ZVAL_COPY(&rowBuffer, _6); + ZEPHIR_INIT_NVAR(&_7$$4); + object_init_ex(&_7$$4, tensor_vector_ce); + ZEPHIR_CALL_METHOD(NULL, &_7$$4, "__construct", &_8, 13, &rowBuffer); + zephir_check_call_status(); + zephir_array_append(&b, &_7$$4, PH_SEPARATE, "tensor/matrix.zep", 555); } ZEND_HASH_FOREACH_END(); } else { - ZEPHIR_CALL_METHOD(NULL, _5, "rewind", NULL, 0); + ZEPHIR_CALL_METHOD(NULL, _4, "rewind", NULL, 0); zephir_check_call_status(); - _12 = 1; + _10 = 1; while (1) { - if (_12) { - _12 = 0; + if (_10) { + _10 = 0; } else { - ZEPHIR_CALL_METHOD(NULL, _5, "next", NULL, 0); + ZEPHIR_CALL_METHOD(NULL, _4, "next", NULL, 0); zephir_check_call_status(); } - ZEPHIR_CALL_METHOD(&_11, _5, "valid", NULL, 0); + ZEPHIR_CALL_METHOD(&_9, _4, "valid", NULL, 0); zephir_check_call_status(); - if (!zend_is_true(&_11)) { + if (!zend_is_true(&_9)) { break; } - ZEPHIR_CALL_METHOD(&i, _5, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowA, _5, "current", NULL, 0); + ZEPHIR_CALL_METHOD(&rowBuffer, _4, "current", NULL, 0); zephir_check_call_status(); - ZEPHIR_OBS_NVAR(&_13$$5); - zephir_array_fetch(&_13$$5, &rowA, &i, PH_NOISY, "tensor/matrix.zep", 515); - zephir_array_append(&b, &_13$$5, PH_SEPARATE, "tensor/matrix.zep", 515); + ZEPHIR_INIT_NVAR(&_11$$5); + object_init_ex(&_11$$5, tensor_vector_ce); + ZEPHIR_CALL_METHOD(NULL, &_11$$5, "__construct", &_8, 13, &rowBuffer); + zephir_check_call_status(); + zephir_array_append(&b, &_11$$5, PH_SEPARATE, "tensor/matrix.zep", 555); } } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_vector_ce, "quick", NULL, 0, &b); - zephir_check_call_status(); - RETURN_MM(); + ZEPHIR_INIT_NVAR(&rowBuffer); + RETURN_CTOR(&b); } /** - * Return the elements of the matrix in a 2-d array. + * Return the columns of the matrix as an array of ColumnVector objects. * - * @return list> + * @return \Tensor\ColumnVector[] */ -PHP_METHOD(Tensor_Matrix, asArray) +PHP_METHOD(Tensor_Matrix, asColumnVectors) { + zend_bool _8; + zval b; + zval columnBuffer, _0, _1, *_2, _3, *_4, _7, _5$$4, _9$$5; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zephir_fcall_cache_entry *_6 = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&columnBuffer); + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_5$$4); + ZVAL_UNDEF(&_9$$5); + ZVAL_UNDEF(&b); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("n", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - RETURN_MEMBER_TYPED(getThis(), "a", IS_ARRAY); + ZEPHIR_INIT_VAR(&b); + array_init(&b); + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + if (UNEXPECTED(ZEPHIR_LT_LONG(&_0, 1))) { + array_init(return_value); + RETURN_MM(); + } + ZEPHIR_CALL_METHOD(&_1, this_ptr, "asColumnBuffers", NULL, 0); + zephir_check_call_status(); + if (Z_TYPE_P(&_1) == IS_STRING) { + ZEPHIR_INIT_VAR(&_3); + zephir_string_to_char_array(&_3, &_1); + _2 = &_3; + } else { + _2 = &_1; + } + zephir_is_iterable(_2, 0, "tensor/matrix.zep", 580); + if (Z_TYPE_P(_2) == IS_ARRAY) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_2), _4) + { + ZEPHIR_INIT_NVAR(&columnBuffer); + ZVAL_COPY(&columnBuffer, _4); + ZEPHIR_INIT_NVAR(&_5$$4); + object_init_ex(&_5$$4, tensor_columnvector_ce); + ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", &_6, 13, &columnBuffer); + zephir_check_call_status(); + zephir_array_append(&b, &_5$$4, PH_SEPARATE, "tensor/matrix.zep", 577); + } ZEND_HASH_FOREACH_END(); + } else { + ZEPHIR_CALL_METHOD(NULL, _2, "rewind", NULL, 0); + zephir_check_call_status(); + _8 = 1; + while (1) { + if (_8) { + _8 = 0; + } else { + ZEPHIR_CALL_METHOD(NULL, _2, "next", NULL, 0); + zephir_check_call_status(); + } + ZEPHIR_CALL_METHOD(&_7, _2, "valid", NULL, 0); + zephir_check_call_status(); + if (!zend_is_true(&_7)) { + break; + } + ZEPHIR_CALL_METHOD(&columnBuffer, _2, "current", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_NVAR(&_9$$5); + object_init_ex(&_9$$5, tensor_columnvector_ce); + ZEPHIR_CALL_METHOD(NULL, &_9$$5, "__construct", &_6, 13, &columnBuffer); + zephir_check_call_status(); + zephir_array_append(&b, &_9$$5, PH_SEPARATE, "tensor/matrix.zep", 577); + } + } + ZEPHIR_INIT_NVAR(&columnBuffer); + RETURN_CTOR(&b); } /** - * Return each row as a vector in an array. + * Return the elements of the matrix as a vector taken in row-major order. * - * @return \Tensor\Vector[] + * @return \Tensor\Vector */ -PHP_METHOD(Tensor_Matrix, asVectors) +PHP_METHOD(Tensor_Matrix, flatten) { - zval _1, _2; zval _0; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&_2); static zend_string *_zephir_prop_0 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); @@ -1462,78 +1792,66 @@ PHP_METHOD(Tensor_Matrix, asVectors) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_INIT_VAR(&_0); - zephir_create_array(&_0, 2, 0); - ZEPHIR_INIT_VAR(&_1); - ZVAL_STRING(&_1, "Tensor\\Vector"); - zephir_array_fast_append(&_0, &_1); - ZEPHIR_INIT_NVAR(&_1); - ZVAL_STRING(&_1, "quick"); - zephir_array_fast_append(&_0, &_1); - zephir_read_property_cached(&_2, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_RETURN_CALL_FUNCTION("array_map", NULL, 14, &_0, &_2); + object_init_ex(return_value, tensor_vector_ce); + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } /** - * Return each column as a column vector in an array. + * Return the matrix as an array of arrays. * - * @return \Tensor\ColumnVector[] + * @return array[] */ -PHP_METHOD(Tensor_Matrix, asColumnVectors) +PHP_METHOD(Tensor_Matrix, asArray) { - zend_bool _1; - zval _0, _4$$3, _5$$3; - zval vectors; - zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zephir_fcall_cache_entry *_6 = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS, i = 0, _2, _3; + zval _0, _1, _2; zval *this_ptr = getThis(); - ZVAL_UNDEF(&vectors); ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_5$$3); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } - ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); - zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - - ZEPHIR_INIT_VAR(&vectors); - array_init(&vectors); + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("a", 1, 1); + } zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); - _3 = (zephir_get_numberval(&_0) - 1); - _2 = 0; - _1 = 0; - if (_2 <= _3) { - while (1) { - if (_1) { - _2++; - if (!(_2 <= _3)) { - break; - } - } else { - _1 = 1; - } - i = _2; - ZVAL_LONG(&_5$$3, i); - ZEPHIR_CALL_METHOD(&_4$$3, this_ptr, "columnasvector", &_6, 0, &_5$$3); - zephir_check_call_status(); - zephir_array_append(&vectors, &_4$$3, PH_SEPARATE, "tensor/matrix.zep", 553); - } + if (UNEXPECTED(ZEPHIR_LT_LONG(&_0, 1))) { + array_init(return_value); + return; } - RETURN_CTOR(&vectors); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + tensor_matrix_to_array(return_value, &_1, &_2); + return; } /** - * Flatten i.e unravel the matrix into a vector. + * Return the underlying TensorBuffer of the matrix. * - * @return \Tensor\Vector + * @internal + * + * @return \Tensor\TensorBuffer */ -PHP_METHOD(Tensor_Matrix, flatten) +PHP_METHOD(Tensor_Matrix, asTensorBuffer) +{ + + RETURN_MEMBER(getThis(), "a"); +} + +/** + * Return each row of the matrix as a TensorBuffer. + * + * @internal + * + * @return \Tensor\TensorBuffer[] + */ +PHP_METHOD(Tensor_Matrix, asRowBuffers) { zval _0, _1, _2; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; @@ -1544,105 +1862,153 @@ PHP_METHOD(Tensor_Matrix, flatten) ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); + _zephir_prop_0 = zend_string_init("n", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("a", 1, 1); } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_INIT_VAR(&_0); - zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_INIT_VAR(&_2); - ZVAL_STRING(&_2, "array_merge"); - ZEPHIR_CALL_USER_FUNC_ARRAY(&_0, &_2, &_1); - zephir_check_call_status(); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_vector_ce, "quick", NULL, 0, &_0); + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + if (UNEXPECTED(ZEPHIR_LT_LONG(&_0, 1))) { + array_init(return_value); + RETURN_MM(); + } + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_RETURN_CALL_METHOD(&_1, "split", NULL, 0, &_2); zephir_check_call_status(); RETURN_MM(); } /** - * Run a function over all of the elements in the matrix. + * Return each column of the matrix as a TensorBuffer. * * @internal * - * @param callable callback - * @return self + * @return \Tensor\TensorBuffer[] */ -PHP_METHOD(Tensor_Matrix, map) +PHP_METHOD(Tensor_Matrix, asColumnBuffers) { - zend_bool _7; + zend_bool _2; zval b; + zval i, _0, _1, _5$$4, _6$$4, _7$$4, _8$$4; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zephir_fcall_cache_entry *_5 = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS; - zval *callback, callback_sub, rowA, _0, *_1, _2, *_3, _6, _4$$3, _8$$4; + zend_long ZEPHIR_LAST_CALL_STATUS, _3, _4; zval *this_ptr = getThis(); - ZVAL_UNDEF(&callback_sub); - ZVAL_UNDEF(&rowA); + ZVAL_UNDEF(&i); ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_6); - ZVAL_UNDEF(&_4$$3); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_5$$4); + ZVAL_UNDEF(&_6$$4); + ZVAL_UNDEF(&_7$$4); ZVAL_UNDEF(&_8$$4); ZVAL_UNDEF(&b); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); + _zephir_prop_0 = zend_string_init("n", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); } - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ZVAL(callback) - ZEND_PARSE_PARAMETERS_END(); ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_fetch_params(1, 1, 0, &callback); + ZEPHIR_INIT_VAR(&b); array_init(&b); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 587); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_CALL_FUNCTION(&_4$$3, "array_map", &_5, 14, callback, &rowA); - zephir_check_call_status(); - zephir_array_append(&b, &_4$$3, PH_SEPARATE, "tensor/matrix.zep", 584); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _7 = 1; + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + if (UNEXPECTED(ZEPHIR_LT_LONG(&_0, 1))) { + array_init(return_value); + RETURN_MM(); + } + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + _4 = (zephir_get_numberval(&_1) - 1); + _3 = 0; + _2 = 0; + if (_3 <= _4) { while (1) { - if (_7) { - _7 = 0; + if (_2) { + _3++; + if (!(_3 <= _4)) { + break; + } } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_6, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_6)) { - break; + _2 = 1; } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); + ZEPHIR_INIT_NVAR(&i); + ZVAL_LONG(&i, _3); + zephir_read_property_cached(&_5$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7$$4, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_8$$4, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_6$$4, &_5$$4, "sliceStrided", NULL, 0, &i, &_7$$4, &_8$$4); zephir_check_call_status(); - ZEPHIR_CALL_FUNCTION(&_8$$4, "array_map", &_5, 14, callback, &rowA); - zephir_check_call_status(); - zephir_array_append(&b, &_8$$4, PH_SEPARATE, "tensor/matrix.zep", 584); + zephir_array_append(&b, &_6$$4, PH_SEPARATE, "tensor/matrix.zep", 654); } } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &b); + RETURN_CTOR(&b); +} + +/** + * Run a function over all of the elements in the matrix. + * + * @internal + * + * @param callable callback + * @return self + */ +PHP_METHOD(Tensor_Matrix, map) +{ + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *callback, callback_sub, b, _0, _1, buffer, _2, _3; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&callback_sub); + ZVAL_UNDEF(&b); + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&buffer); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(callback) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 1, 0, &callback); + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_1, &_0, "toArray", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_FUNCTION(&b, "array_map", NULL, 15, callback, &_1); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&buffer); + tensor_buffer_from_array(&buffer, &b); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &buffer, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -1658,28 +2024,16 @@ PHP_METHOD(Tensor_Matrix, map) */ PHP_METHOD(Tensor_Matrix, reduce) { - zend_bool _12, _9$$3, _18$$6; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; double initial; - zval *callback, callback_sub, *initial_param = NULL, rowA, valueA, carry, _0, *_1, _2, *_3, _11, *_4$$3, _5$$3, *_6$$3, _8$$3, _7$$4, _10$$5, *_13$$6, _14$$6, *_15$$6, _17$$6, _16$$7, _19$$8; + zval *callback, callback_sub, *initial_param = NULL, _0, _1, _2; zval *this_ptr = getThis(); ZVAL_UNDEF(&callback_sub); - ZVAL_UNDEF(&rowA); - ZVAL_UNDEF(&valueA); - ZVAL_UNDEF(&carry); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_11); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_8$$3); - ZVAL_UNDEF(&_7$$4); - ZVAL_UNDEF(&_10$$5); - ZVAL_UNDEF(&_14$$6); - ZVAL_UNDEF(&_17$$6); - ZVAL_UNDEF(&_16$$7); - ZVAL_UNDEF(&_19$$8); static zend_string *_zephir_prop_0 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); @@ -1698,127 +2052,13 @@ PHP_METHOD(Tensor_Matrix, reduce) } else { initial = zephir_get_doubleval(initial_param); } - ZEPHIR_INIT_VAR(&carry); - ZVAL_DOUBLE(&carry, initial); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 611); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_5$$3); - zephir_string_to_char_array(&_5$$3, &rowA); - _4$$3 = &_5$$3; - } else { - _4$$3 = &rowA; - } - zephir_is_iterable(_4$$3, 0, "tensor/matrix.zep", 609); - if (Z_TYPE_P(_4$$3) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_4$$3), _6$$3) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _6$$3); - ZEPHIR_CALL_ZVAL_FUNCTION(&_7$$4, callback, NULL, 0, &carry, &valueA); - zephir_check_call_status(); - ZEPHIR_CPY_WRT(&carry, &_7$$4); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _4$$3, "rewind", NULL, 0); - zephir_check_call_status(); - _9$$3 = 1; - while (1) { - if (_9$$3) { - _9$$3 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _4$$3, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_8$$3, _4$$3, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_8$$3)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _4$$3, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_ZVAL_FUNCTION(&_10$$5, callback, NULL, 0, &carry, &valueA); - zephir_check_call_status(); - ZEPHIR_CPY_WRT(&carry, &_10$$5); - } - } - ZEPHIR_INIT_NVAR(&valueA); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _12 = 1; - while (1) { - if (_12) { - _12 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_11, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_11)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_14$$6); - zephir_string_to_char_array(&_14$$6, &rowA); - _13$$6 = &_14$$6; - } else { - _13$$6 = &rowA; - } - zephir_is_iterable(_13$$6, 0, "tensor/matrix.zep", 609); - if (Z_TYPE_P(_13$$6) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_13$$6), _15$$6) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _15$$6); - ZEPHIR_CALL_ZVAL_FUNCTION(&_16$$7, callback, NULL, 0, &carry, &valueA); - zephir_check_call_status(); - ZEPHIR_CPY_WRT(&carry, &_16$$7); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _13$$6, "rewind", NULL, 0); - zephir_check_call_status(); - _18$$6 = 1; - while (1) { - if (_18$$6) { - _18$$6 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _13$$6, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_17$$6, _13$$6, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_17$$6)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _13$$6, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_ZVAL_FUNCTION(&_19$$8, callback, NULL, 0, &carry, &valueA); - zephir_check_call_status(); - ZEPHIR_CPY_WRT(&carry, &_19$$8); - } - } - ZEPHIR_INIT_NVAR(&valueA); - } - } - ZEPHIR_INIT_NVAR(&rowA); - RETURN_CCTOR(&carry); + ZEPHIR_CALL_METHOD(&_1, &_0, "toArray", NULL, 0); + zephir_check_call_status(); + ZVAL_DOUBLE(&_2, initial); + ZEPHIR_RETURN_CALL_FUNCTION("array_reduce", NULL, 16, &_1, callback, &_2); + zephir_check_call_status(); + RETURN_MM(); } /** @@ -1828,55 +2068,53 @@ PHP_METHOD(Tensor_Matrix, reduce) */ PHP_METHOD(Tensor_Matrix, transpose) { - zend_bool _1; - zval _0, _4$$3, _5$$3, _6$$3; - zval b; + zval _0, result, _3, _4, _5, _6, _7, _1$$3, _2$$3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS, i = 0, _2, _3; - zephir_fcall_cache_entry *_7 = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); - ZVAL_UNDEF(&b); ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_6$$3); + ZVAL_UNDEF(&result); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_INIT_VAR(&b); - array_init(&b); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); - _3 = (zephir_get_numberval(&_0) - 1); - _2 = 0; - _1 = 0; - if (_2 <= _3) { - while (1) { - if (_1) { - _2++; - if (!(_2 <= _3)) { - break; - } - } else { - _1 = 1; - } - i = _2; - zephir_read_property_cached(&_4$$3, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZVAL_LONG(&_5$$3, i); - ZEPHIR_CALL_FUNCTION(&_6$$3, "array_column", &_7, 31, &_4$$3, &_5$$3); - zephir_check_call_status(); - zephir_array_append(&b, &_6$$3, PH_SEPARATE, "tensor/matrix.zep", 626); - } + if (UNEXPECTED(ZEPHIR_LT_LONG(&_0, 1))) { + ZEPHIR_INIT_VAR(&_1$$3); + array_init(&_1$$3); + ZVAL_BOOL(&_2$$3, 0); + ZEPHIR_RETURN_CALL_SELF("fromArray", NULL, 0, &_1$$3, &_2$$3); + zephir_check_call_status(); + RETURN_MM(); } - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &b); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_4, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_5, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + tensor_matrix_transpose(&result, &_3, &_4, &_5); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_6, &_7); zephir_check_call_status(); RETURN_MM(); } @@ -1889,8 +2127,8 @@ PHP_METHOD(Tensor_Matrix, transpose) */ PHP_METHOD(Tensor_Matrix, inverse) { - zval _6$$4, _9$$5; - zval _0, _4, result, _7, _1$$3, _2$$3, _3$$3, _5$$4, _8$$5; + zval _6$$4, _10$$5; + zval _0, _4, result, _7, _8, _11, _12, _1$$3, _2$$3, _3$$3, _5$$4, _9$$5; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); @@ -1899,63 +2137,74 @@ PHP_METHOD(Tensor_Matrix, inverse) ZVAL_UNDEF(&_4); ZVAL_UNDEF(&result); ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_11); + ZVAL_UNDEF(&_12); ZVAL_UNDEF(&_1$$3); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$4); - ZVAL_UNDEF(&_8$$5); - ZVAL_UNDEF(&_6$$4); ZVAL_UNDEF(&_9$$5); + ZVAL_UNDEF(&_6$$4); + ZVAL_UNDEF(&_10$$5); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "issquare", NULL, 0); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "isSquare", NULL, 0); zephir_check_call_status(); if (UNEXPECTED(!zephir_is_true(&_0))) { ZEPHIR_INIT_VAR(&_1$$3); object_init_ex(&_1$$3, tensor_exceptions_invalidargumentexception_ce); - ZEPHIR_CALL_METHOD(&_2$$3, this_ptr, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_2$$3, this_ptr, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3$$3); ZEPHIR_CONCAT_SSVS(&_3$$3, "Matrix must be", " square, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 3, &_3$$3); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/matrix.zep", 642); + zephir_throw_exception_debug(&_1$$3, "tensor/matrix.zep", 717); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_CALL_METHOD(&_4, this_ptr, "fullrank", NULL, 0); + ZEPHIR_CALL_METHOD(&_4, this_ptr, "fullRank", NULL, 0); zephir_check_call_status(); if (UNEXPECTED(!zephir_is_true(&_4))) { ZEPHIR_INIT_VAR(&_5$$4); object_init_ex(&_5$$4, tensor_exceptions_runtimeexception_ce); ZEPHIR_INIT_VAR(&_6$$4); ZEPHIR_CONCAT_SS(&_6$$4, "Failed to compute the inverse", " of a singular matrix."); - ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 32, &_6$$4); + ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 25, &_6$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 647); + zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 722); ZEPHIR_MM_RESTORE(); return; } ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_7, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - tensor_inverse(&result, &_7); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + tensor_inverse(&result, &_7, &_8); if (Z_TYPE_P(&result) == IS_NULL) { - ZEPHIR_INIT_VAR(&_8$$5); - object_init_ex(&_8$$5, tensor_exceptions_runtimeexception_ce); ZEPHIR_INIT_VAR(&_9$$5); - ZEPHIR_CONCAT_SS(&_9$$5, "Failed to compute the inverse", " of a singular matrix."); - ZEPHIR_CALL_METHOD(NULL, &_8$$5, "__construct", NULL, 32, &_9$$5); + object_init_ex(&_9$$5, tensor_exceptions_runtimeexception_ce); + ZEPHIR_INIT_VAR(&_10$$5); + ZEPHIR_CONCAT_SS(&_10$$5, "Failed to compute the inverse", " of a singular matrix."); + ZEPHIR_CALL_METHOD(NULL, &_9$$5, "__construct", NULL, 25, &_10$$5); zephir_check_call_status(); - zephir_throw_exception_debug(&_8$$5, "tensor/matrix.zep", 654); + zephir_throw_exception_debug(&_9$$5, "tensor/matrix.zep", 729); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &result); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_12, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_11, &_12); zephir_check_call_status(); RETURN_MM(); } @@ -1967,38 +2216,55 @@ PHP_METHOD(Tensor_Matrix, inverse) */ PHP_METHOD(Tensor_Matrix, pseudoinverse) { - zval _2$$3; - zval result, _0, _1$$3; + zval _4$$3; + zval result, _0, _1, _2, _5, _6, _3$$3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_1$$3); - ZVAL_UNDEF(&_2$$3); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_3$$3); + ZVAL_UNDEF(&_4$$3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - tensor_pseudoinverse(&result, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_pseudoinverse(&result, &_0, &_1, &_2); if (Z_TYPE_P(&result) == IS_NULL) { - ZEPHIR_INIT_VAR(&_1$$3); - object_init_ex(&_1$$3, tensor_exceptions_runtimeexception_ce); - ZEPHIR_INIT_VAR(&_2$$3); - ZEPHIR_CONCAT_SS(&_2$$3, "Failed to compute the pseudoinverse", " of the matrix."); - ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 32, &_2$$3); + ZEPHIR_INIT_VAR(&_3$$3); + object_init_ex(&_3$$3, tensor_exceptions_runtimeexception_ce); + ZEPHIR_INIT_VAR(&_4$$3); + ZEPHIR_CONCAT_SS(&_4$$3, "Failed to compute the pseudoinverse", " of the matrix."); + ZEPHIR_CALL_METHOD(NULL, &_3$$3, "__construct", NULL, 25, &_4$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/matrix.zep", 671); + zephir_throw_exception_debug(&_3$$3, "tensor/matrix.zep", 746); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &result); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_5, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_5, &_6); zephir_check_call_status(); RETURN_MM(); } @@ -2030,18 +2296,18 @@ PHP_METHOD(Tensor_Matrix, det) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "issquare", NULL, 0); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "isSquare", NULL, 0); zephir_check_call_status(); if (UNEXPECTED(!zephir_is_true(&_0))) { ZEPHIR_INIT_VAR(&_1$$3); object_init_ex(&_1$$3, tensor_exceptions_invalidargumentexception_ce); - ZEPHIR_CALL_METHOD(&_2$$3, this_ptr, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_2$$3, this_ptr, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3$$3); ZEPHIR_CONCAT_SSVS(&_3$$3, "Matrix must be", " square, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 3, &_3$$3); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/matrix.zep", 687); + zephir_throw_exception_debug(&_1$$3, "tensor/matrix.zep", 762); ZEPHIR_MM_RESTORE(); return; } @@ -2049,14 +2315,14 @@ PHP_METHOD(Tensor_Matrix, det) zephir_check_call_status(); ZEPHIR_CALL_METHOD(&_4, &ref, "a", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_5, &_4, "diagonalasvector", NULL, 0); + ZEPHIR_CALL_METHOD(&_5, &_4, "diagonalAsVector", NULL, 0); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&pi, &_5, "product", NULL, 0); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&_6, &ref, "swaps", NULL, 0); zephir_check_call_status(); ZVAL_DOUBLE(&_7, -1.0); - ZEPHIR_CALL_FUNCTION(&_8, "pow", NULL, 16, &_7, &_6); + ZEPHIR_CALL_FUNCTION(&_8, "pow", NULL, 17, &_7, &_6); zephir_check_call_status(); mul_function(return_value, &pi, &_8); RETURN_MM(); @@ -2078,7 +2344,7 @@ PHP_METHOD(Tensor_Matrix, trace) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "diagonalasvector", NULL, 0); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "diagonalAsVector", NULL, 0); zephir_check_call_status(); ZEPHIR_RETURN_CALL_METHOD(&_0, "sum", NULL, 0); zephir_check_call_status(); @@ -2092,103 +2358,31 @@ PHP_METHOD(Tensor_Matrix, trace) */ PHP_METHOD(Tensor_Matrix, rank) { - double epsilon; - zend_bool stop = 0, _11$$3; - zval a, _3; - zval rowA, valueA, _0, _1, _2, *_4, *_5$$3, _6$$3, *_7$$3, _10$$3, _8$$4, _12$$7; + zval rref, _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zephir_fcall_cache_entry *_9 = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS, pivots; + zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); - ZVAL_UNDEF(&valueA); + ZVAL_UNDEF(&rref); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_6$$3); - ZVAL_UNDEF(&_10$$3); - ZVAL_UNDEF(&_8$$4); - ZVAL_UNDEF(&_12$$7); - ZVAL_UNDEF(&a); ZVAL_UNDEF(&_3); ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_INIT_VAR(&a); - array_init(&a); ZEPHIR_CALL_METHOD(&_0, this_ptr, "rref", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_1, &_0, "a", NULL, 0); + ZEPHIR_CALL_METHOD(&rref, &_0, "a", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_2, &_1, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&_1, &rref, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - zephir_get_arrval(&_3, &_2); - ZEPHIR_CPY_WRT(&a, &_3); - pivots = 0; - epsilon = (0.00000001); - zephir_is_iterable(&a, 0, "tensor/matrix.zep", 742); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&a), _4) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _4); - stop = 0; - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_6$$3); - zephir_string_to_char_array(&_6$$3, &rowA); - _5$$3 = &_6$$3; - } else { - _5$$3 = &rowA; - } - zephir_is_iterable(_5$$3, 0, "tensor/matrix.zep", 740); - if (Z_TYPE_P(_5$$3) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_5$$3), _7$$3) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _7$$3); - if (stop) { - continue; - } - ZEPHIR_CALL_FUNCTION(&_8$$4, "abs", &_9, 12, &valueA); - zephir_check_call_status(); - if (!ZEPHIR_LT_DOUBLE(&_8$$4, epsilon)) { - pivots++; - stop = 1; - } - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _5$$3, "rewind", NULL, 0); - zephir_check_call_status(); - _11$$3 = 1; - while (1) { - if (_11$$3) { - _11$$3 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _5$$3, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_10$$3, _5$$3, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_10$$3)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _5$$3, "current", NULL, 0); - zephir_check_call_status(); - if (stop) { - continue; - } - ZEPHIR_CALL_FUNCTION(&_12$$7, "abs", &_9, 12, &valueA); - zephir_check_call_status(); - if (!ZEPHIR_LT_DOUBLE(&_12$$7, epsilon)) { - pivots++; - stop = 1; - } - } - } - ZEPHIR_INIT_NVAR(&valueA); - } ZEND_HASH_FOREACH_END(); - ZEPHIR_INIT_NVAR(&rowA); - RETURN_MM_LONG(pivots); + ZEPHIR_CALL_METHOD(&_2, &rref, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_3, &rref, "n", NULL, 0); + zephir_check_call_status(); + tensor_rank(return_value, &_1, &_2, &_3); + RETURN_MM(); } /** @@ -2213,7 +2407,7 @@ PHP_METHOD(Tensor_Matrix, fullRank) zephir_check_call_status(); ZEPHIR_CALL_METHOD(&_1, this_ptr, "shape", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_FUNCTION(&_2, "min", NULL, 19, &_1); + ZEPHIR_CALL_FUNCTION(&_2, "min", NULL, 26, &_1); zephir_check_call_status(); RETURN_MM_BOOL(ZEPHIR_IS_IDENTICAL(&_0, &_2)); } @@ -2225,89 +2419,34 @@ PHP_METHOD(Tensor_Matrix, fullRank) */ PHP_METHOD(Tensor_Matrix, symmetric) { - zend_bool _2, _7$$4; - zval _0, rowA, _1, _5$$4, _6$$4, _10$$5, _11$$5, _12$$5, _13$$5; + zval _0, _1, _2; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS, i = 0, j = 0, _3, _4, _8$$4, _9$$4; + zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&_5$$4); - ZVAL_UNDEF(&_6$$4); - ZVAL_UNDEF(&_10$$5); - ZVAL_UNDEF(&_11$$5); - ZVAL_UNDEF(&_12$$5); - ZVAL_UNDEF(&_13$$5); + ZVAL_UNDEF(&_2); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; - static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("m", 1, 1); + _zephir_prop_0 = zend_string_init("a", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { - _zephir_prop_1 = zend_string_init("a", 1, 1); - } - if (UNEXPECTED(!_zephir_prop_2)) { - _zephir_prop_2 = zend_string_init("n", 1, 1); + _zephir_prop_1 = zend_string_init("n", 1, 1); } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "issquare", NULL, 0); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "isSquare", NULL, 0); zephir_check_call_status(); if (!(zephir_is_true(&_0))) { RETURN_MM_BOOL(0); } - zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); - _4 = (zephir_get_numberval(&_1) - 2); - _3 = 0; - _2 = 0; - if (_3 <= _4) { - while (1) { - if (_2) { - _3++; - if (!(_3 <= _4)) { - break; - } - } else { - _2 = 1; - } - i = _3; - zephir_read_property_cached(&_5$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&rowA); - zephir_array_fetch_long(&rowA, &_5$$4, i, PH_NOISY, "tensor/matrix.zep", 771); - zephir_read_property_cached(&_6$$4, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); - _9$$4 = (zephir_get_numberval(&_6$$4) - 1); - _8$$4 = (i + 1); - _7$$4 = 0; - if (_8$$4 <= _9$$4) { - while (1) { - if (_7$$4) { - _8$$4++; - if (!(_8$$4 <= _9$$4)) { - break; - } - } else { - _7$$4 = 1; - } - j = _8$$4; - ZEPHIR_OBS_NVAR(&_10$$5); - zephir_array_fetch_long(&_10$$5, &rowA, j, PH_NOISY, "tensor/matrix.zep", 774); - zephir_read_property_cached(&_11$$5, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_12$$5); - zephir_array_fetch_long(&_12$$5, &_11$$5, j, PH_NOISY, "tensor/matrix.zep", 774); - ZEPHIR_OBS_NVAR(&_13$$5); - zephir_array_fetch_long(&_13$$5, &_12$$5, i, PH_NOISY, "tensor/matrix.zep", 774); - if (!ZEPHIR_IS_EQUAL(&_10$$5, &_13$$5)) { - RETURN_MM_BOOL(0); - } - } - } - } - } - RETURN_MM_BOOL(1); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + tensor_is_symmetric(return_value, &_1, &_2); + RETURN_MM(); } /** @@ -2322,15 +2461,20 @@ PHP_METHOD(Tensor_Matrix, matmul) zval _4$$3, _6$$3, _7$$3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, _8, _9, _10, _2$$3, _3$$3, _5$$3; + zval *b, b_sub, _0, _1, result, _8, _9, _10, _11, _12, _13, _14, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); + ZVAL_UNDEF(&_11); + ZVAL_UNDEF(&_12); + ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_14); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); @@ -2339,12 +2483,16 @@ PHP_METHOD(Tensor_Matrix, matmul) ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) @@ -2366,18 +2514,25 @@ PHP_METHOD(Tensor_Matrix, matmul) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A requires ", &_4$$3, " rows but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 795); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 830); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&_8); - zephir_read_property_cached(&_9, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_10, b, "asarray", NULL, 0); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_12, b, "n", NULL, 0); + zephir_check_call_status(); + tensor_matmul(&result, &_8, &_9, &_10, &_11, &_12); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_13, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_14, b, "n", NULL, 0); zephir_check_call_status(); - tensor_matmul(&_8, &_9, &_10); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_13, &_14); zephir_check_call_status(); RETURN_MM(); } @@ -2394,7 +2549,7 @@ PHP_METHOD(Tensor_Matrix, dot) zval _4$$3, _6$$3, _7$$3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, _8, _9, _10, _2$$3, _3$$3, _5$$3; + zval *b, b_sub, _0, _1, _8, _9, _10, _11, _12, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); @@ -2403,6 +2558,8 @@ PHP_METHOD(Tensor_Matrix, dot) ZVAL_UNDEF(&_8); ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); + ZVAL_UNDEF(&_11); + ZVAL_UNDEF(&_12); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); @@ -2410,9 +2567,17 @@ PHP_METHOD(Tensor_Matrix, dot) ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\vector"))) @@ -2434,18 +2599,21 @@ PHP_METHOD(Tensor_Matrix, dot) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 813); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 850); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_CALL_METHOD(&_9, b, "ascolumnmatrix", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_8, this_ptr, "matmul", NULL, 0, &_9); + object_init_ex(return_value, tensor_columnvector_ce); + ZEPHIR_INIT_VAR(&_8); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_10, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - ZVAL_LONG(&_10, 0); - ZEPHIR_RETURN_CALL_METHOD(&_8, "columnasvector", NULL, 0, &_10); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_12, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + tensor_matrix_dot(&_8, &_9, &_10, &_11, &_12); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -2463,8 +2631,8 @@ PHP_METHOD(Tensor_Matrix, convolve) zval _6$$3; zend_bool _2; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long stride, ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, *stride_param = NULL, _0, _1, _3, _4, _11, _12, _13, _14, _5$$3, _7$$4, _8$$4, _9$$4, _10$$4; + zend_long stride, ZEPHIR_LAST_CALL_STATUS, outM, outN; + zval *b, b_sub, *stride_param = NULL, _0, _1, _3, _4, result, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _5$$3, _7$$4, _8$$4, _9$$4, _10$$4; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); @@ -2472,10 +2640,20 @@ PHP_METHOD(Tensor_Matrix, convolve) ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_3); ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_12); ZVAL_UNDEF(&_13); ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_15); + ZVAL_UNDEF(&_16); + ZVAL_UNDEF(&_17); + ZVAL_UNDEF(&_18); + ZVAL_UNDEF(&_19); + ZVAL_UNDEF(&_20); + ZVAL_UNDEF(&_21); + ZVAL_UNDEF(&_22); + ZVAL_UNDEF(&_23); ZVAL_UNDEF(&_5$$3); ZVAL_UNDEF(&_7$$4); ZVAL_UNDEF(&_8$$4); @@ -2522,9 +2700,9 @@ PHP_METHOD(Tensor_Matrix, convolve) object_init_ex(&_5$$3, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_6$$3); ZEPHIR_CONCAT_SS(&_6$$3, "Matrix B cannot be", " larger than Matrix A."); - ZEPHIR_CALL_METHOD(NULL, &_5$$3, "__construct", NULL, 3, &_6$$3); + ZEPHIR_CALL_METHOD(NULL, &_5$$3, "__construct", NULL, 2, &_6$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$3, "tensor/matrix.zep", 831); + zephir_throw_exception_debug(&_5$$3, "tensor/matrix.zep", 868); ZEPHIR_MM_RESTORE(); return; } @@ -2532,23 +2710,43 @@ PHP_METHOD(Tensor_Matrix, convolve) ZEPHIR_INIT_VAR(&_7$$4); object_init_ex(&_7$$4, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_8$$4, stride); - ZEPHIR_CALL_FUNCTION(&_9$$4, "strval", NULL, 4, &_8$$4); + ZEPHIR_CALL_FUNCTION(&_9$$4, "strval", NULL, 3, &_8$$4); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_10$$4); ZEPHIR_CONCAT_SSVS(&_10$$4, "Stride cannot be", " less than 1, ", &_9$$4, " given."); - ZEPHIR_CALL_METHOD(NULL, &_7$$4, "__construct", NULL, 3, &_10$$4); + ZEPHIR_CALL_METHOD(NULL, &_7$$4, "__construct", NULL, 2, &_10$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_7$$4, "tensor/matrix.zep", 836); + zephir_throw_exception_debug(&_7$$4, "tensor/matrix.zep", 873); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&_11); - zephir_read_property_cached(&_12, this_ptr, _zephir_prop_2, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_13, b, "asarray", NULL, 0); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_2, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_12, b, _zephir_prop_2, 0, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_13, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_14, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_15, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_16, b, "n", NULL, 0); + zephir_check_call_status(); + ZVAL_LONG(&_17, stride); + tensor_convolve_2d(&result, &_11, &_12, &_17, &_13, &_14, &_15, &_16); + zephir_read_property_cached(&_18, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_19, ((zephir_get_numberval(&_18) + stride) - 1)); + ZVAL_LONG(&_20, stride); + ZEPHIR_CALL_FUNCTION(&_21, "intdiv", NULL, 27, &_19, &_20); zephir_check_call_status(); - ZVAL_LONG(&_14, stride); - tensor_convolve_2d(&_11, &_12, &_13, &_14); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &_11); + outM = zephir_get_intval(&_21); + zephir_read_property_cached(&_19, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_20, ((zephir_get_numberval(&_19) + stride) - 1)); + ZVAL_LONG(&_22, stride); + ZEPHIR_CALL_FUNCTION(&_23, "intdiv", NULL, 27, &_20, &_22); + zephir_check_call_status(); + outN = zephir_get_intval(&_23); + object_init_ex(return_value, tensor_matrix_ce); + ZVAL_LONG(&_20, outM); + ZVAL_LONG(&_22, outN); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_20, &_22); zephir_check_call_status(); RETURN_MM(); } @@ -2828,15 +3026,15 @@ PHP_METHOD(Tensor_Matrix, multiply) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_2; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplymatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplyMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplycolumnvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplyColumnVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplyvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplyVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -2844,7 +3042,7 @@ PHP_METHOD(Tensor_Matrix, multiply) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplyscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplyScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -2853,9 +3051,9 @@ PHP_METHOD(Tensor_Matrix, multiply) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot multiply", " matrix by the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 975); + zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1017); ZEPHIR_MM_RESTORE(); return; } @@ -2899,15 +3097,15 @@ PHP_METHOD(Tensor_Matrix, divide) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_2; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "dividematrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "divideMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "dividecolumnvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "divideColumnVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "dividevector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "divideVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -2915,7 +3113,7 @@ PHP_METHOD(Tensor_Matrix, divide) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "dividescalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "divideScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -2924,9 +3122,9 @@ PHP_METHOD(Tensor_Matrix, divide) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot divide", " matrix by the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1008); + zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1050); ZEPHIR_MM_RESTORE(); return; } @@ -2971,15 +3169,15 @@ PHP_METHOD(Tensor_Matrix, add) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_2; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "addmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "addMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "addcolumnvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "addColumnVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "addvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "addVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -2987,7 +3185,7 @@ PHP_METHOD(Tensor_Matrix, add) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "addscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "addScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -2996,9 +3194,9 @@ PHP_METHOD(Tensor_Matrix, add) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot add", " matrix with the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1042); + zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1084); ZEPHIR_MM_RESTORE(); return; } @@ -3043,15 +3241,15 @@ PHP_METHOD(Tensor_Matrix, subtract) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_2; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "subtractmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "subtractMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "subtractcolumnvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "subtractColumnVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "subtractvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "subtractVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -3059,7 +3257,7 @@ PHP_METHOD(Tensor_Matrix, subtract) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "subtractscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "subtractScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -3068,9 +3266,9 @@ PHP_METHOD(Tensor_Matrix, subtract) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot subtract", " matrix with the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1076); + zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1118); ZEPHIR_MM_RESTORE(); return; } @@ -3115,15 +3313,15 @@ PHP_METHOD(Tensor_Matrix, pow) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_2; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "powmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "powMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "powcolumnvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "powColumnVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "powvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "powVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -3131,7 +3329,7 @@ PHP_METHOD(Tensor_Matrix, pow) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "powscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "powScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -3140,9 +3338,9 @@ PHP_METHOD(Tensor_Matrix, pow) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot raise", " matrix to the power of the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1110); + zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1152); ZEPHIR_MM_RESTORE(); return; } @@ -3187,15 +3385,15 @@ PHP_METHOD(Tensor_Matrix, mod) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_2; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "modmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "modMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "modcolumnvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "modColumnVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "modvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "modVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -3203,7 +3401,7 @@ PHP_METHOD(Tensor_Matrix, mod) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "modscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "modScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -3212,9 +3410,9 @@ PHP_METHOD(Tensor_Matrix, mod) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot mod", " matrix with the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1144); + zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1186); ZEPHIR_MM_RESTORE(); return; } @@ -3259,15 +3457,15 @@ PHP_METHOD(Tensor_Matrix, equal) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_2; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "equalmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "equalMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "equalcolumnvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "equalColumnVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "equalvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "equalVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -3275,7 +3473,7 @@ PHP_METHOD(Tensor_Matrix, equal) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "equalscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "equalScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -3284,9 +3482,9 @@ PHP_METHOD(Tensor_Matrix, equal) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot compare", " matrix to the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1178); + zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1220); ZEPHIR_MM_RESTORE(); return; } @@ -3331,15 +3529,15 @@ PHP_METHOD(Tensor_Matrix, notEqual) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_2; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "notequalmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "notEqualMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "notequalcolumnvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "notEqualColumnVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "notequalvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "notEqualVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -3347,7 +3545,7 @@ PHP_METHOD(Tensor_Matrix, notEqual) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "notequalscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "notEqualScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -3356,9 +3554,9 @@ PHP_METHOD(Tensor_Matrix, notEqual) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot compare", " matrix to the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1212); + zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1254); ZEPHIR_MM_RESTORE(); return; } @@ -3403,15 +3601,15 @@ PHP_METHOD(Tensor_Matrix, greater) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_2; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greatermatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greatercolumnvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterColumnVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greatervector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -3419,7 +3617,7 @@ PHP_METHOD(Tensor_Matrix, greater) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -3428,9 +3626,9 @@ PHP_METHOD(Tensor_Matrix, greater) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot compare", " matrix to the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1246); + zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1288); ZEPHIR_MM_RESTORE(); return; } @@ -3475,15 +3673,15 @@ PHP_METHOD(Tensor_Matrix, greaterEqual) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_2; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterequalmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterEqualMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterequalcolumnvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterEqualColumnVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterequalvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterEqualVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -3491,7 +3689,7 @@ PHP_METHOD(Tensor_Matrix, greaterEqual) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterequalscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterEqualScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -3500,9 +3698,9 @@ PHP_METHOD(Tensor_Matrix, greaterEqual) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot compare", " matrix to the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1280); + zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1322); ZEPHIR_MM_RESTORE(); return; } @@ -3547,15 +3745,15 @@ PHP_METHOD(Tensor_Matrix, less) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_2; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lesscolumnvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessColumnVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -3563,7 +3761,7 @@ PHP_METHOD(Tensor_Matrix, less) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -3572,9 +3770,9 @@ PHP_METHOD(Tensor_Matrix, less) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot compare", " matrix to the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1314); + zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1356); ZEPHIR_MM_RESTORE(); return; } @@ -3619,15 +3817,15 @@ PHP_METHOD(Tensor_Matrix, lessEqual) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_2; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessequalmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessEqualMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessequalcolumnvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessEqualColumnVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessequalvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessEqualVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -3635,7 +3833,7 @@ PHP_METHOD(Tensor_Matrix, lessEqual) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessequalscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessEqualScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -3644,9 +3842,9 @@ PHP_METHOD(Tensor_Matrix, lessEqual) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot compare", " matrix to the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1348); + zephir_throw_exception_debug(&_2, "tensor/matrix.zep", 1390); ZEPHIR_MM_RESTORE(); return; } @@ -3681,7 +3879,7 @@ PHP_METHOD(Tensor_Matrix, reciprocal) zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); ZEPHIR_CALL_SELF(&_0, "ones", NULL, 0, &_1, &_2); zephir_check_call_status(); - ZEPHIR_RETURN_CALL_METHOD(&_0, "dividematrix", NULL, 0, this_ptr); + ZEPHIR_RETURN_CALL_METHOD(&_0, "divideMatrix", NULL, 0, this_ptr); zephir_check_call_status(); RETURN_MM(); } @@ -3693,18 +3891,37 @@ PHP_METHOD(Tensor_Matrix, reciprocal) */ PHP_METHOD(Tensor_Matrix, abs) { - zval _0; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "abs"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_abs(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -3722,7 +3939,7 @@ PHP_METHOD(Tensor_Matrix, square) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplymatrix", NULL, 0, this_ptr); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplyMatrix", NULL, 0, this_ptr); zephir_check_call_status(); RETURN_MM(); } @@ -3734,18 +3951,37 @@ PHP_METHOD(Tensor_Matrix, square) */ PHP_METHOD(Tensor_Matrix, sqrt) { - zval _0; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "sqrt"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_sqrt(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -3757,18 +3993,37 @@ PHP_METHOD(Tensor_Matrix, sqrt) */ PHP_METHOD(Tensor_Matrix, exp) { - zval _0; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "exp"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_exp(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -3780,18 +4035,37 @@ PHP_METHOD(Tensor_Matrix, exp) */ PHP_METHOD(Tensor_Matrix, expm1) { - zval _0; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "expm1"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_expm1(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -3804,39 +4078,33 @@ PHP_METHOD(Tensor_Matrix, expm1) */ PHP_METHOD(Tensor_Matrix, log) { - zend_bool _16, _12$$4, _23$$7; - zval rowB, b; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zephir_fcall_cache_entry *_10 = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *base_param = NULL, _0$$3, rowA, valueA, _1, *_2, _3, *_4, _15, *_5$$4, _6$$4, *_7$$4, _11$$4, _8$$5, _9$$5, _13$$6, _14$$6, *_17$$7, _18$$7, *_19$$7, _22$$7, _20$$8, _21$$8, _24$$9, _25$$9; + zval *base_param = NULL, _0$$3, _1$$3, _2$$3, _3$$3, _4, _5, _6, _7, _8; double base; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0$$3); - ZVAL_UNDEF(&rowA); - ZVAL_UNDEF(&valueA); - ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&_3); - ZVAL_UNDEF(&_15); - ZVAL_UNDEF(&_6$$4); - ZVAL_UNDEF(&_11$$4); - ZVAL_UNDEF(&_8$$5); - ZVAL_UNDEF(&_9$$5); - ZVAL_UNDEF(&_13$$6); - ZVAL_UNDEF(&_14$$6); - ZVAL_UNDEF(&_18$$7); - ZVAL_UNDEF(&_22$$7); - ZVAL_UNDEF(&_20$$8); - ZVAL_UNDEF(&_21$$8); - ZVAL_UNDEF(&_24$$9); - ZVAL_UNDEF(&_25$$9); - ZVAL_UNDEF(&rowB); - ZVAL_UNDEF(&b); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); + ZVAL_UNDEF(&_3$$3); + ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_8); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL @@ -3851,168 +4119,66 @@ PHP_METHOD(Tensor_Matrix, log) base = zephir_get_doubleval(base_param); } if (base == 2.7182818284590452354) { + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0$$3); - ZVAL_STRING(&_0$$3, "log"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0$$3); + zephir_read_property_cached(&_1$$3, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_log(&_0$$3, &_1$$3); + zephir_read_property_cached(&_2$$3, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3$$3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0$$3, &_2$$3, &_3$$3); zephir_check_call_status(); RETURN_MM(); } - ZEPHIR_INIT_VAR(&rowB); - array_init(&rowB); - ZEPHIR_INIT_VAR(&b); - array_init(&b); - zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_1) == IS_STRING) { - ZEPHIR_INIT_VAR(&_3); - zephir_string_to_char_array(&_3, &_1); - _2 = &_3; - } else { - _2 = &_1; + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_INIT_VAR(&_4); + zephir_read_property_cached(&_5, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + ZVAL_DOUBLE(&_6, base); + tensor_log_base(&_4, &_5, &_6); + zephir_read_property_cached(&_7, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_4, &_7, &_8); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return the log of 1 plus the tensor i.e. a transform. + * + * @return self + */ +PHP_METHOD(Tensor_Matrix, log1p) +{ + zval _0, _1, _2, _3; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); } - zephir_is_iterable(_2, 0, "tensor/matrix.zep", 1439); - if (Z_TYPE_P(_2) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_2), _4) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _4); - ZEPHIR_INIT_NVAR(&rowB); - array_init(&rowB); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_6$$4); - zephir_string_to_char_array(&_6$$4, &rowA); - _5$$4 = &_6$$4; - } else { - _5$$4 = &rowA; - } - zephir_is_iterable(_5$$4, 0, "tensor/matrix.zep", 1436); - if (Z_TYPE_P(_5$$4) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_5$$4), _7$$4) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _7$$4); - ZVAL_DOUBLE(&_8$$5, base); - ZEPHIR_CALL_FUNCTION(&_9$$5, "log", &_10, 8, &valueA, &_8$$5); - zephir_check_call_status(); - zephir_array_append(&rowB, &_9$$5, PH_SEPARATE, "tensor/matrix.zep", 1433); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _5$$4, "rewind", NULL, 0); - zephir_check_call_status(); - _12$$4 = 1; - while (1) { - if (_12$$4) { - _12$$4 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _5$$4, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_11$$4, _5$$4, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_11$$4)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _5$$4, "current", NULL, 0); - zephir_check_call_status(); - ZVAL_DOUBLE(&_13$$6, base); - ZEPHIR_CALL_FUNCTION(&_14$$6, "log", &_10, 8, &valueA, &_13$$6); - zephir_check_call_status(); - zephir_array_append(&rowB, &_14$$6, PH_SEPARATE, "tensor/matrix.zep", 1433); - } - } - ZEPHIR_INIT_NVAR(&valueA); - zephir_array_append(&b, &rowB, PH_SEPARATE, "tensor/matrix.zep", 1436); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _2, "rewind", NULL, 0); - zephir_check_call_status(); - _16 = 1; - while (1) { - if (_16) { - _16 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _2, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_15, _2, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_15)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _2, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&rowB); - array_init(&rowB); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_18$$7); - zephir_string_to_char_array(&_18$$7, &rowA); - _17$$7 = &_18$$7; - } else { - _17$$7 = &rowA; - } - zephir_is_iterable(_17$$7, 0, "tensor/matrix.zep", 1436); - if (Z_TYPE_P(_17$$7) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_17$$7), _19$$7) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _19$$7); - ZVAL_DOUBLE(&_20$$8, base); - ZEPHIR_CALL_FUNCTION(&_21$$8, "log", &_10, 8, &valueA, &_20$$8); - zephir_check_call_status(); - zephir_array_append(&rowB, &_21$$8, PH_SEPARATE, "tensor/matrix.zep", 1433); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _17$$7, "rewind", NULL, 0); - zephir_check_call_status(); - _23$$7 = 1; - while (1) { - if (_23$$7) { - _23$$7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _17$$7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_22$$7, _17$$7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_22$$7)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _17$$7, "current", NULL, 0); - zephir_check_call_status(); - ZVAL_DOUBLE(&_24$$9, base); - ZEPHIR_CALL_FUNCTION(&_25$$9, "log", &_10, 8, &valueA, &_24$$9); - zephir_check_call_status(); - zephir_array_append(&rowB, &_25$$9, PH_SEPARATE, "tensor/matrix.zep", 1433); - } - } - ZEPHIR_INIT_NVAR(&valueA); - zephir_array_append(&b, &rowB, PH_SEPARATE, "tensor/matrix.zep", 1436); - } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &b); - zephir_check_call_status(); - RETURN_MM(); -} - -/** - * Return the log of 1 plus the tensor i.e. a transform. - * - * @return self - */ -PHP_METHOD(Tensor_Matrix, log1p) -{ - zval _0; - zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS; - zval *this_ptr = getThis(); - - ZVAL_UNDEF(&_0); ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "log1p"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_log1p(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -4024,18 +4190,37 @@ PHP_METHOD(Tensor_Matrix, log1p) */ PHP_METHOD(Tensor_Matrix, sin) { - zval _0; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "sin"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_sin(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -4047,18 +4232,37 @@ PHP_METHOD(Tensor_Matrix, sin) */ PHP_METHOD(Tensor_Matrix, asin) { - zval _0; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "asin"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_asin(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -4070,18 +4274,37 @@ PHP_METHOD(Tensor_Matrix, asin) */ PHP_METHOD(Tensor_Matrix, cos) { - zval _0; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "cos"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_cos(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -4093,18 +4316,37 @@ PHP_METHOD(Tensor_Matrix, cos) */ PHP_METHOD(Tensor_Matrix, acos) { - zval _0; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "acos"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_acos(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -4116,18 +4358,37 @@ PHP_METHOD(Tensor_Matrix, acos) */ PHP_METHOD(Tensor_Matrix, tan) { - zval _0; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "tan"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_tan(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -4139,18 +4400,37 @@ PHP_METHOD(Tensor_Matrix, tan) */ PHP_METHOD(Tensor_Matrix, atan) { - zval _0; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "atan"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_atan(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -4162,18 +4442,37 @@ PHP_METHOD(Tensor_Matrix, atan) */ PHP_METHOD(Tensor_Matrix, rad2deg) { - zval _0; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "rad2deg"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_rad2deg(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -4185,18 +4484,37 @@ PHP_METHOD(Tensor_Matrix, rad2deg) */ PHP_METHOD(Tensor_Matrix, deg2rad) { - zval _0; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "deg2rad"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_deg2rad(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -4208,7 +4526,7 @@ PHP_METHOD(Tensor_Matrix, deg2rad) */ PHP_METHOD(Tensor_Matrix, sum) { - zval _0, _1, _2; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); @@ -4216,19 +4534,29 @@ PHP_METHOD(Tensor_Matrix, sum) ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_INIT_VAR(&_1); - ZVAL_STRING(&_1, "array_sum"); - ZEPHIR_CALL_FUNCTION(&_2, "array_map", NULL, 14, &_1, &_0); - zephir_check_call_status(); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_columnvector_ce, "quick", NULL, 0, &_2); + object_init_ex(return_value, tensor_columnvector_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_reduce_sum(&_0, &_1, &_2, &_3); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -4240,7 +4568,7 @@ PHP_METHOD(Tensor_Matrix, sum) */ PHP_METHOD(Tensor_Matrix, product) { - zval _0, _1, _2; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); @@ -4248,19 +4576,29 @@ PHP_METHOD(Tensor_Matrix, product) ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_INIT_VAR(&_1); - ZVAL_STRING(&_1, "array_product"); - ZEPHIR_CALL_FUNCTION(&_2, "array_map", NULL, 14, &_1, &_0); - zephir_check_call_status(); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_columnvector_ce, "quick", NULL, 0, &_2); + object_init_ex(return_value, tensor_columnvector_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_reduce_product(&_0, &_1, &_2, &_3); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -4272,7 +4610,7 @@ PHP_METHOD(Tensor_Matrix, product) */ PHP_METHOD(Tensor_Matrix, min) { - zval _0, _1, _2; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); @@ -4280,19 +4618,29 @@ PHP_METHOD(Tensor_Matrix, min) ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_INIT_VAR(&_1); - ZVAL_STRING(&_1, "min"); - ZEPHIR_CALL_FUNCTION(&_2, "array_map", NULL, 14, &_1, &_0); - zephir_check_call_status(); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_columnvector_ce, "quick", NULL, 0, &_2); + object_init_ex(return_value, tensor_columnvector_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_reduce_min(&_0, &_1, &_2, &_3); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -4304,7 +4652,7 @@ PHP_METHOD(Tensor_Matrix, min) */ PHP_METHOD(Tensor_Matrix, max) { - zval _0, _1, _2; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); @@ -4312,25 +4660,119 @@ PHP_METHOD(Tensor_Matrix, max) ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_INIT_VAR(&_1); - ZVAL_STRING(&_1, "max"); - ZEPHIR_CALL_FUNCTION(&_2, "array_map", NULL, 14, &_1, &_0); - zephir_check_call_status(); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_columnvector_ce, "quick", NULL, 0, &_2); + object_init_ex(return_value, tensor_columnvector_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_reduce_max(&_0, &_1, &_2, &_3); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } /** - * Compute the means of each row and return them in a vector. + * Return the index of the minimum of each row in the matrix. + * + * @return \Tensor\ColumnVector + */ +PHP_METHOD(Tensor_Matrix, argmin) +{ + zval _0, _1, _2, _3; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + object_init_ex(return_value, tensor_columnvector_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_reduce_argmin(&_0, &_1, &_2, &_3); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return the index of the maximum of each row in the matrix. + * + * @return \Tensor\ColumnVector + */ +PHP_METHOD(Tensor_Matrix, argmax) +{ + zval _0, _1, _2, _3; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + object_init_ex(return_value, tensor_columnvector_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_reduce_argmax(&_0, &_1, &_2, &_3); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Compute the means of each row and return them in a vector. * * @return \Tensor\ColumnVector */ @@ -4353,7 +4795,7 @@ PHP_METHOD(Tensor_Matrix, mean) ZEPHIR_CALL_METHOD(&_0, this_ptr, "sum", NULL, 0); zephir_check_call_status(); zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); - ZEPHIR_RETURN_CALL_METHOD(&_0, "dividescalar", NULL, 0, &_1); + ZEPHIR_RETURN_CALL_METHOD(&_0, "divideScalar", NULL, 0, &_1); zephir_check_call_status(); RETURN_MM(); } @@ -4365,122 +4807,31 @@ PHP_METHOD(Tensor_Matrix, mean) */ PHP_METHOD(Tensor_Matrix, median) { - zend_bool odd, _12; - zval b; - zval rowA, median, _0, _1, _2, _3, *_4, _5, *_6, _11, _8$$5, _9$$5, _10$$5, _13$$8, _14$$8, _15$$8; + zval _0, _1, _2; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zephir_fcall_cache_entry *_7 = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS, mid; + zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); - ZVAL_UNDEF(&median); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_3); - ZVAL_UNDEF(&_5); - ZVAL_UNDEF(&_11); - ZVAL_UNDEF(&_8$$5); - ZVAL_UNDEF(&_9$$5); - ZVAL_UNDEF(&_10$$5); - ZVAL_UNDEF(&_13$$8); - ZVAL_UNDEF(&_14$$8); - ZVAL_UNDEF(&_15$$8); - ZVAL_UNDEF(&b); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("n", 1, 1); + _zephir_prop_0 = zend_string_init("a", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { - _zephir_prop_1 = zend_string_init("a", 1, 1); + _zephir_prop_1 = zend_string_init("n", 1, 1); } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_INIT_VAR(&b); - array_init(&b); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); - ZVAL_LONG(&_1, 2); - ZEPHIR_CALL_FUNCTION(&_2, "intdiv", NULL, 21, &_0, &_1); - zephir_check_call_status(); - mid = zephir_get_intval(&_2); - zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); - odd = zephir_safe_mod_zval_long(&_1, 2) == 1; - zephir_read_property_cached(&_3, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_3) == IS_STRING) { - ZEPHIR_INIT_VAR(&_5); - zephir_string_to_char_array(&_5, &_3); - _4 = &_5; - } else { - _4 = &_3; - } - zephir_is_iterable(_4, 0, "tensor/matrix.zep", 1608); - if (Z_TYPE_P(_4) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_4), _6) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _6); - ZEPHIR_MAKE_REF(&rowA); - ZEPHIR_CALL_FUNCTION(NULL, "sort", &_7, 22, &rowA); - ZEPHIR_UNREF(&rowA); - zephir_check_call_status(); - if (odd) { - ZEPHIR_OBS_NVAR(&median); - zephir_array_fetch_long(&median, &rowA, mid, PH_NOISY, "tensor/matrix.zep", 1600); - } else { - ZEPHIR_OBS_NVAR(&_8$$5); - zephir_array_fetch_long(&_8$$5, &rowA, (mid - 1), PH_NOISY, "tensor/matrix.zep", 1602); - ZEPHIR_OBS_NVAR(&_9$$5); - zephir_array_fetch_long(&_9$$5, &rowA, mid, PH_NOISY, "tensor/matrix.zep", 1602); - ZEPHIR_INIT_NVAR(&_10$$5); - zephir_add_function(&_10$$5, &_8$$5, &_9$$5); - ZEPHIR_INIT_NVAR(&median); - ZVAL_DOUBLE(&median, zephir_safe_div_zval_double(&_10$$5, 2.0)); - } - zephir_array_append(&b, &median, PH_SEPARATE, "tensor/matrix.zep", 1605); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _4, "rewind", NULL, 0); - zephir_check_call_status(); - _12 = 1; - while (1) { - if (_12) { - _12 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _4, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_11, _4, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_11)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _4, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_MAKE_REF(&rowA); - ZEPHIR_CALL_FUNCTION(NULL, "sort", &_7, 22, &rowA); - ZEPHIR_UNREF(&rowA); - zephir_check_call_status(); - if (odd) { - ZEPHIR_OBS_NVAR(&median); - zephir_array_fetch_long(&median, &rowA, mid, PH_NOISY, "tensor/matrix.zep", 1600); - } else { - ZEPHIR_OBS_NVAR(&_13$$8); - zephir_array_fetch_long(&_13$$8, &rowA, (mid - 1), PH_NOISY, "tensor/matrix.zep", 1602); - ZEPHIR_OBS_NVAR(&_14$$8); - zephir_array_fetch_long(&_14$$8, &rowA, mid, PH_NOISY, "tensor/matrix.zep", 1602); - ZEPHIR_INIT_NVAR(&_15$$8); - zephir_add_function(&_15$$8, &_13$$8, &_14$$8); - ZEPHIR_INIT_NVAR(&median); - ZVAL_DOUBLE(&median, zephir_safe_div_zval_double(&_15$$8, 2.0)); - } - zephir_array_append(&b, &median, PH_SEPARATE, "tensor/matrix.zep", 1605); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_columnvector_ce, "quick", NULL, 0, &b); + object_init_ex(return_value, tensor_columnvector_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + tensor_median(&_0, &_1, &_2); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -4494,46 +4845,28 @@ PHP_METHOD(Tensor_Matrix, median) */ PHP_METHOD(Tensor_Matrix, quantile) { - zval b; - zend_bool _0, _19; + zend_bool _0; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zephir_fcall_cache_entry *_10 = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS, xHat; - zval *q_param = NULL, rowA, _5, _6, *_7, _8, *_9, _18, _1$$3, _2$$3, _3$$3, _4$$3, _11$$4, _15$$4, _16$$4, _17$$4, _12$$5, _13$$5, _14$$5, _20$$6, _24$$6, _25$$6, _26$$6, _21$$7, _22$$7, _23$$7; - double q, t = 0, x, remainder; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *q_param = NULL, _5, _6, _7, _8, _1$$3, _2$$3, _3$$3, _4$$3; + double q; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&_5); ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_18); ZVAL_UNDEF(&_1$$3); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_11$$4); - ZVAL_UNDEF(&_15$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_17$$4); - ZVAL_UNDEF(&_12$$5); - ZVAL_UNDEF(&_13$$5); - ZVAL_UNDEF(&_14$$5); - ZVAL_UNDEF(&_20$$6); - ZVAL_UNDEF(&_24$$6); - ZVAL_UNDEF(&_25$$6); - ZVAL_UNDEF(&_26$$6); - ZVAL_UNDEF(&_21$$7); - ZVAL_UNDEF(&_22$$7); - ZVAL_UNDEF(&_23$$7); - ZVAL_UNDEF(&b); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("n", 1, 1); + _zephir_prop_0 = zend_string_init("a", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { - _zephir_prop_1 = zend_string_init("a", 1, 1); + _zephir_prop_1 = zend_string_init("n", 1, 1); } ZEND_PARSE_PARAMETERS_START(1, 1) @@ -4551,103 +4884,23 @@ PHP_METHOD(Tensor_Matrix, quantile) ZEPHIR_INIT_VAR(&_1$$3); object_init_ex(&_1$$3, tensor_exceptions_invalidargumentexception_ce); ZVAL_DOUBLE(&_2$$3, q); - ZEPHIR_CALL_FUNCTION(&_3$$3, "strval", NULL, 4, &_2$$3); + ZEPHIR_CALL_FUNCTION(&_3$$3, "strval", NULL, 3, &_2$$3); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_4$$3); ZEPHIR_CONCAT_SSVS(&_4$$3, "Q must be between", " 0 and 1, ", &_3$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 3, &_4$$3); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_4$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/matrix.zep", 1622); + zephir_throw_exception_debug(&_1$$3, "tensor/matrix.zep", 1651); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&b); - array_init(&b); - zephir_read_property_cached(&_5, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); - x = (((q * (double) ((zephir_get_numberval(&_5) - 1))) + (double) (1))); - xHat = (int) x; - remainder = ((x - (double) xHat)); - zephir_read_property_cached(&_6, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_6) == IS_STRING) { - ZEPHIR_INIT_VAR(&_8); - zephir_string_to_char_array(&_8, &_6); - _7 = &_8; - } else { - _7 = &_6; - } - zephir_is_iterable(_7, 0, "tensor/matrix.zep", 1650); - if (Z_TYPE_P(_7) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_7), _9) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _9); - ZEPHIR_MAKE_REF(&rowA); - ZEPHIR_CALL_FUNCTION(NULL, "sort", &_10, 22, &rowA); - ZEPHIR_UNREF(&rowA); - zephir_check_call_status(); - zephir_read_property_cached(&_11$$4, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); - if (ZEPHIR_LE_LONG(&_11$$4, xHat)) { - ZEPHIR_OBS_NVAR(&_12$$5); - zephir_read_property_cached(&_13$$5, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); - zephir_array_fetch_long(&_12$$5, &rowA, (zephir_get_numberval(&_13$$5) - 1), PH_NOISY, "tensor/matrix.zep", 1640); - ZEPHIR_INIT_NVAR(&_14$$5); - ZVAL_DOUBLE(&_14$$5, zephir_get_doubleval(&_12$$5)); - zephir_array_append(&b, &_14$$5, PH_SEPARATE, "tensor/matrix.zep", 1640); - continue; - } - ZEPHIR_OBS_NVAR(&_15$$4); - zephir_array_fetch_long(&_15$$4, &rowA, (xHat - 1), PH_NOISY, "tensor/matrix.zep", 1645); - t = (zephir_get_doubleval(&_15$$4)); - ZEPHIR_OBS_NVAR(&_16$$4); - zephir_array_fetch_long(&_16$$4, &rowA, xHat, PH_NOISY, "tensor/matrix.zep", 1647); - ZEPHIR_INIT_NVAR(&_17$$4); - ZVAL_DOUBLE(&_17$$4, (t + (remainder * (zephir_get_numberval(&_16$$4) - t)))); - zephir_array_append(&b, &_17$$4, PH_SEPARATE, "tensor/matrix.zep", 1647); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "rewind", NULL, 0); - zephir_check_call_status(); - _19 = 1; - while (1) { - if (_19) { - _19 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_18, _7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_18)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_MAKE_REF(&rowA); - ZEPHIR_CALL_FUNCTION(NULL, "sort", &_10, 22, &rowA); - ZEPHIR_UNREF(&rowA); - zephir_check_call_status(); - zephir_read_property_cached(&_20$$6, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); - if (ZEPHIR_LE_LONG(&_20$$6, xHat)) { - ZEPHIR_OBS_NVAR(&_21$$7); - zephir_read_property_cached(&_22$$7, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); - zephir_array_fetch_long(&_21$$7, &rowA, (zephir_get_numberval(&_22$$7) - 1), PH_NOISY, "tensor/matrix.zep", 1640); - ZEPHIR_INIT_NVAR(&_23$$7); - ZVAL_DOUBLE(&_23$$7, zephir_get_doubleval(&_21$$7)); - zephir_array_append(&b, &_23$$7, PH_SEPARATE, "tensor/matrix.zep", 1640); - continue; - } - ZEPHIR_OBS_NVAR(&_24$$6); - zephir_array_fetch_long(&_24$$6, &rowA, (xHat - 1), PH_NOISY, "tensor/matrix.zep", 1645); - t = (zephir_get_doubleval(&_24$$6)); - ZEPHIR_OBS_NVAR(&_25$$6); - zephir_array_fetch_long(&_25$$6, &rowA, xHat, PH_NOISY, "tensor/matrix.zep", 1647); - ZEPHIR_INIT_NVAR(&_26$$6); - ZVAL_DOUBLE(&_26$$6, (t + (remainder * (zephir_get_numberval(&_25$$6) - t)))); - zephir_array_append(&b, &_26$$6, PH_SEPARATE, "tensor/matrix.zep", 1647); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_columnvector_ce, "quick", NULL, 0, &b); + object_init_ex(return_value, tensor_columnvector_ce); + ZEPHIR_INIT_VAR(&_5); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + ZVAL_DOUBLE(&_8, q); + tensor_quantile(&_5, &_6, &_7, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_5); zephir_check_call_status(); RETURN_MM(); } @@ -4716,9 +4969,9 @@ PHP_METHOD(Tensor_Matrix, variance) zephir_gettype(&_1$$4, mean); ZEPHIR_INIT_VAR(&_2$$4); ZEPHIR_CONCAT_SSVS(&_2$$4, "Mean must be a", " column vector ", &_1$$4, " given."); - ZEPHIR_CALL_METHOD(NULL, &_0$$4, "__construct", NULL, 3, &_2$$4); + ZEPHIR_CALL_METHOD(NULL, &_0$$4, "__construct", NULL, 2, &_2$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$4, "tensor/matrix.zep", 1666); + zephir_throw_exception_debug(&_0$$4, "tensor/matrix.zep", 1670); ZEPHIR_MM_RESTORE(); return; } @@ -4736,9 +4989,9 @@ PHP_METHOD(Tensor_Matrix, variance) zephir_cast_to_string(&_9$$5, &_8$$5); ZEPHIR_INIT_VAR(&_10$$5); ZEPHIR_CONCAT_SSVSVS(&_10$$5, "Mean vector must", " have ", &_7$$5, " rows, ", &_9$$5, " given."); - ZEPHIR_CALL_METHOD(NULL, &_5$$5, "__construct", NULL, 3, &_10$$5); + ZEPHIR_CALL_METHOD(NULL, &_5$$5, "__construct", NULL, 2, &_10$$5); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$5, "tensor/matrix.zep", 1672); + zephir_throw_exception_debug(&_5$$5, "tensor/matrix.zep", 1676); ZEPHIR_MM_RESTORE(); return; } @@ -4746,14 +4999,14 @@ PHP_METHOD(Tensor_Matrix, variance) ZEPHIR_CALL_METHOD(mean, this_ptr, "mean", NULL, 0); zephir_check_call_status(); } - ZEPHIR_CALL_METHOD(&_11, this_ptr, "subtractcolumnvector", NULL, 0, mean); + ZEPHIR_CALL_METHOD(&_11, this_ptr, "subtractColumnVector", NULL, 0, mean); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&_12, &_11, "square", NULL, 0); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&_13, &_12, "sum", NULL, 0); zephir_check_call_status(); zephir_read_property_cached(&_14, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); - ZEPHIR_RETURN_CALL_METHOD(&_13, "dividescalar", NULL, 0, &_14); + ZEPHIR_RETURN_CALL_METHOD(&_13, "divideScalar", NULL, 0, &_14); zephir_check_call_status(); RETURN_MM(); } @@ -4825,9 +5078,9 @@ PHP_METHOD(Tensor_Matrix, covariance) zephir_cast_to_string(&_6$$4, &_5$$4); ZEPHIR_INIT_VAR(&_7$$4); ZEPHIR_CONCAT_SSVSVS(&_7$$4, "Mean vector must", " have ", &_4$$4, " rows, ", &_6$$4, " given."); - ZEPHIR_CALL_METHOD(NULL, &_2$$4, "__construct", NULL, 3, &_7$$4); + ZEPHIR_CALL_METHOD(NULL, &_2$$4, "__construct", NULL, 2, &_7$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$4, "tensor/matrix.zep", 1697); + zephir_throw_exception_debug(&_2$$4, "tensor/matrix.zep", 1701); ZEPHIR_MM_RESTORE(); return; } @@ -4835,14 +5088,14 @@ PHP_METHOD(Tensor_Matrix, covariance) ZEPHIR_CALL_METHOD(mean, this_ptr, "mean", NULL, 0); zephir_check_call_status(); } - ZEPHIR_CALL_METHOD(&b, this_ptr, "subtractcolumnvector", NULL, 0, mean); + ZEPHIR_CALL_METHOD(&b, this_ptr, "subtractColumnVector", NULL, 0, mean); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&_9, &b, "transpose", NULL, 0); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&_8, &b, "matmul", NULL, 0, &_9); zephir_check_call_status(); zephir_read_property_cached(&_10, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); - ZEPHIR_RETURN_CALL_METHOD(&_8, "dividescalar", NULL, 0, &_10); + ZEPHIR_RETURN_CALL_METHOD(&_8, "divideScalar", NULL, 0, &_10); zephir_check_call_status(); RETURN_MM(); } @@ -4855,41 +5108,32 @@ PHP_METHOD(Tensor_Matrix, covariance) */ PHP_METHOD(Tensor_Matrix, round) { - zend_bool _19, _15$$5, _26$$8; - zval b, rowB; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zval *precision_param = NULL, _0$$3, _1$$4, _2$$4, _3$$4, _4$$4, rowA, valueA, _5, *_6, _7, *_8, _18, *_9$$5, _10$$5, *_11$$5, _14$$5, _12$$6, _13$$6, _16$$7, _17$$7, *_20$$8, _21$$8, *_22$$8, _25$$8, _23$$9, _24$$9, _27$$10, _28$$10; + zval *precision_param = NULL, _0$$3, _1$$3, _2$$3, _3$$3, _4, _5, _6, _7, _8; zend_long precision, ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0$$3); - ZVAL_UNDEF(&_1$$4); - ZVAL_UNDEF(&_2$$4); - ZVAL_UNDEF(&_3$$4); - ZVAL_UNDEF(&_4$$4); - ZVAL_UNDEF(&rowA); - ZVAL_UNDEF(&valueA); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); + ZVAL_UNDEF(&_3$$3); + ZVAL_UNDEF(&_4); ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); ZVAL_UNDEF(&_7); - ZVAL_UNDEF(&_18); - ZVAL_UNDEF(&_10$$5); - ZVAL_UNDEF(&_14$$5); - ZVAL_UNDEF(&_12$$6); - ZVAL_UNDEF(&_13$$6); - ZVAL_UNDEF(&_16$$7); - ZVAL_UNDEF(&_17$$7); - ZVAL_UNDEF(&_21$$8); - ZVAL_UNDEF(&_25$$8); - ZVAL_UNDEF(&_23$$9); - ZVAL_UNDEF(&_24$$9); - ZVAL_UNDEF(&_27$$10); - ZVAL_UNDEF(&_28$$10); - ZVAL_UNDEF(&b); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&_8); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL @@ -4902,183 +5146,70 @@ PHP_METHOD(Tensor_Matrix, round) precision = 0; } else { } - if (precision == 0) { - ZEPHIR_INIT_VAR(&_0$$3); - ZVAL_STRING(&_0$$3, "round"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0$$3); - zephir_check_call_status(); - RETURN_MM(); - } if (UNEXPECTED(precision < 0)) { - ZEPHIR_INIT_VAR(&_1$$4); - object_init_ex(&_1$$4, tensor_exceptions_invalidargumentexception_ce); - ZVAL_LONG(&_2$$4, precision); - ZEPHIR_CALL_FUNCTION(&_3$$4, "strval", NULL, 4, &_2$$4); + ZEPHIR_INIT_VAR(&_0$$3); + object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); + ZVAL_LONG(&_1$$3, precision); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 3, &_1$$3); zephir_check_call_status(); - ZEPHIR_INIT_VAR(&_4$$4); - ZEPHIR_CONCAT_SSVS(&_4$$4, "Decimal precision cannot", " be less than 0, ", &_3$$4, " given."); - ZEPHIR_CALL_METHOD(NULL, &_1$$4, "__construct", NULL, 3, &_4$$4); + ZEPHIR_INIT_VAR(&_3$$3); + ZEPHIR_CONCAT_SSVS(&_3$$3, "Decimal precision cannot", " be less than 0, ", &_2$$3, " given."); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$4, "tensor/matrix.zep", 1723); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1722); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&b); - array_init(&b); - ZEPHIR_INIT_VAR(&rowB); - array_init(&rowB); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_INIT_VAR(&_4); zephir_read_property_cached(&_5, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_5) == IS_STRING) { - ZEPHIR_INIT_VAR(&_7); - zephir_string_to_char_array(&_7, &_5); - _6 = &_7; - } else { - _6 = &_5; + ZVAL_LONG(&_6, precision); + tensor_round(&_4, &_5, &_6); + zephir_read_property_cached(&_7, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_4, &_7, &_8); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Round the elements in the matrix down to the nearest integer. + * + * @return self + */ +PHP_METHOD(Tensor_Matrix, floor) +{ + zval _0, _1, _2, _3; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); } - zephir_is_iterable(_6, 0, "tensor/matrix.zep", 1741); - if (Z_TYPE_P(_6) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_6), _8) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _8); - ZEPHIR_INIT_NVAR(&rowB); - array_init(&rowB); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_10$$5); - zephir_string_to_char_array(&_10$$5, &rowA); - _9$$5 = &_10$$5; - } else { - _9$$5 = &rowA; - } - zephir_is_iterable(_9$$5, 0, "tensor/matrix.zep", 1738); - if (Z_TYPE_P(_9$$5) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9$$5), _11$$5) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _11$$5); - ZEPHIR_INIT_NVAR(&_12$$6); - ZVAL_LONG(&_13$$6, precision); - zephir_round(&_12$$6, &valueA, &_13$$6, NULL); - zephir_array_append(&rowB, &_12$$6, PH_SEPARATE, "tensor/matrix.zep", 1735); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9$$5, "rewind", NULL, 0); - zephir_check_call_status(); - _15$$5 = 1; - while (1) { - if (_15$$5) { - _15$$5 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9$$5, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_14$$5, _9$$5, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_14$$5)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _9$$5, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_16$$7); - ZVAL_LONG(&_17$$7, precision); - zephir_round(&_16$$7, &valueA, &_17$$7, NULL); - zephir_array_append(&rowB, &_16$$7, PH_SEPARATE, "tensor/matrix.zep", 1735); - } - } - ZEPHIR_INIT_NVAR(&valueA); - zephir_array_append(&b, &rowB, PH_SEPARATE, "tensor/matrix.zep", 1738); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _6, "rewind", NULL, 0); - zephir_check_call_status(); - _19 = 1; - while (1) { - if (_19) { - _19 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _6, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_18, _6, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_18)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _6, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&rowB); - array_init(&rowB); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_21$$8); - zephir_string_to_char_array(&_21$$8, &rowA); - _20$$8 = &_21$$8; - } else { - _20$$8 = &rowA; - } - zephir_is_iterable(_20$$8, 0, "tensor/matrix.zep", 1738); - if (Z_TYPE_P(_20$$8) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_20$$8), _22$$8) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _22$$8); - ZEPHIR_INIT_NVAR(&_23$$9); - ZVAL_LONG(&_24$$9, precision); - zephir_round(&_23$$9, &valueA, &_24$$9, NULL); - zephir_array_append(&rowB, &_23$$9, PH_SEPARATE, "tensor/matrix.zep", 1735); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _20$$8, "rewind", NULL, 0); - zephir_check_call_status(); - _26$$8 = 1; - while (1) { - if (_26$$8) { - _26$$8 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _20$$8, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_25$$8, _20$$8, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_25$$8)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _20$$8, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_27$$10); - ZVAL_LONG(&_28$$10, precision); - zephir_round(&_27$$10, &valueA, &_28$$10, NULL); - zephir_array_append(&rowB, &_27$$10, PH_SEPARATE, "tensor/matrix.zep", 1735); - } - } - ZEPHIR_INIT_NVAR(&valueA); - zephir_array_append(&b, &rowB, PH_SEPARATE, "tensor/matrix.zep", 1738); - } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &b); - zephir_check_call_status(); - RETURN_MM(); -} - -/** - * Round the elements in the matrix down to the nearest integer. - * - * @return self - */ -PHP_METHOD(Tensor_Matrix, floor) -{ - zval _0; - zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS; - zval *this_ptr = getThis(); - - ZVAL_UNDEF(&_0); ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "floor"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_floor(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -5090,18 +5221,37 @@ PHP_METHOD(Tensor_Matrix, floor) */ PHP_METHOD(Tensor_Matrix, ceil) { - zval _0; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_matrix_ce); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "ceil"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_ceil(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -5117,40 +5267,33 @@ PHP_METHOD(Tensor_Matrix, ceil) */ PHP_METHOD(Tensor_Matrix, clip) { - zend_bool _16, _12$$4, _23$$11; - zval b, rowB; zval _1$$3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *min_param = NULL, *max_param = NULL, _0$$3, rowA, valueA, _2, *_3, _4, *_5, _15, *_6$$4, _7$$4, *_8$$4, _11$$4, _9$$6, _10$$7, _13$$9, _14$$10, *_17$$11, _18$$11, *_19$$11, _22$$11, _20$$13, _21$$14, _24$$16, _25$$17; + zval *min_param = NULL, *max_param = NULL, _0$$3, _2, _3, _4, _5, _6, _7; double min, max; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0$$3); - ZVAL_UNDEF(&rowA); - ZVAL_UNDEF(&valueA); ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); ZVAL_UNDEF(&_4); - ZVAL_UNDEF(&_15); - ZVAL_UNDEF(&_7$$4); - ZVAL_UNDEF(&_11$$4); - ZVAL_UNDEF(&_9$$6); - ZVAL_UNDEF(&_10$$7); - ZVAL_UNDEF(&_13$$9); - ZVAL_UNDEF(&_14$$10); - ZVAL_UNDEF(&_18$$11); - ZVAL_UNDEF(&_22$$11); - ZVAL_UNDEF(&_20$$13); - ZVAL_UNDEF(&_21$$14); - ZVAL_UNDEF(&_24$$16); - ZVAL_UNDEF(&_25$$17); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZVAL_UNDEF(&_1$$3); - ZVAL_UNDEF(&b); - ZVAL_UNDEF(&rowB); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_ZVAL(min_param) @@ -5166,181 +5309,21 @@ PHP_METHOD(Tensor_Matrix, clip) object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_1$$3); ZEPHIR_CONCAT_SS(&_1$$3, "Minimum cannot be", " greater than maximum."); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 3, &_1$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_1$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1777); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1761); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&b); - array_init(&b); - ZEPHIR_INIT_VAR(&rowB); - array_init(&rowB); - zephir_read_property_cached(&_2, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_2) == IS_STRING) { - ZEPHIR_INIT_VAR(&_4); - zephir_string_to_char_array(&_4, &_2); - _3 = &_4; - } else { - _3 = &_2; - } - zephir_is_iterable(_3, 0, "tensor/matrix.zep", 1807); - if (Z_TYPE_P(_3) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_3), _5) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _5); - ZEPHIR_INIT_NVAR(&rowB); - array_init(&rowB); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_7$$4); - zephir_string_to_char_array(&_7$$4, &rowA); - _6$$4 = &_7$$4; - } else { - _6$$4 = &rowA; - } - zephir_is_iterable(_6$$4, 0, "tensor/matrix.zep", 1804); - if (Z_TYPE_P(_6$$4) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_6$$4), _8$$4) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _8$$4); - if (ZEPHIR_GT_DOUBLE(&valueA, max)) { - ZEPHIR_INIT_NVAR(&_9$$6); - ZVAL_DOUBLE(&_9$$6, max); - zephir_array_append(&rowB, &_9$$6, PH_SEPARATE, "tensor/matrix.zep", 1790); - continue; - } - if (ZEPHIR_LT_DOUBLE(&valueA, min)) { - ZEPHIR_INIT_NVAR(&_10$$7); - ZVAL_DOUBLE(&_10$$7, min); - zephir_array_append(&rowB, &_10$$7, PH_SEPARATE, "tensor/matrix.zep", 1796); - continue; - } - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1801); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _6$$4, "rewind", NULL, 0); - zephir_check_call_status(); - _12$$4 = 1; - while (1) { - if (_12$$4) { - _12$$4 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _6$$4, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_11$$4, _6$$4, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_11$$4)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _6$$4, "current", NULL, 0); - zephir_check_call_status(); - if (ZEPHIR_GT_DOUBLE(&valueA, max)) { - ZEPHIR_INIT_NVAR(&_13$$9); - ZVAL_DOUBLE(&_13$$9, max); - zephir_array_append(&rowB, &_13$$9, PH_SEPARATE, "tensor/matrix.zep", 1790); - continue; - } - if (ZEPHIR_LT_DOUBLE(&valueA, min)) { - ZEPHIR_INIT_NVAR(&_14$$10); - ZVAL_DOUBLE(&_14$$10, min); - zephir_array_append(&rowB, &_14$$10, PH_SEPARATE, "tensor/matrix.zep", 1796); - continue; - } - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1801); - } - } - ZEPHIR_INIT_NVAR(&valueA); - zephir_array_append(&b, &rowB, PH_SEPARATE, "tensor/matrix.zep", 1804); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _3, "rewind", NULL, 0); - zephir_check_call_status(); - _16 = 1; - while (1) { - if (_16) { - _16 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _3, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_15, _3, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_15)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _3, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&rowB); - array_init(&rowB); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_18$$11); - zephir_string_to_char_array(&_18$$11, &rowA); - _17$$11 = &_18$$11; - } else { - _17$$11 = &rowA; - } - zephir_is_iterable(_17$$11, 0, "tensor/matrix.zep", 1804); - if (Z_TYPE_P(_17$$11) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_17$$11), _19$$11) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _19$$11); - if (ZEPHIR_GT_DOUBLE(&valueA, max)) { - ZEPHIR_INIT_NVAR(&_20$$13); - ZVAL_DOUBLE(&_20$$13, max); - zephir_array_append(&rowB, &_20$$13, PH_SEPARATE, "tensor/matrix.zep", 1790); - continue; - } - if (ZEPHIR_LT_DOUBLE(&valueA, min)) { - ZEPHIR_INIT_NVAR(&_21$$14); - ZVAL_DOUBLE(&_21$$14, min); - zephir_array_append(&rowB, &_21$$14, PH_SEPARATE, "tensor/matrix.zep", 1796); - continue; - } - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1801); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _17$$11, "rewind", NULL, 0); - zephir_check_call_status(); - _23$$11 = 1; - while (1) { - if (_23$$11) { - _23$$11 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _17$$11, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_22$$11, _17$$11, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_22$$11)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _17$$11, "current", NULL, 0); - zephir_check_call_status(); - if (ZEPHIR_GT_DOUBLE(&valueA, max)) { - ZEPHIR_INIT_NVAR(&_24$$16); - ZVAL_DOUBLE(&_24$$16, max); - zephir_array_append(&rowB, &_24$$16, PH_SEPARATE, "tensor/matrix.zep", 1790); - continue; - } - if (ZEPHIR_LT_DOUBLE(&valueA, min)) { - ZEPHIR_INIT_NVAR(&_25$$17); - ZVAL_DOUBLE(&_25$$17, min); - zephir_array_append(&rowB, &_25$$17, PH_SEPARATE, "tensor/matrix.zep", 1796); - continue; - } - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1801); - } - } - ZEPHIR_INIT_NVAR(&valueA); - zephir_array_append(&b, &rowB, PH_SEPARATE, "tensor/matrix.zep", 1804); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &b); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_INIT_VAR(&_2); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + ZVAL_DOUBLE(&_4, min); + ZVAL_DOUBLE(&_5, max); + tensor_clip(&_2, &_3, &_4, &_5); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_2, &_6, &_7); zephir_check_call_status(); RETURN_MM(); } @@ -5353,33 +5336,29 @@ PHP_METHOD(Tensor_Matrix, clip) */ PHP_METHOD(Tensor_Matrix, clipLower) { - zend_bool _12, _9$$3, _18$$8; - zval b, rowB; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *min_param = NULL, rowA, valueA, _0, *_1, _2, *_3, _11, *_4$$3, _5$$3, *_6$$3, _8$$3, _7$$5, _10$$7, *_13$$8, _14$$8, *_15$$8, _17$$8, _16$$10, _19$$12; + zval *min_param = NULL, _0, _1, _2, _3, _4; double min; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); - ZVAL_UNDEF(&valueA); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_11); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_8$$3); - ZVAL_UNDEF(&_7$$5); - ZVAL_UNDEF(&_10$$7); - ZVAL_UNDEF(&_14$$8); - ZVAL_UNDEF(&_17$$8); - ZVAL_UNDEF(&_16$$10); - ZVAL_UNDEF(&_19$$12); - ZVAL_UNDEF(&b); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_4); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(min_param) @@ -5388,151 +5367,14 @@ PHP_METHOD(Tensor_Matrix, clipLower) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &min_param); min = zephir_get_doubleval(min_param); - ZEPHIR_INIT_VAR(&b); - array_init(&b); - ZEPHIR_INIT_VAR(&rowB); - array_init(&rowB); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 1839); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&rowB); - array_init(&rowB); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_5$$3); - zephir_string_to_char_array(&_5$$3, &rowA); - _4$$3 = &_5$$3; - } else { - _4$$3 = &rowA; - } - zephir_is_iterable(_4$$3, 0, "tensor/matrix.zep", 1836); - if (Z_TYPE_P(_4$$3) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_4$$3), _6$$3) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _6$$3); - if (ZEPHIR_LT_DOUBLE(&valueA, min)) { - ZEPHIR_INIT_NVAR(&_7$$5); - ZVAL_DOUBLE(&_7$$5, min); - zephir_array_append(&rowB, &_7$$5, PH_SEPARATE, "tensor/matrix.zep", 1828); - continue; - } - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1833); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _4$$3, "rewind", NULL, 0); - zephir_check_call_status(); - _9$$3 = 1; - while (1) { - if (_9$$3) { - _9$$3 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _4$$3, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_8$$3, _4$$3, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_8$$3)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _4$$3, "current", NULL, 0); - zephir_check_call_status(); - if (ZEPHIR_LT_DOUBLE(&valueA, min)) { - ZEPHIR_INIT_NVAR(&_10$$7); - ZVAL_DOUBLE(&_10$$7, min); - zephir_array_append(&rowB, &_10$$7, PH_SEPARATE, "tensor/matrix.zep", 1828); - continue; - } - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1833); - } - } - ZEPHIR_INIT_NVAR(&valueA); - zephir_array_append(&b, &rowB, PH_SEPARATE, "tensor/matrix.zep", 1836); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _12 = 1; - while (1) { - if (_12) { - _12 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_11, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_11)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&rowB); - array_init(&rowB); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_14$$8); - zephir_string_to_char_array(&_14$$8, &rowA); - _13$$8 = &_14$$8; - } else { - _13$$8 = &rowA; - } - zephir_is_iterable(_13$$8, 0, "tensor/matrix.zep", 1836); - if (Z_TYPE_P(_13$$8) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_13$$8), _15$$8) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _15$$8); - if (ZEPHIR_LT_DOUBLE(&valueA, min)) { - ZEPHIR_INIT_NVAR(&_16$$10); - ZVAL_DOUBLE(&_16$$10, min); - zephir_array_append(&rowB, &_16$$10, PH_SEPARATE, "tensor/matrix.zep", 1828); - continue; - } - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1833); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _13$$8, "rewind", NULL, 0); - zephir_check_call_status(); - _18$$8 = 1; - while (1) { - if (_18$$8) { - _18$$8 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _13$$8, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_17$$8, _13$$8, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_17$$8)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _13$$8, "current", NULL, 0); - zephir_check_call_status(); - if (ZEPHIR_LT_DOUBLE(&valueA, min)) { - ZEPHIR_INIT_NVAR(&_19$$12); - ZVAL_DOUBLE(&_19$$12, min); - zephir_array_append(&rowB, &_19$$12, PH_SEPARATE, "tensor/matrix.zep", 1828); - continue; - } - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1833); - } - } - ZEPHIR_INIT_NVAR(&valueA); - zephir_array_append(&b, &rowB, PH_SEPARATE, "tensor/matrix.zep", 1836); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &b); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + ZVAL_DOUBLE(&_2, min); + tensor_clip_lower(&_0, &_1, &_2); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_4, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_3, &_4); zephir_check_call_status(); RETURN_MM(); } @@ -5545,564 +5387,129 @@ PHP_METHOD(Tensor_Matrix, clipLower) */ PHP_METHOD(Tensor_Matrix, clipUpper) { - zend_bool _12, _9$$3, _18$$8; - zval b, rowB; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *max_param = NULL, rowA, valueA, _0, *_1, _2, *_3, _11, *_4$$3, _5$$3, *_6$$3, _8$$3, _7$$5, _10$$7, *_13$$8, _14$$8, *_15$$8, _17$$8, _16$$10, _19$$12; + zval *max_param = NULL, _0, _1, _2, _3, _4; double max; zval *this_ptr = getThis(); - - ZVAL_UNDEF(&rowA); - ZVAL_UNDEF(&valueA); - ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_11); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_8$$3); - ZVAL_UNDEF(&_7$$5); - ZVAL_UNDEF(&_10$$7); - ZVAL_UNDEF(&_14$$8); - ZVAL_UNDEF(&_17$$8); - ZVAL_UNDEF(&_16$$10); - ZVAL_UNDEF(&_19$$12); - ZVAL_UNDEF(&b); - ZVAL_UNDEF(&rowB); - static zend_string *_zephir_prop_0 = NULL; - if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); - } - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ZVAL(max_param) - ZEND_PARSE_PARAMETERS_END(); - ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); - zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_fetch_params(1, 1, 0, &max_param); - max = zephir_get_doubleval(max_param); - ZEPHIR_INIT_VAR(&b); - array_init(&b); - ZEPHIR_INIT_VAR(&rowB); - array_init(&rowB); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 1871); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&rowB); - array_init(&rowB); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_5$$3); - zephir_string_to_char_array(&_5$$3, &rowA); - _4$$3 = &_5$$3; - } else { - _4$$3 = &rowA; - } - zephir_is_iterable(_4$$3, 0, "tensor/matrix.zep", 1868); - if (Z_TYPE_P(_4$$3) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_4$$3), _6$$3) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _6$$3); - if (ZEPHIR_GT_DOUBLE(&valueA, max)) { - ZEPHIR_INIT_NVAR(&_7$$5); - ZVAL_DOUBLE(&_7$$5, max); - zephir_array_append(&rowB, &_7$$5, PH_SEPARATE, "tensor/matrix.zep", 1860); - continue; - } - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1865); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _4$$3, "rewind", NULL, 0); - zephir_check_call_status(); - _9$$3 = 1; - while (1) { - if (_9$$3) { - _9$$3 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _4$$3, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_8$$3, _4$$3, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_8$$3)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _4$$3, "current", NULL, 0); - zephir_check_call_status(); - if (ZEPHIR_GT_DOUBLE(&valueA, max)) { - ZEPHIR_INIT_NVAR(&_10$$7); - ZVAL_DOUBLE(&_10$$7, max); - zephir_array_append(&rowB, &_10$$7, PH_SEPARATE, "tensor/matrix.zep", 1860); - continue; - } - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1865); - } - } - ZEPHIR_INIT_NVAR(&valueA); - zephir_array_append(&b, &rowB, PH_SEPARATE, "tensor/matrix.zep", 1868); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _12 = 1; - while (1) { - if (_12) { - _12 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_11, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_11)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&rowB); - array_init(&rowB); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_14$$8); - zephir_string_to_char_array(&_14$$8, &rowA); - _13$$8 = &_14$$8; - } else { - _13$$8 = &rowA; - } - zephir_is_iterable(_13$$8, 0, "tensor/matrix.zep", 1868); - if (Z_TYPE_P(_13$$8) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_13$$8), _15$$8) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _15$$8); - if (ZEPHIR_GT_DOUBLE(&valueA, max)) { - ZEPHIR_INIT_NVAR(&_16$$10); - ZVAL_DOUBLE(&_16$$10, max); - zephir_array_append(&rowB, &_16$$10, PH_SEPARATE, "tensor/matrix.zep", 1860); - continue; - } - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1865); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _13$$8, "rewind", NULL, 0); - zephir_check_call_status(); - _18$$8 = 1; - while (1) { - if (_18$$8) { - _18$$8 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _13$$8, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_17$$8, _13$$8, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_17$$8)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _13$$8, "current", NULL, 0); - zephir_check_call_status(); - if (ZEPHIR_GT_DOUBLE(&valueA, max)) { - ZEPHIR_INIT_NVAR(&_19$$12); - ZVAL_DOUBLE(&_19$$12, max); - zephir_array_append(&rowB, &_19$$12, PH_SEPARATE, "tensor/matrix.zep", 1860); - continue; - } - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1865); - } - } - ZEPHIR_INIT_NVAR(&valueA); - zephir_array_append(&b, &rowB, PH_SEPARATE, "tensor/matrix.zep", 1868); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &b); - zephir_check_call_status(); - RETURN_MM(); -} - -/** - * Return the element-wise sign indication. - * - * @return self - */ -PHP_METHOD(Tensor_Matrix, sign) -{ - zend_bool _16, _11$$3, _24$$12; - zval b, rowB; - zval rowA, valueA, _0, *_1, _2, *_3, _15, *_4$$3, _5$$3, *_6$$3, _10$$3, _7$$5, _8$$6, _9$$7, _12$$9, _13$$10, _14$$11, *_17$$12, _18$$12, *_19$$12, _23$$12, _20$$14, _21$$15, _22$$16, _25$$18, _26$$19, _27$$20; - zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS; - zval *this_ptr = getThis(); - - ZVAL_UNDEF(&rowA); - ZVAL_UNDEF(&valueA); - ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_15); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_10$$3); - ZVAL_UNDEF(&_7$$5); - ZVAL_UNDEF(&_8$$6); - ZVAL_UNDEF(&_9$$7); - ZVAL_UNDEF(&_12$$9); - ZVAL_UNDEF(&_13$$10); - ZVAL_UNDEF(&_14$$11); - ZVAL_UNDEF(&_18$$12); - ZVAL_UNDEF(&_23$$12); - ZVAL_UNDEF(&_20$$14); - ZVAL_UNDEF(&_21$$15); - ZVAL_UNDEF(&_22$$16); - ZVAL_UNDEF(&_25$$18); - ZVAL_UNDEF(&_26$$19); - ZVAL_UNDEF(&_27$$20); - ZVAL_UNDEF(&b); - ZVAL_UNDEF(&rowB); - static zend_string *_zephir_prop_0 = NULL; - if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); - } - ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); - zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - - ZEPHIR_INIT_VAR(&b); - array_init(&b); - ZEPHIR_INIT_VAR(&rowB); - array_init(&rowB); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 1902); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&rowB); - array_init(&rowB); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_5$$3); - zephir_string_to_char_array(&_5$$3, &rowA); - _4$$3 = &_5$$3; - } else { - _4$$3 = &rowA; - } - zephir_is_iterable(_4$$3, 0, "tensor/matrix.zep", 1899); - if (Z_TYPE_P(_4$$3) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_4$$3), _6$$3) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _6$$3); - if (ZEPHIR_GT_LONG(&valueA, 0)) { - ZEPHIR_INIT_NVAR(&_7$$5); - ZVAL_DOUBLE(&_7$$5, 1.0); - zephir_array_append(&rowB, &_7$$5, PH_SEPARATE, "tensor/matrix.zep", 1891); - } else if (ZEPHIR_LT_LONG(&valueA, 0)) { - ZEPHIR_INIT_NVAR(&_8$$6); - ZVAL_DOUBLE(&_8$$6, -1.0); - zephir_array_append(&rowB, &_8$$6, PH_SEPARATE, "tensor/matrix.zep", 1893); - } else { - ZEPHIR_INIT_NVAR(&_9$$7); - ZVAL_DOUBLE(&_9$$7, 0.0); - zephir_array_append(&rowB, &_9$$7, PH_SEPARATE, "tensor/matrix.zep", 1895); - } - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _4$$3, "rewind", NULL, 0); - zephir_check_call_status(); - _11$$3 = 1; - while (1) { - if (_11$$3) { - _11$$3 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _4$$3, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_10$$3, _4$$3, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_10$$3)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _4$$3, "current", NULL, 0); - zephir_check_call_status(); - if (ZEPHIR_GT_LONG(&valueA, 0)) { - ZEPHIR_INIT_NVAR(&_12$$9); - ZVAL_DOUBLE(&_12$$9, 1.0); - zephir_array_append(&rowB, &_12$$9, PH_SEPARATE, "tensor/matrix.zep", 1891); - } else if (ZEPHIR_LT_LONG(&valueA, 0)) { - ZEPHIR_INIT_NVAR(&_13$$10); - ZVAL_DOUBLE(&_13$$10, -1.0); - zephir_array_append(&rowB, &_13$$10, PH_SEPARATE, "tensor/matrix.zep", 1893); - } else { - ZEPHIR_INIT_NVAR(&_14$$11); - ZVAL_DOUBLE(&_14$$11, 0.0); - zephir_array_append(&rowB, &_14$$11, PH_SEPARATE, "tensor/matrix.zep", 1895); - } - } - } - ZEPHIR_INIT_NVAR(&valueA); - zephir_array_append(&b, &rowB, PH_SEPARATE, "tensor/matrix.zep", 1899); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _16 = 1; - while (1) { - if (_16) { - _16 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_15, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_15)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&rowB); - array_init(&rowB); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_18$$12); - zephir_string_to_char_array(&_18$$12, &rowA); - _17$$12 = &_18$$12; - } else { - _17$$12 = &rowA; - } - zephir_is_iterable(_17$$12, 0, "tensor/matrix.zep", 1899); - if (Z_TYPE_P(_17$$12) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_17$$12), _19$$12) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _19$$12); - if (ZEPHIR_GT_LONG(&valueA, 0)) { - ZEPHIR_INIT_NVAR(&_20$$14); - ZVAL_DOUBLE(&_20$$14, 1.0); - zephir_array_append(&rowB, &_20$$14, PH_SEPARATE, "tensor/matrix.zep", 1891); - } else if (ZEPHIR_LT_LONG(&valueA, 0)) { - ZEPHIR_INIT_NVAR(&_21$$15); - ZVAL_DOUBLE(&_21$$15, -1.0); - zephir_array_append(&rowB, &_21$$15, PH_SEPARATE, "tensor/matrix.zep", 1893); - } else { - ZEPHIR_INIT_NVAR(&_22$$16); - ZVAL_DOUBLE(&_22$$16, 0.0); - zephir_array_append(&rowB, &_22$$16, PH_SEPARATE, "tensor/matrix.zep", 1895); - } - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _17$$12, "rewind", NULL, 0); - zephir_check_call_status(); - _24$$12 = 1; - while (1) { - if (_24$$12) { - _24$$12 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _17$$12, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_23$$12, _17$$12, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_23$$12)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _17$$12, "current", NULL, 0); - zephir_check_call_status(); - if (ZEPHIR_GT_LONG(&valueA, 0)) { - ZEPHIR_INIT_NVAR(&_25$$18); - ZVAL_DOUBLE(&_25$$18, 1.0); - zephir_array_append(&rowB, &_25$$18, PH_SEPARATE, "tensor/matrix.zep", 1891); - } else if (ZEPHIR_LT_LONG(&valueA, 0)) { - ZEPHIR_INIT_NVAR(&_26$$19); - ZVAL_DOUBLE(&_26$$19, -1.0); - zephir_array_append(&rowB, &_26$$19, PH_SEPARATE, "tensor/matrix.zep", 1893); - } else { - ZEPHIR_INIT_NVAR(&_27$$20); - ZVAL_DOUBLE(&_27$$20, 0.0); - zephir_array_append(&rowB, &_27$$20, PH_SEPARATE, "tensor/matrix.zep", 1895); - } - } - } - ZEPHIR_INIT_NVAR(&valueA); - zephir_array_append(&b, &rowB, PH_SEPARATE, "tensor/matrix.zep", 1899); - } + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_4); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &b); + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(max_param) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 1, 0, &max_param); + max = zephir_get_doubleval(max_param); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + ZVAL_DOUBLE(&_2, max); + tensor_clip_upper(&_0, &_1, &_2); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_4, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_3, &_4); zephir_check_call_status(); RETURN_MM(); } /** - * Negate the matrix i.e take the negative of each value elementwise. + * Return the element-wise sign indication. * * @return self */ -PHP_METHOD(Tensor_Matrix, negate) +PHP_METHOD(Tensor_Matrix, sign) { - zend_bool _10, _8$$3, _15$$6; - zval b, rowB; - zval rowA, valueA, _0, *_1, _2, *_3, _9, *_4$$3, _5$$3, *_6$$3, _7$$3, *_11$$6, _12$$6, *_13$$6, _14$$6; + zval _0, _1, _2, _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); - ZVAL_UNDEF(&valueA); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_9); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_7$$3); - ZVAL_UNDEF(&_12$$6); - ZVAL_UNDEF(&_14$$6); - ZVAL_UNDEF(&b); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_INIT_VAR(&b); - array_init(&b); - ZEPHIR_INIT_VAR(&rowB); - array_init(&rowB); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_sign(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Negate the matrix i.e take the negative of each value elementwise. + * + * @return self + */ +PHP_METHOD(Tensor_Matrix, negate) +{ + zval _0, _1, _2, _3; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 1927); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&rowB); - array_init(&rowB); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_5$$3); - zephir_string_to_char_array(&_5$$3, &rowA); - _4$$3 = &_5$$3; - } else { - _4$$3 = &rowA; - } - zephir_is_iterable(_4$$3, 0, "tensor/matrix.zep", 1924); - if (Z_TYPE_P(_4$$3) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_4$$3), _6$$3) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _6$$3); - zephir_negate(&valueA); - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1921); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _4$$3, "rewind", NULL, 0); - zephir_check_call_status(); - _8$$3 = 1; - while (1) { - if (_8$$3) { - _8$$3 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _4$$3, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_7$$3, _4$$3, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_7$$3)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _4$$3, "current", NULL, 0); - zephir_check_call_status(); - zephir_negate(&valueA); - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1921); - } - } - ZEPHIR_INIT_NVAR(&valueA); - zephir_array_append(&b, &rowB, PH_SEPARATE, "tensor/matrix.zep", 1924); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _10 = 1; - while (1) { - if (_10) { - _10 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_9, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_9)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&rowB); - array_init(&rowB); - if (Z_TYPE_P(&rowA) == IS_STRING) { - ZEPHIR_INIT_NVAR(&_12$$6); - zephir_string_to_char_array(&_12$$6, &rowA); - _11$$6 = &_12$$6; - } else { - _11$$6 = &rowA; - } - zephir_is_iterable(_11$$6, 0, "tensor/matrix.zep", 1924); - if (Z_TYPE_P(_11$$6) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_11$$6), _13$$6) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _13$$6); - zephir_negate(&valueA); - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1921); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _11$$6, "rewind", NULL, 0); - zephir_check_call_status(); - _15$$6 = 1; - while (1) { - if (_15$$6) { - _15$$6 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _11$$6, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_14$$6, _11$$6, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_14$$6)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _11$$6, "current", NULL, 0); - zephir_check_call_status(); - zephir_negate(&valueA); - zephir_array_append(&rowB, &valueA, PH_SEPARATE, "tensor/matrix.zep", 1921); - } - } - ZEPHIR_INIT_NVAR(&valueA); - zephir_array_append(&b, &rowB, PH_SEPARATE, "tensor/matrix.zep", 1924); - } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &b); + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + tensor_negate(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -6117,22 +5524,27 @@ PHP_METHOD(Tensor_Matrix, negate) PHP_METHOD(Tensor_Matrix, augmentAbove) { zval _6$$3, _8$$3, _9$$3; + zval _11; zend_bool _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _2, _3, _10, _11, _12, _4$$3, _5$$3, _7$$3; + zval *b, b_sub, _0, _2, _3, buffer, _10, _12, _13, _14, _15, _4$$3, _5$$3, _7$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_2); ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&buffer); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_12); + ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_15); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); ZVAL_UNDEF(&_7$$3); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_8$$3); ZVAL_UNDEF(&_9$$3); @@ -6174,18 +5586,28 @@ PHP_METHOD(Tensor_Matrix, augmentAbove) zephir_cast_to_string(&_8$$3, &_7$$3); ZEPHIR_INIT_VAR(&_9$$3); ZEPHIR_CONCAT_SVSVS(&_9$$3, "Matrix A requires", &_6$$3, " columns but Matrix B has ", &_8$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_4$$3, "__construct", NULL, 3, &_9$$3); + ZEPHIR_CALL_METHOD(NULL, &_4$$3, "__construct", NULL, 2, &_9$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_4$$3, "tensor/matrix.zep", 1942); + zephir_throw_exception_debug(&_4$$3, "tensor/matrix.zep", 1827); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&_10); - ZEPHIR_CALL_METHOD(&_11, b, "asarray", NULL, 0); + zephir_read_property_cached(&_10, b, _zephir_prop_2, 0, PH_NOISY_CC | PH_READONLY); + ZEPHIR_INIT_VAR(&_11); + zephir_create_array(&_11, 1, 0); + zephir_memory_observe(&_12); + zephir_read_property_cached(&_12, this_ptr, _zephir_prop_2, 14, PH_NOISY_CC); + zephir_array_fast_append(&_11, &_12); + ZEPHIR_CALL_METHOD(&buffer, &_10, "concat", NULL, 0, &_11); + zephir_check_call_status(); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_13, b, "m", NULL, 0); zephir_check_call_status(); - zephir_read_property_cached(&_12, this_ptr, _zephir_prop_2, 14, PH_NOISY_CC | PH_READONLY); - zephir_fast_array_merge(&_10, &_11, &_12); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &_10); + zephir_read_property_cached(&_14, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + ZEPHIR_INIT_VAR(&_15); + zephir_add_function(&_15, &_13, &_14); + zephir_read_property_cached(&_14, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &buffer, &_15, &_14); zephir_check_call_status(); RETURN_MM(); } @@ -6200,22 +5622,27 @@ PHP_METHOD(Tensor_Matrix, augmentAbove) PHP_METHOD(Tensor_Matrix, augmentBelow) { zval _6$$3, _8$$3, _9$$3; + zval _11; zend_bool _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _2, _3, _10, _11, _12, _4$$3, _5$$3, _7$$3; + zval *b, b_sub, _0, _2, _3, buffer, _10, _12, _13, _14, _15, _4$$3, _5$$3, _7$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_2); ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&buffer); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_12); + ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_15); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); ZVAL_UNDEF(&_7$$3); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_8$$3); ZVAL_UNDEF(&_9$$3); @@ -6257,18 +5684,28 @@ PHP_METHOD(Tensor_Matrix, augmentBelow) zephir_cast_to_string(&_8$$3, &_7$$3); ZEPHIR_INIT_VAR(&_9$$3); ZEPHIR_CONCAT_SVSVS(&_9$$3, "Matrix A requires", &_6$$3, " columns but Matrix B has ", &_8$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_4$$3, "__construct", NULL, 3, &_9$$3); + ZEPHIR_CALL_METHOD(NULL, &_4$$3, "__construct", NULL, 2, &_9$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_4$$3, "tensor/matrix.zep", 1960); + zephir_throw_exception_debug(&_4$$3, "tensor/matrix.zep", 1847); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&_10); - zephir_read_property_cached(&_11, this_ptr, _zephir_prop_2, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_12, b, "asarray", NULL, 0); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 14, PH_NOISY_CC | PH_READONLY); + ZEPHIR_INIT_VAR(&_11); + zephir_create_array(&_11, 1, 0); + zephir_memory_observe(&_12); + zephir_read_property_cached(&_12, b, _zephir_prop_2, 0, PH_NOISY_CC); + zephir_array_fast_append(&_11, &_12); + ZEPHIR_CALL_METHOD(&buffer, &_10, "concat", NULL, 0, &_11); + zephir_check_call_status(); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_13, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_14, b, "m", NULL, 0); zephir_check_call_status(); - zephir_fast_array_merge(&_10, &_11, &_12); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &_10); + ZEPHIR_INIT_VAR(&_15); + zephir_add_function(&_15, &_13, &_14); + zephir_read_property_cached(&_13, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &buffer, &_15, &_13); zephir_check_call_status(); RETURN_MM(); } @@ -6283,34 +5720,54 @@ PHP_METHOD(Tensor_Matrix, augmentBelow) PHP_METHOD(Tensor_Matrix, augmentLeft) { zval _6$$3, _8$$3, _9$$3; - zend_bool _1; + zval c, _22$$4; + zend_bool _1, _11; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _2, _3, _10, _11, _12, _13, _4$$3, _5$$3, _7$$3; + zephir_fcall_cache_entry *_16 = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS, _12, _13; + zval *b, b_sub, _0, _2, _3, i, bufferB, bufferA, _10, _23, _24, _25, _26, _27, _4$$3, _5$$3, _7$$3, _14$$4, _15$$4, _17$$4, _18$$4, _19$$4, _20$$4, _21$$4; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_2); ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&i); + ZVAL_UNDEF(&bufferB); + ZVAL_UNDEF(&bufferA); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_11); - ZVAL_UNDEF(&_12); - ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_23); + ZVAL_UNDEF(&_24); + ZVAL_UNDEF(&_25); + ZVAL_UNDEF(&_26); + ZVAL_UNDEF(&_27); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); ZVAL_UNDEF(&_7$$3); + ZVAL_UNDEF(&_14$$4); + ZVAL_UNDEF(&_15$$4); + ZVAL_UNDEF(&_17$$4); + ZVAL_UNDEF(&_18$$4); + ZVAL_UNDEF(&_19$$4); + ZVAL_UNDEF(&_20$$4); + ZVAL_UNDEF(&_21$$4); + ZVAL_UNDEF(&c); + ZVAL_UNDEF(&_22$$4); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_8$$3); ZVAL_UNDEF(&_9$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("m", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) @@ -6337,20 +5794,64 @@ PHP_METHOD(Tensor_Matrix, augmentLeft) zephir_cast_to_string(&_8$$3, &_7$$3); ZEPHIR_INIT_VAR(&_9$$3); ZEPHIR_CONCAT_SVSVS(&_9$$3, "Matrix A requires", &_6$$3, " rows but Matrix B has ", &_8$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_4$$3, "__construct", NULL, 3, &_9$$3); + ZEPHIR_CALL_METHOD(NULL, &_4$$3, "__construct", NULL, 2, &_9$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_4$$3, "tensor/matrix.zep", 1978); + zephir_throw_exception_debug(&_4$$3, "tensor/matrix.zep", 1867); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_CALL_METHOD(&_10, b, "asarray", NULL, 0); + ZEPHIR_INIT_VAR(&c); + array_init(&c); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + _13 = (zephir_get_numberval(&_10) - 1); + _12 = 0; + _11 = 0; + if (_12 <= _13) { + while (1) { + if (_11) { + _12++; + if (!(_12 <= _13)) { + break; + } + } else { + _11 = 1; + } + ZEPHIR_INIT_NVAR(&i); + ZVAL_LONG(&i, _12); + zephir_read_property_cached(&_14$$4, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_15$$4, b, "n", &_16, 0); + zephir_check_call_status(); + ZEPHIR_INIT_NVAR(&_17$$4); + mul_function(&_17$$4, &i, &_15$$4); + ZEPHIR_CALL_METHOD(&_15$$4, b, "n", &_16, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&bufferB, &_14$$4, "slice", NULL, 0, &_17$$4, &_15$$4); + zephir_check_call_status(); + zephir_read_property_cached(&_18$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_19$$4, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_INIT_NVAR(&_20$$4); + mul_function(&_20$$4, &i, &_19$$4); + zephir_read_property_cached(&_19$$4, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&bufferA, &_18$$4, "slice", NULL, 0, &_20$$4, &_19$$4); + zephir_check_call_status(); + ZEPHIR_INIT_NVAR(&_22$$4); + zephir_create_array(&_22$$4, 1, 0); + zephir_array_fast_append(&_22$$4, &bufferA); + ZEPHIR_CALL_METHOD(&_21$$4, &bufferB, "concat", NULL, 0, &_22$$4); + zephir_check_call_status(); + zephir_array_append(&c, &_21$$4, PH_SEPARATE, "tensor/matrix.zep", 1881); + } + } + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_CE_STATIC(&_23, tensor_tensorbuffer_ce, "fromBuffers", NULL, 0, &c); zephir_check_call_status(); - zephir_read_property_cached(&_11, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_INIT_VAR(&_12); - ZVAL_STRING(&_12, "array_merge"); - ZEPHIR_CALL_FUNCTION(&_13, "array_map", NULL, 14, &_12, &_10, &_11); + zephir_read_property_cached(&_24, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_25, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_26, b, "n", &_16, 0); zephir_check_call_status(); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &_13); + ZEPHIR_INIT_VAR(&_27); + zephir_add_function(&_27, &_25, &_26); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_23, &_24, &_27); zephir_check_call_status(); RETURN_MM(); } @@ -6365,34 +5866,54 @@ PHP_METHOD(Tensor_Matrix, augmentLeft) PHP_METHOD(Tensor_Matrix, augmentRight) { zval _6$$3, _8$$3, _9$$3; - zend_bool _1; + zval c, _22$$4; + zend_bool _1, _11; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _2, _3, _10, _11, _12, _13, _4$$3, _5$$3, _7$$3; + zephir_fcall_cache_entry *_19 = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS, _12, _13; + zval *b, b_sub, _0, _2, _3, i, bufferA, bufferB, _10, _23, _24, _25, _26, _27, _4$$3, _5$$3, _7$$3, _14$$4, _15$$4, _16$$4, _17$$4, _18$$4, _20$$4, _21$$4; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_2); ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&i); + ZVAL_UNDEF(&bufferA); + ZVAL_UNDEF(&bufferB); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_11); - ZVAL_UNDEF(&_12); - ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_23); + ZVAL_UNDEF(&_24); + ZVAL_UNDEF(&_25); + ZVAL_UNDEF(&_26); + ZVAL_UNDEF(&_27); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); ZVAL_UNDEF(&_7$$3); + ZVAL_UNDEF(&_14$$4); + ZVAL_UNDEF(&_15$$4); + ZVAL_UNDEF(&_16$$4); + ZVAL_UNDEF(&_17$$4); + ZVAL_UNDEF(&_18$$4); + ZVAL_UNDEF(&_20$$4); + ZVAL_UNDEF(&_21$$4); + ZVAL_UNDEF(&c); + ZVAL_UNDEF(&_22$$4); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_8$$3); ZVAL_UNDEF(&_9$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("m", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) @@ -6419,20 +5940,64 @@ PHP_METHOD(Tensor_Matrix, augmentRight) zephir_cast_to_string(&_8$$3, &_7$$3); ZEPHIR_INIT_VAR(&_9$$3); ZEPHIR_CONCAT_SVSVS(&_9$$3, "Matrix A requires", &_6$$3, " rows but Matrix B has ", &_8$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_4$$3, "__construct", NULL, 3, &_9$$3); + ZEPHIR_CALL_METHOD(NULL, &_4$$3, "__construct", NULL, 2, &_9$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_4$$3, "tensor/matrix.zep", 1996); + zephir_throw_exception_debug(&_4$$3, "tensor/matrix.zep", 1899); ZEPHIR_MM_RESTORE(); return; } - zephir_read_property_cached(&_10, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_11, b, "asarray", NULL, 0); + ZEPHIR_INIT_VAR(&c); + array_init(&c); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + _13 = (zephir_get_numberval(&_10) - 1); + _12 = 0; + _11 = 0; + if (_12 <= _13) { + while (1) { + if (_11) { + _12++; + if (!(_12 <= _13)) { + break; + } + } else { + _11 = 1; + } + ZEPHIR_INIT_NVAR(&i); + ZVAL_LONG(&i, _12); + zephir_read_property_cached(&_14$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_15$$4, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_INIT_NVAR(&_16$$4); + mul_function(&_16$$4, &i, &_15$$4); + zephir_read_property_cached(&_15$$4, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&bufferA, &_14$$4, "slice", NULL, 0, &_16$$4, &_15$$4); + zephir_check_call_status(); + zephir_read_property_cached(&_17$$4, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_18$$4, b, "n", &_19, 0); + zephir_check_call_status(); + ZEPHIR_INIT_NVAR(&_20$$4); + mul_function(&_20$$4, &i, &_18$$4); + ZEPHIR_CALL_METHOD(&_18$$4, b, "n", &_19, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&bufferB, &_17$$4, "slice", NULL, 0, &_20$$4, &_18$$4); + zephir_check_call_status(); + ZEPHIR_INIT_NVAR(&_22$$4); + zephir_create_array(&_22$$4, 1, 0); + zephir_array_fast_append(&_22$$4, &bufferB); + ZEPHIR_CALL_METHOD(&_21$$4, &bufferA, "concat", NULL, 0, &_22$$4); + zephir_check_call_status(); + zephir_array_append(&c, &_21$$4, PH_SEPARATE, "tensor/matrix.zep", 1913); + } + } + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_CE_STATIC(&_23, tensor_tensorbuffer_ce, "fromBuffers", NULL, 0, &c); zephir_check_call_status(); - ZEPHIR_INIT_VAR(&_12); - ZVAL_STRING(&_12, "array_merge"); - ZEPHIR_CALL_FUNCTION(&_13, "array_map", NULL, 14, &_12, &_10, &_11); + zephir_read_property_cached(&_24, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_25, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_26, b, "n", &_19, 0); zephir_check_call_status(); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &_13); + ZEPHIR_INIT_VAR(&_27); + zephir_add_function(&_27, &_25, &_26); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_23, &_24, &_27); zephir_check_call_status(); RETURN_MM(); } @@ -6447,28 +6012,40 @@ PHP_METHOD(Tensor_Matrix, augmentRight) */ PHP_METHOD(Tensor_Matrix, repeat) { - zend_bool _7$$3; - zval b, temp; + zval _4$$4; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zval *m_param = NULL, *n_param = NULL, rowA, _10, _11, _0$$3, *_1$$3, _2$$3, *_3$$3, _6$$3, _4$$4, _5$$4, _8$$6, _9$$6; + zval *m_param = NULL, *n_param = NULL, _0$$3, _1$$3, _2, _5, result, _8, _9, _10, _11, _12, _13, _14, _15, _3$$4, _6$$5, _7$$5; zend_long m, n, ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); + ZVAL_UNDEF(&_0$$3); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&result); + ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); ZVAL_UNDEF(&_11); - ZVAL_UNDEF(&_0$$3); - ZVAL_UNDEF(&_2$$3); - ZVAL_UNDEF(&_6$$3); + ZVAL_UNDEF(&_12); + ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_15); + ZVAL_UNDEF(&_3$$4); + ZVAL_UNDEF(&_6$$5); + ZVAL_UNDEF(&_7$$5); ZVAL_UNDEF(&_4$$4); - ZVAL_UNDEF(&_5$$4); - ZVAL_UNDEF(&_8$$6); - ZVAL_UNDEF(&_9$$6); - ZVAL_UNDEF(&b); - ZVAL_UNDEF(&temp); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); + _zephir_prop_0 = zend_string_init("n", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("a", 1, 1); } ZEND_PARSE_PARAMETERS_START(2, 2) @@ -6478,90 +6055,47 @@ PHP_METHOD(Tensor_Matrix, repeat) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 2, 0, &m_param, &n_param); - ZEPHIR_INIT_VAR(&b); - array_init(&b); - ZEPHIR_INIT_VAR(&temp); - array_init(&temp); - if (n > 0) { - zephir_read_property_cached(&_0$$3, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0$$3) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2$$3); - zephir_string_to_char_array(&_2$$3, &_0$$3); - _1$$3 = &_2$$3; - } else { - _1$$3 = &_0$$3; - } - zephir_is_iterable(_1$$3, 0, "tensor/matrix.zep", 2026); - if (Z_TYPE_P(_1$$3) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1$$3), _3$$3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3$$3); - ZEPHIR_INIT_NVAR(&temp); - array_init(&temp); - while (1) { - if (!(zephir_fast_count_int(&temp) <= n)) { - break; - } - zephir_array_append(&temp, &rowA, PH_SEPARATE, "tensor/matrix.zep", 2021); - } - ZEPHIR_INIT_NVAR(&_4$$4); - ZEPHIR_INIT_NVAR(&_5$$4); - ZVAL_STRING(&_5$$4, "array_merge"); - ZEPHIR_CALL_USER_FUNC_ARRAY(&_4$$4, &_5$$4, &temp); - zephir_check_call_status(); - zephir_array_append(&b, &_4$$4, PH_SEPARATE, "tensor/matrix.zep", 2024); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1$$3, "rewind", NULL, 0); - zephir_check_call_status(); - _7$$3 = 1; - while (1) { - if (_7$$3) { - _7$$3 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1$$3, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_6$$3, _1$$3, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_6$$3)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1$$3, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&temp); - array_init(&temp); - while (1) { - if (!(zephir_fast_count_int(&temp) <= n)) { - break; - } - zephir_array_append(&temp, &rowA, PH_SEPARATE, "tensor/matrix.zep", 2021); - } - ZEPHIR_INIT_NVAR(&_8$$6); - ZEPHIR_INIT_NVAR(&_9$$6); - ZVAL_STRING(&_9$$6, "array_merge"); - ZEPHIR_CALL_USER_FUNC_ARRAY(&_8$$6, &_9$$6, &temp); - zephir_check_call_status(); - zephir_array_append(&b, &_8$$6, PH_SEPARATE, "tensor/matrix.zep", 2024); - } - } - ZEPHIR_INIT_NVAR(&rowA); + if (UNEXPECTED(n < 1)) { + ZEPHIR_INIT_VAR(&_0$$3); + array_init(&_0$$3); + ZVAL_BOOL(&_1$$3, 0); + ZEPHIR_RETURN_CALL_SELF("fromArray", NULL, 0, &_0$$3, &_1$$3); + zephir_check_call_status(); + RETURN_MM(); } - ZEPHIR_INIT_NVAR(&temp); - array_init(&temp); - while (1) { - if (!(zephir_fast_count_int(&temp) <= m)) { - break; - } - zephir_array_append(&temp, &b, PH_SEPARATE, "tensor/matrix.zep", 2031); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + if (UNEXPECTED(ZEPHIR_LT_LONG(&_2, 1))) { + ZEPHIR_INIT_VAR(&_3$$4); + object_init_ex(&_3$$4, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_VAR(&_4$$4); + ZEPHIR_CONCAT_SS(&_4$$4, "Chunk length must be", " greater than 0, 0 given."); + ZEPHIR_CALL_METHOD(NULL, &_3$$4, "__construct", NULL, 2, &_4$$4); + zephir_check_call_status(); + zephir_throw_exception_debug(&_3$$4, "tensor/matrix.zep", 1935); + ZEPHIR_MM_RESTORE(); + return; } - ZEPHIR_INIT_VAR(&_10); - ZEPHIR_INIT_VAR(&_11); - ZVAL_STRING(&_11, "array_merge"); - ZEPHIR_CALL_USER_FUNC_ARRAY(&_10, &_11, &temp); - zephir_check_call_status(); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &_10); + zephir_read_property_cached(&_5, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + if (UNEXPECTED(ZEPHIR_LT_LONG(&_5, 1))) { + ZEPHIR_INIT_VAR(&_6$$5); + array_init(&_6$$5); + ZVAL_BOOL(&_7$$5, 0); + ZEPHIR_RETURN_CALL_SELF("fromArray", NULL, 0, &_6$$5, &_7$$5); + zephir_check_call_status(); + RETURN_MM(); + } + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_2, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_10, m); + ZVAL_LONG(&_11, n); + tensor_matrix_repeat(&result, &_8, &_9, &_10, &_11); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_12, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_13, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_14, (zephir_get_numberval(&_12) * ((m + 1)))); + ZVAL_LONG(&_15, (zephir_get_numberval(&_13) * ((n + 1)))); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_14, &_15); zephir_check_call_status(); RETURN_MM(); } @@ -6575,38 +6109,35 @@ PHP_METHOD(Tensor_Matrix, repeat) */ PHP_METHOD(Tensor_Matrix, multiplyMatrix) { - zend_bool _16; - zend_string *_11; - zend_ulong _10; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, _6, *_7, _8, *_9, _15, _2$$3, _3$$3, _4$$3, _5$$3, _12$$4, _13$$4, _14$$4, _17$$5, _18$$5, _19$$5; + zval *b, b_sub, _0, _1, result, _6, _7, _8, _9, _2$$3, _3$$3, _4$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_15); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&c); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) @@ -6621,79 +6152,26 @@ PHP_METHOD(Tensor_Matrix, multiplyMatrix) if (UNEXPECTED(!ZEPHIR_IS_IDENTICAL(&_0, &_1))) { ZEPHIR_INIT_VAR(&_2$$3); object_init_ex(&_2$$3, tensor_exceptions_dimensionalitymismatch_ce); - ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapeString", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_4$$3, b, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_4$$3, b, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_5$$3); ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_5$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2048); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1958); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_6, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_6) == IS_STRING) { - ZEPHIR_INIT_VAR(&_8); - zephir_string_to_char_array(&_8, &_6); - _7 = &_8; - } else { - _7 = &_6; - } - zephir_is_iterable(_7, 0, "tensor/matrix.zep", 2059); - if (Z_TYPE_P(_7) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_7), _10, _11, _9) - { - ZEPHIR_INIT_NVAR(&i); - if (_11 != NULL) { - ZVAL_STR_COPY(&i, _11); - } else { - ZVAL_LONG(&i, _10); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _9); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_14$$4); - zephir_array_fetch(&_14$$4, &_13$$4, &i, PH_NOISY, "tensor/matrix.zep", 2056); - tensor_multiply(&_12$$4, &_14$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2056); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "rewind", NULL, 0); - zephir_check_call_status(); - _16 = 1; - while (1) { - if (_16) { - _16 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_15, _7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_15)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _7, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_17$$5); - zephir_read_property_cached(&_18$$5, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_19$$5); - zephir_array_fetch(&_19$$5, &_18$$5, &i, PH_NOISY, "tensor/matrix.zep", 2056); - tensor_multiply(&_17$$5, &_19$$5, &rowB); - zephir_array_append(&c, &_17$$5, PH_SEPARATE, "tensor/matrix.zep", 2056); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, b, _zephir_prop_0, 0, PH_NOISY_CC | PH_READONLY); + tensor_multiply(&result, &_6, &_7); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_8, &_9); zephir_check_call_status(); RETURN_MM(); } @@ -6707,38 +6185,35 @@ PHP_METHOD(Tensor_Matrix, multiplyMatrix) */ PHP_METHOD(Tensor_Matrix, divideMatrix) { - zend_bool _16; - zend_string *_11; - zend_ulong _10; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, _6, *_7, _8, *_9, _15, _2$$3, _3$$3, _4$$3, _5$$3, _12$$4, _13$$4, _14$$4, _17$$5, _18$$5, _19$$5; + zval *b, b_sub, _0, _1, result, _6, _7, _8, _9, _2$$3, _3$$3, _4$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_15); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&c); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) @@ -6753,79 +6228,26 @@ PHP_METHOD(Tensor_Matrix, divideMatrix) if (UNEXPECTED(!ZEPHIR_IS_IDENTICAL(&_0, &_1))) { ZEPHIR_INIT_VAR(&_2$$3); object_init_ex(&_2$$3, tensor_exceptions_dimensionalitymismatch_ce); - ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapeString", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_4$$3, b, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_4$$3, b, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_5$$3); ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_5$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2073); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1977); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_6, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_6) == IS_STRING) { - ZEPHIR_INIT_VAR(&_8); - zephir_string_to_char_array(&_8, &_6); - _7 = &_8; - } else { - _7 = &_6; - } - zephir_is_iterable(_7, 0, "tensor/matrix.zep", 2084); - if (Z_TYPE_P(_7) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_7), _10, _11, _9) - { - ZEPHIR_INIT_NVAR(&i); - if (_11 != NULL) { - ZVAL_STR_COPY(&i, _11); - } else { - ZVAL_LONG(&i, _10); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _9); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_14$$4); - zephir_array_fetch(&_14$$4, &_13$$4, &i, PH_NOISY, "tensor/matrix.zep", 2081); - tensor_divide(&_12$$4, &_14$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2081); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "rewind", NULL, 0); - zephir_check_call_status(); - _16 = 1; - while (1) { - if (_16) { - _16 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_15, _7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_15)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _7, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_17$$5); - zephir_read_property_cached(&_18$$5, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_19$$5); - zephir_array_fetch(&_19$$5, &_18$$5, &i, PH_NOISY, "tensor/matrix.zep", 2081); - tensor_divide(&_17$$5, &_19$$5, &rowB); - zephir_array_append(&c, &_17$$5, PH_SEPARATE, "tensor/matrix.zep", 2081); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, b, _zephir_prop_0, 0, PH_NOISY_CC | PH_READONLY); + tensor_divide(&result, &_6, &_7); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_8, &_9); zephir_check_call_status(); RETURN_MM(); } @@ -6839,38 +6261,35 @@ PHP_METHOD(Tensor_Matrix, divideMatrix) */ PHP_METHOD(Tensor_Matrix, addMatrix) { - zend_bool _16; - zend_string *_11; - zend_ulong _10; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, _6, *_7, _8, *_9, _15, _2$$3, _3$$3, _4$$3, _5$$3, _12$$4, _13$$4, _14$$4, _17$$5, _18$$5, _19$$5; + zval *b, b_sub, _0, _1, result, _6, _7, _8, _9, _2$$3, _3$$3, _4$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_15); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&c); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) @@ -6885,79 +6304,26 @@ PHP_METHOD(Tensor_Matrix, addMatrix) if (UNEXPECTED(!ZEPHIR_IS_IDENTICAL(&_0, &_1))) { ZEPHIR_INIT_VAR(&_2$$3); object_init_ex(&_2$$3, tensor_exceptions_dimensionalitymismatch_ce); - ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapeString", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_4$$3, b, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_4$$3, b, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_5$$3); ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_5$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2098); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1996); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_6, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_6) == IS_STRING) { - ZEPHIR_INIT_VAR(&_8); - zephir_string_to_char_array(&_8, &_6); - _7 = &_8; - } else { - _7 = &_6; - } - zephir_is_iterable(_7, 0, "tensor/matrix.zep", 2109); - if (Z_TYPE_P(_7) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_7), _10, _11, _9) - { - ZEPHIR_INIT_NVAR(&i); - if (_11 != NULL) { - ZVAL_STR_COPY(&i, _11); - } else { - ZVAL_LONG(&i, _10); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _9); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_14$$4); - zephir_array_fetch(&_14$$4, &_13$$4, &i, PH_NOISY, "tensor/matrix.zep", 2106); - tensor_add(&_12$$4, &_14$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2106); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "rewind", NULL, 0); - zephir_check_call_status(); - _16 = 1; - while (1) { - if (_16) { - _16 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_15, _7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_15)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _7, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_17$$5); - zephir_read_property_cached(&_18$$5, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_19$$5); - zephir_array_fetch(&_19$$5, &_18$$5, &i, PH_NOISY, "tensor/matrix.zep", 2106); - tensor_add(&_17$$5, &_19$$5, &rowB); - zephir_array_append(&c, &_17$$5, PH_SEPARATE, "tensor/matrix.zep", 2106); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, b, _zephir_prop_0, 0, PH_NOISY_CC | PH_READONLY); + tensor_add(&result, &_6, &_7); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_8, &_9); zephir_check_call_status(); RETURN_MM(); } @@ -6971,38 +6337,35 @@ PHP_METHOD(Tensor_Matrix, addMatrix) */ PHP_METHOD(Tensor_Matrix, subtractMatrix) { - zend_bool _16; - zend_string *_11; - zend_ulong _10; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, _6, *_7, _8, *_9, _15, _2$$3, _3$$3, _4$$3, _5$$3, _12$$4, _13$$4, _14$$4, _17$$5, _18$$5, _19$$5; + zval *b, b_sub, _0, _1, result, _6, _7, _8, _9, _2$$3, _3$$3, _4$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_15); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&c); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) @@ -7017,79 +6380,26 @@ PHP_METHOD(Tensor_Matrix, subtractMatrix) if (UNEXPECTED(!ZEPHIR_IS_IDENTICAL(&_0, &_1))) { ZEPHIR_INIT_VAR(&_2$$3); object_init_ex(&_2$$3, tensor_exceptions_dimensionalitymismatch_ce); - ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapeString", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_4$$3, b, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_4$$3, b, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_5$$3); ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_5$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2123); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2015); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_6, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_6) == IS_STRING) { - ZEPHIR_INIT_VAR(&_8); - zephir_string_to_char_array(&_8, &_6); - _7 = &_8; - } else { - _7 = &_6; - } - zephir_is_iterable(_7, 0, "tensor/matrix.zep", 2134); - if (Z_TYPE_P(_7) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_7), _10, _11, _9) - { - ZEPHIR_INIT_NVAR(&i); - if (_11 != NULL) { - ZVAL_STR_COPY(&i, _11); - } else { - ZVAL_LONG(&i, _10); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _9); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_14$$4); - zephir_array_fetch(&_14$$4, &_13$$4, &i, PH_NOISY, "tensor/matrix.zep", 2131); - tensor_subtract(&_12$$4, &_14$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2131); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "rewind", NULL, 0); - zephir_check_call_status(); - _16 = 1; - while (1) { - if (_16) { - _16 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_15, _7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_15)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _7, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_17$$5); - zephir_read_property_cached(&_18$$5, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_19$$5); - zephir_array_fetch(&_19$$5, &_18$$5, &i, PH_NOISY, "tensor/matrix.zep", 2131); - tensor_subtract(&_17$$5, &_19$$5, &rowB); - zephir_array_append(&c, &_17$$5, PH_SEPARATE, "tensor/matrix.zep", 2131); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, b, _zephir_prop_0, 0, PH_NOISY_CC | PH_READONLY); + tensor_subtract(&result, &_6, &_7); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_8, &_9); zephir_check_call_status(); RETURN_MM(); } @@ -7104,38 +6414,35 @@ PHP_METHOD(Tensor_Matrix, subtractMatrix) */ PHP_METHOD(Tensor_Matrix, powMatrix) { - zend_bool _16; - zend_string *_11; - zend_ulong _10; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, _6, *_7, _8, *_9, _15, _2$$3, _3$$3, _4$$3, _5$$3, _12$$4, _13$$4, _14$$4, _17$$5, _18$$5, _19$$5; + zval *b, b_sub, _0, _1, result, _6, _7, _8, _9, _2$$3, _3$$3, _4$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_15); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&c); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) @@ -7150,79 +6457,26 @@ PHP_METHOD(Tensor_Matrix, powMatrix) if (UNEXPECTED(!ZEPHIR_IS_IDENTICAL(&_0, &_1))) { ZEPHIR_INIT_VAR(&_2$$3); object_init_ex(&_2$$3, tensor_exceptions_dimensionalitymismatch_ce); - ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapestring", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_4$$3, b, "shapestring", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_VAR(&_5$$3); - ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_5$$3); - zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2149); - ZEPHIR_MM_RESTORE(); - return; - } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_6, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_6) == IS_STRING) { - ZEPHIR_INIT_VAR(&_8); - zephir_string_to_char_array(&_8, &_6); - _7 = &_8; - } else { - _7 = &_6; - } - zephir_is_iterable(_7, 0, "tensor/matrix.zep", 2160); - if (Z_TYPE_P(_7) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_7), _10, _11, _9) - { - ZEPHIR_INIT_NVAR(&i); - if (_11 != NULL) { - ZVAL_STR_COPY(&i, _11); - } else { - ZVAL_LONG(&i, _10); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _9); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_14$$4); - zephir_array_fetch(&_14$$4, &_13$$4, &i, PH_NOISY, "tensor/matrix.zep", 2157); - tensor_pow(&_12$$4, &_14$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2157); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "rewind", NULL, 0); - zephir_check_call_status(); - _16 = 1; - while (1) { - if (_16) { - _16 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_15, _7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_15)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _7, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_17$$5); - zephir_read_property_cached(&_18$$5, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_19$$5); - zephir_array_fetch(&_19$$5, &_18$$5, &i, PH_NOISY, "tensor/matrix.zep", 2157); - tensor_pow(&_17$$5, &_19$$5, &rowB); - zephir_array_append(&c, &_17$$5, PH_SEPARATE, "tensor/matrix.zep", 2157); - } + ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapeString", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_4$$3, b, "shapeString", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&_5$$3); + ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2035); + ZEPHIR_MM_RESTORE(); + return; } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, b, _zephir_prop_0, 0, PH_NOISY_CC | PH_READONLY); + tensor_pow(&result, &_6, &_7); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_8, &_9); zephir_check_call_status(); RETURN_MM(); } @@ -7237,38 +6491,35 @@ PHP_METHOD(Tensor_Matrix, powMatrix) */ PHP_METHOD(Tensor_Matrix, modMatrix) { - zend_bool _16; - zend_string *_11; - zend_ulong _10; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, _6, *_7, _8, *_9, _15, _2$$3, _3$$3, _4$$3, _5$$3, _12$$4, _13$$4, _14$$4, _17$$5, _18$$5, _19$$5; + zval *b, b_sub, _0, _1, result, _6, _7, _8, _9, _2$$3, _3$$3, _4$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_15); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&c); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) @@ -7283,79 +6534,26 @@ PHP_METHOD(Tensor_Matrix, modMatrix) if (UNEXPECTED(!ZEPHIR_IS_IDENTICAL(&_0, &_1))) { ZEPHIR_INIT_VAR(&_2$$3); object_init_ex(&_2$$3, tensor_exceptions_dimensionalitymismatch_ce); - ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapeString", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_4$$3, b, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_4$$3, b, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_5$$3); ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_5$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2175); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2055); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_6, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_6) == IS_STRING) { - ZEPHIR_INIT_VAR(&_8); - zephir_string_to_char_array(&_8, &_6); - _7 = &_8; - } else { - _7 = &_6; - } - zephir_is_iterable(_7, 0, "tensor/matrix.zep", 2186); - if (Z_TYPE_P(_7) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_7), _10, _11, _9) - { - ZEPHIR_INIT_NVAR(&i); - if (_11 != NULL) { - ZVAL_STR_COPY(&i, _11); - } else { - ZVAL_LONG(&i, _10); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _9); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_14$$4); - zephir_array_fetch(&_14$$4, &_13$$4, &i, PH_NOISY, "tensor/matrix.zep", 2183); - tensor_mod(&_12$$4, &_14$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2183); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "rewind", NULL, 0); - zephir_check_call_status(); - _16 = 1; - while (1) { - if (_16) { - _16 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_15, _7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_15)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _7, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_17$$5); - zephir_read_property_cached(&_18$$5, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_19$$5); - zephir_array_fetch(&_19$$5, &_18$$5, &i, PH_NOISY, "tensor/matrix.zep", 2183); - tensor_mod(&_17$$5, &_19$$5, &rowB); - zephir_array_append(&c, &_17$$5, PH_SEPARATE, "tensor/matrix.zep", 2183); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, b, _zephir_prop_0, 0, PH_NOISY_CC | PH_READONLY); + tensor_mod(&result, &_6, &_7); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_8, &_9); zephir_check_call_status(); RETURN_MM(); } @@ -7370,38 +6568,35 @@ PHP_METHOD(Tensor_Matrix, modMatrix) */ PHP_METHOD(Tensor_Matrix, equalMatrix) { - zend_bool _16; - zend_string *_11; - zend_ulong _10; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, _6, *_7, _8, *_9, _15, _2$$3, _3$$3, _4$$3, _5$$3, _12$$4, _13$$4, _14$$4, _17$$5, _18$$5, _19$$5; + zval *b, b_sub, _0, _1, result, _6, _7, _8, _9, _2$$3, _3$$3, _4$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_15); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&c); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) @@ -7416,79 +6611,26 @@ PHP_METHOD(Tensor_Matrix, equalMatrix) if (UNEXPECTED(!ZEPHIR_IS_IDENTICAL(&_0, &_1))) { ZEPHIR_INIT_VAR(&_2$$3); object_init_ex(&_2$$3, tensor_exceptions_dimensionalitymismatch_ce); - ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapeString", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_4$$3, b, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_4$$3, b, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_5$$3); ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_5$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2201); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2075); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_6, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_6) == IS_STRING) { - ZEPHIR_INIT_VAR(&_8); - zephir_string_to_char_array(&_8, &_6); - _7 = &_8; - } else { - _7 = &_6; - } - zephir_is_iterable(_7, 0, "tensor/matrix.zep", 2212); - if (Z_TYPE_P(_7) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_7), _10, _11, _9) - { - ZEPHIR_INIT_NVAR(&i); - if (_11 != NULL) { - ZVAL_STR_COPY(&i, _11); - } else { - ZVAL_LONG(&i, _10); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _9); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_14$$4); - zephir_array_fetch(&_14$$4, &_13$$4, &i, PH_NOISY, "tensor/matrix.zep", 2209); - tensor_equal(&_12$$4, &_14$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2209); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "rewind", NULL, 0); - zephir_check_call_status(); - _16 = 1; - while (1) { - if (_16) { - _16 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_15, _7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_15)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _7, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_17$$5); - zephir_read_property_cached(&_18$$5, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_19$$5); - zephir_array_fetch(&_19$$5, &_18$$5, &i, PH_NOISY, "tensor/matrix.zep", 2209); - tensor_equal(&_17$$5, &_19$$5, &rowB); - zephir_array_append(&c, &_17$$5, PH_SEPARATE, "tensor/matrix.zep", 2209); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, b, _zephir_prop_0, 0, PH_NOISY_CC | PH_READONLY); + tensor_equal(&result, &_6, &_7); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_8, &_9); zephir_check_call_status(); RETURN_MM(); } @@ -7502,38 +6644,35 @@ PHP_METHOD(Tensor_Matrix, equalMatrix) */ PHP_METHOD(Tensor_Matrix, notEqualMatrix) { - zend_bool _16; - zend_string *_11; - zend_ulong _10; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, _6, *_7, _8, *_9, _15, _2$$3, _3$$3, _4$$3, _5$$3, _12$$4, _13$$4, _14$$4, _17$$5, _18$$5, _19$$5; + zval *b, b_sub, _0, _1, result, _6, _7, _8, _9, _2$$3, _3$$3, _4$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_15); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&c); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) @@ -7548,79 +6687,26 @@ PHP_METHOD(Tensor_Matrix, notEqualMatrix) if (UNEXPECTED(!ZEPHIR_IS_IDENTICAL(&_0, &_1))) { ZEPHIR_INIT_VAR(&_2$$3); object_init_ex(&_2$$3, tensor_exceptions_dimensionalitymismatch_ce); - ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapeString", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_4$$3, b, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_4$$3, b, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_5$$3); ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_5$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2226); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2094); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_6, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_6) == IS_STRING) { - ZEPHIR_INIT_VAR(&_8); - zephir_string_to_char_array(&_8, &_6); - _7 = &_8; - } else { - _7 = &_6; - } - zephir_is_iterable(_7, 0, "tensor/matrix.zep", 2237); - if (Z_TYPE_P(_7) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_7), _10, _11, _9) - { - ZEPHIR_INIT_NVAR(&i); - if (_11 != NULL) { - ZVAL_STR_COPY(&i, _11); - } else { - ZVAL_LONG(&i, _10); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _9); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_14$$4); - zephir_array_fetch(&_14$$4, &_13$$4, &i, PH_NOISY, "tensor/matrix.zep", 2234); - tensor_not_equal(&_12$$4, &_14$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2234); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "rewind", NULL, 0); - zephir_check_call_status(); - _16 = 1; - while (1) { - if (_16) { - _16 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_15, _7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_15)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _7, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_17$$5); - zephir_read_property_cached(&_18$$5, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_19$$5); - zephir_array_fetch(&_19$$5, &_18$$5, &i, PH_NOISY, "tensor/matrix.zep", 2234); - tensor_not_equal(&_17$$5, &_19$$5, &rowB); - zephir_array_append(&c, &_17$$5, PH_SEPARATE, "tensor/matrix.zep", 2234); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, b, _zephir_prop_0, 0, PH_NOISY_CC | PH_READONLY); + tensor_not_equal(&result, &_6, &_7); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_8, &_9); zephir_check_call_status(); RETURN_MM(); } @@ -7635,38 +6721,35 @@ PHP_METHOD(Tensor_Matrix, notEqualMatrix) */ PHP_METHOD(Tensor_Matrix, greaterMatrix) { - zend_bool _16; - zend_string *_11; - zend_ulong _10; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, _6, *_7, _8, *_9, _15, _2$$3, _3$$3, _4$$3, _5$$3, _12$$4, _13$$4, _14$$4, _17$$5, _18$$5, _19$$5; + zval *b, b_sub, _0, _1, result, _6, _7, _8, _9, _2$$3, _3$$3, _4$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_15); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&c); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) @@ -7681,79 +6764,26 @@ PHP_METHOD(Tensor_Matrix, greaterMatrix) if (UNEXPECTED(!ZEPHIR_IS_IDENTICAL(&_0, &_1))) { ZEPHIR_INIT_VAR(&_2$$3); object_init_ex(&_2$$3, tensor_exceptions_dimensionalitymismatch_ce); - ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapeString", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_4$$3, b, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_4$$3, b, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_5$$3); ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_5$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2252); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2114); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_6, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_6) == IS_STRING) { - ZEPHIR_INIT_VAR(&_8); - zephir_string_to_char_array(&_8, &_6); - _7 = &_8; - } else { - _7 = &_6; - } - zephir_is_iterable(_7, 0, "tensor/matrix.zep", 2263); - if (Z_TYPE_P(_7) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_7), _10, _11, _9) - { - ZEPHIR_INIT_NVAR(&i); - if (_11 != NULL) { - ZVAL_STR_COPY(&i, _11); - } else { - ZVAL_LONG(&i, _10); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _9); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_14$$4); - zephir_array_fetch(&_14$$4, &_13$$4, &i, PH_NOISY, "tensor/matrix.zep", 2260); - tensor_greater(&_12$$4, &_14$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2260); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "rewind", NULL, 0); - zephir_check_call_status(); - _16 = 1; - while (1) { - if (_16) { - _16 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_15, _7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_15)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _7, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_17$$5); - zephir_read_property_cached(&_18$$5, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_19$$5); - zephir_array_fetch(&_19$$5, &_18$$5, &i, PH_NOISY, "tensor/matrix.zep", 2260); - tensor_greater(&_17$$5, &_19$$5, &rowB); - zephir_array_append(&c, &_17$$5, PH_SEPARATE, "tensor/matrix.zep", 2260); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, b, _zephir_prop_0, 0, PH_NOISY_CC | PH_READONLY); + tensor_greater(&result, &_6, &_7); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_8, &_9); zephir_check_call_status(); RETURN_MM(); } @@ -7768,38 +6798,35 @@ PHP_METHOD(Tensor_Matrix, greaterMatrix) */ PHP_METHOD(Tensor_Matrix, greaterEqualMatrix) { - zend_bool _16; - zend_string *_11; - zend_ulong _10; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, _6, *_7, _8, *_9, _15, _2$$3, _3$$3, _4$$3, _5$$3, _12$$4, _13$$4, _14$$4, _17$$5, _18$$5, _19$$5; + zval *b, b_sub, _0, _1, result, _6, _7, _8, _9, _2$$3, _3$$3, _4$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_15); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&c); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) @@ -7814,79 +6841,26 @@ PHP_METHOD(Tensor_Matrix, greaterEqualMatrix) if (UNEXPECTED(!ZEPHIR_IS_IDENTICAL(&_0, &_1))) { ZEPHIR_INIT_VAR(&_2$$3); object_init_ex(&_2$$3, tensor_exceptions_dimensionalitymismatch_ce); - ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapeString", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_4$$3, b, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_4$$3, b, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_5$$3); ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_5$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2278); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2134); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_6, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_6) == IS_STRING) { - ZEPHIR_INIT_VAR(&_8); - zephir_string_to_char_array(&_8, &_6); - _7 = &_8; - } else { - _7 = &_6; - } - zephir_is_iterable(_7, 0, "tensor/matrix.zep", 2289); - if (Z_TYPE_P(_7) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_7), _10, _11, _9) - { - ZEPHIR_INIT_NVAR(&i); - if (_11 != NULL) { - ZVAL_STR_COPY(&i, _11); - } else { - ZVAL_LONG(&i, _10); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _9); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_14$$4); - zephir_array_fetch(&_14$$4, &_13$$4, &i, PH_NOISY, "tensor/matrix.zep", 2286); - tensor_greater_equal(&_12$$4, &_14$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2286); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "rewind", NULL, 0); - zephir_check_call_status(); - _16 = 1; - while (1) { - if (_16) { - _16 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_15, _7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_15)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _7, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_17$$5); - zephir_read_property_cached(&_18$$5, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_19$$5); - zephir_array_fetch(&_19$$5, &_18$$5, &i, PH_NOISY, "tensor/matrix.zep", 2286); - tensor_greater_equal(&_17$$5, &_19$$5, &rowB); - zephir_array_append(&c, &_17$$5, PH_SEPARATE, "tensor/matrix.zep", 2286); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, b, _zephir_prop_0, 0, PH_NOISY_CC | PH_READONLY); + tensor_greater_equal(&result, &_6, &_7); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_8, &_9); zephir_check_call_status(); RETURN_MM(); } @@ -7900,38 +6874,35 @@ PHP_METHOD(Tensor_Matrix, greaterEqualMatrix) */ PHP_METHOD(Tensor_Matrix, lessMatrix) { - zend_bool _16; - zend_string *_11; - zend_ulong _10; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, _6, *_7, _8, *_9, _15, _2$$3, _3$$3, _4$$3, _5$$3, _12$$4, _13$$4, _14$$4, _17$$5, _18$$5, _19$$5; + zval *b, b_sub, _0, _1, result, _6, _7, _8, _9, _2$$3, _3$$3, _4$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_15); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&c); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) @@ -7946,79 +6917,26 @@ PHP_METHOD(Tensor_Matrix, lessMatrix) if (UNEXPECTED(!ZEPHIR_IS_IDENTICAL(&_0, &_1))) { ZEPHIR_INIT_VAR(&_2$$3); object_init_ex(&_2$$3, tensor_exceptions_dimensionalitymismatch_ce); - ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapeString", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_4$$3, b, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_4$$3, b, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_5$$3); ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_5$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2303); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2153); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_6, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_6) == IS_STRING) { - ZEPHIR_INIT_VAR(&_8); - zephir_string_to_char_array(&_8, &_6); - _7 = &_8; - } else { - _7 = &_6; - } - zephir_is_iterable(_7, 0, "tensor/matrix.zep", 2314); - if (Z_TYPE_P(_7) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_7), _10, _11, _9) - { - ZEPHIR_INIT_NVAR(&i); - if (_11 != NULL) { - ZVAL_STR_COPY(&i, _11); - } else { - ZVAL_LONG(&i, _10); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _9); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_14$$4); - zephir_array_fetch(&_14$$4, &_13$$4, &i, PH_NOISY, "tensor/matrix.zep", 2311); - tensor_less(&_12$$4, &_14$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2311); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "rewind", NULL, 0); - zephir_check_call_status(); - _16 = 1; - while (1) { - if (_16) { - _16 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_15, _7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_15)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _7, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_17$$5); - zephir_read_property_cached(&_18$$5, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_19$$5); - zephir_array_fetch(&_19$$5, &_18$$5, &i, PH_NOISY, "tensor/matrix.zep", 2311); - tensor_less(&_17$$5, &_19$$5, &rowB); - zephir_array_append(&c, &_17$$5, PH_SEPARATE, "tensor/matrix.zep", 2311); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, b, _zephir_prop_0, 0, PH_NOISY_CC | PH_READONLY); + tensor_less(&result, &_6, &_7); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_8, &_9); zephir_check_call_status(); RETURN_MM(); } @@ -8032,38 +6950,35 @@ PHP_METHOD(Tensor_Matrix, lessMatrix) */ PHP_METHOD(Tensor_Matrix, lessEqualMatrix) { - zend_bool _16; - zend_string *_11; - zend_ulong _10; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, rowB, _6, *_7, _8, *_9, _15, _2$$3, _3$$3, _4$$3, _5$$3, _12$$4, _13$$4, _14$$4, _17$$5, _18$$5, _19$$5; + zval *b, b_sub, _0, _1, result, _6, _7, _8, _9, _2$$3, _3$$3, _4$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_15); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&_18$$5); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&c); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\matrix"))) @@ -8078,79 +6993,26 @@ PHP_METHOD(Tensor_Matrix, lessEqualMatrix) if (UNEXPECTED(!ZEPHIR_IS_IDENTICAL(&_0, &_1))) { ZEPHIR_INIT_VAR(&_2$$3); object_init_ex(&_2$$3, tensor_exceptions_dimensionalitymismatch_ce); - ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_3$$3, this_ptr, "shapeString", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_4$$3, b, "shapestring", NULL, 0); + ZEPHIR_CALL_METHOD(&_4$$3, b, "shapeString", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_5$$3); ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_5$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2328); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2172); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_6, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_6) == IS_STRING) { - ZEPHIR_INIT_VAR(&_8); - zephir_string_to_char_array(&_8, &_6); - _7 = &_8; - } else { - _7 = &_6; - } - zephir_is_iterable(_7, 0, "tensor/matrix.zep", 2339); - if (Z_TYPE_P(_7) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_7), _10, _11, _9) - { - ZEPHIR_INIT_NVAR(&i); - if (_11 != NULL) { - ZVAL_STR_COPY(&i, _11); - } else { - ZVAL_LONG(&i, _10); - } - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _9); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_14$$4); - zephir_array_fetch(&_14$$4, &_13$$4, &i, PH_NOISY, "tensor/matrix.zep", 2336); - tensor_less_equal(&_12$$4, &_14$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2336); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "rewind", NULL, 0); - zephir_check_call_status(); - _16 = 1; - while (1) { - if (_16) { - _16 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _7, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_15, _7, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_15)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _7, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&rowB, _7, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_17$$5); - zephir_read_property_cached(&_18$$5, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_19$$5); - zephir_array_fetch(&_19$$5, &_18$$5, &i, PH_NOISY, "tensor/matrix.zep", 2336); - tensor_less_equal(&_17$$5, &_19$$5, &rowB); - zephir_array_append(&c, &_17$$5, PH_SEPARATE, "tensor/matrix.zep", 2336); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_7, b, _zephir_prop_0, 0, PH_NOISY_CC | PH_READONLY); + tensor_less_equal(&result, &_6, &_7); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_8, &_9); zephir_check_call_status(); RETURN_MM(); } @@ -8165,38 +7027,38 @@ PHP_METHOD(Tensor_Matrix, lessEqualMatrix) PHP_METHOD(Tensor_Matrix, multiplyVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _14; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowA, bHat, _8, *_9, _10, *_11, _13, _2$$3, _3$$3, _5$$3, _12$$4, _15$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_15$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\vector"))) @@ -8218,59 +7080,22 @@ PHP_METHOD(Tensor_Matrix, multiplyVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2354); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2192); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&bHat, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2367); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - tensor_multiply(&_12$$4, &rowA, &bHat); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2364); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _14 = 1; - while (1) { - if (_14) { - _14 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_13, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_13)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_15$$5); - tensor_multiply(&_15$$5, &rowA, &bHat); - zephir_array_append(&c, &_15$$5, PH_SEPARATE, "tensor/matrix.zep", 2364); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + tensor_multiply_row(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -8285,38 +7110,38 @@ PHP_METHOD(Tensor_Matrix, multiplyVector) PHP_METHOD(Tensor_Matrix, divideVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _14; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowA, bHat, _8, *_9, _10, *_11, _13, _2$$3, _3$$3, _5$$3, _12$$4, _15$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_15$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\vector"))) @@ -8338,59 +7163,22 @@ PHP_METHOD(Tensor_Matrix, divideVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2382); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2216); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&bHat, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2395); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - tensor_divide(&_12$$4, &rowA, &bHat); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2392); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _14 = 1; - while (1) { - if (_14) { - _14 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_13, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_13)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_15$$5); - tensor_divide(&_15$$5, &rowA, &bHat); - zephir_array_append(&c, &_15$$5, PH_SEPARATE, "tensor/matrix.zep", 2392); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + tensor_divide_row(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -8405,38 +7193,38 @@ PHP_METHOD(Tensor_Matrix, divideVector) PHP_METHOD(Tensor_Matrix, addVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _14; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowA, bHat, _8, *_9, _10, *_11, _13, _2$$3, _3$$3, _5$$3, _12$$4, _15$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_15$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\vector"))) @@ -8458,59 +7246,22 @@ PHP_METHOD(Tensor_Matrix, addVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2410); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2240); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&bHat, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2423); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - tensor_add(&_12$$4, &rowA, &bHat); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2420); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _14 = 1; - while (1) { - if (_14) { - _14 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_13, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_13)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_15$$5); - tensor_add(&_15$$5, &rowA, &bHat); - zephir_array_append(&c, &_15$$5, PH_SEPARATE, "tensor/matrix.zep", 2420); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + tensor_add_row(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -8525,38 +7276,38 @@ PHP_METHOD(Tensor_Matrix, addVector) PHP_METHOD(Tensor_Matrix, subtractVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _14; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowA, bHat, _8, *_9, _10, *_11, _13, _2$$3, _3$$3, _5$$3, _12$$4, _15$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_15$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\vector"))) @@ -8578,59 +7329,22 @@ PHP_METHOD(Tensor_Matrix, subtractVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2438); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2264); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&bHat, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2451); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - tensor_subtract(&_12$$4, &rowA, &bHat); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2448); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _14 = 1; - while (1) { - if (_14) { - _14 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_13, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_13)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_15$$5); - tensor_subtract(&_15$$5, &rowA, &bHat); - zephir_array_append(&c, &_15$$5, PH_SEPARATE, "tensor/matrix.zep", 2448); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + tensor_subtract_row(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -8645,38 +7359,38 @@ PHP_METHOD(Tensor_Matrix, subtractVector) PHP_METHOD(Tensor_Matrix, powVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _14; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowA, bHat, _8, *_9, _10, *_11, _13, _2$$3, _3$$3, _5$$3, _12$$4, _15$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_15$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\vector"))) @@ -8698,59 +7412,22 @@ PHP_METHOD(Tensor_Matrix, powVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2466); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2288); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&bHat, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2479); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - tensor_pow(&_12$$4, &rowA, &bHat); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2476); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _14 = 1; - while (1) { - if (_14) { - _14 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_13, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_13)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_15$$5); - tensor_pow(&_15$$5, &rowA, &bHat); - zephir_array_append(&c, &_15$$5, PH_SEPARATE, "tensor/matrix.zep", 2476); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + tensor_pow_row(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -8765,38 +7442,38 @@ PHP_METHOD(Tensor_Matrix, powVector) PHP_METHOD(Tensor_Matrix, modVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _14; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowA, bHat, _8, *_9, _10, *_11, _13, _2$$3, _3$$3, _5$$3, _12$$4, _15$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_15$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\vector"))) @@ -8818,59 +7495,22 @@ PHP_METHOD(Tensor_Matrix, modVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2494); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2312); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&bHat, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2507); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - tensor_mod(&_12$$4, &rowA, &bHat); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2504); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _14 = 1; - while (1) { - if (_14) { - _14 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_13, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_13)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_15$$5); - tensor_mod(&_15$$5, &rowA, &bHat); - zephir_array_append(&c, &_15$$5, PH_SEPARATE, "tensor/matrix.zep", 2504); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + tensor_mod_row(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -8886,38 +7526,38 @@ PHP_METHOD(Tensor_Matrix, modVector) PHP_METHOD(Tensor_Matrix, equalVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _14; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowA, bHat, _8, *_9, _10, *_11, _13, _2$$3, _3$$3, _5$$3, _12$$4, _15$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_15$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\vector"))) @@ -8939,59 +7579,22 @@ PHP_METHOD(Tensor_Matrix, equalVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2523); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2337); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&bHat, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2536); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - tensor_equal(&_12$$4, &rowA, &bHat); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2533); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _14 = 1; - while (1) { - if (_14) { - _14 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_13, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_13)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_15$$5); - tensor_equal(&_15$$5, &rowA, &bHat); - zephir_array_append(&c, &_15$$5, PH_SEPARATE, "tensor/matrix.zep", 2533); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + tensor_equal_row(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -9006,38 +7609,38 @@ PHP_METHOD(Tensor_Matrix, equalVector) PHP_METHOD(Tensor_Matrix, notEqualVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _14; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowA, bHat, _8, *_9, _10, *_11, _13, _2$$3, _3$$3, _5$$3, _12$$4, _15$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_15$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\vector"))) @@ -9059,59 +7662,22 @@ PHP_METHOD(Tensor_Matrix, notEqualVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2551); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2361); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&bHat, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2564); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - tensor_not_equal(&_12$$4, &rowA, &bHat); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2561); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _14 = 1; - while (1) { - if (_14) { - _14 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_13, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_13)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_15$$5); - tensor_not_equal(&_15$$5, &rowA, &bHat); - zephir_array_append(&c, &_15$$5, PH_SEPARATE, "tensor/matrix.zep", 2561); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + tensor_not_equal_row(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -9126,38 +7692,38 @@ PHP_METHOD(Tensor_Matrix, notEqualVector) PHP_METHOD(Tensor_Matrix, greaterVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _14; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowA, bHat, _8, *_9, _10, *_11, _13, _2$$3, _3$$3, _5$$3, _12$$4, _15$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_15$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\vector"))) @@ -9179,59 +7745,22 @@ PHP_METHOD(Tensor_Matrix, greaterVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2579); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2385); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&bHat, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2592); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - tensor_greater(&_12$$4, &rowA, &bHat); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2589); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _14 = 1; - while (1) { - if (_14) { - _14 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_13, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_13)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_15$$5); - tensor_greater(&_15$$5, &rowA, &bHat); - zephir_array_append(&c, &_15$$5, PH_SEPARATE, "tensor/matrix.zep", 2589); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + tensor_greater_row(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -9246,38 +7775,38 @@ PHP_METHOD(Tensor_Matrix, greaterVector) PHP_METHOD(Tensor_Matrix, greaterEqualVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _14; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowA, bHat, _8, *_9, _10, *_11, _13, _2$$3, _3$$3, _5$$3, _12$$4, _15$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_15$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\vector"))) @@ -9299,59 +7828,22 @@ PHP_METHOD(Tensor_Matrix, greaterEqualVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2607); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2409); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&bHat, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2620); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - tensor_greater_equal(&_12$$4, &rowA, &bHat); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2617); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _14 = 1; - while (1) { - if (_14) { - _14 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_13, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_13)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_15$$5); - tensor_greater_equal(&_15$$5, &rowA, &bHat); - zephir_array_append(&c, &_15$$5, PH_SEPARATE, "tensor/matrix.zep", 2617); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + tensor_greater_equal_row(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -9366,38 +7858,38 @@ PHP_METHOD(Tensor_Matrix, greaterEqualVector) PHP_METHOD(Tensor_Matrix, lessVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _14; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowA, bHat, _8, *_9, _10, *_11, _13, _2$$3, _3$$3, _5$$3, _12$$4, _15$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_15$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\vector"))) @@ -9419,59 +7911,22 @@ PHP_METHOD(Tensor_Matrix, lessVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2635); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2433); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&bHat, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2648); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - tensor_less(&_12$$4, &rowA, &bHat); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2645); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _14 = 1; - while (1) { - if (_14) { - _14 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_13, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_13)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_15$$5); - tensor_less(&_15$$5, &rowA, &bHat); - zephir_array_append(&c, &_15$$5, PH_SEPARATE, "tensor/matrix.zep", 2645); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + tensor_less_row(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -9487,38 +7942,38 @@ PHP_METHOD(Tensor_Matrix, lessVector) PHP_METHOD(Tensor_Matrix, lessEqualVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _14; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowA, bHat, _8, *_9, _10, *_11, _13, _2$$3, _3$$3, _5$$3, _12$$4, _15$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowA); ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_13); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_15$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("n", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("m", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\vector"))) @@ -9540,59 +7995,22 @@ PHP_METHOD(Tensor_Matrix, lessEqualVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2664); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2458); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&bHat, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2677); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - tensor_less_equal(&_12$$4, &rowA, &bHat); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/matrix.zep", 2674); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _14 = 1; - while (1) { - if (_14) { - _14 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_13, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_13)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_15$$5); - tensor_less_equal(&_15$$5, &rowA, &bHat); - zephir_array_append(&c, &_15$$5, PH_SEPARATE, "tensor/matrix.zep", 2674); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + tensor_less_equal_row(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_0, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -9607,44 +8025,38 @@ PHP_METHOD(Tensor_Matrix, lessEqualVector) PHP_METHOD(Tensor_Matrix, multiplyColumnVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _18; - zend_string *_13; - zend_ulong _12; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, valueB, _8, *_9, _10, *_11, _17, _2$$3, _3$$3, _5$$3, _14$$4, _15$$4, _16$$4, _19$$5, _20$$5, _21$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&valueB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_17); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_15$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&_20$$5); - ZVAL_UNDEF(&_21$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("m", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\columnvector"))) @@ -9666,73 +8078,22 @@ PHP_METHOD(Tensor_Matrix, multiplyColumnVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2692); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2482); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2703); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _11); - ZEPHIR_INIT_NVAR(&_14$$4); - zephir_read_property_cached(&_15$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_16$$4); - zephir_array_fetch(&_16$$4, &_15$$4, &i, PH_NOISY, "tensor/matrix.zep", 2700); - tensor_multiply_scalar(&_14$$4, &_16$$4, &valueB); - zephir_array_append(&c, &_14$$4, PH_SEPARATE, "tensor/matrix.zep", 2700); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _18 = 1; - while (1) { - if (_18) { - _18 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_17, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_17)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&valueB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_19$$5); - zephir_read_property_cached(&_20$$5, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_21$$5); - zephir_array_fetch(&_21$$5, &_20$$5, &i, PH_NOISY, "tensor/matrix.zep", 2700); - tensor_multiply_scalar(&_19$$5, &_21$$5, &valueB); - zephir_array_append(&c, &_19$$5, PH_SEPARATE, "tensor/matrix.zep", 2700); - } - } - ZEPHIR_INIT_NVAR(&valueB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_multiply_col(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -9747,44 +8108,38 @@ PHP_METHOD(Tensor_Matrix, multiplyColumnVector) PHP_METHOD(Tensor_Matrix, divideColumnVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _18; - zend_string *_13; - zend_ulong _12; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, valueB, _8, *_9, _10, *_11, _17, _2$$3, _3$$3, _5$$3, _14$$4, _15$$4, _16$$4, _19$$5, _20$$5, _21$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&valueB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_17); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_15$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&_20$$5); - ZVAL_UNDEF(&_21$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("m", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\columnvector"))) @@ -9806,73 +8161,22 @@ PHP_METHOD(Tensor_Matrix, divideColumnVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2718); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2506); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2729); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _11); - ZEPHIR_INIT_NVAR(&_14$$4); - zephir_read_property_cached(&_15$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_16$$4); - zephir_array_fetch(&_16$$4, &_15$$4, &i, PH_NOISY, "tensor/matrix.zep", 2726); - tensor_divide_scalar(&_14$$4, &_16$$4, &valueB); - zephir_array_append(&c, &_14$$4, PH_SEPARATE, "tensor/matrix.zep", 2726); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _18 = 1; - while (1) { - if (_18) { - _18 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_17, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_17)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&valueB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_19$$5); - zephir_read_property_cached(&_20$$5, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_21$$5); - zephir_array_fetch(&_21$$5, &_20$$5, &i, PH_NOISY, "tensor/matrix.zep", 2726); - tensor_divide_scalar(&_19$$5, &_21$$5, &valueB); - zephir_array_append(&c, &_19$$5, PH_SEPARATE, "tensor/matrix.zep", 2726); - } - } - ZEPHIR_INIT_NVAR(&valueB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_divide_col(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -9887,44 +8191,38 @@ PHP_METHOD(Tensor_Matrix, divideColumnVector) PHP_METHOD(Tensor_Matrix, addColumnVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _18; - zend_string *_13; - zend_ulong _12; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, valueB, _8, *_9, _10, *_11, _17, _2$$3, _3$$3, _5$$3, _14$$4, _15$$4, _16$$4, _19$$5, _20$$5, _21$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&valueB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_17); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_15$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&_20$$5); - ZVAL_UNDEF(&_21$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("m", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\columnvector"))) @@ -9946,73 +8244,22 @@ PHP_METHOD(Tensor_Matrix, addColumnVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); - zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2744); - ZEPHIR_MM_RESTORE(); - return; - } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2755); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _11); - ZEPHIR_INIT_NVAR(&_14$$4); - zephir_read_property_cached(&_15$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_16$$4); - zephir_array_fetch(&_16$$4, &_15$$4, &i, PH_NOISY, "tensor/matrix.zep", 2752); - tensor_add_scalar(&_14$$4, &_16$$4, &valueB); - zephir_array_append(&c, &_14$$4, PH_SEPARATE, "tensor/matrix.zep", 2752); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - _18 = 1; - while (1) { - if (_18) { - _18 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_17, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_17)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&valueB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_19$$5); - zephir_read_property_cached(&_20$$5, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_21$$5); - zephir_array_fetch(&_21$$5, &_20$$5, &i, PH_NOISY, "tensor/matrix.zep", 2752); - tensor_add_scalar(&_19$$5, &_21$$5, &valueB); - zephir_array_append(&c, &_19$$5, PH_SEPARATE, "tensor/matrix.zep", 2752); - } + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2530); + ZEPHIR_MM_RESTORE(); + return; } - ZEPHIR_INIT_NVAR(&valueB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_add_col(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -10027,44 +8274,38 @@ PHP_METHOD(Tensor_Matrix, addColumnVector) PHP_METHOD(Tensor_Matrix, subtractColumnVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _18; - zend_string *_13; - zend_ulong _12; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, valueB, _8, *_9, _10, *_11, _17, _2$$3, _3$$3, _5$$3, _14$$4, _15$$4, _16$$4, _19$$5, _20$$5, _21$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&valueB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_17); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_15$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&_20$$5); - ZVAL_UNDEF(&_21$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("m", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\columnvector"))) @@ -10086,73 +8327,22 @@ PHP_METHOD(Tensor_Matrix, subtractColumnVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2770); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2554); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2781); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _11); - ZEPHIR_INIT_NVAR(&_14$$4); - zephir_read_property_cached(&_15$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_16$$4); - zephir_array_fetch(&_16$$4, &_15$$4, &i, PH_NOISY, "tensor/matrix.zep", 2778); - tensor_subtract_scalar(&_14$$4, &_16$$4, &valueB); - zephir_array_append(&c, &_14$$4, PH_SEPARATE, "tensor/matrix.zep", 2778); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _18 = 1; - while (1) { - if (_18) { - _18 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_17, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_17)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&valueB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_19$$5); - zephir_read_property_cached(&_20$$5, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_21$$5); - zephir_array_fetch(&_21$$5, &_20$$5, &i, PH_NOISY, "tensor/matrix.zep", 2778); - tensor_subtract_scalar(&_19$$5, &_21$$5, &valueB); - zephir_array_append(&c, &_19$$5, PH_SEPARATE, "tensor/matrix.zep", 2778); - } - } - ZEPHIR_INIT_NVAR(&valueB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_subtract_col(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -10167,44 +8357,38 @@ PHP_METHOD(Tensor_Matrix, subtractColumnVector) PHP_METHOD(Tensor_Matrix, powColumnVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _18; - zend_string *_13; - zend_ulong _12; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, valueB, _8, *_9, _10, *_11, _17, _2$$3, _3$$3, _5$$3, _14$$4, _15$$4, _16$$4, _19$$5, _20$$5, _21$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&valueB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_17); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_15$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&_20$$5); - ZVAL_UNDEF(&_21$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("m", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\columnvector"))) @@ -10226,73 +8410,22 @@ PHP_METHOD(Tensor_Matrix, powColumnVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2796); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2578); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2807); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _11); - ZEPHIR_INIT_NVAR(&_14$$4); - zephir_read_property_cached(&_15$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_16$$4); - zephir_array_fetch(&_16$$4, &_15$$4, &i, PH_NOISY, "tensor/matrix.zep", 2804); - tensor_pow_scalar(&_14$$4, &_16$$4, &valueB); - zephir_array_append(&c, &_14$$4, PH_SEPARATE, "tensor/matrix.zep", 2804); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _18 = 1; - while (1) { - if (_18) { - _18 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_17, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_17)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&valueB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_19$$5); - zephir_read_property_cached(&_20$$5, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_21$$5); - zephir_array_fetch(&_21$$5, &_20$$5, &i, PH_NOISY, "tensor/matrix.zep", 2804); - tensor_pow_scalar(&_19$$5, &_21$$5, &valueB); - zephir_array_append(&c, &_19$$5, PH_SEPARATE, "tensor/matrix.zep", 2804); - } - } - ZEPHIR_INIT_NVAR(&valueB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_pow_col(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -10307,44 +8440,38 @@ PHP_METHOD(Tensor_Matrix, powColumnVector) PHP_METHOD(Tensor_Matrix, modColumnVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _18; - zend_string *_13; - zend_ulong _12; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, valueB, _8, *_9, _10, *_11, _17, _2$$3, _3$$3, _5$$3, _14$$4, _15$$4, _16$$4, _19$$5, _20$$5, _21$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&valueB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_17); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_15$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&_20$$5); - ZVAL_UNDEF(&_21$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("m", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\columnvector"))) @@ -10366,73 +8493,22 @@ PHP_METHOD(Tensor_Matrix, modColumnVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2822); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2602); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2833); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _11); - ZEPHIR_INIT_NVAR(&_14$$4); - zephir_read_property_cached(&_15$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_16$$4); - zephir_array_fetch(&_16$$4, &_15$$4, &i, PH_NOISY, "tensor/matrix.zep", 2830); - tensor_mod_scalar(&_14$$4, &_16$$4, &valueB); - zephir_array_append(&c, &_14$$4, PH_SEPARATE, "tensor/matrix.zep", 2830); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _18 = 1; - while (1) { - if (_18) { - _18 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_17, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_17)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&valueB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_19$$5); - zephir_read_property_cached(&_20$$5, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_21$$5); - zephir_array_fetch(&_21$$5, &_20$$5, &i, PH_NOISY, "tensor/matrix.zep", 2830); - tensor_mod_scalar(&_19$$5, &_21$$5, &valueB); - zephir_array_append(&c, &_19$$5, PH_SEPARATE, "tensor/matrix.zep", 2830); - } - } - ZEPHIR_INIT_NVAR(&valueB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_mod_col(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -10447,44 +8523,38 @@ PHP_METHOD(Tensor_Matrix, modColumnVector) PHP_METHOD(Tensor_Matrix, equalColumnVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _18; - zend_string *_13; - zend_ulong _12; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, valueB, _8, *_9, _10, *_11, _17, _2$$3, _3$$3, _5$$3, _14$$4, _15$$4, _16$$4, _19$$5, _20$$5, _21$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&valueB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_17); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_15$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&_20$$5); - ZVAL_UNDEF(&_21$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("m", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\columnvector"))) @@ -10506,73 +8576,22 @@ PHP_METHOD(Tensor_Matrix, equalColumnVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2848); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2626); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2859); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _11); - ZEPHIR_INIT_NVAR(&_14$$4); - zephir_read_property_cached(&_15$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_16$$4); - zephir_array_fetch(&_16$$4, &_15$$4, &i, PH_NOISY, "tensor/matrix.zep", 2856); - tensor_equal_scalar(&_14$$4, &_16$$4, &valueB); - zephir_array_append(&c, &_14$$4, PH_SEPARATE, "tensor/matrix.zep", 2856); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _18 = 1; - while (1) { - if (_18) { - _18 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_17, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_17)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&valueB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_19$$5); - zephir_read_property_cached(&_20$$5, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_21$$5); - zephir_array_fetch(&_21$$5, &_20$$5, &i, PH_NOISY, "tensor/matrix.zep", 2856); - tensor_equal_scalar(&_19$$5, &_21$$5, &valueB); - zephir_array_append(&c, &_19$$5, PH_SEPARATE, "tensor/matrix.zep", 2856); - } - } - ZEPHIR_INIT_NVAR(&valueB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_equal_col(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -10587,44 +8606,38 @@ PHP_METHOD(Tensor_Matrix, equalColumnVector) PHP_METHOD(Tensor_Matrix, notEqualColumnVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _18; - zend_string *_13; - zend_ulong _12; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, valueB, _8, *_9, _10, *_11, _17, _2$$3, _3$$3, _5$$3, _14$$4, _15$$4, _16$$4, _19$$5, _20$$5, _21$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&valueB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_17); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_15$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&_20$$5); - ZVAL_UNDEF(&_21$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("m", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\columnvector"))) @@ -10646,73 +8659,22 @@ PHP_METHOD(Tensor_Matrix, notEqualColumnVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2874); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2650); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2885); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _11); - ZEPHIR_INIT_NVAR(&_14$$4); - zephir_read_property_cached(&_15$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_16$$4); - zephir_array_fetch(&_16$$4, &_15$$4, &i, PH_NOISY, "tensor/matrix.zep", 2882); - tensor_not_equal_scalar(&_14$$4, &_16$$4, &valueB); - zephir_array_append(&c, &_14$$4, PH_SEPARATE, "tensor/matrix.zep", 2882); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _18 = 1; - while (1) { - if (_18) { - _18 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_17, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_17)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&valueB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_19$$5); - zephir_read_property_cached(&_20$$5, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_21$$5); - zephir_array_fetch(&_21$$5, &_20$$5, &i, PH_NOISY, "tensor/matrix.zep", 2882); - tensor_not_equal_scalar(&_19$$5, &_21$$5, &valueB); - zephir_array_append(&c, &_19$$5, PH_SEPARATE, "tensor/matrix.zep", 2882); - } - } - ZEPHIR_INIT_NVAR(&valueB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_not_equal_col(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -10727,44 +8689,38 @@ PHP_METHOD(Tensor_Matrix, notEqualColumnVector) PHP_METHOD(Tensor_Matrix, greaterColumnVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _18; - zend_string *_13; - zend_ulong _12; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, valueB, _8, *_9, _10, *_11, _17, _2$$3, _3$$3, _5$$3, _14$$4, _15$$4, _16$$4, _19$$5, _20$$5, _21$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&valueB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_17); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_15$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&_20$$5); - ZVAL_UNDEF(&_21$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("m", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\columnvector"))) @@ -10781,78 +8737,27 @@ PHP_METHOD(Tensor_Matrix, greaterColumnVector) zephir_memory_observe(&_3$$3); zephir_read_property_cached(&_3$$3, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC); zephir_cast_to_string(&_4$$3, &_3$$3); - ZEPHIR_CALL_METHOD(&_5$$3, b, "m", NULL, 0); - zephir_check_call_status(); - zephir_cast_to_string(&_6$$3, &_5$$3); - ZEPHIR_INIT_VAR(&_7$$3); - ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); - zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2900); - ZEPHIR_MM_RESTORE(); - return; - } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2911); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _11); - ZEPHIR_INIT_NVAR(&_14$$4); - zephir_read_property_cached(&_15$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_16$$4); - zephir_array_fetch(&_16$$4, &_15$$4, &i, PH_NOISY, "tensor/matrix.zep", 2908); - tensor_greater_scalar(&_14$$4, &_16$$4, &valueB); - zephir_array_append(&c, &_14$$4, PH_SEPARATE, "tensor/matrix.zep", 2908); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _18 = 1; - while (1) { - if (_18) { - _18 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_17, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_17)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&valueB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_19$$5); - zephir_read_property_cached(&_20$$5, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_21$$5); - zephir_array_fetch(&_21$$5, &_20$$5, &i, PH_NOISY, "tensor/matrix.zep", 2908); - tensor_greater_scalar(&_19$$5, &_21$$5, &valueB); - zephir_array_append(&c, &_19$$5, PH_SEPARATE, "tensor/matrix.zep", 2908); - } + ZEPHIR_CALL_METHOD(&_5$$3, b, "m", NULL, 0); + zephir_check_call_status(); + zephir_cast_to_string(&_6$$3, &_5$$3); + ZEPHIR_INIT_VAR(&_7$$3); + ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2674); + ZEPHIR_MM_RESTORE(); + return; } - ZEPHIR_INIT_NVAR(&valueB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_greater_col(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -10867,44 +8772,38 @@ PHP_METHOD(Tensor_Matrix, greaterColumnVector) PHP_METHOD(Tensor_Matrix, greaterEqualColumnVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _18; - zend_string *_13; - zend_ulong _12; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, valueB, _8, *_9, _10, *_11, _17, _2$$3, _3$$3, _5$$3, _14$$4, _15$$4, _16$$4, _19$$5, _20$$5, _21$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&valueB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_17); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_15$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&_20$$5); - ZVAL_UNDEF(&_21$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("m", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\columnvector"))) @@ -10926,73 +8825,22 @@ PHP_METHOD(Tensor_Matrix, greaterEqualColumnVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2926); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2698); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2937); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _11); - ZEPHIR_INIT_NVAR(&_14$$4); - zephir_read_property_cached(&_15$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_16$$4); - zephir_array_fetch(&_16$$4, &_15$$4, &i, PH_NOISY, "tensor/matrix.zep", 2934); - tensor_greater_equal_scalar(&_14$$4, &_16$$4, &valueB); - zephir_array_append(&c, &_14$$4, PH_SEPARATE, "tensor/matrix.zep", 2934); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _18 = 1; - while (1) { - if (_18) { - _18 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_17, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_17)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&valueB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_19$$5); - zephir_read_property_cached(&_20$$5, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_21$$5); - zephir_array_fetch(&_21$$5, &_20$$5, &i, PH_NOISY, "tensor/matrix.zep", 2934); - tensor_greater_equal_scalar(&_19$$5, &_21$$5, &valueB); - zephir_array_append(&c, &_19$$5, PH_SEPARATE, "tensor/matrix.zep", 2934); - } - } - ZEPHIR_INIT_NVAR(&valueB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_greater_equal_col(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -11007,44 +8855,38 @@ PHP_METHOD(Tensor_Matrix, greaterEqualColumnVector) PHP_METHOD(Tensor_Matrix, lessColumnVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _18; - zend_string *_13; - zend_ulong _12; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, valueB, _8, *_9, _10, *_11, _17, _2$$3, _3$$3, _5$$3, _14$$4, _15$$4, _16$$4, _19$$5, _20$$5, _21$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&valueB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_17); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_15$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&_20$$5); - ZVAL_UNDEF(&_21$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("m", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\columnvector"))) @@ -11066,73 +8908,22 @@ PHP_METHOD(Tensor_Matrix, lessColumnVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2952); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2722); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2963); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _11); - ZEPHIR_INIT_NVAR(&_14$$4); - zephir_read_property_cached(&_15$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_16$$4); - zephir_array_fetch(&_16$$4, &_15$$4, &i, PH_NOISY, "tensor/matrix.zep", 2960); - tensor_less_scalar(&_14$$4, &_16$$4, &valueB); - zephir_array_append(&c, &_14$$4, PH_SEPARATE, "tensor/matrix.zep", 2960); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _18 = 1; - while (1) { - if (_18) { - _18 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_17, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_17)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&valueB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_19$$5); - zephir_read_property_cached(&_20$$5, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_21$$5); - zephir_array_fetch(&_21$$5, &_20$$5, &i, PH_NOISY, "tensor/matrix.zep", 2960); - tensor_less_scalar(&_19$$5, &_21$$5, &valueB); - zephir_array_append(&c, &_19$$5, PH_SEPARATE, "tensor/matrix.zep", 2960); - } - } - ZEPHIR_INIT_NVAR(&valueB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_less_col(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -11147,44 +8938,38 @@ PHP_METHOD(Tensor_Matrix, lessColumnVector) PHP_METHOD(Tensor_Matrix, lessEqualColumnVector) { zval _4$$3, _6$$3, _7$$3; - zend_bool _18; - zend_string *_13; - zend_ulong _12; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, i, valueB, _8, *_9, _10, *_11, _17, _2$$3, _3$$3, _5$$3, _14$$4, _15$$4, _16$$4, _19$$5, _20$$5, _21$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&i); - ZVAL_UNDEF(&valueB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_17); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_14$$4); - ZVAL_UNDEF(&_15$$4); - ZVAL_UNDEF(&_16$$4); - ZVAL_UNDEF(&_19$$5); - ZVAL_UNDEF(&_20$$5); - ZVAL_UNDEF(&_21$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("m", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { _zephir_prop_1 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\columnvector"))) @@ -11206,73 +8991,22 @@ PHP_METHOD(Tensor_Matrix, lessEqualColumnVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2978); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2746); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/matrix.zep", 2989); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(_9), _12, _13, _11) - { - ZEPHIR_INIT_NVAR(&i); - if (_13 != NULL) { - ZVAL_STR_COPY(&i, _13); - } else { - ZVAL_LONG(&i, _12); - } - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _11); - ZEPHIR_INIT_NVAR(&_14$$4); - zephir_read_property_cached(&_15$$4, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_16$$4); - zephir_array_fetch(&_16$$4, &_15$$4, &i, PH_NOISY, "tensor/matrix.zep", 2986); - tensor_less_equal_scalar(&_14$$4, &_16$$4, &valueB); - zephir_array_append(&c, &_14$$4, PH_SEPARATE, "tensor/matrix.zep", 2986); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _18 = 1; - while (1) { - if (_18) { - _18 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_17, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_17)) { - break; - } - ZEPHIR_CALL_METHOD(&i, _9, "key", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&valueB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_19$$5); - zephir_read_property_cached(&_20$$5, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_21$$5); - zephir_array_fetch(&_21$$5, &_20$$5, &i, PH_NOISY, "tensor/matrix.zep", 2986); - tensor_less_equal_scalar(&_19$$5, &_21$$5, &valueB); - zephir_array_append(&c, &_19$$5, PH_SEPARATE, "tensor/matrix.zep", 2986); - } - } - ZEPHIR_INIT_NVAR(&valueB); - ZEPHIR_INIT_NVAR(&i); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + tensor_less_equal_col(&result, &_8, &bHat, &_9); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_11, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -11285,27 +9019,29 @@ PHP_METHOD(Tensor_Matrix, lessEqualColumnVector) */ PHP_METHOD(Tensor_Matrix, multiplyScalar) { - zend_bool _7; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b_param = NULL, rowA, _0, *_1, _2, *_3, _6, _4$$3, _5$$3, _8$$4, _9$$4; + zval *b_param = NULL, result, _0, _1, _2, _3; double b; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_6); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_8$$4); - ZVAL_UNDEF(&_9$$4); - ZVAL_UNDEF(&c); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(b_param) @@ -11314,53 +9050,14 @@ PHP_METHOD(Tensor_Matrix, multiplyScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); - ZEPHIR_INIT_VAR(&c); - array_init(&c); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 3008); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&_4$$3); - ZVAL_DOUBLE(&_5$$3, b); - tensor_multiply_scalar(&_4$$3, &rowA, &_5$$3); - zephir_array_append(&c, &_4$$3, PH_SEPARATE, "tensor/matrix.zep", 3005); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _7 = 1; - while (1) { - if (_7) { - _7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_6, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_6)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_8$$4); - ZVAL_DOUBLE(&_9$$4, b); - tensor_multiply_scalar(&_8$$4, &rowA, &_9$$4); - zephir_array_append(&c, &_8$$4, PH_SEPARATE, "tensor/matrix.zep", 3005); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZVAL_DOUBLE(&_1, b); + tensor_multiply_scalar(&result, &_0, &_1); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -11373,27 +9070,29 @@ PHP_METHOD(Tensor_Matrix, multiplyScalar) */ PHP_METHOD(Tensor_Matrix, divideScalar) { - zend_bool _7; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b_param = NULL, rowA, _0, *_1, _2, *_3, _6, _4$$3, _5$$3, _8$$4, _9$$4; + zval *b_param = NULL, result, _0, _1, _2, _3; double b; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_6); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_8$$4); - ZVAL_UNDEF(&_9$$4); - ZVAL_UNDEF(&c); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(b_param) @@ -11402,53 +9101,14 @@ PHP_METHOD(Tensor_Matrix, divideScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); - ZEPHIR_INIT_VAR(&c); - array_init(&c); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 3027); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&_4$$3); - ZVAL_DOUBLE(&_5$$3, b); - tensor_divide_scalar(&_4$$3, &rowA, &_5$$3); - zephir_array_append(&c, &_4$$3, PH_SEPARATE, "tensor/matrix.zep", 3024); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _7 = 1; - while (1) { - if (_7) { - _7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_6, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_6)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_8$$4); - ZVAL_DOUBLE(&_9$$4, b); - tensor_divide_scalar(&_8$$4, &rowA, &_9$$4); - zephir_array_append(&c, &_8$$4, PH_SEPARATE, "tensor/matrix.zep", 3024); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZVAL_DOUBLE(&_1, b); + tensor_divide_scalar(&result, &_0, &_1); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -11461,82 +9121,45 @@ PHP_METHOD(Tensor_Matrix, divideScalar) */ PHP_METHOD(Tensor_Matrix, addScalar) { - zend_bool _7; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b_param = NULL, rowA, _0, *_1, _2, *_3, _6, _4$$3, _5$$3, _8$$4, _9$$4; + zval *b_param = NULL, result, _0, _1, _2, _3; double b; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_6); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_8$$4); - ZVAL_UNDEF(&_9$$4); - ZVAL_UNDEF(&c); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ZVAL(b_param) - ZEND_PARSE_PARAMETERS_END(); - ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); - zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_fetch_params(1, 1, 0, &b_param); - b = zephir_get_doubleval(b_param); - ZEPHIR_INIT_VAR(&c); - array_init(&c); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 3046); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&_4$$3); - ZVAL_DOUBLE(&_5$$3, b); - tensor_add_scalar(&_4$$3, &rowA, &_5$$3); - zephir_array_append(&c, &_4$$3, PH_SEPARATE, "tensor/matrix.zep", 3043); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _7 = 1; - while (1) { - if (_7) { - _7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_6, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_6)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_8$$4); - ZVAL_DOUBLE(&_9$$4, b); - tensor_add_scalar(&_8$$4, &rowA, &_9$$4); - zephir_array_append(&c, &_8$$4, PH_SEPARATE, "tensor/matrix.zep", 3043); - } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(b_param) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 1, 0, &b_param); + b = zephir_get_doubleval(b_param); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + ZVAL_DOUBLE(&_1, b); + tensor_add_scalar(&result, &_0, &_1); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -11549,27 +9172,29 @@ PHP_METHOD(Tensor_Matrix, addScalar) */ PHP_METHOD(Tensor_Matrix, subtractScalar) { - zend_bool _7; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b_param = NULL, rowA, _0, *_1, _2, *_3, _6, _4$$3, _5$$3, _8$$4, _9$$4; + zval *b_param = NULL, result, _0, _1, _2, _3; double b; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_6); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_8$$4); - ZVAL_UNDEF(&_9$$4); - ZVAL_UNDEF(&c); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(b_param) @@ -11578,53 +9203,14 @@ PHP_METHOD(Tensor_Matrix, subtractScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); - ZEPHIR_INIT_VAR(&c); - array_init(&c); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 3065); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&_4$$3); - ZVAL_DOUBLE(&_5$$3, b); - tensor_subtract_scalar(&_4$$3, &rowA, &_5$$3); - zephir_array_append(&c, &_4$$3, PH_SEPARATE, "tensor/matrix.zep", 3062); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _7 = 1; - while (1) { - if (_7) { - _7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_6, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_6)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_8$$4); - ZVAL_DOUBLE(&_9$$4, b); - tensor_subtract_scalar(&_8$$4, &rowA, &_9$$4); - zephir_array_append(&c, &_8$$4, PH_SEPARATE, "tensor/matrix.zep", 3062); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZVAL_DOUBLE(&_1, b); + tensor_subtract_scalar(&result, &_0, &_1); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -11637,27 +9223,29 @@ PHP_METHOD(Tensor_Matrix, subtractScalar) */ PHP_METHOD(Tensor_Matrix, powScalar) { - zend_bool _7; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b_param = NULL, rowA, _0, *_1, _2, *_3, _6, _4$$3, _5$$3, _8$$4, _9$$4; + zval *b_param = NULL, result, _0, _1, _2, _3; double b; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_6); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_8$$4); - ZVAL_UNDEF(&_9$$4); - ZVAL_UNDEF(&c); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(b_param) @@ -11666,53 +9254,14 @@ PHP_METHOD(Tensor_Matrix, powScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); - ZEPHIR_INIT_VAR(&c); - array_init(&c); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 3084); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&_4$$3); - ZVAL_DOUBLE(&_5$$3, b); - tensor_pow_scalar(&_4$$3, &rowA, &_5$$3); - zephir_array_append(&c, &_4$$3, PH_SEPARATE, "tensor/matrix.zep", 3081); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _7 = 1; - while (1) { - if (_7) { - _7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_6, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_6)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_8$$4); - ZVAL_DOUBLE(&_9$$4, b); - tensor_pow_scalar(&_8$$4, &rowA, &_9$$4); - zephir_array_append(&c, &_8$$4, PH_SEPARATE, "tensor/matrix.zep", 3081); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZVAL_DOUBLE(&_1, b); + tensor_pow_scalar(&result, &_0, &_1); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -11725,27 +9274,29 @@ PHP_METHOD(Tensor_Matrix, powScalar) */ PHP_METHOD(Tensor_Matrix, modScalar) { - zend_bool _7; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b_param = NULL, rowA, _0, *_1, _2, *_3, _6, _4$$3, _5$$3, _8$$4, _9$$4; + zval *b_param = NULL, result, _0, _1, _2, _3; double b; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_6); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_8$$4); - ZVAL_UNDEF(&_9$$4); - ZVAL_UNDEF(&c); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(b_param) @@ -11754,53 +9305,14 @@ PHP_METHOD(Tensor_Matrix, modScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); - ZEPHIR_INIT_VAR(&c); - array_init(&c); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 3103); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&_4$$3); - ZVAL_DOUBLE(&_5$$3, b); - tensor_mod_scalar(&_4$$3, &rowA, &_5$$3); - zephir_array_append(&c, &_4$$3, PH_SEPARATE, "tensor/matrix.zep", 3100); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _7 = 1; - while (1) { - if (_7) { - _7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_6, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_6)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_8$$4); - ZVAL_DOUBLE(&_9$$4, b); - tensor_mod_scalar(&_8$$4, &rowA, &_9$$4); - zephir_array_append(&c, &_8$$4, PH_SEPARATE, "tensor/matrix.zep", 3100); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZVAL_DOUBLE(&_1, b); + tensor_mod_scalar(&result, &_0, &_1); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -11813,27 +9325,29 @@ PHP_METHOD(Tensor_Matrix, modScalar) */ PHP_METHOD(Tensor_Matrix, equalScalar) { - zend_bool _7; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b_param = NULL, rowA, _0, *_1, _2, *_3, _6, _4$$3, _5$$3, _8$$4, _9$$4; + zval *b_param = NULL, result, _0, _1, _2, _3; double b; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_6); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_8$$4); - ZVAL_UNDEF(&_9$$4); - ZVAL_UNDEF(&c); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(b_param) @@ -11842,53 +9356,14 @@ PHP_METHOD(Tensor_Matrix, equalScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); - ZEPHIR_INIT_VAR(&c); - array_init(&c); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 3122); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&_4$$3); - ZVAL_DOUBLE(&_5$$3, b); - tensor_equal_scalar(&_4$$3, &rowA, &_5$$3); - zephir_array_append(&c, &_4$$3, PH_SEPARATE, "tensor/matrix.zep", 3119); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _7 = 1; - while (1) { - if (_7) { - _7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_6, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_6)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_8$$4); - ZVAL_DOUBLE(&_9$$4, b); - tensor_equal_scalar(&_8$$4, &rowA, &_9$$4); - zephir_array_append(&c, &_8$$4, PH_SEPARATE, "tensor/matrix.zep", 3119); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZVAL_DOUBLE(&_1, b); + tensor_equal_scalar(&result, &_0, &_1); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -11901,27 +9376,29 @@ PHP_METHOD(Tensor_Matrix, equalScalar) */ PHP_METHOD(Tensor_Matrix, notEqualScalar) { - zend_bool _7; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b_param = NULL, rowA, _0, *_1, _2, *_3, _6, _4$$3, _5$$3, _8$$4, _9$$4; + zval *b_param = NULL, result, _0, _1, _2, _3; double b; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_6); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_8$$4); - ZVAL_UNDEF(&_9$$4); - ZVAL_UNDEF(&c); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(b_param) @@ -11930,53 +9407,14 @@ PHP_METHOD(Tensor_Matrix, notEqualScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); - ZEPHIR_INIT_VAR(&c); - array_init(&c); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 3141); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&_4$$3); - ZVAL_DOUBLE(&_5$$3, b); - tensor_not_equal_scalar(&_4$$3, &rowA, &_5$$3); - zephir_array_append(&c, &_4$$3, PH_SEPARATE, "tensor/matrix.zep", 3138); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _7 = 1; - while (1) { - if (_7) { - _7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_6, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_6)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_8$$4); - ZVAL_DOUBLE(&_9$$4, b); - tensor_not_equal_scalar(&_8$$4, &rowA, &_9$$4); - zephir_array_append(&c, &_8$$4, PH_SEPARATE, "tensor/matrix.zep", 3138); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZVAL_DOUBLE(&_1, b); + tensor_not_equal_scalar(&result, &_0, &_1); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -11989,82 +9427,45 @@ PHP_METHOD(Tensor_Matrix, notEqualScalar) */ PHP_METHOD(Tensor_Matrix, greaterScalar) { - zend_bool _7; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b_param = NULL, rowA, _0, *_1, _2, *_3, _6, _4$$3, _5$$3, _8$$4, _9$$4; + zval *b_param = NULL, result, _0, _1, _2, _3; double b; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_6); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_8$$4); - ZVAL_UNDEF(&_9$$4); - ZVAL_UNDEF(&c); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ZVAL(b_param) - ZEND_PARSE_PARAMETERS_END(); - ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); - zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_fetch_params(1, 1, 0, &b_param); - b = zephir_get_doubleval(b_param); - ZEPHIR_INIT_VAR(&c); - array_init(&c); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 3160); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&_4$$3); - ZVAL_DOUBLE(&_5$$3, b); - tensor_greater_scalar(&_4$$3, &rowA, &_5$$3); - zephir_array_append(&c, &_4$$3, PH_SEPARATE, "tensor/matrix.zep", 3157); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _7 = 1; - while (1) { - if (_7) { - _7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_6, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_6)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_8$$4); - ZVAL_DOUBLE(&_9$$4, b); - tensor_greater_scalar(&_8$$4, &rowA, &_9$$4); - zephir_array_append(&c, &_8$$4, PH_SEPARATE, "tensor/matrix.zep", 3157); - } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(b_param) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 1, 0, &b_param); + b = zephir_get_doubleval(b_param); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); + ZVAL_DOUBLE(&_1, b); + tensor_greater_scalar(&result, &_0, &_1); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -12078,27 +9479,29 @@ PHP_METHOD(Tensor_Matrix, greaterScalar) */ PHP_METHOD(Tensor_Matrix, greaterEqualScalar) { - zend_bool _7; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b_param = NULL, rowA, _0, *_1, _2, *_3, _6, _4$$3, _5$$3, _8$$4, _9$$4; + zval *b_param = NULL, result, _0, _1, _2, _3; double b; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_6); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_8$$4); - ZVAL_UNDEF(&_9$$4); - ZVAL_UNDEF(&c); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(b_param) @@ -12107,53 +9510,14 @@ PHP_METHOD(Tensor_Matrix, greaterEqualScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); - ZEPHIR_INIT_VAR(&c); - array_init(&c); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 3180); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&_4$$3); - ZVAL_DOUBLE(&_5$$3, b); - tensor_greater_equal_scalar(&_4$$3, &rowA, &_5$$3); - zephir_array_append(&c, &_4$$3, PH_SEPARATE, "tensor/matrix.zep", 3177); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _7 = 1; - while (1) { - if (_7) { - _7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_6, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_6)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_8$$4); - ZVAL_DOUBLE(&_9$$4, b); - tensor_greater_equal_scalar(&_8$$4, &rowA, &_9$$4); - zephir_array_append(&c, &_8$$4, PH_SEPARATE, "tensor/matrix.zep", 3177); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZVAL_DOUBLE(&_1, b); + tensor_greater_equal_scalar(&result, &_0, &_1); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -12166,27 +9530,29 @@ PHP_METHOD(Tensor_Matrix, greaterEqualScalar) */ PHP_METHOD(Tensor_Matrix, lessScalar) { - zend_bool _7; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b_param = NULL, rowA, _0, *_1, _2, *_3, _6, _4$$3, _5$$3, _8$$4, _9$$4; + zval *b_param = NULL, result, _0, _1, _2, _3; double b; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_6); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_8$$4); - ZVAL_UNDEF(&_9$$4); - ZVAL_UNDEF(&c); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(b_param) @@ -12195,53 +9561,14 @@ PHP_METHOD(Tensor_Matrix, lessScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); - ZEPHIR_INIT_VAR(&c); - array_init(&c); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 3199); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&_4$$3); - ZVAL_DOUBLE(&_5$$3, b); - tensor_less_scalar(&_4$$3, &rowA, &_5$$3); - zephir_array_append(&c, &_4$$3, PH_SEPARATE, "tensor/matrix.zep", 3196); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _7 = 1; - while (1) { - if (_7) { - _7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_6, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_6)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_8$$4); - ZVAL_DOUBLE(&_9$$4, b); - tensor_less_scalar(&_8$$4, &rowA, &_9$$4); - zephir_array_append(&c, &_8$$4, PH_SEPARATE, "tensor/matrix.zep", 3196); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZVAL_DOUBLE(&_1, b); + tensor_less_scalar(&result, &_0, &_1); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -12255,27 +9582,29 @@ PHP_METHOD(Tensor_Matrix, lessScalar) */ PHP_METHOD(Tensor_Matrix, lessEqualScalar) { - zend_bool _7; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b_param = NULL, rowA, _0, *_1, _2, *_3, _6, _4$$3, _5$$3, _8$$4, _9$$4; + zval *b_param = NULL, result, _0, _1, _2, _3; double b; zval *this_ptr = getThis(); - ZVAL_UNDEF(&rowA); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_6); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_8$$4); - ZVAL_UNDEF(&_9$$4); - ZVAL_UNDEF(&c); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(b_param) @@ -12284,53 +9613,14 @@ PHP_METHOD(Tensor_Matrix, lessEqualScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); - ZEPHIR_INIT_VAR(&c); - array_init(&c); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/matrix.zep", 3219); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&rowA); - ZVAL_COPY(&rowA, _3); - ZEPHIR_INIT_NVAR(&_4$$3); - ZVAL_DOUBLE(&_5$$3, b); - tensor_less_equal_scalar(&_4$$3, &rowA, &_5$$3); - zephir_array_append(&c, &_4$$3, PH_SEPARATE, "tensor/matrix.zep", 3216); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _7 = 1; - while (1) { - if (_7) { - _7 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_6, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_6)) { - break; - } - ZEPHIR_CALL_METHOD(&rowA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_8$$4); - ZVAL_DOUBLE(&_9$$4, b); - tensor_less_equal_scalar(&_8$$4, &rowA, &_9$$4); - zephir_array_append(&c, &_8$$4, PH_SEPARATE, "tensor/matrix.zep", 3216); - } - } - ZEPHIR_INIT_NVAR(&rowA); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &c); + ZVAL_DOUBLE(&_1, b); + tensor_less_equal_scalar(&result, &_0, &_1); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 15, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -12367,7 +9657,7 @@ PHP_METHOD(Tensor_Matrix, offsetSet) Z_PARAM_ZVAL(values) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(2, 0, &index, &values); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 3237); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2931); return; } @@ -12379,22 +9669,30 @@ PHP_METHOD(Tensor_Matrix, offsetSet) */ PHP_METHOD(Tensor_Matrix, offsetExists) { - zval *index, index_sub, _0; + zend_bool _0; + zval *index, index_sub, _1; zval *this_ptr = getThis(); ZVAL_UNDEF(&index_sub); - ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); static zend_string *_zephir_prop_0 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); + _zephir_prop_0 = zend_string_init("m", 1, 1); } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(index) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(1, 0, &index); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - RETURN_BOOL(zephir_array_isset_value(&_0, index)); + if (Z_TYPE_P(index) != IS_LONG) { + RETURN_BOOL(0); + } + _0 = ZEPHIR_GE_LONG(index, 0); + if (_0) { + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + _0 = ZEPHIR_LT(index, &_1); + } + RETURN_BOOL(_0); } /** @@ -12410,7 +9708,7 @@ PHP_METHOD(Tensor_Matrix, offsetUnset) Z_PARAM_ZVAL(index) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(1, 0, &index); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 3257); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2955); return; } @@ -12423,21 +9721,36 @@ PHP_METHOD(Tensor_Matrix, offsetUnset) */ PHP_METHOD(Tensor_Matrix, offsetGet) { - zval _2, _3; + zval _6$$4, _7$$4; + zend_bool _3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *index, index_sub, row, _0, _1; + zval *index, index_sub, _0$$3, _1$$3, _2$$3, _4, _8, _9, _10, _11, _5$$4; zval *this_ptr = getThis(); ZVAL_UNDEF(&index_sub); - ZVAL_UNDEF(&row); - ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_0$$3); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); + ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); + ZVAL_UNDEF(&_10); + ZVAL_UNDEF(&_11); + ZVAL_UNDEF(&_5$$4); + ZVAL_UNDEF(&_6$$4); + ZVAL_UNDEF(&_7$$4); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); + _zephir_prop_0 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); } ZEND_PARSE_PARAMETERS_START(1, 1) @@ -12446,23 +9759,47 @@ PHP_METHOD(Tensor_Matrix, offsetGet) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &index); - zephir_memory_observe(&row); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 14, PH_NOISY_CC | PH_READONLY); - if (EXPECTED(zephir_array_isset_fetch(&row, &_0, index, 0))) { - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_vector_ce, "quick", NULL, 0, &row); + if (UNEXPECTED(Z_TYPE_P(index) != IS_LONG)) { + ZEPHIR_INIT_VAR(&_0$$3); + object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_VAR(&_1$$3); + zephir_gettype(&_1$$3, index); + ZEPHIR_INIT_VAR(&_2$$3); + ZEPHIR_CONCAT_SSVS(&_2$$3, "Row offset must be", " an integer, ", &_1$$3, " given."); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - RETURN_MM(); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 2969); + ZEPHIR_MM_RESTORE(); + return; } - ZEPHIR_INIT_VAR(&_1); - object_init_ex(&_1, tensor_exceptions_invalidargumentexception_ce); - zephir_cast_to_string(&_2, index); - ZEPHIR_INIT_VAR(&_3); - ZEPHIR_CONCAT_SSVS(&_3, "Element not found at", " offset ", &_2, "."); - ZEPHIR_CALL_METHOD(NULL, &_1, "__construct", NULL, 3, &_3); + _3 = ZEPHIR_LT_LONG(index, 0); + if (!(_3)) { + zephir_read_property_cached(&_4, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + _3 = ZEPHIR_GE(index, &_4); + } + if (UNEXPECTED(_3)) { + ZEPHIR_INIT_VAR(&_5$$4); + object_init_ex(&_5$$4, tensor_exceptions_invalidargumentexception_ce); + zephir_cast_to_string(&_6$$4, index); + ZEPHIR_INIT_VAR(&_7$$4); + ZEPHIR_CONCAT_SSVS(&_7$$4, "Row offset out of", " bounds, ", &_6$$4, " given."); + ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_7$$4); + zephir_check_call_status(); + zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 2974); + ZEPHIR_MM_RESTORE(); + return; + } + object_init_ex(return_value, tensor_vector_ce); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 14, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_INIT_VAR(&_11); + mul_function(&_11, index, &_10); + zephir_read_property_cached(&_10, this_ptr, _zephir_prop_2, 16, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_9, &_8, "slice", NULL, 0, &_11, &_10); zephir_check_call_status(); - zephir_throw_exception_debug(&_1, "tensor/matrix.zep", 3276); - ZEPHIR_MM_RESTORE(); - return; + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_9); + zephir_check_call_status(); + RETURN_MM(); } /** @@ -12482,10 +9819,106 @@ PHP_METHOD(Tensor_Matrix, getIterator) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); object_init_ex(return_value, spl_ce_ArrayIterator); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "asvectors", NULL, 0); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "asVectors", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 23, &_0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 18, &_0); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return the elements of the matrix as a plain PHP array of rows so that + * only the values, and not the object structure, appear in the + * serialized form. + * + * @return array[] + */ +PHP_METHOD(Tensor_Matrix, __serialize) +{ + zval _0, _1; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("n", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + zephir_create_array(return_value, 3, 0); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "asArray", NULL, 0); zephir_check_call_status(); + zephir_array_update_string(return_value, SL("data"), &_0, PH_COPY | PH_SEPARATE); + zephir_memory_observe(&_1); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC); + zephir_array_update_string(return_value, SL("m"), &_1, PH_COPY | PH_SEPARATE); + ZEPHIR_OBS_NVAR(&_1); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC); + zephir_array_update_string(return_value, SL("n"), &_1, PH_COPY | PH_SEPARATE); RETURN_MM(); } +/** + * Restore the matrix from the plain array of rows produced by + * __serialize() by rebuilding its TensorBuffer and shape. + * + * @param array> data + * @throws \Tensor\Exceptions\InvalidArgumentException + */ +PHP_METHOD(Tensor_Matrix, __unserialize) +{ + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *data_param = NULL, rebuilt, _0, _1, _2, _3, _4; + zval data; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&data); + ZVAL_UNDEF(&rebuilt); + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_4); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } + + ZEND_PARSE_PARAMETERS_START(1, 1) + ZEPHIR_Z_PARAM_ARRAY(data, data_param) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 1, 0, &data_param); + zephir_get_arrval(&data, data_param); + zephir_array_fetch_string(&_0, &data, SL("data"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 3017); + ZVAL_BOOL(&_1, 0); + ZEPHIR_CALL_SELF(&rebuilt, "fromArray", NULL, 0, &_0, &_1); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_2, &rebuilt, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 14, &_2); + zephir_array_fetch_string(&_3, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 3020); + zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 15, &_3); + zephir_array_fetch_string(&_4, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 3021); + zephir_update_property_zval_cached(this_ptr, _zephir_prop_2, 16, &_4); + ZEPHIR_MM_RESTORE(); +} + diff --git a/ext/tensor/matrix.zep.h b/ext/tensor/matrix.zep.h index ca10e6f..cf5346d 100644 --- a/ext/tensor/matrix.zep.h +++ b/ext/tensor/matrix.zep.h @@ -3,8 +3,6 @@ extern zend_class_entry *tensor_matrix_ce; ZEPHIR_INIT_CLASS(Tensor_Matrix); -PHP_METHOD(Tensor_Matrix, build); -PHP_METHOD(Tensor_Matrix, quick); PHP_METHOD(Tensor_Matrix, identity); PHP_METHOD(Tensor_Matrix, zeros); PHP_METHOD(Tensor_Matrix, ones); @@ -14,6 +12,7 @@ PHP_METHOD(Tensor_Matrix, rand); PHP_METHOD(Tensor_Matrix, gaussian); PHP_METHOD(Tensor_Matrix, poisson); PHP_METHOD(Tensor_Matrix, uniform); +PHP_METHOD(Tensor_Matrix, fromArray); PHP_METHOD(Tensor_Matrix, __construct); PHP_METHOD(Tensor_Matrix, shape); PHP_METHOD(Tensor_Matrix, shapeString); @@ -24,10 +23,13 @@ PHP_METHOD(Tensor_Matrix, n); PHP_METHOD(Tensor_Matrix, rowAsVector); PHP_METHOD(Tensor_Matrix, columnAsVector); PHP_METHOD(Tensor_Matrix, diagonalAsVector); -PHP_METHOD(Tensor_Matrix, asArray); PHP_METHOD(Tensor_Matrix, asVectors); PHP_METHOD(Tensor_Matrix, asColumnVectors); PHP_METHOD(Tensor_Matrix, flatten); +PHP_METHOD(Tensor_Matrix, asArray); +PHP_METHOD(Tensor_Matrix, asTensorBuffer); +PHP_METHOD(Tensor_Matrix, asRowBuffers); +PHP_METHOD(Tensor_Matrix, asColumnBuffers); PHP_METHOD(Tensor_Matrix, map); PHP_METHOD(Tensor_Matrix, reduce); PHP_METHOD(Tensor_Matrix, transpose); @@ -83,6 +85,8 @@ PHP_METHOD(Tensor_Matrix, sum); PHP_METHOD(Tensor_Matrix, product); PHP_METHOD(Tensor_Matrix, min); PHP_METHOD(Tensor_Matrix, max); +PHP_METHOD(Tensor_Matrix, argmin); +PHP_METHOD(Tensor_Matrix, argmax); PHP_METHOD(Tensor_Matrix, mean); PHP_METHOD(Tensor_Matrix, median); PHP_METHOD(Tensor_Matrix, quantile); @@ -155,14 +159,8 @@ PHP_METHOD(Tensor_Matrix, offsetExists); PHP_METHOD(Tensor_Matrix, offsetUnset); PHP_METHOD(Tensor_Matrix, offsetGet); PHP_METHOD(Tensor_Matrix, getIterator); - -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_build, 0, 0, Tensor\\Matrix, 0) -ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, a, IS_ARRAY, 0, "[]") -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_quick, 0, 0, Tensor\\Matrix, 0) -ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, a, IS_ARRAY, 0, "[]") -ZEND_END_ARG_INFO() +PHP_METHOD(Tensor_Matrix, __serialize); +PHP_METHOD(Tensor_Matrix, __unserialize); ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_identity, 0, 1, Tensor\\Matrix, 0) ZEND_ARG_TYPE_INFO(0, n, IS_LONG, 0) @@ -209,11 +207,17 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_uniform, 0, 2, Tens ZEND_ARG_TYPE_INFO(0, n, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_matrix___construct, 0, 0, 1) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_fromarray, 0, 1, Tensor\\Matrix, 0) ZEND_ARG_ARRAY_INFO(0, a, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, validate, _IS_BOOL, 0, "true") ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_matrix___construct, 0, 0, 3) + ZEND_ARG_OBJ_INFO(0, a, Tensor\\TensorBuffer, 0) + ZEND_ARG_TYPE_INFO(0, m, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, n, IS_LONG, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_matrix_shape, 0, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() @@ -243,9 +247,6 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_diagonalasvector, 0, 0, Tensor\\Vector, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_matrix_asarray, 0, 0, IS_ARRAY, 0) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_matrix_asvectors, 0, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() @@ -255,6 +256,18 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_flatten, 0, 0, Tensor\\Vector, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_matrix_asarray, 0, 0, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_astensorbuffer, 0, 0, Tensor\\TensorBuffer, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_matrix_asrowbuffers, 0, 0, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_matrix_ascolumnbuffers, 0, 0, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_map, 0, 1, Tensor\\Matrix, 0) ZEND_ARG_INFO(0, callback) ZEND_END_ARG_INFO() @@ -441,6 +454,12 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_max, 0, 0, Tensor\\ColumnVector, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_argmin, 0, 0, Tensor\\ColumnVector, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_argmax, 0, 0, Tensor\\ColumnVector, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_mean, 0, 0, Tensor\\ColumnVector, 0) ZEND_END_ARG_INFO() @@ -726,9 +745,14 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_getiterator, 0, 0, Traversable, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_matrix___serialize, 0, 0, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_matrix___unserialize, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, data, 0) +ZEND_END_ARG_INFO() + ZEPHIR_INIT_FUNCS(tensor_matrix_method_entry) { - PHP_ME(Tensor_Matrix, build, arginfo_tensor_matrix_build, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME(Tensor_Matrix, quick, arginfo_tensor_matrix_quick, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Tensor_Matrix, identity, arginfo_tensor_matrix_identity, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Tensor_Matrix, zeros, arginfo_tensor_matrix_zeros, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Tensor_Matrix, ones, arginfo_tensor_matrix_ones, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) @@ -738,6 +762,7 @@ ZEPHIR_INIT_FUNCS(tensor_matrix_method_entry) { PHP_ME(Tensor_Matrix, gaussian, arginfo_tensor_matrix_gaussian, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Tensor_Matrix, poisson, arginfo_tensor_matrix_poisson, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Tensor_Matrix, uniform, arginfo_tensor_matrix_uniform, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(Tensor_Matrix, fromArray, arginfo_tensor_matrix_fromarray, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Tensor_Matrix, __construct, arginfo_tensor_matrix___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_ME(Tensor_Matrix, shape, arginfo_tensor_matrix_shape, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, shapeString, arginfo_tensor_matrix_shapestring, ZEND_ACC_PUBLIC) @@ -748,10 +773,13 @@ ZEPHIR_INIT_FUNCS(tensor_matrix_method_entry) { PHP_ME(Tensor_Matrix, rowAsVector, arginfo_tensor_matrix_rowasvector, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, columnAsVector, arginfo_tensor_matrix_columnasvector, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, diagonalAsVector, arginfo_tensor_matrix_diagonalasvector, ZEND_ACC_PUBLIC) - PHP_ME(Tensor_Matrix, asArray, arginfo_tensor_matrix_asarray, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, asVectors, arginfo_tensor_matrix_asvectors, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, asColumnVectors, arginfo_tensor_matrix_ascolumnvectors, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, flatten, arginfo_tensor_matrix_flatten, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Matrix, asArray, arginfo_tensor_matrix_asarray, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Matrix, asTensorBuffer, arginfo_tensor_matrix_astensorbuffer, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Matrix, asRowBuffers, arginfo_tensor_matrix_asrowbuffers, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Matrix, asColumnBuffers, arginfo_tensor_matrix_ascolumnbuffers, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, map, arginfo_tensor_matrix_map, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, reduce, arginfo_tensor_matrix_reduce, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, transpose, arginfo_tensor_matrix_transpose, ZEND_ACC_PUBLIC) @@ -807,6 +835,8 @@ ZEPHIR_INIT_FUNCS(tensor_matrix_method_entry) { PHP_ME(Tensor_Matrix, product, arginfo_tensor_matrix_product, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, min, arginfo_tensor_matrix_min, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, max, arginfo_tensor_matrix_max, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Matrix, argmin, arginfo_tensor_matrix_argmin, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Matrix, argmax, arginfo_tensor_matrix_argmax, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, mean, arginfo_tensor_matrix_mean, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, median, arginfo_tensor_matrix_median, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, quantile, arginfo_tensor_matrix_quantile, ZEND_ACC_PUBLIC) @@ -879,5 +909,7 @@ ZEPHIR_INIT_FUNCS(tensor_matrix_method_entry) { PHP_ME(Tensor_Matrix, offsetUnset, arginfo_tensor_matrix_offsetunset, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, offsetGet, arginfo_tensor_matrix_offsetget, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, getIterator, arginfo_tensor_matrix_getiterator, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Matrix, __serialize, arginfo_tensor_matrix___serialize, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Matrix, __unserialize, arginfo_tensor_matrix___unserialize, ZEND_ACC_PUBLIC) PHP_FE_END }; diff --git a/ext/tensor/reductions/ref.zep.c b/ext/tensor/reductions/ref.zep.c index c63a2c4..533e871 100644 --- a/ext/tensor/reductions/ref.zep.c +++ b/ext/tensor/reductions/ref.zep.c @@ -59,20 +59,25 @@ ZEPHIR_INIT_CLASS(Tensor_Reductions_Ref) */ PHP_METHOD(Tensor_Reductions_Ref, reduce) { - zval ref, _2; + zval ref, _4; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS; - zval *a, a_sub, result, _0, _1, b, _3, swaps; + zend_long ZEPHIR_LAST_CALL_STATUS, swaps; + zval *a, a_sub, result, _0, _1, _2, _3, b, _5, _6, _7, _8, _9; ZVAL_UNDEF(&a_sub); ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&b); + ZVAL_UNDEF(&_2); ZVAL_UNDEF(&_3); - ZVAL_UNDEF(&swaps); + ZVAL_UNDEF(&b); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&ref); - ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_4); ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(a, zephir_get_internal_ce(SL("tensor\\matrix"))) ZEND_PARSE_PARAMETERS_END(); @@ -80,25 +85,37 @@ PHP_METHOD(Tensor_Reductions_Ref, reduce) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &a); ZEPHIR_INIT_VAR(&result); - ZEPHIR_CALL_METHOD(&_0, a, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&_0, a, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - tensor_ref(&result, &_0); + ZEPHIR_CALL_METHOD(&_1, a, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_2, a, "n", NULL, 0); + zephir_check_call_status(); + tensor_ref(&result, &_0, &_1, &_2); if (Z_TYPE_P(&result) == IS_NULL) { ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Failed to decompose matrix.", "tensor/reductions/ref.zep", 44); return; } ZEPHIR_INIT_VAR(&ref); array_init(&ref); - ZEPHIR_CPY_WRT(&_1, &result); - zephir_get_arrval(&_2, &_1); - ZEPHIR_CPY_WRT(&ref, &_2); - zephir_array_fetch_long(&_3, &ref, 0, PH_NOISY | PH_READONLY, "tensor/reductions/ref.zep", 51); - ZEPHIR_CALL_CE_STATIC(&b, tensor_matrix_ce, "quick", NULL, 0, &_3); + ZEPHIR_CPY_WRT(&_3, &result); + zephir_get_arrval(&_4, &_3); + ZEPHIR_CPY_WRT(&ref, &_4); + ZEPHIR_INIT_VAR(&b); + object_init_ex(&b, tensor_matrix_ce); + zephir_array_fetch_long(&_5, &ref, 0, PH_NOISY | PH_READONLY, "tensor/reductions/ref.zep", 51); + ZEPHIR_CALL_METHOD(&_6, a, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_7, a, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, &b, "__construct", NULL, 14, &_5, &_6, &_7); zephir_check_call_status(); - zephir_memory_observe(&swaps); - zephir_array_fetch_long(&swaps, &ref, 1, PH_NOISY, "tensor/reductions/ref.zep", 52); + zephir_memory_observe(&_8); + zephir_array_fetch_long(&_8, &ref, 1, PH_NOISY, "tensor/reductions/ref.zep", 52); + swaps = zephir_get_intval(&_8); object_init_ex(return_value, tensor_reductions_ref_ce); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 33, &b, &swaps); + ZVAL_LONG(&_9, swaps); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 28, &b, &_9); zephir_check_call_status(); RETURN_MM(); } @@ -141,11 +158,11 @@ PHP_METHOD(Tensor_Reductions_Ref, __construct) ZEPHIR_INIT_VAR(&_0$$3); object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_1$$3, swaps); - ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 4, &_1$$3); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 3, &_1$$3); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3$$3); ZEPHIR_CONCAT_SSVS(&_3$$3, "The number of swaps must", " be greater than or equal to 0, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 3, &_3$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); zephir_throw_exception_debug(&_0$$3, "tensor/reductions/ref.zep", 67); ZEPHIR_MM_RESTORE(); diff --git a/ext/tensor/reductions/rref.zep.c b/ext/tensor/reductions/rref.zep.c index cf2e07f..80bc6ff 100644 --- a/ext/tensor/reductions/rref.zep.c +++ b/ext/tensor/reductions/rref.zep.c @@ -14,9 +14,9 @@ #include "kernel/main.h" #include "kernel/memory.h" #include "kernel/fcall.h" -#include "kernel/operators.h" -#include "kernel/array.h" +#include "kernel/exception.h" #include "kernel/object.h" +#include "include/linear_algebra.h" /** @@ -49,222 +49,46 @@ ZEPHIR_INIT_CLASS(Tensor_Reductions_Rref) */ PHP_METHOD(Tensor_Reductions_Rref, reduce) { - zval b, rowB, t, _5, _8$$3, _31$$11; - zend_bool hasPivot = 0, _6, _27$$3, _12$$4, _17$$7, _22$$9, _35$$12; - double scale = 0, divisor = 0, epsilon; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zephir_fcall_cache_entry *_11 = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS, i = 0, j = 0, m, n, row, col, _28$$3, _29$$3, _13$$4, _14$$4, _18$$7, _19$$7, _23$$9, _24$$9, _36$$12, _37$$12; - zval *a, a_sub, _0, _1, _2, _3, _4, _41, _7$$3, _9$$3, _10$$3, _21$$3, _15$$5, _16$$5, _20$$8, _25$$10, _26$$10, _30$$11, _32$$11, _33$$11, _34$$11, _38$$13, _39$$13, _40$$13; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *a, a_sub, result, _0, _1, _2, _3, _4, _5; ZVAL_UNDEF(&a_sub); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); ZVAL_UNDEF(&_3); ZVAL_UNDEF(&_4); - ZVAL_UNDEF(&_41); - ZVAL_UNDEF(&_7$$3); - ZVAL_UNDEF(&_9$$3); - ZVAL_UNDEF(&_10$$3); - ZVAL_UNDEF(&_21$$3); - ZVAL_UNDEF(&_15$$5); - ZVAL_UNDEF(&_16$$5); - ZVAL_UNDEF(&_20$$8); - ZVAL_UNDEF(&_25$$10); - ZVAL_UNDEF(&_26$$10); - ZVAL_UNDEF(&_30$$11); - ZVAL_UNDEF(&_32$$11); - ZVAL_UNDEF(&_33$$11); - ZVAL_UNDEF(&_34$$11); - ZVAL_UNDEF(&_38$$13); - ZVAL_UNDEF(&_39$$13); - ZVAL_UNDEF(&_40$$13); - ZVAL_UNDEF(&b); - ZVAL_UNDEF(&rowB); - ZVAL_UNDEF(&t); ZVAL_UNDEF(&_5); - ZVAL_UNDEF(&_8$$3); - ZVAL_UNDEF(&_31$$11); ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(a, zephir_get_internal_ce(SL("tensor\\matrix"))) ZEND_PARSE_PARAMETERS_END(); ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &a); - epsilon = (0.00000001); - ZEPHIR_INIT_VAR(&b); - array_init(&b); - ZEPHIR_INIT_VAR(&rowB); - array_init(&rowB); - ZEPHIR_INIT_VAR(&t); - array_init(&t); - ZEPHIR_CALL_METHOD(&_0, a, "m", NULL, 0); + ZEPHIR_INIT_VAR(&result); + ZEPHIR_CALL_METHOD(&_0, a, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - m = zephir_get_intval(&_0); - ZEPHIR_CALL_METHOD(&_1, a, "n", NULL, 0); + ZEPHIR_CALL_METHOD(&_1, a, "m", NULL, 0); zephir_check_call_status(); - n = zephir_get_intval(&_1); - row = 0; - col = 0; - ZEPHIR_CALL_METHOD(&_2, a, "ref", NULL, 0); + ZEPHIR_CALL_METHOD(&_2, a, "n", NULL, 0); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_3, &_2, "a", NULL, 0); - zephir_check_call_status(); - ZEPHIR_CALL_METHOD(&_4, &_3, "asarray", NULL, 0); - zephir_check_call_status(); - zephir_get_arrval(&_5, &_4); - ZEPHIR_CPY_WRT(&b, &_5); - while (1) { - _6 = row < m; - if (_6) { - _6 = col < n; - } - if (!(_6)) { - break; - } - ZEPHIR_OBS_NVAR(&_7$$3); - zephir_array_fetch_long(&_7$$3, &b, row, PH_NOISY, "tensor/reductions/rref.zep", 52); - zephir_get_arrval(&_8$$3, &_7$$3); - ZEPHIR_CPY_WRT(&t, &_8$$3); - zephir_array_fetch_long(&_9$$3, &t, col, PH_NOISY | PH_READONLY, "tensor/reductions/rref.zep", 54); - ZEPHIR_CALL_FUNCTION(&_10$$3, "abs", &_11, 12, &_9$$3); - zephir_check_call_status(); - if (ZEPHIR_LT_DOUBLE(&_10$$3, epsilon)) { - hasPivot = 0; - _14$$4 = (n - 1); - _13$$4 = col; - _12$$4 = 0; - if (_13$$4 <= _14$$4) { - while (1) { - if (_12$$4) { - _13$$4++; - if (!(_13$$4 <= _14$$4)) { - break; - } - } else { - _12$$4 = 1; - } - i = _13$$4; - zephir_array_fetch_long(&_15$$5, &t, i, PH_NOISY | PH_READONLY, "tensor/reductions/rref.zep", 58); - ZEPHIR_CALL_FUNCTION(&_16$$5, "abs", &_11, 12, &_15$$5); - zephir_check_call_status(); - if (!ZEPHIR_LT_DOUBLE(&_16$$5, epsilon)) { - hasPivot = 1; - break; - } - } - } - if (hasPivot == 0) { - _19$$7 = (n - 1); - _18$$7 = col; - _17$$7 = 0; - if (_18$$7 <= _19$$7) { - while (1) { - if (_17$$7) { - _18$$7++; - if (!(_18$$7 <= _19$$7)) { - break; - } - } else { - _17$$7 = 1; - } - i = _18$$7; - ZEPHIR_INIT_NVAR(&_20$$8); - ZVAL_DOUBLE(&_20$$8, 0.0); - zephir_array_update_long(&t, i, &_20$$8, PH_COPY | PH_SEPARATE ZEPHIR_DEBUG_PARAMS_DUMMY); - } - } - zephir_array_update_long(&b, row, &t, PH_COPY | PH_SEPARATE ZEPHIR_DEBUG_PARAMS_DUMMY); - row++; - continue; - } - col++; - continue; - } - ZEPHIR_OBS_NVAR(&_21$$3); - zephir_array_fetch_long(&_21$$3, &t, col, PH_NOISY, "tensor/reductions/rref.zep", 82); - divisor = (zephir_get_doubleval(&_21$$3)); - if (divisor != 1.0) { - _24$$9 = (n - 1); - _23$$9 = 0; - _22$$9 = 0; - if (_23$$9 <= _24$$9) { - while (1) { - if (_22$$9) { - _23$$9++; - if (!(_23$$9 <= _24$$9)) { - break; - } - } else { - _22$$9 = 1; - } - i = _23$$9; - zephir_array_fetch_long(&_25$$10, &t, i, PH_NOISY | PH_READONLY, "tensor/reductions/rref.zep", 86); - ZEPHIR_INIT_NVAR(&_26$$10); - ZVAL_DOUBLE(&_26$$10, zephir_safe_div_zval_double(&_25$$10, divisor)); - zephir_array_update_long(&t, i, &_26$$10, PH_COPY | PH_SEPARATE ZEPHIR_DEBUG_PARAMS_DUMMY); - } - } - } - _29$$3 = (row - 1); - _28$$3 = _29$$3; - _27$$3 = 0; - if (_28$$3 >= 0) { - while (1) { - if (_27$$3) { - _28$$3--; - if (!(_28$$3 >= 0)) { - break; - } - } else { - _27$$3 = 1; - } - i = _28$$3; - ZEPHIR_OBS_NVAR(&_30$$11); - zephir_array_fetch_long(&_30$$11, &b, i, PH_NOISY, "tensor/reductions/rref.zep", 91); - zephir_get_arrval(&_31$$11, &_30$$11); - ZEPHIR_CPY_WRT(&rowB, &_31$$11); - ZEPHIR_OBS_NVAR(&_32$$11); - zephir_array_fetch_long(&_32$$11, &rowB, col, PH_NOISY, "tensor/reductions/rref.zep", 93); - scale = (zephir_get_doubleval(&_32$$11)); - ZVAL_DOUBLE(&_33$$11, scale); - ZEPHIR_CALL_FUNCTION(&_34$$11, "abs", &_11, 12, &_33$$11); - zephir_check_call_status(); - if (!ZEPHIR_LT_DOUBLE(&_34$$11, epsilon)) { - _37$$12 = (n - 1); - _36$$12 = 0; - _35$$12 = 0; - if (_36$$12 <= _37$$12) { - while (1) { - if (_35$$12) { - _36$$12++; - if (!(_36$$12 <= _37$$12)) { - break; - } - } else { - _35$$12 = 1; - } - j = _36$$12; - zephir_array_fetch_long(&_38$$13, &rowB, j, PH_NOISY | PH_READONLY, "tensor/reductions/rref.zep", 97); - zephir_array_fetch_long(&_39$$13, &t, j, PH_NOISY | PH_READONLY, "tensor/reductions/rref.zep", 97); - ZEPHIR_INIT_NVAR(&_40$$13); - ZVAL_LONG(&_40$$13, (zephir_get_numberval(&_38$$13) - (scale * (zend_long) zephir_get_numberval(&_39$$13)))); - zephir_array_update_long(&rowB, j, &_40$$13, PH_COPY | PH_SEPARATE ZEPHIR_DEBUG_PARAMS_DUMMY); - } - } - } - zephir_array_update_long(&b, i, &rowB, PH_COPY | PH_SEPARATE ZEPHIR_DEBUG_PARAMS_DUMMY); - } - } - zephir_array_update_long(&b, row, &t, PH_COPY | PH_SEPARATE ZEPHIR_DEBUG_PARAMS_DUMMY); - row++; - col++; + tensor_rref(&result, &_0, &_1, &_2); + if (Z_TYPE_P(&result) == IS_NULL) { + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Failed to reduce matrix.", "tensor/reductions/rref.zep", 36); + return; } object_init_ex(return_value, tensor_reductions_rref_ce); - ZEPHIR_CALL_CE_STATIC(&_41, tensor_matrix_ce, "quick", NULL, 0, &b); + ZEPHIR_INIT_VAR(&_3); + object_init_ex(&_3, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_4, a, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_5, a, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, &_3, "__construct", NULL, 14, &result, &_4, &_5); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 34, &_41); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 29, &_3); zephir_check_call_status(); RETURN_MM(); } diff --git a/ext/tensor/settings.zep.c b/ext/tensor/settings.zep.c index 6f5f309..d1b41db 100644 --- a/ext/tensor/settings.zep.c +++ b/ext/tensor/settings.zep.c @@ -65,11 +65,11 @@ PHP_METHOD(Tensor_Settings, setNumThreads) ZEPHIR_INIT_VAR(&_0$$3); object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_1$$3, threads); - ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 4, &_1$$3); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 3, &_1$$3); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3$$3); ZEPHIR_CONCAT_SSVS(&_3$$3, "The number of threads", " must be greater than 0, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 3, &_3$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); zephir_throw_exception_debug(&_0$$3, "tensor/settings.zep", 26); ZEPHIR_MM_RESTORE(); diff --git a/ext/tensor/special.zep.c b/ext/tensor/special.zep.c index 893009a..2ce658e 100644 --- a/ext/tensor/special.zep.c +++ b/ext/tensor/special.zep.c @@ -43,6 +43,18 @@ ZEPHIR_DOC_METHOD(Tensor_Special, min); * @return mixed */ ZEPHIR_DOC_METHOD(Tensor_Special, max); +/** + * Return the index (or per-row indices) of the minimum of the tensor. + * + * @return mixed + */ +ZEPHIR_DOC_METHOD(Tensor_Special, argmin); +/** + * Return the index (or per-row indices) of the maximum of the tensor. + * + * @return mixed + */ +ZEPHIR_DOC_METHOD(Tensor_Special, argmax); /** * Clip the tensor to be between the given minimum and maximum. * diff --git a/ext/tensor/special.zep.h b/ext/tensor/special.zep.h index da9312d..f43bfcc 100644 --- a/ext/tensor/special.zep.h +++ b/ext/tensor/special.zep.h @@ -15,6 +15,12 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_max, 0, 0, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_argmin, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_argmax, 0, 0, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_clip, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, min, IS_DOUBLE, 0) ZEND_ARG_TYPE_INFO(0, max, IS_DOUBLE, 0) @@ -33,6 +39,8 @@ ZEPHIR_INIT_FUNCS(tensor_special_method_entry) { PHP_ABSTRACT_ME(Tensor_Special, product, arginfo_tensor_special_product) PHP_ABSTRACT_ME(Tensor_Special, min, arginfo_tensor_special_min) PHP_ABSTRACT_ME(Tensor_Special, max, arginfo_tensor_special_max) + PHP_ABSTRACT_ME(Tensor_Special, argmin, arginfo_tensor_special_argmin) + PHP_ABSTRACT_ME(Tensor_Special, argmax, arginfo_tensor_special_argmax) PHP_ABSTRACT_ME(Tensor_Special, clip, arginfo_tensor_special_clip) PHP_ABSTRACT_ME(Tensor_Special, clipLower, arginfo_tensor_special_cliplower) PHP_ABSTRACT_ME(Tensor_Special, clipUpper, arginfo_tensor_special_clipupper) diff --git a/ext/tensor/tensorbuffer.zep.c b/ext/tensor/tensorbuffer.zep.c new file mode 100644 index 0000000..83d9887 --- /dev/null +++ b/ext/tensor/tensorbuffer.zep.c @@ -0,0 +1,751 @@ + +#ifdef HAVE_CONFIG_H +#include "../ext_config.h" +#endif + +#include +#include "../php_ext.h" +#include "../ext.h" + +#include +#include +#include + +#include "kernel/main.h" +#include "kernel/memory.h" +#include "kernel/array.h" +#include "kernel/fcall.h" +#include "kernel/operators.h" +#include "kernel/object.h" +#include "kernel/exception.h" +#include "kernel/concat.h" +#include "kernel/string.h" +#include "include/buffer.h" + + +/** + * TensorBuffer + * + * A decorator that wraps the kernel Buffer class and provides structural + * operations such as sorting, slicing, splitting, concatenating, and + * repeating. + * + * @internal + * + * @category Scientific Computing + * @package Rubix/Tensor + * @author Andrew DalPino + */ +ZEPHIR_INIT_CLASS(Tensor_TensorBuffer) +{ + ZEPHIR_REGISTER_CLASS(Tensor, TensorBuffer, tensor, tensorbuffer, tensor_tensorbuffer_method_entry, 0); + + /** + * The underlying buffer being decorated. + * + * @var \Tensor\Buffer + */ + zend_declare_property_null(tensor_tensorbuffer_ce, SL("buffer"), ZEND_ACC_PROTECTED); + return SUCCESS; +} + +/** + * Build a buffer by concatenating an array of buffers into a single + * contiguous buffer. + * + * @param \Tensor\TensorBuffer[] buffers + * @return self + */ +PHP_METHOD(Tensor_TensorBuffer, fromBuffers) +{ + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS, rows; + zval *buffers_param = NULL, _2, _3, _4, _0$$3, _1$$4; + zval buffers; + + ZVAL_UNDEF(&buffers); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_0$$3); + ZVAL_UNDEF(&_1$$4); + ZEND_PARSE_PARAMETERS_START(1, 1) + ZEPHIR_Z_PARAM_ARRAY(buffers, buffers_param) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 1, 0, &buffers_param); + zephir_get_arrval(&buffers, buffers_param); + rows = zephir_fast_count_int(&buffers); + if (UNEXPECTED(rows < 1)) { + ZEPHIR_INIT_VAR(&_0$$3); + array_init(&_0$$3); + tensor_buffer_from_array(return_value, &_0$$3); + RETURN_MM(); + } + if (UNEXPECTED(rows == 1)) { + zephir_memory_observe(&_1$$4); + zephir_array_fetch_long(&_1$$4, &buffers, 0, PH_NOISY, "tensor/tensorbuffer.zep", 43); + RETURN_CCTOR(&_1$$4); + } + zephir_memory_observe(&_2); + zephir_array_fetch_long(&_2, &buffers, 0, PH_NOISY, "tensor/tensorbuffer.zep", 46); + ZVAL_LONG(&_3, 1); + ZEPHIR_CALL_FUNCTION(&_4, "array_slice", NULL, 30, &buffers, &_3); + zephir_check_call_status(); + ZEPHIR_RETURN_CALL_METHOD(&_2, "concat", NULL, 0, &_4); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * @param \Tensor\Buffer buffer + */ +PHP_METHOD(Tensor_TensorBuffer, __construct) +{ + zval *buffer, buffer_sub; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&buffer_sub); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("buffer", 6, 1); + } + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_OBJECT_OF_CLASS(buffer, zephir_get_internal_ce(SL("tensor\\buffer"))) + ZEND_PARSE_PARAMETERS_END(); + zephir_fetch_params_without_memory_grow(1, 0, &buffer); + zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 20, buffer); +} + +/** + * Return the element type of the buffer. + * + * @return int + */ +PHP_METHOD(Tensor_TensorBuffer, type) +{ + zval _0; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("buffer", 6, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 20, PH_NOISY_CC | PH_READONLY); + ZEPHIR_RETURN_CALL_METHOD(&_0, "type", NULL, 0); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return the element at the given index. + * + * @param int index + * @return mixed + */ +PHP_METHOD(Tensor_TensorBuffer, get) +{ + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zval *index_param = NULL, _0, _1; + zend_long index; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("buffer", 6, 1); + } + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(index) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 1, 0, &index_param); + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 20, PH_NOISY_CC | PH_READONLY); + zephir_memory_observe(&_1); + zephir_array_fetch_long(&_1, &_0, index, PH_NOISY, "tensor/tensorbuffer.zep", 75); + RETURN_CCTOR(&_1); +} + +/** + * Set the element at the given index. + * + * @param int index + * @param mixed value + * @return void + */ +PHP_METHOD(Tensor_TensorBuffer, set) +{ + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zval *index_param = NULL, *value, value_sub, _0; + zend_long index; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&value_sub); + ZVAL_UNDEF(&_0); + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_LONG(index) + Z_PARAM_ZVAL(value) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 2, 0, &index_param, &value); + ZEPHIR_INIT_VAR(&_0); + ZVAL_LONG(&_0, index); + zephir_update_property_array(this_ptr, SL("buffer"), &_0, value); + ZEPHIR_MM_RESTORE(); +} + +/** + * Sort the buffer in place. + * + * @param bool ascending + * @return void + */ +PHP_METHOD(Tensor_TensorBuffer, sort) +{ + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zval *ascending_param = NULL, status, _0, _1; + zend_bool ascending; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&status); + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("buffer", 6, 1); + } + + ZEND_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(ascending) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 0, 1, &ascending_param); + if (!ascending_param) { + ascending = 1; + } else { + } + ZEPHIR_INIT_VAR(&status); + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 20, PH_NOISY_CC | PH_READONLY); + if (ascending) { + ZVAL_BOOL(&_1, 1); + } else { + ZVAL_BOOL(&_1, 0); + } + tensor_buffer_sort(&status, &_0, &_1); + ZEPHIR_MM_RESTORE(); +} + +/** + * Return a slice of the buffer as a new decorator. + * + * @param int offset + * @param int length + * @throws \Tensor\Exceptions\InvalidArgumentException + * @return self + */ +PHP_METHOD(Tensor_TensorBuffer, slice) +{ + zval _5$$3; + zend_bool _0, _1; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zval *offset_param = NULL, *length_param = NULL, _2, _3, b, _6, _7, _8, _4$$3; + zend_long offset, length, ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&b); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_4$$3); + ZVAL_UNDEF(&_5$$3); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("buffer", 6, 1); + } + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_LONG(offset) + Z_PARAM_LONG(length) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 2, 0, &offset_param, &length_param); + _0 = offset < 0; + if (!(_0)) { + _0 = length < 0; + } + _1 = _0; + if (!(_1)) { + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_0, 20, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_3, &_2, "count", NULL, 0); + zephir_check_call_status(); + _1 = offset > (zephir_get_numberval(&_3) - length); + } + if (UNEXPECTED(_1)) { + ZEPHIR_INIT_VAR(&_4$$3); + object_init_ex(&_4$$3, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_VAR(&_5$$3); + ZEPHIR_CONCAT_SS(&_5$$3, "Offset and length", " must be within the bounds of the buffer."); + ZEPHIR_CALL_METHOD(NULL, &_4$$3, "__construct", NULL, 2, &_5$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_4$$3, "tensor/tensorbuffer.zep", 113); + ZEPHIR_MM_RESTORE(); + return; + } + ZEPHIR_INIT_VAR(&b); + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_0, 20, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_7, offset); + ZVAL_LONG(&_8, length); + tensor_buffer_slice(&b, &_6, &_7, &_8); + object_init_ex(return_value, tensor_tensorbuffer_ce); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 31, &b); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return a slice of the buffer with a given stride as a new decorator. + * + * @param int offset + * @param int length + * @param int stride + * @throws \Tensor\Exceptions\InvalidArgumentException + * @return self + */ +PHP_METHOD(Tensor_TensorBuffer, sliceStrided) +{ + zval _8$$10; + zend_bool invalid, _0, _1, _2, _5$$3, _6$$3; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zval *offset_param = NULL, *length_param = NULL, *stride_param = NULL, b, _9, _10, _11, _12, _3$$3, _4$$3, _7$$10; + zend_long offset, length, stride, ZEPHIR_LAST_CALL_STATUS, limit, a, acc, product; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&b); + ZVAL_UNDEF(&_9); + ZVAL_UNDEF(&_10); + ZVAL_UNDEF(&_11); + ZVAL_UNDEF(&_12); + ZVAL_UNDEF(&_3$$3); + ZVAL_UNDEF(&_4$$3); + ZVAL_UNDEF(&_7$$10); + ZVAL_UNDEF(&_8$$10); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("buffer", 6, 1); + } + + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_LONG(offset) + Z_PARAM_LONG(length) + Z_PARAM_LONG(stride) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 3, 0, &offset_param, &length_param, &stride_param); + limit = 0; + a = 0; + acc = 0; + product = 0; + _0 = offset < 0; + if (!(_0)) { + _0 = length < 0; + } + _1 = _0; + if (!(_1)) { + _1 = stride < 1; + } + invalid = _1; + _2 = !invalid; + if (_2) { + _2 = length > 0; + } + if (EXPECTED(_2)) { + zephir_read_property_cached(&_3$$3, this_ptr, _zephir_prop_0, 20, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_4$$3, &_3$$3, "count", NULL, 0); + zephir_check_call_status(); + limit = ((zephir_get_numberval(&_4$$3) - 1) - offset); + _5$$3 = limit < 0; + if (!(_5$$3)) { + _6$$3 = length > 1; + if (_6$$3) { + _6$$3 = stride > limit; + } + _5$$3 = _6$$3; + } + invalid = _5$$3; + if (EXPECTED(!invalid)) { + a = (length - 1); + acc = stride; + while (1) { + if (!(a > 0)) { + break; + } + if ((a & 1)) { + product += acc; + if (product > limit) { + invalid = 1; + break; + } + } + a = (a >> 1); + if (a > 0) { + if (acc > ((limit >> 1))) { + invalid = 1; + break; + } + acc = (acc << 1); + } + } + } + } + if (UNEXPECTED(invalid)) { + ZEPHIR_INIT_VAR(&_7$$10); + object_init_ex(&_7$$10, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_VAR(&_8$$10); + ZEPHIR_CONCAT_SS(&_8$$10, "Offset, length, and", " stride must be within the bounds of the buffer."); + ZEPHIR_CALL_METHOD(NULL, &_7$$10, "__construct", NULL, 2, &_8$$10); + zephir_check_call_status(); + zephir_throw_exception_debug(&_7$$10, "tensor/tensorbuffer.zep", 176); + ZEPHIR_MM_RESTORE(); + return; + } + ZEPHIR_INIT_VAR(&b); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 20, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_10, offset); + ZVAL_LONG(&_11, length); + ZVAL_LONG(&_12, stride); + tensor_buffer_slice_strided(&b, &_9, &_10, &_11, &_12); + object_init_ex(return_value, tensor_tensorbuffer_ce); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 31, &b); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return a new decorator wrapping a new buffer containing the elements of + * this buffer concatenated with the given buffers. + * + * @param \Tensor\TensorBuffer[] buffers + * @return self + */ +PHP_METHOD(Tensor_TensorBuffer, concat) +{ + zend_bool _3; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *buffers_param = NULL, buffer, *_0, _2, b, _5, _1$$3, _4$$4; + zval buffers, unwrapped; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&buffers); + ZVAL_UNDEF(&unwrapped); + ZVAL_UNDEF(&buffer); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&b); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_4$$4); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("buffer", 6, 1); + } + + ZEND_PARSE_PARAMETERS_START(1, 1) + ZEPHIR_Z_PARAM_ARRAY(buffers, buffers_param) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 1, 0, &buffers_param); + zephir_get_arrval(&buffers, buffers_param); + ZEPHIR_INIT_VAR(&unwrapped); + array_init(&unwrapped); + zephir_is_iterable(&buffers, 0, "tensor/tensorbuffer.zep", 201); + if (Z_TYPE_P(&buffers) == IS_ARRAY) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&buffers), _0) + { + ZEPHIR_INIT_NVAR(&buffer); + ZVAL_COPY(&buffer, _0); + ZEPHIR_CALL_METHOD(&_1$$3, &buffer, "asBuffer", NULL, 0); + zephir_check_call_status(); + zephir_array_append(&unwrapped, &_1$$3, PH_SEPARATE, "tensor/tensorbuffer.zep", 198); + } ZEND_HASH_FOREACH_END(); + } else { + ZEPHIR_CALL_METHOD(NULL, &buffers, "rewind", NULL, 0); + zephir_check_call_status(); + _3 = 1; + while (1) { + if (_3) { + _3 = 0; + } else { + ZEPHIR_CALL_METHOD(NULL, &buffers, "next", NULL, 0); + zephir_check_call_status(); + } + ZEPHIR_CALL_METHOD(&_2, &buffers, "valid", NULL, 0); + zephir_check_call_status(); + if (!zend_is_true(&_2)) { + break; + } + ZEPHIR_CALL_METHOD(&buffer, &buffers, "current", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_4$$4, &buffer, "asBuffer", NULL, 0); + zephir_check_call_status(); + zephir_array_append(&unwrapped, &_4$$4, PH_SEPARATE, "tensor/tensorbuffer.zep", 198); + } + } + ZEPHIR_INIT_NVAR(&buffer); + ZEPHIR_INIT_VAR(&b); + zephir_read_property_cached(&_5, this_ptr, _zephir_prop_0, 20, PH_NOISY_CC | PH_READONLY); + tensor_buffer_concat(&b, &_5, &unwrapped); + object_init_ex(return_value, tensor_tensorbuffer_ce); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 31, &b); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return an array of new decorators each wrapping a chunk of this buffer + * of the given length. + * + * @param int chunkLength + * @throws \Tensor\Exceptions\InvalidArgumentException + * @return \Tensor\TensorBuffer[] + */ +PHP_METHOD(Tensor_TensorBuffer, split) +{ + zend_bool _12; + zval tensorBuffers; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zephir_fcall_cache_entry *_10 = NULL; + zval *chunkLength_param = NULL, _0$$3, _1$$3, _2$$3, _3$$3, buffer, buffers, _4, _5, *_6, _7, *_8, _11, _9$$4, _13$$5; + zend_long chunkLength, ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0$$3); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); + ZVAL_UNDEF(&_3$$3); + ZVAL_UNDEF(&buffer); + ZVAL_UNDEF(&buffers); + ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_11); + ZVAL_UNDEF(&_9$$4); + ZVAL_UNDEF(&_13$$5); + ZVAL_UNDEF(&tensorBuffers); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("buffer", 6, 1); + } + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(chunkLength) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 1, 0, &chunkLength_param); + if (UNEXPECTED(chunkLength < 1)) { + ZEPHIR_INIT_VAR(&_0$$3); + object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); + ZVAL_LONG(&_1$$3, chunkLength); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 3, &_1$$3); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&_3$$3); + ZEPHIR_CONCAT_SSVS(&_3$$3, "Chunk length must be", " greater than 0, ", &_2$$3, " given."); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_0$$3, "tensor/tensorbuffer.zep", 218); + ZEPHIR_MM_RESTORE(); + return; + } + ZEPHIR_INIT_VAR(&buffers); + zephir_read_property_cached(&_4, this_ptr, _zephir_prop_0, 20, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_5, chunkLength); + tensor_buffer_split(&buffers, &_4, &_5); + ZEPHIR_INIT_VAR(&tensorBuffers); + array_init(&tensorBuffers); + if (Z_TYPE_P(&buffers) == IS_STRING) { + ZEPHIR_INIT_VAR(&_7); + zephir_string_to_char_array(&_7, &buffers); + _6 = &_7; + } else { + _6 = &buffers; + } + zephir_is_iterable(_6, 0, "tensor/tensorbuffer.zep", 231); + if (Z_TYPE_P(_6) == IS_ARRAY) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_6), _8) + { + ZEPHIR_INIT_NVAR(&buffer); + ZVAL_COPY(&buffer, _8); + ZEPHIR_INIT_NVAR(&_9$$4); + object_init_ex(&_9$$4, tensor_tensorbuffer_ce); + ZEPHIR_CALL_METHOD(NULL, &_9$$4, "__construct", &_10, 31, &buffer); + zephir_check_call_status(); + zephir_array_append(&tensorBuffers, &_9$$4, PH_SEPARATE, "tensor/tensorbuffer.zep", 228); + } ZEND_HASH_FOREACH_END(); + } else { + ZEPHIR_CALL_METHOD(NULL, _6, "rewind", NULL, 0); + zephir_check_call_status(); + _12 = 1; + while (1) { + if (_12) { + _12 = 0; + } else { + ZEPHIR_CALL_METHOD(NULL, _6, "next", NULL, 0); + zephir_check_call_status(); + } + ZEPHIR_CALL_METHOD(&_11, _6, "valid", NULL, 0); + zephir_check_call_status(); + if (!zend_is_true(&_11)) { + break; + } + ZEPHIR_CALL_METHOD(&buffer, _6, "current", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_NVAR(&_13$$5); + object_init_ex(&_13$$5, tensor_tensorbuffer_ce); + ZEPHIR_CALL_METHOD(NULL, &_13$$5, "__construct", &_10, 31, &buffer); + zephir_check_call_status(); + zephir_array_append(&tensorBuffers, &_13$$5, PH_SEPARATE, "tensor/tensorbuffer.zep", 228); + } + } + ZEPHIR_INIT_NVAR(&buffer); + RETURN_CTOR(&tensorBuffers); +} + +/** + * Return a new decorator wrapping a new buffer with the elements of this + * buffer repeated the given number of times. + * + * @param int times + * @throws \Tensor\Exceptions\InvalidArgumentException + * @return self + */ +PHP_METHOD(Tensor_TensorBuffer, repeat) +{ + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zval *times_param = NULL, _0$$3, _1$$3, _2$$3, _3$$3, b, _4, _5; + zend_long times, ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0$$3); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); + ZVAL_UNDEF(&_3$$3); + ZVAL_UNDEF(&b); + ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_5); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("buffer", 6, 1); + } + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(times) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 1, 0, ×_param); + if (UNEXPECTED(times < 1)) { + ZEPHIR_INIT_VAR(&_0$$3); + object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); + ZVAL_LONG(&_1$$3, times); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 3, &_1$$3); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&_3$$3); + ZEPHIR_CONCAT_SSVS(&_3$$3, "Times must be", " greater than 0, ", &_2$$3, " given."); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_0$$3, "tensor/tensorbuffer.zep", 246); + ZEPHIR_MM_RESTORE(); + return; + } + ZEPHIR_INIT_VAR(&b); + zephir_read_property_cached(&_4, this_ptr, _zephir_prop_0, 20, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_5, times); + tensor_buffer_repeat(&b, &_4, &_5); + object_init_ex(return_value, tensor_tensorbuffer_ce); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 31, &b); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return the underlying buffer. + * + * @return \Tensor\Buffer + */ +PHP_METHOD(Tensor_TensorBuffer, asBuffer) +{ + + RETURN_MEMBER(getThis(), "buffer"); +} + +/** + * Return the number of elements in the buffer. + * + * @return int + */ +PHP_METHOD(Tensor_TensorBuffer, count) +{ + zval _0; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("buffer", 6, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 20, PH_NOISY_CC | PH_READONLY); + ZEPHIR_RETURN_CALL_METHOD(&_0, "count", NULL, 0); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return the buffer as a PHP array. + * + * @return list + */ +PHP_METHOD(Tensor_TensorBuffer, toArray) +{ + zval _0; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("buffer", 6, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 20, PH_NOISY_CC | PH_READONLY); + ZEPHIR_RETURN_CALL_METHOD(&_0, "toArray", NULL, 0); + zephir_check_call_status(); + RETURN_MM(); +} + diff --git a/ext/tensor/tensorbuffer.zep.h b/ext/tensor/tensorbuffer.zep.h new file mode 100644 index 0000000..6c30ca8 --- /dev/null +++ b/ext/tensor/tensorbuffer.zep.h @@ -0,0 +1,95 @@ + +extern zend_class_entry *tensor_tensorbuffer_ce; + +ZEPHIR_INIT_CLASS(Tensor_TensorBuffer); + +PHP_METHOD(Tensor_TensorBuffer, fromBuffers); +PHP_METHOD(Tensor_TensorBuffer, __construct); +PHP_METHOD(Tensor_TensorBuffer, type); +PHP_METHOD(Tensor_TensorBuffer, get); +PHP_METHOD(Tensor_TensorBuffer, set); +PHP_METHOD(Tensor_TensorBuffer, sort); +PHP_METHOD(Tensor_TensorBuffer, slice); +PHP_METHOD(Tensor_TensorBuffer, sliceStrided); +PHP_METHOD(Tensor_TensorBuffer, concat); +PHP_METHOD(Tensor_TensorBuffer, split); +PHP_METHOD(Tensor_TensorBuffer, repeat); +PHP_METHOD(Tensor_TensorBuffer, asBuffer); +PHP_METHOD(Tensor_TensorBuffer, count); +PHP_METHOD(Tensor_TensorBuffer, toArray); + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_tensorbuffer_frombuffers, 0, 1, Tensor\\TensorBuffer, 0) + ZEND_ARG_ARRAY_INFO(0, buffers, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_tensorbuffer___construct, 0, 0, 1) + ZEND_ARG_OBJ_INFO(0, buffer, Tensor\\Buffer, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_tensorbuffer_type, 0, 0, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_tensorbuffer_get, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_tensorbuffer_set, 0, 2, IS_VOID, 0) + + ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_tensorbuffer_sort, 0, 0, IS_VOID, 0) + + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, ascending, _IS_BOOL, 0, "true") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_tensorbuffer_slice, 0, 2, Tensor\\TensorBuffer, 0) + ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_tensorbuffer_slicestrided, 0, 3, Tensor\\TensorBuffer, 0) + ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, stride, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_tensorbuffer_concat, 0, 1, Tensor\\TensorBuffer, 0) + ZEND_ARG_ARRAY_INFO(0, buffers, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_tensorbuffer_split, 0, 1, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, chunkLength, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_tensorbuffer_repeat, 0, 1, Tensor\\TensorBuffer, 0) + ZEND_ARG_TYPE_INFO(0, times, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_tensorbuffer_asbuffer, 0, 0, Tensor\\Buffer, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_tensorbuffer_count, 0, 0, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_tensorbuffer_toarray, 0, 0, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +ZEPHIR_INIT_FUNCS(tensor_tensorbuffer_method_entry) { + PHP_ME(Tensor_TensorBuffer, fromBuffers, arginfo_tensor_tensorbuffer_frombuffers, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(Tensor_TensorBuffer, __construct, arginfo_tensor_tensorbuffer___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(Tensor_TensorBuffer, type, arginfo_tensor_tensorbuffer_type, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_TensorBuffer, get, arginfo_tensor_tensorbuffer_get, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_TensorBuffer, set, arginfo_tensor_tensorbuffer_set, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_TensorBuffer, sort, arginfo_tensor_tensorbuffer_sort, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_TensorBuffer, slice, arginfo_tensor_tensorbuffer_slice, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_TensorBuffer, sliceStrided, arginfo_tensor_tensorbuffer_slicestrided, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_TensorBuffer, concat, arginfo_tensor_tensorbuffer_concat, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_TensorBuffer, split, arginfo_tensor_tensorbuffer_split, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_TensorBuffer, repeat, arginfo_tensor_tensorbuffer_repeat, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_TensorBuffer, asBuffer, arginfo_tensor_tensorbuffer_asbuffer, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_TensorBuffer, count, arginfo_tensor_tensorbuffer_count, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_TensorBuffer, toArray, arginfo_tensor_tensorbuffer_toarray, ZEND_ACC_PUBLIC) + PHP_FE_END +}; diff --git a/ext/tensor/vector.zep.c b/ext/tensor/vector.zep.c index e20167e..543e0a0 100644 --- a/ext/tensor/vector.zep.c +++ b/ext/tensor/vector.zep.c @@ -13,18 +13,20 @@ #include "kernel/main.h" #include "kernel/fcall.h" -#include "kernel/memory.h" #include "kernel/operators.h" +#include "kernel/memory.h" #include "kernel/object.h" #include "kernel/exception.h" #include "kernel/concat.h" #include "kernel/array.h" #include "math.h" -#include "kernel/string.h" #include "kernel/math.h" #include "ext/spl/spl_array.h" +#include "include/buffer.h" #include "include/linear_algebra.h" #include "include/signal_processing.h" +#include "include/unary.h" +#include "include/reductions.h" #include "include/arithmetic.h" #include "include/comparison.h" @@ -43,9 +45,9 @@ ZEPHIR_INIT_CLASS(Tensor_Vector) ZEPHIR_REGISTER_CLASS(Tensor, Vector, tensor, vector, tensor_vector_method_entry, 0); /** - * A 1-d sequential array holding the elements of the vector. + * A 1-d contiguous buffer holding the elements of the vector. * - * @var list + * @var \Tensor\TensorBuffer */ zend_declare_property_null(tensor_vector_ce, SL("a"), ZEND_ACC_PROTECTED); /** @@ -58,76 +60,6 @@ ZEPHIR_INIT_CLASS(Tensor_Vector) return SUCCESS; } -/** - * Factory method to build a new vector from an array. - * - * @param float[] a - * @return self - */ -PHP_METHOD(Tensor_Vector, build) -{ - zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS; - zval *a_param = NULL, _0; - zval a; - - ZVAL_UNDEF(&a); - ZVAL_UNDEF(&_0); - ZEND_PARSE_PARAMETERS_START(0, 1) - Z_PARAM_OPTIONAL - ZEPHIR_Z_PARAM_ARRAY(a, a_param) - ZEND_PARSE_PARAMETERS_END(); - ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); - zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_fetch_params(1, 0, 1, &a_param); - if (!a_param) { - ZEPHIR_INIT_VAR(&a); - array_init(&a); - } else { - zephir_get_arrval(&a, a_param); - } - object_init_ex(return_value, tensor_vector_ce); - ZVAL_BOOL(&_0, 1); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 1, &a, &_0); - zephir_check_call_status(); - RETURN_MM(); -} - -/** - * Build a vector foregoing any validation for quicker instantiation. - * - * @param float[] a - * @return self - */ -PHP_METHOD(Tensor_Vector, quick) -{ - zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS; - zval *a_param = NULL, _0; - zval a; - - ZVAL_UNDEF(&a); - ZVAL_UNDEF(&_0); - ZEND_PARSE_PARAMETERS_START(0, 1) - Z_PARAM_OPTIONAL - ZEPHIR_Z_PARAM_ARRAY(a, a_param) - ZEND_PARSE_PARAMETERS_END(); - ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); - zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_fetch_params(1, 0, 1, &a_param); - if (!a_param) { - ZEPHIR_INIT_VAR(&a); - array_init(&a); - } else { - zephir_get_arrval(&a, a_param); - } - object_init_ex(return_value, tensor_vector_ce); - ZVAL_BOOL(&_0, 0); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 1, &a, &_0); - zephir_check_call_status(); - RETURN_MM(); -} - /** * Build a vector of zeros with n elements. * @@ -226,7 +158,7 @@ PHP_METHOD(Tensor_Vector, fill) _1 = !(Z_TYPE_P(&_0) == IS_LONG); if (_1) { ZVAL_DOUBLE(&_2, value); - ZEPHIR_CALL_FUNCTION(&_3, "is_float", NULL, 2, &_2); + ZEPHIR_CALL_FUNCTION(&_3, "is_float", NULL, 1, &_2); zephir_check_call_status(); _1 = !zephir_is_true(&_3); } @@ -238,9 +170,9 @@ PHP_METHOD(Tensor_Vector, fill) zephir_gettype(&_5$$3, &_6$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SSVS(&_7$$3, "Value must be an", " integer or floating point number, ", &_5$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_4$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_4$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_4$$3, "tensor/vector.zep", 92); + zephir_throw_exception_debug(&_4$$3, "tensor/vector.zep", 70); ZEPHIR_MM_RESTORE(); return; } @@ -248,22 +180,23 @@ PHP_METHOD(Tensor_Vector, fill) ZEPHIR_INIT_VAR(&_8$$4); object_init_ex(&_8$$4, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_9$$4, n); - ZEPHIR_CALL_FUNCTION(&_10$$4, "strval", NULL, 4, &_9$$4); + ZEPHIR_CALL_FUNCTION(&_10$$4, "strval", NULL, 3, &_9$$4); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_11$$4); ZEPHIR_CONCAT_SSVS(&_11$$4, "N must be", " greater than 0, ", &_10$$4, " given."); - ZEPHIR_CALL_METHOD(NULL, &_8$$4, "__construct", NULL, 3, &_11$$4); + ZEPHIR_CALL_METHOD(NULL, &_8$$4, "__construct", NULL, 2, &_11$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_8$$4, "tensor/vector.zep", 97); + zephir_throw_exception_debug(&_8$$4, "tensor/vector.zep", 75); ZEPHIR_MM_RESTORE(); return; } ZVAL_LONG(&_2, 0); ZVAL_LONG(&_12, n); ZVAL_DOUBLE(&_13, value); - ZEPHIR_CALL_FUNCTION(&_14, "array_fill", NULL, 5, &_2, &_12, &_13); + ZEPHIR_CALL_FUNCTION(&_14, "array_fill", NULL, 4, &_2, &_12, &_13); zephir_check_call_status(); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_14); + ZVAL_BOOL(&_2, 0); + ZEPHIR_RETURN_CALL_STATIC("fromArray", NULL, 0, &_14, &_2); zephir_check_call_status(); RETURN_MM(); } @@ -280,7 +213,7 @@ PHP_METHOD(Tensor_Vector, rand) zval a; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zephir_fcall_cache_entry *_6 = NULL; - zval *n_param = NULL, _0$$3, _1$$3, _2$$3, _3$$3, _4, _5$$4, _7$$4; + zval *n_param = NULL, _0$$3, _1$$3, _2$$3, _3$$3, _4, _8, _5$$4, _7$$4; zend_long n, ZEPHIR_LAST_CALL_STATUS, max; ZVAL_UNDEF(&_0$$3); @@ -288,6 +221,7 @@ PHP_METHOD(Tensor_Vector, rand) ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_8); ZVAL_UNDEF(&_5$$4); ZVAL_UNDEF(&_7$$4); ZVAL_UNDEF(&a); @@ -301,32 +235,33 @@ PHP_METHOD(Tensor_Vector, rand) ZEPHIR_INIT_VAR(&_0$$3); object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_1$$3, n); - ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 4, &_1$$3); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 3, &_1$$3); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3$$3); ZEPHIR_CONCAT_SSVS(&_3$$3, "N must be", " greater than 0, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 3, &_3$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 114); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 92); ZEPHIR_MM_RESTORE(); return; } ZEPHIR_INIT_VAR(&a); array_init(&a); - ZEPHIR_CALL_FUNCTION(&_4, "getrandmax", NULL, 6); + ZEPHIR_CALL_FUNCTION(&_4, "getrandmax", NULL, 5); zephir_check_call_status(); max = zephir_get_intval(&_4); while (1) { if (!(zephir_fast_count_int(&a) < n)) { break; } - ZEPHIR_CALL_FUNCTION(&_5$$4, "rand", &_6, 7); + ZEPHIR_CALL_FUNCTION(&_5$$4, "rand", &_6, 6); zephir_check_call_status(); ZEPHIR_INIT_NVAR(&_7$$4); ZVAL_DOUBLE(&_7$$4, zephir_safe_div_zval_long(&_5$$4, max)); - zephir_array_append(&a, &_7$$4, PH_SEPARATE, "tensor/vector.zep", 122); + zephir_array_append(&a, &_7$$4, PH_SEPARATE, "tensor/vector.zep", 100); } - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &a); + ZVAL_BOOL(&_8, 0); + ZEPHIR_RETURN_CALL_STATIC("fromArray", NULL, 0, &a, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -345,7 +280,7 @@ PHP_METHOD(Tensor_Vector, gaussian) double r = 0, phi = 0; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zephir_fcall_cache_entry *_6 = NULL, *_9 = NULL; - zval *n_param = NULL, _0$$3, _1$$3, _2$$3, _3$$3, _4, _5$$4, _7$$4, _8$$4, _10$$4, _11$$4, _12$$4, _13$$4; + zval *n_param = NULL, _0$$3, _1$$3, _2$$3, _3$$3, _4, _14, _5$$4, _7$$4, _8$$4, _10$$4, _11$$4, _12$$4, _13$$4; zend_long n, ZEPHIR_LAST_CALL_STATUS, max; ZVAL_UNDEF(&_0$$3); @@ -353,6 +288,7 @@ PHP_METHOD(Tensor_Vector, gaussian) ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_14); ZVAL_UNDEF(&_5$$4); ZVAL_UNDEF(&_7$$4); ZVAL_UNDEF(&_8$$4); @@ -371,51 +307,52 @@ PHP_METHOD(Tensor_Vector, gaussian) ZEPHIR_INIT_VAR(&_0$$3); object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_1$$3, n); - ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 4, &_1$$3); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 3, &_1$$3); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3$$3); ZEPHIR_CONCAT_SSVS(&_3$$3, "N must be", " greater than 0, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 3, &_3$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 140); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 118); ZEPHIR_MM_RESTORE(); return; } ZEPHIR_INIT_VAR(&a); array_init(&a); - ZEPHIR_CALL_FUNCTION(&_4, "getrandmax", NULL, 6); + ZEPHIR_CALL_FUNCTION(&_4, "getrandmax", NULL, 5); zephir_check_call_status(); max = zephir_get_intval(&_4); while (1) { if (!(zephir_fast_count_int(&a) < n)) { break; } - ZEPHIR_CALL_FUNCTION(&_5$$4, "rand", &_6, 7); + ZEPHIR_CALL_FUNCTION(&_5$$4, "rand", &_6, 6); zephir_check_call_status(); ZVAL_DOUBLE(&_7$$4, zephir_safe_div_zval_long(&_5$$4, max)); - ZEPHIR_CALL_FUNCTION(&_8$$4, "log", &_9, 8, &_7$$4); + ZEPHIR_CALL_FUNCTION(&_8$$4, "log", &_9, 7, &_7$$4); zephir_check_call_status(); ZVAL_DOUBLE(&_7$$4, (-2.0 * zephir_get_numberval(&_8$$4))); r = (sqrt((-2.0 * zephir_get_numberval(&_8$$4)))); - ZEPHIR_CALL_FUNCTION(&_10$$4, "rand", &_6, 7); + ZEPHIR_CALL_FUNCTION(&_10$$4, "rand", &_6, 6); zephir_check_call_status(); phi = ((zephir_safe_div_zval_long(&_10$$4, max) * 6.28318530718)); ZVAL_DOUBLE(&_11$$4, phi); ZEPHIR_INIT_NVAR(&_12$$4); ZVAL_DOUBLE(&_12$$4, (r * sin(phi))); - zephir_array_append(&a, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 154); + zephir_array_append(&a, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 132); ZVAL_DOUBLE(&_13$$4, phi); ZEPHIR_INIT_NVAR(&_12$$4); ZVAL_DOUBLE(&_12$$4, (r * cos(phi))); - zephir_array_append(&a, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 155); + zephir_array_append(&a, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 133); } if (zephir_fast_count_int(&a) > n) { ZEPHIR_MAKE_REF(&a); - ZEPHIR_CALL_FUNCTION(NULL, "array_pop", NULL, 9, &a); + ZEPHIR_CALL_FUNCTION(NULL, "array_pop", NULL, 8, &a); ZEPHIR_UNREF(&a); zephir_check_call_status(); } - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &a); + ZVAL_BOOL(&_14, 0); + ZEPHIR_RETURN_CALL_STATIC("fromArray", NULL, 0, &a, &_14); zephir_check_call_status(); RETURN_MM(); } @@ -470,13 +407,13 @@ PHP_METHOD(Tensor_Vector, poisson) ZEPHIR_INIT_VAR(&_0$$3); object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_1$$3, n); - ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", &_3, 4, &_1$$3); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", &_3, 3, &_1$$3); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_4$$3); ZEPHIR_CONCAT_SSVS(&_4$$3, "N must be", " greater than 0, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 3, &_4$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_4$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 177); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 155); ZEPHIR_MM_RESTORE(); return; } @@ -484,13 +421,13 @@ PHP_METHOD(Tensor_Vector, poisson) ZEPHIR_INIT_VAR(&_5$$4); object_init_ex(&_5$$4, tensor_exceptions_invalidargumentexception_ce); ZVAL_DOUBLE(&_6$$4, lambda); - ZEPHIR_CALL_FUNCTION(&_7$$4, "strval", &_3, 4, &_6$$4); + ZEPHIR_CALL_FUNCTION(&_7$$4, "strval", &_3, 3, &_6$$4); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_8$$4); ZEPHIR_CONCAT_SSVS(&_8$$4, "Lambda must be", " greater than or equal to 0, ", &_7$$4, " given."); - ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 3, &_8$$4); + ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_8$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/vector.zep", 182); + zephir_throw_exception_debug(&_5$$4, "tensor/vector.zep", 160); ZEPHIR_MM_RESTORE(); return; } @@ -504,10 +441,10 @@ PHP_METHOD(Tensor_Vector, poisson) ZEPHIR_INIT_VAR(&a); array_init(&a); ZVAL_DOUBLE(&_11, -lambda); - ZEPHIR_CALL_FUNCTION(&_12, "exp", NULL, 10, &_11); + ZEPHIR_CALL_FUNCTION(&_12, "exp", NULL, 9, &_11); zephir_check_call_status(); l = (zephir_get_doubleval(&_12)); - ZEPHIR_CALL_FUNCTION(&_13, "getrandmax", NULL, 6); + ZEPHIR_CALL_FUNCTION(&_13, "getrandmax", NULL, 5); zephir_check_call_status(); max = zephir_get_intval(&_13); while (1) { @@ -521,15 +458,16 @@ PHP_METHOD(Tensor_Vector, poisson) break; } k++; - ZEPHIR_CALL_FUNCTION(&_14$$7, "rand", &_15, 7); + ZEPHIR_CALL_FUNCTION(&_14$$7, "rand", &_15, 6); zephir_check_call_status(); p *= (zephir_safe_div_zval_long(&_14$$7, max)); } ZEPHIR_INIT_NVAR(&_16$$6); ZVAL_DOUBLE(&_16$$6, (k - 1.0)); - zephir_array_append(&a, &_16$$6, PH_SEPARATE, "tensor/vector.zep", 207); + zephir_array_append(&a, &_16$$6, PH_SEPARATE, "tensor/vector.zep", 185); } - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &a); + ZVAL_BOOL(&_11, 0); + ZEPHIR_RETURN_CALL_STATIC("fromArray", NULL, 0, &a, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -546,7 +484,7 @@ PHP_METHOD(Tensor_Vector, uniform) zval a; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zephir_fcall_cache_entry *_8 = NULL; - zval *n_param = NULL, _0$$3, _1$$3, _2$$3, _3$$3, _4, _5$$4, _6$$4, _7$$4, _9$$4; + zval *n_param = NULL, _0$$3, _1$$3, _2$$3, _3$$3, _4, _10, _5$$4, _6$$4, _7$$4, _9$$4; zend_long n, ZEPHIR_LAST_CALL_STATUS, max; ZVAL_UNDEF(&_0$$3); @@ -554,6 +492,7 @@ PHP_METHOD(Tensor_Vector, uniform) ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_10); ZVAL_UNDEF(&_5$$4); ZVAL_UNDEF(&_6$$4); ZVAL_UNDEF(&_7$$4); @@ -569,19 +508,19 @@ PHP_METHOD(Tensor_Vector, uniform) ZEPHIR_INIT_VAR(&_0$$3); object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_1$$3, n); - ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 4, &_1$$3); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 3, &_1$$3); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3$$3); ZEPHIR_CONCAT_SSVS(&_3$$3, "N must be", " greater than 0, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 3, &_3$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 224); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 202); ZEPHIR_MM_RESTORE(); return; } ZEPHIR_INIT_VAR(&a); array_init(&a); - ZEPHIR_CALL_FUNCTION(&_4, "getrandmax", NULL, 6); + ZEPHIR_CALL_FUNCTION(&_4, "getrandmax", NULL, 5); zephir_check_call_status(); max = zephir_get_intval(&_4); while (1) { @@ -590,13 +529,14 @@ PHP_METHOD(Tensor_Vector, uniform) } ZVAL_LONG(&_5$$4, -max); ZVAL_LONG(&_6$$4, max); - ZEPHIR_CALL_FUNCTION(&_7$$4, "rand", &_8, 7, &_5$$4, &_6$$4); + ZEPHIR_CALL_FUNCTION(&_7$$4, "rand", &_8, 6, &_5$$4, &_6$$4); zephir_check_call_status(); ZEPHIR_INIT_NVAR(&_9$$4); ZVAL_DOUBLE(&_9$$4, zephir_safe_div_zval_long(&_7$$4, max)); - zephir_array_append(&a, &_9$$4, PH_SEPARATE, "tensor/vector.zep", 232); + zephir_array_append(&a, &_9$$4, PH_SEPARATE, "tensor/vector.zep", 210); } - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &a); + ZVAL_BOOL(&_10, 0); + ZEPHIR_RETURN_CALL_STATIC("fromArray", NULL, 0, &a, &_10); zephir_check_call_status(); RETURN_MM(); } @@ -639,9 +579,10 @@ PHP_METHOD(Tensor_Vector, range) ZVAL_DOUBLE(&_0, start); ZVAL_DOUBLE(&_1, end); ZVAL_DOUBLE(&_2, interval); - ZEPHIR_CALL_FUNCTION(&_3, "range", NULL, 11, &_0, &_1, &_2); + ZEPHIR_CALL_FUNCTION(&_3, "range", NULL, 10, &_0, &_1, &_2); zephir_check_call_status(); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_3); + ZVAL_BOOL(&_0, 0); + ZEPHIR_RETURN_CALL_STATIC("fromArray", NULL, 0, &_3, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -685,26 +626,26 @@ PHP_METHOD(Tensor_Vector, linspace) min = zephir_get_doubleval(min_param); max = zephir_get_doubleval(max_param); if (UNEXPECTED(min > max)) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_invalidargumentexception_ce, "Minimum must be less than maximum.", "tensor/vector.zep", 263); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_invalidargumentexception_ce, "Minimum must be less than maximum.", "tensor/vector.zep", 241); return; } if (UNEXPECTED(n < 2)) { ZEPHIR_INIT_VAR(&_0$$4); object_init_ex(&_0$$4, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_1$$4, n); - ZEPHIR_CALL_FUNCTION(&_2$$4, "strval", NULL, 4, &_1$$4); + ZEPHIR_CALL_FUNCTION(&_2$$4, "strval", NULL, 3, &_1$$4); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3$$4); ZEPHIR_CONCAT_SSVS(&_3$$4, "Number of elements", " must be greater than 1, ", &_2$$4, " given."); - ZEPHIR_CALL_METHOD(NULL, &_0$$4, "__construct", NULL, 3, &_3$$4); + ZEPHIR_CALL_METHOD(NULL, &_0$$4, "__construct", NULL, 2, &_3$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$4, "tensor/vector.zep", 268); + zephir_throw_exception_debug(&_0$$4, "tensor/vector.zep", 246); ZEPHIR_MM_RESTORE(); return; } k = (n - 1); ZVAL_DOUBLE(&_4, (max - min)); - ZEPHIR_CALL_FUNCTION(&_5, "abs", NULL, 12, &_4); + ZEPHIR_CALL_FUNCTION(&_5, "abs", NULL, 11, &_4); zephir_check_call_status(); interval = (zephir_safe_div_zval_long(&_5, k)); ZEPHIR_INIT_VAR(&a); @@ -717,53 +658,50 @@ PHP_METHOD(Tensor_Vector, linspace) break; } ZEPHIR_MAKE_REF(&a); - ZEPHIR_CALL_FUNCTION(&_7$$5, "end", &_8, 13, &a); + ZEPHIR_CALL_FUNCTION(&_7$$5, "end", &_8, 12, &a); ZEPHIR_UNREF(&a); zephir_check_call_status(); ZEPHIR_INIT_NVAR(&_9$$5); ZVAL_DOUBLE(&_9$$5, (zephir_get_numberval(&_7$$5) + interval)); - zephir_array_append(&a, &_9$$5, PH_SEPARATE, "tensor/vector.zep", 278); + zephir_array_append(&a, &_9$$5, PH_SEPARATE, "tensor/vector.zep", 256); } ZEPHIR_INIT_NVAR(&_6); ZVAL_DOUBLE(&_6, max); - zephir_array_append(&a, &_6, PH_SEPARATE, "tensor/vector.zep", 281); - ZEPHIR_RETURN_CALL_SELF("quick", NULL, 0, &a); + zephir_array_append(&a, &_6, PH_SEPARATE, "tensor/vector.zep", 259); + ZVAL_BOOL(&_4, 0); + ZEPHIR_RETURN_CALL_SELF("fromArray", NULL, 0, &a, &_4); zephir_check_call_status(); RETURN_MM(); } /** - * @param float[] a + * Build a new vector from a flat PHP array of numeric elements. + * + * @param array a * @param bool validate + * @throws \Tensor\Exceptions\InvalidArgumentException + * @return self */ -PHP_METHOD(Tensor_Vector, __construct) +PHP_METHOD(Tensor_Vector, fromArray) { + zval _4$$5, _9$$7; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zephir_fcall_cache_entry *_3 = NULL; + zephir_fcall_cache_entry *_5 = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zend_bool validate, _5$$3; - zval *a_param = NULL, *validate_param = NULL, valueA, _8, *_0$$3, _4$$3, _1$$4, _2$$4, _6$$5, _7$$5; - zval a, b$$3; - zval *this_ptr = getThis(); + zend_bool validate, _7$$3; + zval *a_param = NULL, *validate_param = NULL, buffer, valueA, _0$$3, *_2$$3, _6$$3, _3$$5, _8$$7; + zval a, _1$$3; ZVAL_UNDEF(&a); - ZVAL_UNDEF(&b$$3); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&buffer); ZVAL_UNDEF(&valueA); - ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_1$$4); - ZVAL_UNDEF(&_2$$4); - ZVAL_UNDEF(&_6$$5); - ZVAL_UNDEF(&_7$$5); - static zend_string *_zephir_prop_0 = NULL; - static zend_string *_zephir_prop_1 = NULL; - if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); - } - if (UNEXPECTED(!_zephir_prop_1)) { - _zephir_prop_1 = zend_string_init("n", 1, 1); - } - + ZVAL_UNDEF(&_0$$3); + ZVAL_UNDEF(&_6$$3); + ZVAL_UNDEF(&_3$$5); + ZVAL_UNDEF(&_8$$7); + ZVAL_UNDEF(&_4$$5); + ZVAL_UNDEF(&_9$$7); ZEND_PARSE_PARAMETERS_START(1, 2) ZEPHIR_Z_PARAM_ARRAY(a, a_param) Z_PARAM_OPTIONAL @@ -777,63 +715,104 @@ PHP_METHOD(Tensor_Vector, __construct) validate = 1; } else { } - if (validate) { - ZEPHIR_INIT_VAR(&b$$3); - array_init(&b$$3); - zephir_is_iterable(&a, 0, "tensor/vector.zep", 301); - if (Z_TYPE_P(&a) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&a), _0$$3) + if (UNEXPECTED(validate)) { + ZEPHIR_CPY_WRT(&_0$$3, &a); + zephir_get_arrval(&_1$$3, &_0$$3); + zephir_is_iterable(&_1$$3, 0, "tensor/vector.zep", 283); + if (Z_TYPE_P(&_1$$3) == IS_ARRAY) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&_1$$3), _2$$3) { ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _0$$3); - ZEPHIR_INIT_NVAR(&_1$$4); - ZEPHIR_CALL_FUNCTION(&_2$$4, "is_float", &_3, 2, &valueA); - zephir_check_call_status(); - if (zephir_is_true(&_2$$4)) { - ZEPHIR_CPY_WRT(&_1$$4, &valueA); - } else { - ZEPHIR_INIT_NVAR(&_1$$4); - ZVAL_DOUBLE(&_1$$4, zephir_get_doubleval(&valueA)); + ZVAL_COPY(&valueA, _2$$3); + if (UNEXPECTED(Z_TYPE_P(&valueA) == IS_ARRAY)) { + ZEPHIR_INIT_NVAR(&_3$$5); + object_init_ex(&_3$$5, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_NVAR(&_4$$5); + ZEPHIR_CONCAT_SS(&_4$$5, "Vector requires a", " flat array of numeric elements."); + ZEPHIR_CALL_METHOD(NULL, &_3$$5, "__construct", &_5, 2, &_4$$5); + zephir_check_call_status(); + zephir_throw_exception_debug(&_3$$5, "tensor/vector.zep", 280); + ZEPHIR_MM_RESTORE(); + return; } - zephir_array_append(&b$$3, &_1$$4, PH_SEPARATE, "tensor/vector.zep", 298); } ZEND_HASH_FOREACH_END(); } else { - ZEPHIR_CALL_METHOD(NULL, &a, "rewind", NULL, 0); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "rewind", NULL, 0); zephir_check_call_status(); - _5$$3 = 1; + _7$$3 = 1; while (1) { - if (_5$$3) { - _5$$3 = 0; + if (_7$$3) { + _7$$3 = 0; } else { - ZEPHIR_CALL_METHOD(NULL, &a, "next", NULL, 0); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "next", NULL, 0); zephir_check_call_status(); } - ZEPHIR_CALL_METHOD(&_4$$3, &a, "valid", NULL, 0); + ZEPHIR_CALL_METHOD(&_6$$3, &_1$$3, "valid", NULL, 0); zephir_check_call_status(); - if (!zend_is_true(&_4$$3)) { + if (!zend_is_true(&_6$$3)) { break; } - ZEPHIR_CALL_METHOD(&valueA, &a, "current", NULL, 0); + ZEPHIR_CALL_METHOD(&valueA, &_1$$3, "current", NULL, 0); zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_6$$5); - ZEPHIR_CALL_FUNCTION(&_7$$5, "is_float", &_3, 2, &valueA); - zephir_check_call_status(); - if (zephir_is_true(&_7$$5)) { - ZEPHIR_CPY_WRT(&_6$$5, &valueA); - } else { - ZEPHIR_INIT_NVAR(&_6$$5); - ZVAL_DOUBLE(&_6$$5, zephir_get_doubleval(&valueA)); + if (UNEXPECTED(Z_TYPE_P(&valueA) == IS_ARRAY)) { + ZEPHIR_INIT_NVAR(&_8$$7); + object_init_ex(&_8$$7, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_NVAR(&_9$$7); + ZEPHIR_CONCAT_SS(&_9$$7, "Vector requires a", " flat array of numeric elements."); + ZEPHIR_CALL_METHOD(NULL, &_8$$7, "__construct", &_5, 2, &_9$$7); + zephir_check_call_status(); + zephir_throw_exception_debug(&_8$$7, "tensor/vector.zep", 280); + ZEPHIR_MM_RESTORE(); + return; } - zephir_array_append(&b$$3, &_6$$5, PH_SEPARATE, "tensor/vector.zep", 298); } } ZEPHIR_INIT_NVAR(&valueA); - ZEPHIR_CPY_WRT(&a, &b$$3); } - zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 1, &a); - ZVAL_UNDEF(&_8); - ZVAL_LONG(&_8, zephir_fast_count_int(&a)); - zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 2, &_8); + ZEPHIR_INIT_VAR(&buffer); + tensor_buffer_from_array(&buffer, &a); + object_init_ex(return_value, zend_get_called_scope(execute_data)); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &buffer); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Construct a new vector from a TensorBuffer holding its elements. + * + * @param \Tensor\TensorBuffer a + * @throws \Tensor\Exceptions\InvalidArgumentException + */ +PHP_METHOD(Tensor_Vector, __construct) +{ + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *a, a_sub, _0, _1; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&a_sub); + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("n", 1, 1); + } + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_OBJECT_OF_CLASS(a, zephir_get_internal_ce(SL("tensor\\tensorbuffer"))) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 1, 0, &a); + zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 1, a); + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_1, &_0, "count", NULL, 0); + zephir_check_call_status(); + zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 2, &_1); ZEPHIR_MM_RESTORE(); } @@ -929,9 +908,35 @@ PHP_METHOD(Tensor_Vector, n) * @return list */ PHP_METHOD(Tensor_Vector, asArray) +{ + zval _0; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + ZEPHIR_RETURN_CALL_METHOD(&_0, "toArray", NULL, 0); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return the underlying TensorBuffer of the vector. + * + * @return \Tensor\TensorBuffer + */ +PHP_METHOD(Tensor_Vector, asTensorBuffer) { - RETURN_MEMBER_TYPED(getThis(), "a", IS_ARRAY); + RETURN_MEMBER(getThis(), "a"); } /** @@ -941,27 +946,30 @@ PHP_METHOD(Tensor_Vector, asArray) */ PHP_METHOD(Tensor_Vector, asRowMatrix) { - zval _1; - zval _0; + zval _0, _1, _2; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_INIT_VAR(&_0); - zephir_create_array(&_0, 1, 0); - zephir_memory_observe(&_1); - zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC); - zephir_array_fast_append(&_0, &_1); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &_0); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_1, 2, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_2, 1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_2, &_1); zephir_check_call_status(); RETURN_MM(); } @@ -973,74 +981,30 @@ PHP_METHOD(Tensor_Vector, asRowMatrix) */ PHP_METHOD(Tensor_Vector, asColumnMatrix) { - zend_bool _6; - zval b, _4$$3, _7$$4; - zval valueA, _0, *_1, _2, *_3, _5; + zval _0, _1, _2; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); - ZVAL_UNDEF(&valueA); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_5); - ZVAL_UNDEF(&b); - ZVAL_UNDEF(&_4$$3); - ZVAL_UNDEF(&_7$$4); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_INIT_VAR(&b); - array_init(&b); + object_init_ex(return_value, tensor_matrix_ce); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/vector.zep", 393); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _3); - ZEPHIR_INIT_NVAR(&_4$$3); - zephir_create_array(&_4$$3, 1, 0); - zephir_array_fast_append(&_4$$3, &valueA); - zephir_array_append(&b, &_4$$3, PH_SEPARATE, "tensor/vector.zep", 390); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _6 = 1; - while (1) { - if (_6) { - _6 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_5, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_5)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _1, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_7$$4); - zephir_create_array(&_7$$4, 1, 0); - zephir_array_fast_append(&_7$$4, &valueA); - zephir_array_append(&b, &_7$$4, PH_SEPARATE, "tensor/vector.zep", 390); - } - } - ZEPHIR_INIT_NVAR(&valueA); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &b); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_1, 2, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_2, 1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_0, &_1, &_2); zephir_check_call_status(); RETURN_MM(); } @@ -1056,23 +1020,21 @@ PHP_METHOD(Tensor_Vector, asColumnMatrix) PHP_METHOD(Tensor_Vector, reshape) { zval _2$$3; - zval b, rowB; zend_bool _0; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zval *m_param = NULL, *n_param = NULL, _3, _1$$3, _4$$4, _5$$4, _6$$4, _7$$4, _8$$6, _9$$6; - zend_long m, n, ZEPHIR_LAST_CALL_STATUS, nHat, i; + zval *m_param = NULL, *n_param = NULL, _3, _8, _9, _10, _1$$3, _4$$4, _5$$4, _6$$4, _7$$4; + zend_long m, n, ZEPHIR_LAST_CALL_STATUS, nHat; zval *this_ptr = getThis(); ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); + ZVAL_UNDEF(&_10); ZVAL_UNDEF(&_1$$3); ZVAL_UNDEF(&_4$$4); ZVAL_UNDEF(&_5$$4); ZVAL_UNDEF(&_6$$4); ZVAL_UNDEF(&_7$$4); - ZVAL_UNDEF(&_8$$6); - ZVAL_UNDEF(&_9$$6); - ZVAL_UNDEF(&b); - ZVAL_UNDEF(&rowB); ZVAL_UNDEF(&_2$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; @@ -1099,9 +1061,9 @@ PHP_METHOD(Tensor_Vector, reshape) object_init_ex(&_1$$3, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_2$$3); ZEPHIR_CONCAT_SS(&_2$$3, "The number of rows", " and/or columns cannot be less than 0."); - ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 3, &_2$$3); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 408); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 404); ZEPHIR_MM_RESTORE(); return; } @@ -1111,41 +1073,22 @@ PHP_METHOD(Tensor_Vector, reshape) ZEPHIR_INIT_VAR(&_4$$4); object_init_ex(&_4$$4, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_5$$4, nHat); - ZEPHIR_CALL_FUNCTION(&_6$$4, "strval", NULL, 4, &_5$$4); + ZEPHIR_CALL_FUNCTION(&_6$$4, "strval", NULL, 3, &_5$$4); zephir_check_call_status(); zephir_read_property_cached(&_5$$4, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); ZEPHIR_INIT_VAR(&_7$$4); ZEPHIR_CONCAT_VSSVS(&_7$$4, &_6$$4, " elements", " are needed but vector only has ", &_5$$4, "."); - ZEPHIR_CALL_METHOD(NULL, &_4$$4, "__construct", NULL, 3, &_7$$4); + ZEPHIR_CALL_METHOD(NULL, &_4$$4, "__construct", NULL, 2, &_7$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_4$$4, "tensor/vector.zep", 415); + zephir_throw_exception_debug(&_4$$4, "tensor/vector.zep", 411); ZEPHIR_MM_RESTORE(); return; } - i = 0; - ZEPHIR_INIT_VAR(&b); - array_init(&b); - ZEPHIR_INIT_VAR(&rowB); - array_init(&rowB); - while (1) { - if (!(zephir_fast_count_int(&b) < m)) { - break; - } - ZEPHIR_INIT_NVAR(&rowB); - array_init(&rowB); - while (1) { - if (!(zephir_fast_count_int(&rowB) < n)) { - break; - } - zephir_read_property_cached(&_8$$6, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_OBS_NVAR(&_9$$6); - zephir_array_fetch_long(&_9$$6, &_8$$6, i, PH_NOISY, "tensor/vector.zep", 427); - zephir_array_append(&rowB, &_9$$6, PH_SEPARATE, "tensor/vector.zep", 427); - i++; - } - zephir_array_append(&b, &rowB, PH_SEPARATE, "tensor/vector.zep", 432); - } - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &b); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_9, m); + ZVAL_LONG(&_10, n); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &_8, &_9, &_10); zephir_check_call_status(); RETURN_MM(); } @@ -1170,8 +1113,9 @@ PHP_METHOD(Tensor_Vector, transpose) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, tensor_columnvector_ce); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_columnvector_ce, "quick", NULL, 0, &_0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -1188,12 +1132,14 @@ PHP_METHOD(Tensor_Vector, map) { zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *callback, callback_sub, _0, _1; + zval *callback, callback_sub, _0, _1, _2, _3; zval *this_ptr = getThis(); ZVAL_UNDEF(&callback_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); static zend_string *_zephir_prop_0 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); @@ -1206,9 +1152,12 @@ PHP_METHOD(Tensor_Vector, map) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &callback); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_FUNCTION(&_1, "array_map", NULL, 14, callback, &_0); + ZEPHIR_CALL_METHOD(&_1, &_0, "toArray", NULL, 0); zephir_check_call_status(); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_1); + ZEPHIR_CALL_FUNCTION(&_2, "array_map", NULL, 15, callback, &_1); + zephir_check_call_status(); + ZVAL_BOOL(&_3, 0); + ZEPHIR_RETURN_CALL_STATIC("fromArray", NULL, 0, &_2, &_3); zephir_check_call_status(); RETURN_MM(); } @@ -1227,12 +1176,13 @@ PHP_METHOD(Tensor_Vector, reduce) zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; double initial; - zval *callback, callback_sub, *initial_param = NULL, _0, _1; + zval *callback, callback_sub, *initial_param = NULL, _0, _1, _2; zval *this_ptr = getThis(); ZVAL_UNDEF(&callback_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); static zend_string *_zephir_prop_0 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); @@ -1252,8 +1202,10 @@ PHP_METHOD(Tensor_Vector, reduce) initial = zephir_get_doubleval(initial_param); } zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - ZVAL_DOUBLE(&_1, initial); - ZEPHIR_RETURN_CALL_FUNCTION("array_reduce", NULL, 15, &_0, callback, &_1); + ZEPHIR_CALL_METHOD(&_1, &_0, "toArray", NULL, 0); + zephir_check_call_status(); + ZVAL_DOUBLE(&_2, initial); + ZEPHIR_RETURN_CALL_FUNCTION("array_reduce", NULL, 16, &_1, callback, &_2); zephir_check_call_status(); RETURN_MM(); } @@ -1313,15 +1265,14 @@ PHP_METHOD(Tensor_Vector, dot) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " elements but vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 487); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 466); ZEPHIR_MM_RESTORE(); return; } zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_9, b, "asarray", NULL, 0); - zephir_check_call_status(); + zephir_read_property_cached(&_9, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); tensor_dot(return_value, &_8, &_9); RETURN_MM(); } @@ -1384,9 +1335,9 @@ PHP_METHOD(Tensor_Vector, convolve) object_init_ex(&_2$$3, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3$$3); ZEPHIR_CONCAT_SS(&_3$$3, "Vector B cannot be", " larger than Vector A."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_3$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 505); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 484); ZEPHIR_MM_RESTORE(); return; } @@ -1394,23 +1345,23 @@ PHP_METHOD(Tensor_Vector, convolve) ZEPHIR_INIT_VAR(&_4$$4); object_init_ex(&_4$$4, tensor_exceptions_invalidargumentexception_ce); ZVAL_LONG(&_5$$4, stride); - ZEPHIR_CALL_FUNCTION(&_6$$4, "strval", NULL, 4, &_5$$4); + ZEPHIR_CALL_FUNCTION(&_6$$4, "strval", NULL, 3, &_5$$4); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_7$$4); ZEPHIR_CONCAT_SSVS(&_7$$4, "Stride cannot be", " less than 1, ", &_6$$4, " given."); - ZEPHIR_CALL_METHOD(NULL, &_4$$4, "__construct", NULL, 3, &_7$$4); + ZEPHIR_CALL_METHOD(NULL, &_4$$4, "__construct", NULL, 2, &_7$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_4$$4, "tensor/vector.zep", 510); + zephir_throw_exception_debug(&_4$$4, "tensor/vector.zep", 489); ZEPHIR_MM_RESTORE(); return; } + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_8); zephir_read_property_cached(&_9, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_10, b, "asarray", NULL, 0); - zephir_check_call_status(); + zephir_read_property_cached(&_10, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); ZVAL_LONG(&_11, stride); tensor_convolve_1d(&_8, &_9, &_10, &_11); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -1436,7 +1387,7 @@ PHP_METHOD(Tensor_Vector, matmul) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "asrowmatrix", NULL, 0); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "asRowMatrix", NULL, 0); zephir_check_call_status(); ZEPHIR_RETURN_CALL_METHOD(&_0, "matmul", NULL, 0, b); zephir_check_call_status(); @@ -1476,33 +1427,27 @@ PHP_METHOD(Tensor_Vector, inner) */ PHP_METHOD(Tensor_Vector, outer) { - zend_string *_8$$3, *_14$$5; - zend_ulong _7$$3, _13$$5; - zend_bool _11; - zval bHat, c, rowC, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, j, valueA, valueB, _0, _2, *_3, _4, *_5, _10, *_6$$3, _9$$4, *_12$$5, _15$$6; + zval *b, b_sub, result, _0, _1, _2, _3, _4, _5; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); - ZVAL_UNDEF(&j); - ZVAL_UNDEF(&valueA); - ZVAL_UNDEF(&valueB); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); ZVAL_UNDEF(&_4); - ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_9$$4); - ZVAL_UNDEF(&_15$$6); - ZVAL_UNDEF(&bHat); - ZVAL_UNDEF(&c); - ZVAL_UNDEF(&rowC); - ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_5); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("n", 1, 1); + } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(b, zephir_get_internal_ce(SL("tensor\\vector"))) @@ -1510,93 +1455,19 @@ PHP_METHOD(Tensor_Vector, outer) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b); - ZEPHIR_INIT_VAR(&bHat); - array_init(&bHat); - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_INIT_VAR(&rowC); - array_init(&rowC); - ZEPHIR_CALL_METHOD(&_0, b, "asarray", NULL, 0); - zephir_check_call_status(); - zephir_get_arrval(&_1, &_0); - ZEPHIR_CPY_WRT(&bHat, &_1); - zephir_read_property_cached(&_2, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_2) == IS_STRING) { - ZEPHIR_INIT_VAR(&_4); - zephir_string_to_char_array(&_4, &_2); - _3 = &_4; - } else { - _3 = &_2; - } - zephir_is_iterable(_3, 0, "tensor/vector.zep", 564); - if (Z_TYPE_P(_3) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_3), _5) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _5); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - zephir_is_iterable(&bHat, 0, "tensor/vector.zep", 561); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(&bHat), _7$$3, _8$$3, _6$$3) - { - ZEPHIR_INIT_NVAR(&j); - if (_8$$3 != NULL) { - ZVAL_STR_COPY(&j, _8$$3); - } else { - ZVAL_LONG(&j, _7$$3); - } - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _6$$3); - ZEPHIR_INIT_NVAR(&_9$$4); - mul_function(&_9$$4, &valueA, &valueB); - zephir_array_append(&rowC, &_9$$4, PH_SEPARATE, "tensor/vector.zep", 558); - } ZEND_HASH_FOREACH_END(); - ZEPHIR_INIT_NVAR(&valueB); - ZEPHIR_INIT_NVAR(&j); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/vector.zep", 561); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _3, "rewind", NULL, 0); - zephir_check_call_status(); - _11 = 1; - while (1) { - if (_11) { - _11 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _3, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_10, _3, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_10)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _3, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&rowC); - array_init(&rowC); - zephir_is_iterable(&bHat, 0, "tensor/vector.zep", 561); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(&bHat), _13$$5, _14$$5, _12$$5) - { - ZEPHIR_INIT_NVAR(&j); - if (_14$$5 != NULL) { - ZVAL_STR_COPY(&j, _14$$5); - } else { - ZVAL_LONG(&j, _13$$5); - } - ZEPHIR_INIT_NVAR(&valueB); - ZVAL_COPY(&valueB, _12$$5); - ZEPHIR_INIT_NVAR(&_15$$6); - mul_function(&_15$$6, &valueA, &valueB); - zephir_array_append(&rowC, &_15$$6, PH_SEPARATE, "tensor/vector.zep", 558); - } ZEND_HASH_FOREACH_END(); - ZEPHIR_INIT_NVAR(&valueB); - ZEPHIR_INIT_NVAR(&j); - zephir_array_append(&c, &rowC, PH_SEPARATE, "tensor/vector.zep", 561); - } - } - ZEPHIR_INIT_NVAR(&valueA); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_1, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 2, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_3, b, "n", NULL, 0); + zephir_check_call_status(); + tensor_outer(&result, &_0, &_1, &_2, &_3); + object_init_ex(return_value, tensor_matrix_ce); + zephir_read_property_cached(&_4, this_ptr, _zephir_prop_1, 2, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(&_5, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_4, &_5); zephir_check_call_status(); RETURN_MM(); } @@ -1687,25 +1558,25 @@ PHP_METHOD(Tensor_Vector, pNorm) ZEPHIR_INIT_VAR(&_0$$3); object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); ZVAL_DOUBLE(&_1$$3, p); - ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 4, &_1$$3); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 3, &_1$$3); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3$$3); ZEPHIR_CONCAT_SSVS(&_3$$3, "P must be greater", " than 0, ", &_2$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 3, &_3$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 598); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 561); ZEPHIR_MM_RESTORE(); return; } ZEPHIR_CALL_METHOD(&_4, this_ptr, "abs", NULL, 0); zephir_check_call_status(); ZVAL_DOUBLE(&_6, p); - ZEPHIR_CALL_METHOD(&_5, &_4, "powscalar", NULL, 0, &_6); + ZEPHIR_CALL_METHOD(&_5, &_4, "powScalar", NULL, 0, &_6); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&_7, &_5, "sum", NULL, 0); zephir_check_call_status(); ZVAL_DOUBLE(&_6, zephir_safe_div_double_double(1.0, p)); - ZEPHIR_RETURN_CALL_FUNCTION("pow", NULL, 16, &_7, &_6); + ZEPHIR_RETURN_CALL_FUNCTION("pow", NULL, 17, &_7, &_6); zephir_check_call_status(); RETURN_MM(); } @@ -1772,11 +1643,11 @@ PHP_METHOD(Tensor_Vector, multiply) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_1; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplymatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplyMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplyvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplyVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -1784,7 +1655,7 @@ PHP_METHOD(Tensor_Vector, multiply) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplyscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplyScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -1793,9 +1664,9 @@ PHP_METHOD(Tensor_Vector, multiply) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot multiply", " vector by the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/vector.zep", 641); + zephir_throw_exception_debug(&_2, "tensor/vector.zep", 604); ZEPHIR_MM_RESTORE(); return; } @@ -1838,11 +1709,11 @@ PHP_METHOD(Tensor_Vector, divide) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_1; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "dividematrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "divideMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "dividevector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "divideVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -1850,7 +1721,7 @@ PHP_METHOD(Tensor_Vector, divide) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "dividescalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "divideScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -1859,9 +1730,9 @@ PHP_METHOD(Tensor_Vector, divide) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot divide", " vector by the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/vector.zep", 671); + zephir_throw_exception_debug(&_2, "tensor/vector.zep", 634); ZEPHIR_MM_RESTORE(); return; } @@ -1905,11 +1776,11 @@ PHP_METHOD(Tensor_Vector, add) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_1; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "addmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "addMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "addvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "addVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -1917,7 +1788,7 @@ PHP_METHOD(Tensor_Vector, add) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "addscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "addScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -1926,9 +1797,9 @@ PHP_METHOD(Tensor_Vector, add) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot add", " vector by the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/vector.zep", 702); + zephir_throw_exception_debug(&_2, "tensor/vector.zep", 665); ZEPHIR_MM_RESTORE(); return; } @@ -1972,11 +1843,11 @@ PHP_METHOD(Tensor_Vector, subtract) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_1; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "subtractmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "subtractMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "subtractvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "subtractVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -1984,7 +1855,7 @@ PHP_METHOD(Tensor_Vector, subtract) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "subtractscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "subtractScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -1993,9 +1864,9 @@ PHP_METHOD(Tensor_Vector, subtract) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot subtract", " vector from the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/vector.zep", 733); + zephir_throw_exception_debug(&_2, "tensor/vector.zep", 696); ZEPHIR_MM_RESTORE(); return; } @@ -2039,11 +1910,11 @@ PHP_METHOD(Tensor_Vector, pow) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_1; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "powmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "powMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "powvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "powVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -2051,7 +1922,7 @@ PHP_METHOD(Tensor_Vector, pow) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "powscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "powScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -2060,9 +1931,9 @@ PHP_METHOD(Tensor_Vector, pow) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot raise", " vector to the power of the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/vector.zep", 764); + zephir_throw_exception_debug(&_2, "tensor/vector.zep", 727); ZEPHIR_MM_RESTORE(); return; } @@ -2106,11 +1977,11 @@ PHP_METHOD(Tensor_Vector, mod) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_1; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "modmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "modMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "modvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "modVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -2118,7 +1989,7 @@ PHP_METHOD(Tensor_Vector, mod) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "modscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "modScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -2127,9 +1998,9 @@ PHP_METHOD(Tensor_Vector, mod) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot mod", " vector with the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/vector.zep", 795); + zephir_throw_exception_debug(&_2, "tensor/vector.zep", 758); ZEPHIR_MM_RESTORE(); return; } @@ -2173,11 +2044,11 @@ PHP_METHOD(Tensor_Vector, equal) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_1; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "equalmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "equalMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "equalvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "equalVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -2185,7 +2056,7 @@ PHP_METHOD(Tensor_Vector, equal) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "equalscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "equalScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -2194,9 +2065,9 @@ PHP_METHOD(Tensor_Vector, equal) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot compare", " vector to the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/vector.zep", 826); + zephir_throw_exception_debug(&_2, "tensor/vector.zep", 789); ZEPHIR_MM_RESTORE(); return; } @@ -2240,11 +2111,11 @@ PHP_METHOD(Tensor_Vector, notEqual) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_1; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "notequalmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "notEqualMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "notequalvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "notEqualVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -2252,7 +2123,7 @@ PHP_METHOD(Tensor_Vector, notEqual) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "notequalscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "notEqualScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -2261,9 +2132,9 @@ PHP_METHOD(Tensor_Vector, notEqual) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot compare", " vector to the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/vector.zep", 857); + zephir_throw_exception_debug(&_2, "tensor/vector.zep", 820); ZEPHIR_MM_RESTORE(); return; } @@ -2307,11 +2178,11 @@ PHP_METHOD(Tensor_Vector, greater) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_1; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greatermatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greatervector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -2319,7 +2190,7 @@ PHP_METHOD(Tensor_Vector, greater) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -2328,9 +2199,9 @@ PHP_METHOD(Tensor_Vector, greater) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot compare", " vector to the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/vector.zep", 888); + zephir_throw_exception_debug(&_2, "tensor/vector.zep", 851); ZEPHIR_MM_RESTORE(); return; } @@ -2374,11 +2245,11 @@ PHP_METHOD(Tensor_Vector, greaterEqual) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_1; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterequalmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterEqualMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterequalvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterEqualVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -2386,7 +2257,7 @@ PHP_METHOD(Tensor_Vector, greaterEqual) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterequalscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "greaterEqualScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -2395,9 +2266,9 @@ PHP_METHOD(Tensor_Vector, greaterEqual) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot compare", " vector to the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/vector.zep", 919); + zephir_throw_exception_debug(&_2, "tensor/vector.zep", 882); ZEPHIR_MM_RESTORE(); return; } @@ -2441,11 +2312,11 @@ PHP_METHOD(Tensor_Vector, less) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_1; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -2453,7 +2324,7 @@ PHP_METHOD(Tensor_Vector, less) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -2462,9 +2333,9 @@ PHP_METHOD(Tensor_Vector, less) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot compare", " vector to the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/vector.zep", 950); + zephir_throw_exception_debug(&_2, "tensor/vector.zep", 913); ZEPHIR_MM_RESTORE(); return; } @@ -2508,11 +2379,11 @@ PHP_METHOD(Tensor_Vector, lessEqual) if (_1$$3 == zephir_instance_of_ev(b, tensor_vector_ce)) { goto zephir_switch_1_clause_1; } goto zephir_switch_1_end; zephir_switch_1_clause_0: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessequalmatrix", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessEqualMatrix", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_clause_1: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessequalvector", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessEqualVector", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_1_end: ; @@ -2520,7 +2391,7 @@ PHP_METHOD(Tensor_Vector, lessEqual) goto zephir_switch_0_end; zephir_switch_0_clause_1: ; zephir_switch_0_clause_2: ; - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessequalscalar", NULL, 0, b); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "lessEqualScalar", NULL, 0, b); zephir_check_call_status(); RETURN_MM(); zephir_switch_0_end: ; @@ -2529,9 +2400,9 @@ PHP_METHOD(Tensor_Vector, lessEqual) object_init_ex(&_2, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_3); ZEPHIR_CONCAT_SS(&_3, "Cannot compare", " vector to the given input."); - ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 3, &_3); + ZEPHIR_CALL_METHOD(NULL, &_2, "__construct", NULL, 2, &_3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2, "tensor/vector.zep", 981); + zephir_throw_exception_debug(&_2, "tensor/vector.zep", 944); ZEPHIR_MM_RESTORE(); return; } @@ -2560,7 +2431,7 @@ PHP_METHOD(Tensor_Vector, reciprocal) zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); ZEPHIR_CALL_STATIC(&_0, "ones", NULL, 0, &_1); zephir_check_call_status(); - ZEPHIR_RETURN_CALL_METHOD(&_0, "dividevector", NULL, 0, this_ptr); + ZEPHIR_RETURN_CALL_METHOD(&_0, "divideVector", NULL, 0, this_ptr); zephir_check_call_status(); RETURN_MM(); } @@ -2572,18 +2443,25 @@ PHP_METHOD(Tensor_Vector, reciprocal) */ PHP_METHOD(Tensor_Vector, abs) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "abs"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_abs(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -2601,7 +2479,7 @@ PHP_METHOD(Tensor_Vector, square) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplyvector", NULL, 0, this_ptr); + ZEPHIR_RETURN_CALL_METHOD(this_ptr, "multiplyVector", NULL, 0, this_ptr); zephir_check_call_status(); RETURN_MM(); } @@ -2613,18 +2491,25 @@ PHP_METHOD(Tensor_Vector, square) */ PHP_METHOD(Tensor_Vector, sqrt) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "sqrt"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_sqrt(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -2636,18 +2521,25 @@ PHP_METHOD(Tensor_Vector, sqrt) */ PHP_METHOD(Tensor_Vector, exp) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "exp"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_exp(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -2659,18 +2551,25 @@ PHP_METHOD(Tensor_Vector, exp) */ PHP_METHOD(Tensor_Vector, expm1) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "expm1"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_expm1(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -2683,25 +2582,21 @@ PHP_METHOD(Tensor_Vector, expm1) */ PHP_METHOD(Tensor_Vector, log) { - zend_bool _9; - zval b; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zephir_fcall_cache_entry *_7 = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *base_param = NULL, _0$$3, valueA, _1, *_2, _3, *_4, _8, _5$$4, _6$$4, _10$$5, _11$$5; + zval *base_param = NULL, _0$$3, _1$$3, _2$$3, _3$$3, _4$$4, _5$$4, _6, _7, _8; double base; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0$$3); - ZVAL_UNDEF(&valueA); - ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&_3); - ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); + ZVAL_UNDEF(&_3$$3); + ZVAL_UNDEF(&_4$$4); ZVAL_UNDEF(&_5$$4); - ZVAL_UNDEF(&_6$$4); - ZVAL_UNDEF(&_10$$5); - ZVAL_UNDEF(&_11$$5); - ZVAL_UNDEF(&b); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_8); static zend_string *_zephir_prop_0 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); @@ -2719,60 +2614,35 @@ PHP_METHOD(Tensor_Vector, log) } else { base = zephir_get_doubleval(base_param); } - if (base == 2.7182818284590452354) { + if (UNEXPECTED(base <= 0.0)) { ZEPHIR_INIT_VAR(&_0$$3); - ZVAL_STRING(&_0$$3, "log"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0$$3); + object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); + ZVAL_DOUBLE(&_1$$3, base); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 3, &_1$$3); zephir_check_call_status(); - RETURN_MM(); + ZEPHIR_INIT_VAR(&_3$$3); + ZEPHIR_CONCAT_SSVS(&_3$$3, "Log base must be greater", " than 0, ", &_2$$3, " given."); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1018); + ZEPHIR_MM_RESTORE(); + return; } - ZEPHIR_INIT_VAR(&b); - array_init(&b); - zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_1) == IS_STRING) { - ZEPHIR_INIT_VAR(&_3); - zephir_string_to_char_array(&_3, &_1); - _2 = &_3; - } else { - _2 = &_1; - } - zephir_is_iterable(_2, 0, "tensor/vector.zep", 1065); - if (Z_TYPE_P(_2) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_2), _4) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _4); - ZVAL_DOUBLE(&_5$$4, base); - ZEPHIR_CALL_FUNCTION(&_6$$4, "log", &_7, 8, &valueA, &_5$$4); - zephir_check_call_status(); - zephir_array_append(&b, &_6$$4, PH_SEPARATE, "tensor/vector.zep", 1062); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _2, "rewind", NULL, 0); + if (base == 2.7182818284590452354) { + object_init_ex(return_value, zend_get_called_scope(execute_data)); + ZEPHIR_INIT_VAR(&_4$$4); + zephir_read_property_cached(&_5$$4, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_log(&_4$$4, &_5$$4); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_4$$4); zephir_check_call_status(); - _9 = 1; - while (1) { - if (_9) { - _9 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _2, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_8, _2, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_8)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _2, "current", NULL, 0); - zephir_check_call_status(); - ZVAL_DOUBLE(&_10$$5, base); - ZEPHIR_CALL_FUNCTION(&_11$$5, "log", &_7, 8, &valueA, &_10$$5); - zephir_check_call_status(); - zephir_array_append(&b, &_11$$5, PH_SEPARATE, "tensor/vector.zep", 1062); - } + RETURN_MM(); } - ZEPHIR_INIT_NVAR(&valueA); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &b); + object_init_ex(return_value, zend_get_called_scope(execute_data)); + ZEPHIR_INIT_VAR(&_6); + zephir_read_property_cached(&_7, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + ZVAL_DOUBLE(&_8, base); + tensor_log_base(&_6, &_7, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_6); zephir_check_call_status(); RETURN_MM(); } @@ -2784,18 +2654,25 @@ PHP_METHOD(Tensor_Vector, log) */ PHP_METHOD(Tensor_Vector, log1p) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "log1p"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_log1p(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -2807,18 +2684,25 @@ PHP_METHOD(Tensor_Vector, log1p) */ PHP_METHOD(Tensor_Vector, sin) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "sin"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_sin(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -2830,18 +2714,25 @@ PHP_METHOD(Tensor_Vector, sin) */ PHP_METHOD(Tensor_Vector, asin) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "asin"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_asin(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -2853,18 +2744,25 @@ PHP_METHOD(Tensor_Vector, asin) */ PHP_METHOD(Tensor_Vector, cos) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "cos"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_cos(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -2876,18 +2774,25 @@ PHP_METHOD(Tensor_Vector, cos) */ PHP_METHOD(Tensor_Vector, acos) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "acos"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_acos(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -2899,18 +2804,25 @@ PHP_METHOD(Tensor_Vector, acos) */ PHP_METHOD(Tensor_Vector, tan) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "tan"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_tan(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -2922,18 +2834,25 @@ PHP_METHOD(Tensor_Vector, tan) */ PHP_METHOD(Tensor_Vector, atan) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "atan"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_atan(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -2945,18 +2864,25 @@ PHP_METHOD(Tensor_Vector, atan) */ PHP_METHOD(Tensor_Vector, rad2deg) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "rad2deg"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_rad2deg(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -2968,18 +2894,25 @@ PHP_METHOD(Tensor_Vector, rad2deg) */ PHP_METHOD(Tensor_Vector, deg2rad) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "deg2rad"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_deg2rad(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -2991,24 +2924,37 @@ PHP_METHOD(Tensor_Vector, deg2rad) */ PHP_METHOD(Tensor_Vector, sum) { - zval _0, _1; + zval result, _0, _1, _2, _3, _4; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_4); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_FUNCTION(&_1, "array_sum", NULL, 17, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_1, 2, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_2, 1); + tensor_reduce_sum(&result, &_0, &_2, &_1); + ZVAL_LONG(&_4, 0); + ZEPHIR_CALL_METHOD(&_3, &result, "get", NULL, 0, &_4); zephir_check_call_status(); - RETURN_MM_DOUBLE(zephir_get_doubleval(&_1)); + RETURN_MM_DOUBLE(zephir_get_doubleval(&_3)); } /** @@ -3018,24 +2964,37 @@ PHP_METHOD(Tensor_Vector, sum) */ PHP_METHOD(Tensor_Vector, product) { - zval _0, _1; + zval result, _0, _1, _2, _3, _4; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_4); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("n", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + ZEPHIR_INIT_VAR(&result); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_FUNCTION(&_1, "array_product", NULL, 18, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_1, 2, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_2, 1); + tensor_reduce_product(&result, &_0, &_2, &_1); + ZVAL_LONG(&_4, 0); + ZEPHIR_CALL_METHOD(&_3, &result, "get", NULL, 0, &_4); zephir_check_call_status(); - RETURN_MM_DOUBLE(zephir_get_doubleval(&_1)); + RETURN_MM_DOUBLE(zephir_get_doubleval(&_3)); } /** @@ -3045,24 +3004,53 @@ PHP_METHOD(Tensor_Vector, product) */ PHP_METHOD(Tensor_Vector, min) { - zval _0, _1; + zval _2$$3; + zval _0, result, _3, _4, _5, _6, _7, _1$$3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&result); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); + _zephir_prop_0 = zend_string_init("n", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("a", 1, 1); } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_FUNCTION(&_1, "min", NULL, 19, &_0); + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + if (UNEXPECTED(ZEPHIR_LT_LONG(&_0, 1))) { + ZEPHIR_INIT_VAR(&_1$$3); + object_init_ex(&_1$$3, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_VAR(&_2$$3); + ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the minimum of an empty vector."); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1151); + ZEPHIR_MM_RESTORE(); + return; + } + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_4, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_5, 1); + tensor_reduce_min(&result, &_3, &_5, &_4); + ZVAL_LONG(&_7, 0); + ZEPHIR_CALL_METHOD(&_6, &result, "get", NULL, 0, &_7); zephir_check_call_status(); - RETURN_MM_DOUBLE(zephir_get_doubleval(&_1)); + RETURN_MM_DOUBLE(zephir_get_doubleval(&_6)); } /** @@ -3072,24 +3060,165 @@ PHP_METHOD(Tensor_Vector, min) */ PHP_METHOD(Tensor_Vector, max) { - zval _0, _1; + zval _2$$3; + zval _0, result, _3, _4, _5, _6, _7, _1$$3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&result); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); + _zephir_prop_0 = zend_string_init("n", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("a", 1, 1); } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_FUNCTION(&_1, "max", NULL, 20, &_0); + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + if (UNEXPECTED(ZEPHIR_LT_LONG(&_0, 1))) { + ZEPHIR_INIT_VAR(&_1$$3); + object_init_ex(&_1$$3, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_VAR(&_2$$3); + ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the maximum of an empty vector."); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1168); + ZEPHIR_MM_RESTORE(); + return; + } + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_4, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_5, 1); + tensor_reduce_max(&result, &_3, &_5, &_4); + ZVAL_LONG(&_7, 0); + ZEPHIR_CALL_METHOD(&_6, &result, "get", NULL, 0, &_7); zephir_check_call_status(); - RETURN_MM_DOUBLE(zephir_get_doubleval(&_1)); + RETURN_MM_DOUBLE(zephir_get_doubleval(&_6)); +} + +/** + * Return the index of the minimum element in the vector. + * + * @return int + */ +PHP_METHOD(Tensor_Vector, argmin) +{ + zval _2$$3; + zval _0, result, _3, _4, _5, _6, _7, _1$$3; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&result); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("n", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("a", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + if (UNEXPECTED(ZEPHIR_LT_LONG(&_0, 1))) { + ZEPHIR_INIT_VAR(&_1$$3); + object_init_ex(&_1$$3, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_VAR(&_2$$3); + ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the argmin of an empty vector."); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1185); + ZEPHIR_MM_RESTORE(); + return; + } + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_4, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_5, 1); + tensor_reduce_argmin(&result, &_3, &_5, &_4); + ZVAL_LONG(&_7, 0); + ZEPHIR_CALL_METHOD(&_6, &result, "get", NULL, 0, &_7); + zephir_check_call_status(); + RETURN_MM_LONG(zephir_get_intval(&_6)); +} + +/** + * Return the index of the maximum element in the vector. + * + * @return int + */ +PHP_METHOD(Tensor_Vector, argmax) +{ + zval _2$$3; + zval _0, result, _3, _4, _5, _6, _7, _1$$3; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&result); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_7); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("n", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("a", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + if (UNEXPECTED(ZEPHIR_LT_LONG(&_0, 1))) { + ZEPHIR_INIT_VAR(&_1$$3); + object_init_ex(&_1$$3, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_VAR(&_2$$3); + ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the argmax of an empty vector."); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1202); + ZEPHIR_MM_RESTORE(); + return; + } + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_4, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + ZVAL_LONG(&_5, 1); + tensor_reduce_argmax(&result, &_3, &_5, &_4); + ZVAL_LONG(&_7, 0); + ZEPHIR_CALL_METHOD(&_6, &result, "get", NULL, 0, &_7); + zephir_check_call_status(); + RETURN_MM_LONG(zephir_get_intval(&_6)); } /** @@ -3127,19 +3256,20 @@ PHP_METHOD(Tensor_Vector, mean) */ PHP_METHOD(Tensor_Vector, median) { - zval median, _0, _1, _2, a, _3$$4, _4$$4, _5$$4; + zval _2$$3; + zval _0, result, _3, _4, _5, _6, _1$$3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS, mid; + zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); - ZVAL_UNDEF(&median); ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&a); - ZVAL_UNDEF(&_3$$4); - ZVAL_UNDEF(&_4$$4); - ZVAL_UNDEF(&_5$$4); + ZVAL_UNDEF(&result); + ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_4); + ZVAL_UNDEF(&_5); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { @@ -3152,31 +3282,25 @@ PHP_METHOD(Tensor_Vector, median) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); - ZVAL_LONG(&_1, 2); - ZEPHIR_CALL_FUNCTION(&_2, "intdiv", NULL, 21, &_0, &_1); - zephir_check_call_status(); - mid = zephir_get_intval(&_2); - zephir_read_property_cached(&_1, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CPY_WRT(&a, &_1); - ZEPHIR_MAKE_REF(&a); - ZEPHIR_CALL_FUNCTION(NULL, "sort", NULL, 22, &a); - ZEPHIR_UNREF(&a); - zephir_check_call_status(); - zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); - if (zephir_safe_mod_zval_long(&_1, 2) == 1) { - zephir_memory_observe(&median); - zephir_array_fetch_long(&median, &a, mid, PH_NOISY, "tensor/vector.zep", 1224); - } else { - zephir_memory_observe(&_3$$4); - zephir_array_fetch_long(&_3$$4, &a, (mid - 1), PH_NOISY, "tensor/vector.zep", 1226); - zephir_memory_observe(&_4$$4); - zephir_array_fetch_long(&_4$$4, &a, mid, PH_NOISY, "tensor/vector.zep", 1226); - ZEPHIR_INIT_VAR(&_5$$4); - zephir_add_function(&_5$$4, &_3$$4, &_4$$4); - ZEPHIR_INIT_NVAR(&median); - ZVAL_DOUBLE(&median, zephir_safe_div_zval_double(&_5$$4, 2.0)); + if (UNEXPECTED(ZEPHIR_LT_LONG(&_0, 1))) { + ZEPHIR_INIT_VAR(&_1$$3); + object_init_ex(&_1$$3, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_VAR(&_2$$3); + ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the median of an empty vector."); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1229); + ZEPHIR_MM_RESTORE(); + return; } - RETURN_CCTOR(&median); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_4, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + tensor_median(&result, &_3, &_4); + ZVAL_LONG(&_6, 0); + ZEPHIR_CALL_METHOD(&_5, &result, "get", NULL, 0, &_6); + zephir_check_call_status(); + RETURN_MM_DOUBLE(zephir_get_doubleval(&_5)); } /** @@ -3188,31 +3312,34 @@ PHP_METHOD(Tensor_Vector, median) */ PHP_METHOD(Tensor_Vector, quantile) { + zval _7$$4; zend_bool _0; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS, xHat; - zval *q_param = NULL, a, _5, _6, _9, _10, _1$$3, _2$$3, _3$$3, _4$$3, _7$$4, _8$$4; - double q, x, remainder, t; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *q_param = NULL, _5, result, _8, _9, _10, _11, _12, _1$$3, _2$$3, _3$$3, _4$$3, _6$$4; + double q; zval *this_ptr = getThis(); - ZVAL_UNDEF(&a); ZVAL_UNDEF(&_5); - ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&result); + ZVAL_UNDEF(&_8); ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); + ZVAL_UNDEF(&_11); + ZVAL_UNDEF(&_12); ZVAL_UNDEF(&_1$$3); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$3); + ZVAL_UNDEF(&_6$$4); ZVAL_UNDEF(&_7$$4); - ZVAL_UNDEF(&_8$$4); static zend_string *_zephir_prop_0 = NULL; static zend_string *_zephir_prop_1 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); + _zephir_prop_0 = zend_string_init("n", 1, 1); } if (UNEXPECTED(!_zephir_prop_1)) { - _zephir_prop_1 = zend_string_init("n", 1, 1); + _zephir_prop_1 = zend_string_init("a", 1, 1); } ZEND_PARSE_PARAMETERS_START(1, 1) @@ -3230,39 +3357,37 @@ PHP_METHOD(Tensor_Vector, quantile) ZEPHIR_INIT_VAR(&_1$$3); object_init_ex(&_1$$3, tensor_exceptions_invalidargumentexception_ce); ZVAL_DOUBLE(&_2$$3, q); - ZEPHIR_CALL_FUNCTION(&_3$$3, "strval", NULL, 4, &_2$$3); + ZEPHIR_CALL_FUNCTION(&_3$$3, "strval", NULL, 3, &_2$$3); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_4$$3); ZEPHIR_CONCAT_SSVS(&_4$$3, "Q must be", " between 0 and 1, ", &_3$$3, " given."); - ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 3, &_4$$3); + ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_4$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1243); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1248); ZEPHIR_MM_RESTORE(); return; } - zephir_read_property_cached(&_5, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CPY_WRT(&a, &_5); - ZEPHIR_MAKE_REF(&a); - ZEPHIR_CALL_FUNCTION(NULL, "sort", NULL, 22, &a); - ZEPHIR_UNREF(&a); - zephir_check_call_status(); - zephir_read_property_cached(&_5, this_ptr, _zephir_prop_1, 2, PH_NOISY_CC | PH_READONLY); - x = (((q * (double) ((zephir_get_numberval(&_5) - 1))) + (double) (1))); - xHat = (int) x; - zephir_read_property_cached(&_6, this_ptr, _zephir_prop_1, 2, PH_NOISY_CC | PH_READONLY); - if (ZEPHIR_LE_LONG(&_6, xHat)) { - zephir_memory_observe(&_7$$4); - zephir_read_property_cached(&_8$$4, this_ptr, _zephir_prop_1, 2, PH_NOISY_CC | PH_READONLY); - zephir_array_fetch_long(&_7$$4, &a, (zephir_get_numberval(&_8$$4) - 1), PH_NOISY, "tensor/vector.zep", 1255); - RETURN_MM_DOUBLE(zephir_get_doubleval(&_7$$4)); - } - remainder = ((x - (double) xHat)); - zephir_memory_observe(&_9); - zephir_array_fetch_long(&_9, &a, (xHat - 1), PH_NOISY, "tensor/vector.zep", 1260); - t = (zephir_get_doubleval(&_9)); - zephir_memory_observe(&_10); - zephir_array_fetch_long(&_10, &a, xHat, PH_NOISY, "tensor/vector.zep", 1262); - RETURN_MM_DOUBLE((t + (remainder * (zephir_get_numberval(&_10) - t)))); + zephir_read_property_cached(&_5, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + if (UNEXPECTED(ZEPHIR_LT_LONG(&_5, 1))) { + ZEPHIR_INIT_VAR(&_6$$4); + object_init_ex(&_6$$4, tensor_exceptions_invalidargumentexception_ce); + ZEPHIR_INIT_VAR(&_7$$4); + ZEPHIR_CONCAT_SS(&_7$$4, "Cannot compute", " the quantile of an empty vector."); + ZEPHIR_CALL_METHOD(NULL, &_6$$4, "__construct", NULL, 2, &_7$$4); + zephir_check_call_status(); + zephir_throw_exception_debug(&_6$$4, "tensor/vector.zep", 1253); + ZEPHIR_MM_RESTORE(); + return; + } + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + ZVAL_DOUBLE(&_10, q); + tensor_quantile(&result, &_8, &_9, &_10); + ZVAL_LONG(&_12, 0); + ZEPHIR_CALL_METHOD(&_11, &result, "get", NULL, 0, &_12); + zephir_check_call_status(); + RETURN_MM_DOUBLE(zephir_get_doubleval(&_11)); } /** @@ -3309,7 +3434,7 @@ PHP_METHOD(Tensor_Vector, variance) ZEPHIR_SEPARATE_PARAM(mean); } if (!(Z_TYPE_P(mean) == IS_NULL)) { - ZEPHIR_CALL_FUNCTION(&_0$$3, "is_float", NULL, 2, mean); + ZEPHIR_CALL_FUNCTION(&_0$$3, "is_float", NULL, 1, mean); zephir_check_call_status(); if (UNEXPECTED(!zephir_is_true(&_0$$3))) { ZEPHIR_INIT_VAR(&_1$$4); @@ -3318,9 +3443,9 @@ PHP_METHOD(Tensor_Vector, variance) zephir_gettype(&_2$$4, mean); ZEPHIR_INIT_VAR(&_3$$4); ZEPHIR_CONCAT_SSVS(&_3$$4, "Mean scalar must be", " a floating point number ", &_2$$4, " given."); - ZEPHIR_CALL_METHOD(NULL, &_1$$4, "__construct", NULL, 3, &_3$$4); + ZEPHIR_CALL_METHOD(NULL, &_1$$4, "__construct", NULL, 2, &_3$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$4, "tensor/vector.zep", 1277); + zephir_throw_exception_debug(&_1$$4, "tensor/vector.zep", 1273); ZEPHIR_MM_RESTORE(); return; } @@ -3328,7 +3453,7 @@ PHP_METHOD(Tensor_Vector, variance) ZEPHIR_CALL_METHOD(mean, this_ptr, "mean", NULL, 0); zephir_check_call_status(); } - ZEPHIR_CALL_METHOD(&_4, this_ptr, "subtractscalar", NULL, 0, mean); + ZEPHIR_CALL_METHOD(&_4, this_ptr, "subtractScalar", NULL, 0, mean); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&_5, &_4, "square", NULL, 0); zephir_check_call_status(); @@ -3348,27 +3473,18 @@ PHP_METHOD(Tensor_Vector, variance) */ PHP_METHOD(Tensor_Vector, round) { - zend_bool _12; - zval b; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zval *precision_param = NULL, _0$$3, _1$$4, _2$$4, _3$$4, _4$$4, valueA, _5, *_6, _7, *_8, _11, _9$$5, _10$$5, _13$$6, _14$$6; + zval *precision_param = NULL, _0$$3, _1$$3, _2$$3, _3$$3, _4, _5, _6; zend_long precision, ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); - ZVAL_UNDEF(&_0$$3); - ZVAL_UNDEF(&_1$$4); - ZVAL_UNDEF(&_2$$4); - ZVAL_UNDEF(&_3$$4); - ZVAL_UNDEF(&_4$$4); - ZVAL_UNDEF(&valueA); + ZVAL_UNDEF(&_0$$3); + ZVAL_UNDEF(&_1$$3); + ZVAL_UNDEF(&_2$$3); + ZVAL_UNDEF(&_3$$3); + ZVAL_UNDEF(&_4); ZVAL_UNDEF(&_5); - ZVAL_UNDEF(&_7); - ZVAL_UNDEF(&_11); - ZVAL_UNDEF(&_9$$5); - ZVAL_UNDEF(&_10$$5); - ZVAL_UNDEF(&_13$$6); - ZVAL_UNDEF(&_14$$6); - ZVAL_UNDEF(&b); + ZVAL_UNDEF(&_6); static zend_string *_zephir_prop_0 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); @@ -3385,74 +3501,26 @@ PHP_METHOD(Tensor_Vector, round) precision = 0; } else { } - if (precision == 0) { - ZEPHIR_INIT_VAR(&_0$$3); - ZVAL_STRING(&_0$$3, "round"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0$$3); - zephir_check_call_status(); - RETURN_MM(); - } if (UNEXPECTED(precision < 0)) { - ZEPHIR_INIT_VAR(&_1$$4); - object_init_ex(&_1$$4, tensor_exceptions_invalidargumentexception_ce); - ZVAL_LONG(&_2$$4, precision); - ZEPHIR_CALL_FUNCTION(&_3$$4, "strval", NULL, 4, &_2$$4); + ZEPHIR_INIT_VAR(&_0$$3); + object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); + ZVAL_LONG(&_1$$3, precision); + ZEPHIR_CALL_FUNCTION(&_2$$3, "strval", NULL, 3, &_1$$3); zephir_check_call_status(); - ZEPHIR_INIT_VAR(&_4$$4); - ZEPHIR_CONCAT_SSVS(&_4$$4, "Decimal precision cannot", " be less than 0, ", &_3$$4, " given."); - ZEPHIR_CALL_METHOD(NULL, &_1$$4, "__construct", NULL, 3, &_4$$4); + ZEPHIR_INIT_VAR(&_3$$3); + ZEPHIR_CONCAT_SSVS(&_3$$3, "Decimal precision cannot", " be less than 0, ", &_2$$3, " given."); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$4, "tensor/vector.zep", 1305); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1297); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&b); - array_init(&b); + object_init_ex(return_value, zend_get_called_scope(execute_data)); + ZEPHIR_INIT_VAR(&_4); zephir_read_property_cached(&_5, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_5) == IS_STRING) { - ZEPHIR_INIT_VAR(&_7); - zephir_string_to_char_array(&_7, &_5); - _6 = &_7; - } else { - _6 = &_5; - } - zephir_is_iterable(_6, 0, "tensor/vector.zep", 1316); - if (Z_TYPE_P(_6) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_6), _8) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _8); - ZEPHIR_INIT_NVAR(&_9$$5); - ZVAL_LONG(&_10$$5, precision); - zephir_round(&_9$$5, &valueA, &_10$$5, NULL); - zephir_array_append(&b, &_9$$5, PH_SEPARATE, "tensor/vector.zep", 1313); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _6, "rewind", NULL, 0); - zephir_check_call_status(); - _12 = 1; - while (1) { - if (_12) { - _12 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _6, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_11, _6, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_11)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _6, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_13$$6); - ZVAL_LONG(&_14$$6, precision); - zephir_round(&_13$$6, &valueA, &_14$$6, NULL); - zephir_array_append(&b, &_13$$6, PH_SEPARATE, "tensor/vector.zep", 1313); - } - } - ZEPHIR_INIT_NVAR(&valueA); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &b); + ZVAL_LONG(&_6, precision); + tensor_round(&_4, &_5, &_6); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_4); zephir_check_call_status(); RETURN_MM(); } @@ -3464,18 +3532,25 @@ PHP_METHOD(Tensor_Vector, round) */ PHP_METHOD(Tensor_Vector, floor) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "floor"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_floor(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -3487,18 +3562,25 @@ PHP_METHOD(Tensor_Vector, floor) */ PHP_METHOD(Tensor_Vector, ceil) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); - ZVAL_STRING(&_0, "ceil"); - ZEPHIR_RETURN_CALL_METHOD(this_ptr, "map", NULL, 0, &_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_ceil(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -3514,26 +3596,19 @@ PHP_METHOD(Tensor_Vector, ceil) */ PHP_METHOD(Tensor_Vector, clip) { - zend_bool _9; - zval b; zval _1$$3; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *min_param = NULL, *max_param = NULL, _0$$3, valueA, _2, *_3, _4, *_5, _8, _6$$5, _7$$6, _10$$8, _11$$9; + zval *min_param = NULL, *max_param = NULL, _0$$3, _2, _3, _4, _5; double min, max; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0$$3); - ZVAL_UNDEF(&valueA); ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); ZVAL_UNDEF(&_4); - ZVAL_UNDEF(&_8); - ZVAL_UNDEF(&_6$$5); - ZVAL_UNDEF(&_7$$6); - ZVAL_UNDEF(&_10$$8); - ZVAL_UNDEF(&_11$$9); + ZVAL_UNDEF(&_5); ZVAL_UNDEF(&_1$$3); - ZVAL_UNDEF(&b); static zend_string *_zephir_prop_0 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); @@ -3553,77 +3628,19 @@ PHP_METHOD(Tensor_Vector, clip) object_init_ex(&_0$$3, tensor_exceptions_invalidargumentexception_ce); ZEPHIR_INIT_VAR(&_1$$3); ZEPHIR_CONCAT_SS(&_1$$3, "Minimum cannot be", " greater than maximum."); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 3, &_1$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_1$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1352); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1336); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&b); - array_init(&b); - zephir_read_property_cached(&_2, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_2) == IS_STRING) { - ZEPHIR_INIT_VAR(&_4); - zephir_string_to_char_array(&_4, &_2); - _3 = &_4; - } else { - _3 = &_2; - } - zephir_is_iterable(_3, 0, "tensor/vector.zep", 1375); - if (Z_TYPE_P(_3) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_3), _5) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _5); - if (ZEPHIR_GT_DOUBLE(&valueA, max)) { - ZEPHIR_INIT_NVAR(&_6$$5); - ZVAL_DOUBLE(&_6$$5, max); - zephir_array_append(&b, &_6$$5, PH_SEPARATE, "tensor/vector.zep", 1361); - continue; - } - if (ZEPHIR_LT_DOUBLE(&valueA, min)) { - ZEPHIR_INIT_NVAR(&_7$$6); - ZVAL_DOUBLE(&_7$$6, min); - zephir_array_append(&b, &_7$$6, PH_SEPARATE, "tensor/vector.zep", 1367); - continue; - } - zephir_array_append(&b, &valueA, PH_SEPARATE, "tensor/vector.zep", 1372); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _3, "rewind", NULL, 0); - zephir_check_call_status(); - _9 = 1; - while (1) { - if (_9) { - _9 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _3, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_8, _3, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_8)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _3, "current", NULL, 0); - zephir_check_call_status(); - if (ZEPHIR_GT_DOUBLE(&valueA, max)) { - ZEPHIR_INIT_NVAR(&_10$$8); - ZVAL_DOUBLE(&_10$$8, max); - zephir_array_append(&b, &_10$$8, PH_SEPARATE, "tensor/vector.zep", 1361); - continue; - } - if (ZEPHIR_LT_DOUBLE(&valueA, min)) { - ZEPHIR_INIT_NVAR(&_11$$9); - ZVAL_DOUBLE(&_11$$9, min); - zephir_array_append(&b, &_11$$9, PH_SEPARATE, "tensor/vector.zep", 1367); - continue; - } - zephir_array_append(&b, &valueA, PH_SEPARATE, "tensor/vector.zep", 1372); - } - } - ZEPHIR_INIT_NVAR(&valueA); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &b); + object_init_ex(return_value, zend_get_called_scope(execute_data)); + ZEPHIR_INIT_VAR(&_2); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + ZVAL_DOUBLE(&_4, min); + ZVAL_DOUBLE(&_5, max); + tensor_clip(&_2, &_3, &_4, &_5); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_2); zephir_check_call_status(); RETURN_MM(); } @@ -3636,21 +3653,15 @@ PHP_METHOD(Tensor_Vector, clip) */ PHP_METHOD(Tensor_Vector, clipLower) { - zend_bool _6; - zval b; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *min_param = NULL, valueA, _0, *_1, _2, *_3, _5, _4$$4, _7$$6; + zval *min_param = NULL, _0, _1, _2; double min; zval *this_ptr = getThis(); - ZVAL_UNDEF(&valueA); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_5); - ZVAL_UNDEF(&_4$$4); - ZVAL_UNDEF(&_7$$6); - ZVAL_UNDEF(&b); static zend_string *_zephir_prop_0 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); @@ -3663,59 +3674,12 @@ PHP_METHOD(Tensor_Vector, clipLower) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &min_param); min = zephir_get_doubleval(min_param); - ZEPHIR_INIT_VAR(&b); - array_init(&b); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/vector.zep", 1400); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _3); - if (ZEPHIR_LT_DOUBLE(&valueA, min)) { - ZEPHIR_INIT_NVAR(&_4$$4); - ZVAL_DOUBLE(&_4$$4, min); - zephir_array_append(&b, &_4$$4, PH_SEPARATE, "tensor/vector.zep", 1392); - continue; - } - zephir_array_append(&b, &valueA, PH_SEPARATE, "tensor/vector.zep", 1397); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _6 = 1; - while (1) { - if (_6) { - _6 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_5, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_5)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _1, "current", NULL, 0); - zephir_check_call_status(); - if (ZEPHIR_LT_DOUBLE(&valueA, min)) { - ZEPHIR_INIT_NVAR(&_7$$6); - ZVAL_DOUBLE(&_7$$6, min); - zephir_array_append(&b, &_7$$6, PH_SEPARATE, "tensor/vector.zep", 1392); - continue; - } - zephir_array_append(&b, &valueA, PH_SEPARATE, "tensor/vector.zep", 1397); - } - } - ZEPHIR_INIT_NVAR(&valueA); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &b); + object_init_ex(return_value, zend_get_called_scope(execute_data)); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + ZVAL_DOUBLE(&_2, min); + tensor_clip_lower(&_0, &_1, &_2); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -3728,21 +3692,15 @@ PHP_METHOD(Tensor_Vector, clipLower) */ PHP_METHOD(Tensor_Vector, clipUpper) { - zend_bool _6; - zval b; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *max_param = NULL, valueA, _0, *_1, _2, *_3, _5, _4$$4, _7$$6; + zval *max_param = NULL, _0, _1, _2; double max; zval *this_ptr = getThis(); - ZVAL_UNDEF(&valueA); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_5); - ZVAL_UNDEF(&_4$$4); - ZVAL_UNDEF(&_7$$6); - ZVAL_UNDEF(&b); static zend_string *_zephir_prop_0 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); @@ -3755,59 +3713,12 @@ PHP_METHOD(Tensor_Vector, clipUpper) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &max_param); max = zephir_get_doubleval(max_param); - ZEPHIR_INIT_VAR(&b); - array_init(&b); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/vector.zep", 1425); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _3); - if (ZEPHIR_GT_DOUBLE(&valueA, max)) { - ZEPHIR_INIT_NVAR(&_4$$4); - ZVAL_DOUBLE(&_4$$4, max); - zephir_array_append(&b, &_4$$4, PH_SEPARATE, "tensor/vector.zep", 1417); - continue; - } - zephir_array_append(&b, &valueA, PH_SEPARATE, "tensor/vector.zep", 1422); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _6 = 1; - while (1) { - if (_6) { - _6 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_5, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_5)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _1, "current", NULL, 0); - zephir_check_call_status(); - if (ZEPHIR_GT_DOUBLE(&valueA, max)) { - ZEPHIR_INIT_NVAR(&_7$$6); - ZVAL_DOUBLE(&_7$$6, max); - zephir_array_append(&b, &_7$$6, PH_SEPARATE, "tensor/vector.zep", 1417); - continue; - } - zephir_array_append(&b, &valueA, PH_SEPARATE, "tensor/vector.zep", 1422); - } - } - ZEPHIR_INIT_NVAR(&valueA); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &b); + object_init_ex(return_value, zend_get_called_scope(execute_data)); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + ZVAL_DOUBLE(&_2, max); + tensor_clip_upper(&_0, &_1, &_2); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -3819,24 +3730,13 @@ PHP_METHOD(Tensor_Vector, clipUpper) */ PHP_METHOD(Tensor_Vector, sign) { - zend_bool _8; - zval b; - zval valueA, _0, *_1, _2, *_3, _7, _4$$4, _5$$5, _6$$6, _9$$8, _10$$9, _11$$10; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); - ZVAL_UNDEF(&valueA); ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_7); - ZVAL_UNDEF(&_4$$4); - ZVAL_UNDEF(&_5$$5); - ZVAL_UNDEF(&_6$$6); - ZVAL_UNDEF(&_9$$8); - ZVAL_UNDEF(&_10$$9); - ZVAL_UNDEF(&_11$$10); - ZVAL_UNDEF(&b); + ZVAL_UNDEF(&_1); static zend_string *_zephir_prop_0 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); @@ -3844,71 +3744,11 @@ PHP_METHOD(Tensor_Vector, sign) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_INIT_VAR(&b); - array_init(&b); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/vector.zep", 1449); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _3); - if (ZEPHIR_GT_LONG(&valueA, 0)) { - ZEPHIR_INIT_NVAR(&_4$$4); - ZVAL_DOUBLE(&_4$$4, 1.0); - zephir_array_append(&b, &_4$$4, PH_SEPARATE, "tensor/vector.zep", 1441); - } else if (ZEPHIR_LT_LONG(&valueA, 0)) { - ZEPHIR_INIT_NVAR(&_5$$5); - ZVAL_DOUBLE(&_5$$5, -1.0); - zephir_array_append(&b, &_5$$5, PH_SEPARATE, "tensor/vector.zep", 1443); - } else { - ZEPHIR_INIT_NVAR(&_6$$6); - ZVAL_DOUBLE(&_6$$6, 0.0); - zephir_array_append(&b, &_6$$6, PH_SEPARATE, "tensor/vector.zep", 1445); - } - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _8 = 1; - while (1) { - if (_8) { - _8 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_7, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_7)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _1, "current", NULL, 0); - zephir_check_call_status(); - if (ZEPHIR_GT_LONG(&valueA, 0)) { - ZEPHIR_INIT_NVAR(&_9$$8); - ZVAL_DOUBLE(&_9$$8, 1.0); - zephir_array_append(&b, &_9$$8, PH_SEPARATE, "tensor/vector.zep", 1441); - } else if (ZEPHIR_LT_LONG(&valueA, 0)) { - ZEPHIR_INIT_NVAR(&_10$$9); - ZVAL_DOUBLE(&_10$$9, -1.0); - zephir_array_append(&b, &_10$$9, PH_SEPARATE, "tensor/vector.zep", 1443); - } else { - ZEPHIR_INIT_NVAR(&_11$$10); - ZVAL_DOUBLE(&_11$$10, 0.0); - zephir_array_append(&b, &_11$$10, PH_SEPARATE, "tensor/vector.zep", 1445); - } - } - } - ZEPHIR_INIT_NVAR(&valueA); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &b); + object_init_ex(return_value, zend_get_called_scope(execute_data)); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_sign(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -3920,18 +3760,13 @@ PHP_METHOD(Tensor_Vector, sign) */ PHP_METHOD(Tensor_Vector, negate) { - zend_bool _5; - zval b; - zval valueA, _0, *_1, _2, *_3, _4; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); - ZVAL_UNDEF(&valueA); ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_4); - ZVAL_UNDEF(&b); + ZVAL_UNDEF(&_1); static zend_string *_zephir_prop_0 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); @@ -3939,49 +3774,11 @@ PHP_METHOD(Tensor_Vector, negate) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - ZEPHIR_INIT_VAR(&b); - array_init(&b); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - if (Z_TYPE_P(&_0) == IS_STRING) { - ZEPHIR_INIT_VAR(&_2); - zephir_string_to_char_array(&_2, &_0); - _1 = &_2; - } else { - _1 = &_0; - } - zephir_is_iterable(_1, 0, "tensor/vector.zep", 1467); - if (Z_TYPE_P(_1) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_1), _3) - { - ZEPHIR_INIT_NVAR(&valueA); - ZVAL_COPY(&valueA, _3); - zephir_negate(&valueA); - zephir_array_append(&b, &valueA, PH_SEPARATE, "tensor/vector.zep", 1464); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "rewind", NULL, 0); - zephir_check_call_status(); - _5 = 1; - while (1) { - if (_5) { - _5 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _1, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_4, _1, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_4)) { - break; - } - ZEPHIR_CALL_METHOD(&valueA, _1, "current", NULL, 0); - zephir_check_call_status(); - zephir_negate(&valueA); - zephir_array_append(&b, &valueA, PH_SEPARATE, "tensor/vector.zep", 1464); - } - } - ZEPHIR_INIT_NVAR(&valueA); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &b); + object_init_ex(return_value, zend_get_called_scope(execute_data)); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_negate(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -3996,28 +3793,23 @@ PHP_METHOD(Tensor_Vector, negate) PHP_METHOD(Tensor_Vector, multiplyMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _15; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowB, _8, *_9, _10, *_11, _14, _2$$3, _3$$3, _5$$3, _12$$4, _13$$4, _16$$5, _17$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_16$$5); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -4050,60 +3842,24 @@ PHP_METHOD(Tensor_Vector, multiplyMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1482); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1396); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/vector.zep", 1493); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_multiply(&_12$$4, &_13$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 1490); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _15 = 1; - while (1) { - if (_15) { - _15 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_14, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_14)) { - break; - } - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_16$$5); - zephir_read_property_cached(&_17$$5, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_multiply(&_16$$5, &_17$$5, &rowB); - zephir_array_append(&c, &_16$$5, PH_SEPARATE, "tensor/vector.zep", 1490); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + tensor_multiply_row(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -4118,28 +3874,23 @@ PHP_METHOD(Tensor_Vector, multiplyMatrix) PHP_METHOD(Tensor_Vector, divideMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _15; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowB, _8, *_9, _10, *_11, _14, _2$$3, _3$$3, _5$$3, _12$$4, _13$$4, _16$$5, _17$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_16$$5); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -4172,60 +3923,24 @@ PHP_METHOD(Tensor_Vector, divideMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1508); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1420); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/vector.zep", 1519); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_divide(&_12$$4, &_13$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 1516); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _15 = 1; - while (1) { - if (_15) { - _15 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_14, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_14)) { - break; - } - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_16$$5); - zephir_read_property_cached(&_17$$5, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_divide(&_16$$5, &_17$$5, &rowB); - zephir_array_append(&c, &_16$$5, PH_SEPARATE, "tensor/vector.zep", 1516); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + tensor_divide_row_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -4240,28 +3955,23 @@ PHP_METHOD(Tensor_Vector, divideMatrix) PHP_METHOD(Tensor_Vector, addMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _15; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowB, _8, *_9, _10, *_11, _14, _2$$3, _3$$3, _5$$3, _12$$4, _13$$4, _16$$5, _17$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_16$$5); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -4294,60 +4004,24 @@ PHP_METHOD(Tensor_Vector, addMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1534); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1444); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/vector.zep", 1545); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_add(&_12$$4, &_13$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 1542); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _15 = 1; - while (1) { - if (_15) { - _15 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_14, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_14)) { - break; - } - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_16$$5); - zephir_read_property_cached(&_17$$5, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_add(&_16$$5, &_17$$5, &rowB); - zephir_array_append(&c, &_16$$5, PH_SEPARATE, "tensor/vector.zep", 1542); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + tensor_add_row(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -4362,28 +4036,23 @@ PHP_METHOD(Tensor_Vector, addMatrix) PHP_METHOD(Tensor_Vector, subtractMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _15; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowB, _8, *_9, _10, *_11, _14, _2$$3, _3$$3, _5$$3, _12$$4, _13$$4, _16$$5, _17$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_16$$5); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -4416,60 +4085,24 @@ PHP_METHOD(Tensor_Vector, subtractMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1560); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1468); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/vector.zep", 1571); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_subtract(&_12$$4, &_13$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 1568); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _15 = 1; - while (1) { - if (_15) { - _15 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_14, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_14)) { - break; - } - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_16$$5); - zephir_read_property_cached(&_17$$5, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_subtract(&_16$$5, &_17$$5, &rowB); - zephir_array_append(&c, &_16$$5, PH_SEPARATE, "tensor/vector.zep", 1568); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + tensor_subtract_row_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -4484,28 +4117,23 @@ PHP_METHOD(Tensor_Vector, subtractMatrix) PHP_METHOD(Tensor_Vector, powMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _15; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowB, _8, *_9, _10, *_11, _14, _2$$3, _3$$3, _5$$3, _12$$4, _13$$4, _16$$5, _17$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_16$$5); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -4538,60 +4166,24 @@ PHP_METHOD(Tensor_Vector, powMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1586); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1492); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); - zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/vector.zep", 1597); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_pow(&_12$$4, &_13$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 1594); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _15 = 1; - while (1) { - if (_15) { - _15 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_14, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_14)) { - break; - } - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_16$$5); - zephir_read_property_cached(&_17$$5, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_pow(&_16$$5, &_17$$5, &rowB); - zephir_array_append(&c, &_16$$5, PH_SEPARATE, "tensor/vector.zep", 1594); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + tensor_pow_row_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -4606,28 +4198,23 @@ PHP_METHOD(Tensor_Vector, powMatrix) PHP_METHOD(Tensor_Vector, modMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _15; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowB, _8, *_9, _10, *_11, _14, _2$$3, _3$$3, _5$$3, _12$$4, _13$$4, _16$$5, _17$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_16$$5); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -4660,60 +4247,24 @@ PHP_METHOD(Tensor_Vector, modMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1612); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1516); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/vector.zep", 1623); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_mod(&_12$$4, &_13$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 1620); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _15 = 1; - while (1) { - if (_15) { - _15 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_14, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_14)) { - break; - } - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_16$$5); - zephir_read_property_cached(&_17$$5, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_mod(&_16$$5, &_17$$5, &rowB); - zephir_array_append(&c, &_16$$5, PH_SEPARATE, "tensor/vector.zep", 1620); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + tensor_mod_row_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -4728,28 +4279,23 @@ PHP_METHOD(Tensor_Vector, modMatrix) PHP_METHOD(Tensor_Vector, equalMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _15; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowB, _8, *_9, _10, *_11, _14, _2$$3, _3$$3, _5$$3, _12$$4, _13$$4, _16$$5, _17$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_16$$5); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -4782,60 +4328,24 @@ PHP_METHOD(Tensor_Vector, equalMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1638); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1540); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/vector.zep", 1649); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_equal(&_12$$4, &_13$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 1646); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _15 = 1; - while (1) { - if (_15) { - _15 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_14, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_14)) { - break; - } - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_16$$5); - zephir_read_property_cached(&_17$$5, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_equal(&_16$$5, &_17$$5, &rowB); - zephir_array_append(&c, &_16$$5, PH_SEPARATE, "tensor/vector.zep", 1646); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + tensor_equal_row(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -4850,28 +4360,23 @@ PHP_METHOD(Tensor_Vector, equalMatrix) PHP_METHOD(Tensor_Vector, notEqualMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _15; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowB, _8, *_9, _10, *_11, _14, _2$$3, _3$$3, _5$$3, _12$$4, _13$$4, _16$$5, _17$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_16$$5); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -4904,60 +4409,24 @@ PHP_METHOD(Tensor_Vector, notEqualMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1664); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1564); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/vector.zep", 1675); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_not_equal(&_12$$4, &_13$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 1672); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _15 = 1; - while (1) { - if (_15) { - _15 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_14, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_14)) { - break; - } - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_16$$5); - zephir_read_property_cached(&_17$$5, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_not_equal(&_16$$5, &_17$$5, &rowB); - zephir_array_append(&c, &_16$$5, PH_SEPARATE, "tensor/vector.zep", 1672); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + tensor_not_equal_row(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -4972,28 +4441,23 @@ PHP_METHOD(Tensor_Vector, notEqualMatrix) PHP_METHOD(Tensor_Vector, greaterMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _15; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowB, _8, *_9, _10, *_11, _14, _2$$3, _3$$3, _5$$3, _12$$4, _13$$4, _16$$5, _17$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_16$$5); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -5026,60 +4490,24 @@ PHP_METHOD(Tensor_Vector, greaterMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1690); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1588); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/vector.zep", 1701); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_greater(&_12$$4, &_13$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 1698); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _15 = 1; - while (1) { - if (_15) { - _15 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_14, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_14)) { - break; - } - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_16$$5); - zephir_read_property_cached(&_17$$5, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_greater(&_16$$5, &_17$$5, &rowB); - zephir_array_append(&c, &_16$$5, PH_SEPARATE, "tensor/vector.zep", 1698); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + tensor_greater_row_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -5094,28 +4522,23 @@ PHP_METHOD(Tensor_Vector, greaterMatrix) PHP_METHOD(Tensor_Vector, greaterEqualMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _15; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowB, _8, *_9, _10, *_11, _14, _2$$3, _3$$3, _5$$3, _12$$4, _13$$4, _16$$5, _17$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_16$$5); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -5148,60 +4571,24 @@ PHP_METHOD(Tensor_Vector, greaterEqualMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1716); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1612); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/vector.zep", 1727); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_greater_equal(&_12$$4, &_13$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 1724); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _15 = 1; - while (1) { - if (_15) { - _15 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_14, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_14)) { - break; - } - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_16$$5); - zephir_read_property_cached(&_17$$5, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_greater_equal(&_16$$5, &_17$$5, &rowB); - zephir_array_append(&c, &_16$$5, PH_SEPARATE, "tensor/vector.zep", 1724); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + tensor_greater_equal_row_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -5216,28 +4603,23 @@ PHP_METHOD(Tensor_Vector, greaterEqualMatrix) PHP_METHOD(Tensor_Vector, lessMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _15; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowB, _8, *_9, _10, *_11, _14, _2$$3, _3$$3, _5$$3, _12$$4, _13$$4, _16$$5, _17$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_16$$5); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -5270,60 +4652,24 @@ PHP_METHOD(Tensor_Vector, lessMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1742); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1636); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/vector.zep", 1753); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_less(&_12$$4, &_13$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 1750); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _15 = 1; - while (1) { - if (_15) { - _15 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_14, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_14)) { - break; - } - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_16$$5); - zephir_read_property_cached(&_17$$5, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_less(&_16$$5, &_17$$5, &rowB); - zephir_array_append(&c, &_16$$5, PH_SEPARATE, "tensor/vector.zep", 1750); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + tensor_less_row_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -5338,28 +4684,23 @@ PHP_METHOD(Tensor_Vector, lessMatrix) PHP_METHOD(Tensor_Vector, lessEqualMatrix) { zval _4$$3, _6$$3, _7$$3; - zend_bool _15; - zval c; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *b, b_sub, _0, _1, rowB, _8, *_9, _10, *_11, _14, _2$$3, _3$$3, _5$$3, _12$$4, _13$$4, _16$$5, _17$$5; + zval *b, b_sub, _0, _1, bHat, result, _8, _9, _10, _11, _2$$3, _3$$3, _5$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&b_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&rowB); + ZVAL_UNDEF(&bHat); + ZVAL_UNDEF(&result); ZVAL_UNDEF(&_8); + ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10); - ZVAL_UNDEF(&_14); + ZVAL_UNDEF(&_11); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_5$$3); - ZVAL_UNDEF(&_12$$4); - ZVAL_UNDEF(&_13$$4); - ZVAL_UNDEF(&_16$$5); - ZVAL_UNDEF(&_17$$5); - ZVAL_UNDEF(&c); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&_7$$3); @@ -5392,60 +4733,24 @@ PHP_METHOD(Tensor_Vector, lessEqualMatrix) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1768); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1660); ZEPHIR_MM_RESTORE(); return; } - ZEPHIR_INIT_VAR(&c); - array_init(&c); - ZEPHIR_CALL_METHOD(&_8, b, "asarray", NULL, 0); + ZEPHIR_CALL_METHOD(&bHat, b, "asTensorBuffer", NULL, 0); zephir_check_call_status(); - if (Z_TYPE_P(&_8) == IS_STRING) { - ZEPHIR_INIT_VAR(&_10); - zephir_string_to_char_array(&_10, &_8); - _9 = &_10; - } else { - _9 = &_8; - } - zephir_is_iterable(_9, 0, "tensor/vector.zep", 1779); - if (Z_TYPE_P(_9) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(_9), _11) - { - ZEPHIR_INIT_NVAR(&rowB); - ZVAL_COPY(&rowB, _11); - ZEPHIR_INIT_NVAR(&_12$$4); - zephir_read_property_cached(&_13$$4, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_less_equal(&_12$$4, &_13$$4, &rowB); - zephir_array_append(&c, &_12$$4, PH_SEPARATE, "tensor/vector.zep", 1776); - } ZEND_HASH_FOREACH_END(); - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "rewind", NULL, 0); - zephir_check_call_status(); - _15 = 1; - while (1) { - if (_15) { - _15 = 0; - } else { - ZEPHIR_CALL_METHOD(NULL, _9, "next", NULL, 0); - zephir_check_call_status(); - } - ZEPHIR_CALL_METHOD(&_14, _9, "valid", NULL, 0); - zephir_check_call_status(); - if (!zend_is_true(&_14)) { - break; - } - ZEPHIR_CALL_METHOD(&rowB, _9, "current", NULL, 0); - zephir_check_call_status(); - ZEPHIR_INIT_NVAR(&_16$$5); - zephir_read_property_cached(&_17$$5, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - tensor_less_equal(&_16$$5, &_17$$5, &rowB); - zephir_array_append(&c, &_16$$5, PH_SEPARATE, "tensor/vector.zep", 1776); - } - } - ZEPHIR_INIT_NVAR(&rowB); - ZEPHIR_RETURN_CALL_CE_STATIC(tensor_matrix_ce, "quick", NULL, 0, &c); + ZEPHIR_INIT_VAR(&result); + zephir_read_property_cached(&_8, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_9, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + tensor_less_equal_row_reverse(&result, &bHat, &_8, &_9); + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_CALL_METHOD(&_10, b, "m", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(&_11, b, "n", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 14, &result, &_10, &_11); zephir_check_call_status(); RETURN_MM(); } @@ -5506,18 +4811,18 @@ PHP_METHOD(Tensor_Vector, multiplyVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1794); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1684); ZEPHIR_MM_RESTORE(); return; } + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_8); zephir_read_property_cached(&_9, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_10, b, "asarray", NULL, 0); - zephir_check_call_status(); + zephir_read_property_cached(&_10, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); tensor_multiply(&_8, &_9, &_10); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -5578,18 +4883,18 @@ PHP_METHOD(Tensor_Vector, divideVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1812); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1702); ZEPHIR_MM_RESTORE(); return; } + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_8); zephir_read_property_cached(&_9, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_10, b, "asarray", NULL, 0); - zephir_check_call_status(); + zephir_read_property_cached(&_10, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); tensor_divide(&_8, &_9, &_10); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -5650,18 +4955,18 @@ PHP_METHOD(Tensor_Vector, addVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1830); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1720); ZEPHIR_MM_RESTORE(); return; } + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_8); zephir_read_property_cached(&_9, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_10, b, "asarray", NULL, 0); - zephir_check_call_status(); + zephir_read_property_cached(&_10, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); tensor_add(&_8, &_9, &_10); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -5722,18 +5027,18 @@ PHP_METHOD(Tensor_Vector, subtractVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1848); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1738); ZEPHIR_MM_RESTORE(); return; } + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_8); zephir_read_property_cached(&_9, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_10, b, "asarray", NULL, 0); - zephir_check_call_status(); + zephir_read_property_cached(&_10, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); tensor_subtract(&_8, &_9, &_10); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -5794,18 +5099,18 @@ PHP_METHOD(Tensor_Vector, powVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1866); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1756); ZEPHIR_MM_RESTORE(); return; } + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_8); zephir_read_property_cached(&_9, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_10, b, "asarray", NULL, 0); - zephir_check_call_status(); + zephir_read_property_cached(&_10, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); tensor_pow(&_8, &_9, &_10); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -5866,18 +5171,18 @@ PHP_METHOD(Tensor_Vector, modVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1884); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1774); ZEPHIR_MM_RESTORE(); return; } + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_8); zephir_read_property_cached(&_9, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_10, b, "asarray", NULL, 0); - zephir_check_call_status(); + zephir_read_property_cached(&_10, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); tensor_mod(&_8, &_9, &_10); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -5939,18 +5244,18 @@ PHP_METHOD(Tensor_Vector, equalVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1903); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1793); ZEPHIR_MM_RESTORE(); return; } + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_8); zephir_read_property_cached(&_9, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_10, b, "asarray", NULL, 0); - zephir_check_call_status(); + zephir_read_property_cached(&_10, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); tensor_equal(&_8, &_9, &_10); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -6011,18 +5316,18 @@ PHP_METHOD(Tensor_Vector, notEqualVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1921); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1811); ZEPHIR_MM_RESTORE(); return; } + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_8); zephir_read_property_cached(&_9, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_10, b, "asarray", NULL, 0); - zephir_check_call_status(); + zephir_read_property_cached(&_10, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); tensor_not_equal(&_8, &_9, &_10); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -6083,18 +5388,18 @@ PHP_METHOD(Tensor_Vector, greaterVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1939); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1829); ZEPHIR_MM_RESTORE(); return; } + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_8); zephir_read_property_cached(&_9, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_10, b, "asarray", NULL, 0); - zephir_check_call_status(); + zephir_read_property_cached(&_10, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); tensor_greater(&_8, &_9, &_10); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -6155,18 +5460,18 @@ PHP_METHOD(Tensor_Vector, greaterEqualVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1957); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1847); ZEPHIR_MM_RESTORE(); return; } + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_8); zephir_read_property_cached(&_9, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_10, b, "asarray", NULL, 0); - zephir_check_call_status(); + zephir_read_property_cached(&_10, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); tensor_greater_equal(&_8, &_9, &_10); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -6227,18 +5532,18 @@ PHP_METHOD(Tensor_Vector, lessVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1975); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1865); ZEPHIR_MM_RESTORE(); return; } + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_8); zephir_read_property_cached(&_9, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_10, b, "asarray", NULL, 0); - zephir_check_call_status(); + zephir_read_property_cached(&_10, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); tensor_less(&_8, &_9, &_10); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -6299,18 +5604,18 @@ PHP_METHOD(Tensor_Vector, lessEqualVector) zephir_cast_to_string(&_6$$3, &_5$$3); ZEPHIR_INIT_VAR(&_7$$3); ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 3, &_7$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1993); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1883); ZEPHIR_MM_RESTORE(); return; } + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_8); zephir_read_property_cached(&_9, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(&_10, b, "asarray", NULL, 0); - zephir_check_call_status(); + zephir_read_property_cached(&_10, b, _zephir_prop_1, 0, PH_NOISY_CC | PH_READONLY); tensor_less_equal(&_8, &_9, &_10); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_8); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_8); zephir_check_call_status(); RETURN_MM(); } @@ -6344,11 +5649,12 @@ PHP_METHOD(Tensor_Vector, multiplyScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); ZVAL_DOUBLE(&_2, b); tensor_multiply_scalar(&_0, &_1, &_2); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -6382,11 +5688,12 @@ PHP_METHOD(Tensor_Vector, divideScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); ZVAL_DOUBLE(&_2, b); tensor_divide_scalar(&_0, &_1, &_2); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -6420,11 +5727,12 @@ PHP_METHOD(Tensor_Vector, addScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); ZVAL_DOUBLE(&_2, b); tensor_add_scalar(&_0, &_1, &_2); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -6458,11 +5766,12 @@ PHP_METHOD(Tensor_Vector, subtractScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); ZVAL_DOUBLE(&_2, b); tensor_subtract_scalar(&_0, &_1, &_2); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -6496,11 +5805,12 @@ PHP_METHOD(Tensor_Vector, powScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); ZVAL_DOUBLE(&_2, b); tensor_pow_scalar(&_0, &_1, &_2); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -6534,11 +5844,12 @@ PHP_METHOD(Tensor_Vector, modScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); ZVAL_DOUBLE(&_2, b); tensor_mod_scalar(&_0, &_1, &_2); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -6572,11 +5883,12 @@ PHP_METHOD(Tensor_Vector, equalScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); ZVAL_DOUBLE(&_2, b); tensor_equal_scalar(&_0, &_1, &_2); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -6610,11 +5922,12 @@ PHP_METHOD(Tensor_Vector, notEqualScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); ZVAL_DOUBLE(&_2, b); tensor_not_equal_scalar(&_0, &_1, &_2); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -6648,11 +5961,12 @@ PHP_METHOD(Tensor_Vector, greaterScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); ZVAL_DOUBLE(&_2, b); tensor_greater_scalar(&_0, &_1, &_2); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -6687,11 +6001,12 @@ PHP_METHOD(Tensor_Vector, greaterEqualScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); ZVAL_DOUBLE(&_2, b); tensor_greater_equal_scalar(&_0, &_1, &_2); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -6725,11 +6040,12 @@ PHP_METHOD(Tensor_Vector, lessScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); ZVAL_DOUBLE(&_2, b); tensor_less_scalar(&_0, &_1, &_2); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -6764,11 +6080,12 @@ PHP_METHOD(Tensor_Vector, lessEqualScalar) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &b_param); b = zephir_get_doubleval(b_param); + object_init_ex(return_value, zend_get_called_scope(execute_data)); ZEPHIR_INIT_VAR(&_0); zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); ZVAL_DOUBLE(&_2, b); tensor_less_equal_scalar(&_0, &_1, &_2); - ZEPHIR_RETURN_CALL_STATIC("quick", NULL, 0, &_0); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 13, &_0); zephir_check_call_status(); RETURN_MM(); } @@ -6800,34 +6117,42 @@ PHP_METHOD(Tensor_Vector, offsetSet) Z_PARAM_ZVAL(values) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(2, 0, &index, &values); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2150); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2040); return; } /** - * Does a given column exist in the matrix. + * Does a given element exist in the vector. * * @param mixed index * @return bool */ PHP_METHOD(Tensor_Vector, offsetExists) { - zval *index, index_sub, _0; + zend_bool _0; + zval *index, index_sub, _1; zval *this_ptr = getThis(); ZVAL_UNDEF(&index_sub); - ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); static zend_string *_zephir_prop_0 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); + _zephir_prop_0 = zend_string_init("n", 1, 1); } ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(index) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(1, 0, &index); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - RETURN_BOOL(zephir_array_isset_value(&_0, index)); + if (UNEXPECTED(!(Z_TYPE_P(index) == IS_LONG))) { + RETURN_BOOL(0); + } + _0 = ZEPHIR_GE_LONG(index, 0); + if (_0) { + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + _0 = ZEPHIR_LT(index, &_1); + } + RETURN_BOOL(_0); } /** @@ -6843,12 +6168,12 @@ PHP_METHOD(Tensor_Vector, offsetUnset) Z_PARAM_ZVAL(index) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(1, 0, &index); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2170); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2064); return; } /** - * Return a row from the matrix at the given index. + * Return an element from the vector at the given index. * * @param mixed index * @throws \Tensor\Exceptions\InvalidArgumentException @@ -6856,21 +6181,26 @@ PHP_METHOD(Tensor_Vector, offsetUnset) */ PHP_METHOD(Tensor_Vector, offsetGet) { - zval _2, _3; + zval _4$$3, _5$$3; + zend_bool _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; - zval *index, index_sub, value, _0, _1; + zval *index, index_sub, _2, _6, _3$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&index_sub); - ZVAL_UNDEF(&value); - ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_3); + ZVAL_UNDEF(&_6); + ZVAL_UNDEF(&_3$$3); + ZVAL_UNDEF(&_4$$3); + ZVAL_UNDEF(&_5$$3); static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); + _zephir_prop_0 = zend_string_init("n", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("a", 1, 1); } ZEND_PARSE_PARAMETERS_START(1, 1) @@ -6879,36 +6209,47 @@ PHP_METHOD(Tensor_Vector, offsetGet) ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &index); - zephir_memory_observe(&value); - zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - if (EXPECTED(zephir_array_isset_fetch(&value, &_0, index, 0))) { - RETURN_CCTOR(&value); + _0 = !(Z_TYPE_P(index) == IS_LONG); + if (!(_0)) { + _1 = ZEPHIR_LT_LONG(index, 0); + if (!(_1)) { + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC | PH_READONLY); + _1 = ZEPHIR_GE(index, &_2); + } + _0 = _1; } - ZEPHIR_INIT_VAR(&_1); - object_init_ex(&_1, tensor_exceptions_invalidargumentexception_ce); - zephir_cast_to_string(&_2, index); - ZEPHIR_INIT_VAR(&_3); - ZEPHIR_CONCAT_SSVS(&_3, "Element not found at", " offset ", &_2, "."); - ZEPHIR_CALL_METHOD(NULL, &_1, "__construct", NULL, 3, &_3); + if (UNEXPECTED(_0)) { + ZEPHIR_INIT_VAR(&_3$$3); + object_init_ex(&_3$$3, tensor_exceptions_invalidargumentexception_ce); + zephir_cast_to_string(&_4$$3, index); + ZEPHIR_INIT_VAR(&_5$$3); + ZEPHIR_CONCAT_SSVS(&_5$$3, "Element not found at", " offset ", &_4$$3, "."); + ZEPHIR_CALL_METHOD(NULL, &_3$$3, "__construct", NULL, 2, &_5$$3); + zephir_check_call_status(); + zephir_throw_exception_debug(&_3$$3, "tensor/vector.zep", 2078); + ZEPHIR_MM_RESTORE(); + return; + } + zephir_read_property_cached(&_6, this_ptr, _zephir_prop_1, 1, PH_NOISY_CC | PH_READONLY); + ZEPHIR_RETURN_CALL_METHOD(&_6, "get", NULL, 0, index); zephir_check_call_status(); - zephir_throw_exception_debug(&_1, "tensor/vector.zep", 2189); - ZEPHIR_MM_RESTORE(); - return; + RETURN_MM(); } /** - * Get an iterator for the rows in the matrix. + * Get an iterator for the items in the vector. * * @return \ArrayIterator */ PHP_METHOD(Tensor_Vector, getIterator) { - zval _0; + zval _0, _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); static zend_string *_zephir_prop_0 = NULL; if (UNEXPECTED(!_zephir_prop_0)) { _zephir_prop_0 = zend_string_init("a", 1, 1); @@ -6918,8 +6259,89 @@ PHP_METHOD(Tensor_Vector, getIterator) object_init_ex(return_value, spl_ce_ArrayIterator); zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 23, &_0); + ZEPHIR_CALL_METHOD(&_1, &_0, "toArray", NULL, 0); + zephir_check_call_status(); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 18, &_1); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return the elements of the vector as a plain PHP array so that only the + * values, and not the object structure, appear in the serialized form. + * + * @return list + */ +PHP_METHOD(Tensor_Vector, __serialize) +{ + zval _0, _1; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("n", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + zephir_create_array(return_value, 2, 0); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "asArray", NULL, 0); zephir_check_call_status(); + zephir_array_update_string(return_value, SL("data"), &_0, PH_COPY | PH_SEPARATE); + zephir_memory_observe(&_1); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 2, PH_NOISY_CC); + zephir_array_update_string(return_value, SL("n"), &_1, PH_COPY | PH_SEPARATE); RETURN_MM(); } +/** + * Restore the vector from the plain array of elements produced by + * __serialize() by rebuilding its TensorBuffer. + * + * @param float[] data + * @throws \Tensor\Exceptions\InvalidArgumentException + */ +PHP_METHOD(Tensor_Vector, __unserialize) +{ + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *data_param = NULL, rebuilt, _0, _1, _2; + zval data; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&data); + ZVAL_UNDEF(&rebuilt); + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("n", 1, 1); + } + + ZEND_PARSE_PARAMETERS_START(1, 1) + ZEPHIR_Z_PARAM_ARRAY(data, data_param) + ZEND_PARSE_PARAMETERS_END(); + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + zephir_fetch_params(1, 1, 0, &data_param); + zephir_get_arrval(&data, data_param); + zephir_array_fetch_string(&_0, &data, SL("data"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2119); + ZVAL_BOOL(&_1, 0); + ZEPHIR_CALL_SELF(&rebuilt, "fromArray", NULL, 0, &_0, &_1); + zephir_check_call_status(); + zephir_read_property_cached(&_1, &rebuilt, _zephir_prop_0, 0, PH_NOISY_CC | PH_READONLY); + zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 1, &_1); + zephir_array_fetch_string(&_2, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2122); + zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 2, &_2); + ZEPHIR_MM_RESTORE(); +} + diff --git a/ext/tensor/vector.zep.h b/ext/tensor/vector.zep.h index 566df68..ebe64fe 100644 --- a/ext/tensor/vector.zep.h +++ b/ext/tensor/vector.zep.h @@ -3,8 +3,6 @@ extern zend_class_entry *tensor_vector_ce; ZEPHIR_INIT_CLASS(Tensor_Vector); -PHP_METHOD(Tensor_Vector, build); -PHP_METHOD(Tensor_Vector, quick); PHP_METHOD(Tensor_Vector, zeros); PHP_METHOD(Tensor_Vector, ones); PHP_METHOD(Tensor_Vector, fill); @@ -14,6 +12,7 @@ PHP_METHOD(Tensor_Vector, poisson); PHP_METHOD(Tensor_Vector, uniform); PHP_METHOD(Tensor_Vector, range); PHP_METHOD(Tensor_Vector, linspace); +PHP_METHOD(Tensor_Vector, fromArray); PHP_METHOD(Tensor_Vector, __construct); PHP_METHOD(Tensor_Vector, shape); PHP_METHOD(Tensor_Vector, shapeString); @@ -21,6 +20,7 @@ PHP_METHOD(Tensor_Vector, size); PHP_METHOD(Tensor_Vector, m); PHP_METHOD(Tensor_Vector, n); PHP_METHOD(Tensor_Vector, asArray); +PHP_METHOD(Tensor_Vector, asTensorBuffer); PHP_METHOD(Tensor_Vector, asRowMatrix); PHP_METHOD(Tensor_Vector, asColumnMatrix); PHP_METHOD(Tensor_Vector, reshape); @@ -68,6 +68,8 @@ PHP_METHOD(Tensor_Vector, sum); PHP_METHOD(Tensor_Vector, product); PHP_METHOD(Tensor_Vector, min); PHP_METHOD(Tensor_Vector, max); +PHP_METHOD(Tensor_Vector, argmin); +PHP_METHOD(Tensor_Vector, argmax); PHP_METHOD(Tensor_Vector, mean); PHP_METHOD(Tensor_Vector, median); PHP_METHOD(Tensor_Vector, quantile); @@ -122,14 +124,8 @@ PHP_METHOD(Tensor_Vector, offsetExists); PHP_METHOD(Tensor_Vector, offsetUnset); PHP_METHOD(Tensor_Vector, offsetGet); PHP_METHOD(Tensor_Vector, getIterator); - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_vector_build, 0, 0, 0) -ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, a, IS_ARRAY, 0, "[]") -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_vector_quick, 0, 0, 0) -ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, a, IS_ARRAY, 0, "[]") -ZEND_END_ARG_INFO() +PHP_METHOD(Tensor_Vector, __serialize); +PHP_METHOD(Tensor_Vector, __unserialize); ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_zeros, 0, 1, Tensor\\Vector, 0) ZEND_ARG_TYPE_INFO(0, n, IS_LONG, 0) @@ -173,11 +169,15 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_linspace, 0, 3, Ten ZEND_ARG_TYPE_INFO(0, n, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_vector___construct, 0, 0, 1) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_fromarray, 0, 1, Tensor\\Vector, 0) ZEND_ARG_ARRAY_INFO(0, a, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, validate, _IS_BOOL, 0, "true") ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_vector___construct, 0, 0, 1) + ZEND_ARG_OBJ_INFO(0, a, Tensor\\TensorBuffer, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_vector_shape, 0, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() @@ -196,6 +196,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_vector_asarray, 0, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_astensorbuffer, 0, 0, Tensor\\TensorBuffer, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_asrowmatrix, 0, 0, Tensor\\Matrix, 0) ZEND_END_ARG_INFO() @@ -362,6 +365,12 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_vector_max, 0, 0, IS_DOUBLE, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_vector_argmin, 0, 0, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_vector_argmax, 0, 0, IS_LONG, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_vector_mean, 0, 0, IS_DOUBLE, 0) ZEND_END_ARG_INFO() @@ -574,9 +583,14 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_getiterator, 0, 0, Traversable, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_vector___serialize, 0, 0, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_vector___unserialize, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, data, 0) +ZEND_END_ARG_INFO() + ZEPHIR_INIT_FUNCS(tensor_vector_method_entry) { - PHP_ME(Tensor_Vector, build, arginfo_tensor_vector_build, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME(Tensor_Vector, quick, arginfo_tensor_vector_quick, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Tensor_Vector, zeros, arginfo_tensor_vector_zeros, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Tensor_Vector, ones, arginfo_tensor_vector_ones, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Tensor_Vector, fill, arginfo_tensor_vector_fill, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) @@ -586,6 +600,7 @@ ZEPHIR_INIT_FUNCS(tensor_vector_method_entry) { PHP_ME(Tensor_Vector, uniform, arginfo_tensor_vector_uniform, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Tensor_Vector, range, arginfo_tensor_vector_range, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Tensor_Vector, linspace, arginfo_tensor_vector_linspace, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(Tensor_Vector, fromArray, arginfo_tensor_vector_fromarray, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(Tensor_Vector, __construct, arginfo_tensor_vector___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_ME(Tensor_Vector, shape, arginfo_tensor_vector_shape, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, shapeString, arginfo_tensor_vector_shapestring, ZEND_ACC_PUBLIC) @@ -593,6 +608,7 @@ ZEPHIR_INIT_FUNCS(tensor_vector_method_entry) { PHP_ME(Tensor_Vector, m, arginfo_tensor_vector_m, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, n, arginfo_tensor_vector_n, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, asArray, arginfo_tensor_vector_asarray, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Vector, asTensorBuffer, arginfo_tensor_vector_astensorbuffer, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, asRowMatrix, arginfo_tensor_vector_asrowmatrix, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, asColumnMatrix, arginfo_tensor_vector_ascolumnmatrix, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, reshape, arginfo_tensor_vector_reshape, ZEND_ACC_PUBLIC) @@ -640,6 +656,8 @@ PHP_ME(Tensor_Vector, transpose, arginfo_tensor_vector_transpose, ZEND_ACC_PUBLI PHP_ME(Tensor_Vector, product, arginfo_tensor_vector_product, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, min, arginfo_tensor_vector_min, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, max, arginfo_tensor_vector_max, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Vector, argmin, arginfo_tensor_vector_argmin, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Vector, argmax, arginfo_tensor_vector_argmax, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, mean, arginfo_tensor_vector_mean, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, median, arginfo_tensor_vector_median, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, quantile, arginfo_tensor_vector_quantile, ZEND_ACC_PUBLIC) @@ -694,5 +712,7 @@ PHP_ME(Tensor_Vector, transpose, arginfo_tensor_vector_transpose, ZEND_ACC_PUBLI PHP_ME(Tensor_Vector, offsetUnset, arginfo_tensor_vector_offsetunset, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, offsetGet, arginfo_tensor_vector_offsetget, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, getIterator, arginfo_tensor_vector_getiterator, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Vector, __serialize, arginfo_tensor_vector___serialize, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Vector, __unserialize, arginfo_tensor_vector___unserialize, ZEND_ACC_PUBLIC) PHP_FE_END }; diff --git a/ext/tensor_ext.c b/ext/tensor_ext.c index e04cba5..7f100a3 100644 --- a/ext/tensor_ext.c +++ b/ext/tensor_ext.c @@ -47,6 +47,7 @@ zend_class_entry *tensor_matrix_ce; zend_class_entry *tensor_reductions_ref_ce; zend_class_entry *tensor_reductions_rref_ce; zend_class_entry *tensor_settings_ce; +zend_class_entry *tensor_tensorbuffer_ce; ZEND_DECLARE_MODULE_GLOBALS(tensor_ext) @@ -54,6 +55,18 @@ PHP_INI_BEGIN() PHP_INI_END() +/** + * Directives whose globals are put back to their php.ini value at the start + * of every request. globals_set() writes the struct member directly, so the + * engine cannot restore it the way it restores an ini_set(); without this the + * value would survive into the next request. Module-scoped globals are + * deliberately absent: they are set up once per process. + */ +static const char *const zephir_request_ini_entries[] = { + + NULL +}; + static PHP_MINIT_FUNCTION(tensor_ext) { REGISTER_INI_ENTRIES(); @@ -81,7 +94,9 @@ static PHP_MINIT_FUNCTION(tensor_ext) ZEPHIR_INIT(Tensor_Reductions_Ref); ZEPHIR_INIT(Tensor_Reductions_Rref); ZEPHIR_INIT(Tensor_Settings); + ZEPHIR_INIT(Tensor_TensorBuffer); openblas_set_num_threads(1); + extern zend_class_entry *tensor_buffer_ce; extern zend_class_entry *zephir_buffer_ce; tensor_buffer_ce = zephir_buffer_ce;; return SUCCESS; } @@ -142,6 +157,7 @@ static PHP_RINIT_FUNCTION(tensor_ext) tensor_ext_globals_ptr = ZEPHIR_VGLOBAL; php_zephir_init_globals(tensor_ext_globals_ptr); + zephir_ini_activate_globals(zephir_request_ini_entries); zephir_initialize_memory(tensor_ext_globals_ptr); diff --git a/ext/tensor_ext.h b/ext/tensor_ext.h index 5919df2..c72baf3 100644 --- a/ext/tensor_ext.h +++ b/ext/tensor_ext.h @@ -27,5 +27,6 @@ #include "tensor/reductions/ref.zep.h" #include "tensor/reductions/rref.zep.h" #include "tensor/settings.zep.h" +#include "tensor/tensorbuffer.zep.h" #endif \ No newline at end of file diff --git a/optimizers/TensorAbsOptimizer.php b/optimizers/TensorAbsOptimizer.php new file mode 100644 index 0000000..c1fd2ab --- /dev/null +++ b/optimizers/TensorAbsOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_abs($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorAcosOptimizer.php b/optimizers/TensorAcosOptimizer.php new file mode 100644 index 0000000..94bcaa4 --- /dev/null +++ b/optimizers/TensorAcosOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_acos($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorAddColOptimizer.php b/optimizers/TensorAddColOptimizer.php new file mode 100644 index 0000000..01d5d28 --- /dev/null +++ b/optimizers/TensorAddColOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_add_col($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorAddRowOptimizer.php b/optimizers/TensorAddRowOptimizer.php new file mode 100644 index 0000000..510bcf6 --- /dev/null +++ b/optimizers/TensorAddRowOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_add_row($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorAsinOptimizer.php b/optimizers/TensorAsinOptimizer.php new file mode 100644 index 0000000..550e7de --- /dev/null +++ b/optimizers/TensorAsinOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_asin($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorAtanOptimizer.php b/optimizers/TensorAtanOptimizer.php new file mode 100644 index 0000000..4beccfb --- /dev/null +++ b/optimizers/TensorAtanOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_atan($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorBufferConcatOptimizer.php b/optimizers/TensorBufferConcatOptimizer.php new file mode 100644 index 0000000..f6c5b09 --- /dev/null +++ b/optimizers/TensorBufferConcatOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/buffer', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_buffer_concat($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorBufferFromArrayOptimizer.php b/optimizers/TensorBufferFromArrayOptimizer.php new file mode 100644 index 0000000..e64917a --- /dev/null +++ b/optimizers/TensorBufferFromArrayOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/buffer', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_buffer_from_array($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorBufferRepeatOptimizer.php b/optimizers/TensorBufferRepeatOptimizer.php new file mode 100644 index 0000000..b0c8fad --- /dev/null +++ b/optimizers/TensorBufferRepeatOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/buffer', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_buffer_repeat($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorBufferSliceOptimizer.php b/optimizers/TensorBufferSliceOptimizer.php new file mode 100644 index 0000000..c379f87 --- /dev/null +++ b/optimizers/TensorBufferSliceOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/buffer', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_buffer_slice($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorBufferSliceStridedOptimizer.php b/optimizers/TensorBufferSliceStridedOptimizer.php new file mode 100644 index 0000000..ecfaf2e --- /dev/null +++ b/optimizers/TensorBufferSliceStridedOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/buffer', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_buffer_slice_strided($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]}, {$resolvedParams[3]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorBufferSortOptimizer.php b/optimizers/TensorBufferSortOptimizer.php new file mode 100644 index 0000000..b374183 --- /dev/null +++ b/optimizers/TensorBufferSortOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/buffer', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_buffer_sort($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorBufferSplitOptimizer.php b/optimizers/TensorBufferSplitOptimizer.php new file mode 100644 index 0000000..ccc87dd --- /dev/null +++ b/optimizers/TensorBufferSplitOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/buffer', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_buffer_split($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorCeilOptimizer.php b/optimizers/TensorCeilOptimizer.php new file mode 100644 index 0000000..5cd859b --- /dev/null +++ b/optimizers/TensorCeilOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_ceil($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorCholeskyOptimizer.php b/optimizers/TensorCholeskyOptimizer.php index e5e237a..c3a8270 100644 --- a/optimizers/TensorCholeskyOptimizer.php +++ b/optimizers/TensorCholeskyOptimizer.php @@ -24,9 +24,9 @@ public function optimize(array $expression, Call $call, CompilationContext $cont return false; } - if (count($expression['parameters']) !== 1) { + if (count($expression['parameters']) !== 2) { throw new CompilerException( - 'Cholesky accepts exactly one argument, ' . count($expression['parameters']) . 'given.', + 'Cholesky accepts exactly two arguments, ' . count($expression['parameters']) . 'given.', $expression ); } @@ -64,7 +64,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont $symbol = $context->backend->getVariableCode($symbolVariable); $context->codePrinter->output( - "tensor_cholesky($symbol, {$resolvedParams[0]});" + "tensor_cholesky($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" ); return new CompiledExpression( diff --git a/optimizers/TensorClipLowerOptimizer.php b/optimizers/TensorClipLowerOptimizer.php new file mode 100644 index 0000000..6effc03 --- /dev/null +++ b/optimizers/TensorClipLowerOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_clip_lower($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorClipOptimizer.php b/optimizers/TensorClipOptimizer.php new file mode 100644 index 0000000..68e5283 --- /dev/null +++ b/optimizers/TensorClipOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_clip($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorClipUpperOptimizer.php b/optimizers/TensorClipUpperOptimizer.php new file mode 100644 index 0000000..fae1caa --- /dev/null +++ b/optimizers/TensorClipUpperOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_clip_upper($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorConvolve2dOptimizer.php b/optimizers/TensorConvolve2dOptimizer.php index 1a63d06..2dc938b 100644 --- a/optimizers/TensorConvolve2dOptimizer.php +++ b/optimizers/TensorConvolve2dOptimizer.php @@ -24,9 +24,9 @@ public function optimize(array $expression, Call $call, CompilationContext $cont return false; } - if (count($expression['parameters']) !== 3) { + if (count($expression['parameters']) !== 7) { throw new CompilerException( - 'Convolve 1D accepts exactly three arguments, ' . count($expression['parameters']) . 'given.', + 'Convolve 2D accepts exactly seven arguments, ' . count($expression['parameters']) . 'given.', $expression ); } @@ -64,7 +64,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont $symbol = $context->backend->getVariableCode($symbolVariable); $context->codePrinter->output( - "tensor_convolve_2d($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + "tensor_convolve_2d($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]}, {$resolvedParams[3]}, {$resolvedParams[4]}, {$resolvedParams[5]}, {$resolvedParams[6]});" ); return new CompiledExpression( diff --git a/optimizers/TensorCosOptimizer.php b/optimizers/TensorCosOptimizer.php new file mode 100644 index 0000000..4eee563 --- /dev/null +++ b/optimizers/TensorCosOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_cos($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorCovarianceOptimizer.php b/optimizers/TensorCovarianceOptimizer.php new file mode 100644 index 0000000..82f7e75 --- /dev/null +++ b/optimizers/TensorCovarianceOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/linear_algebra', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_covariance($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorCovarianceWithMeanOptimizer.php b/optimizers/TensorCovarianceWithMeanOptimizer.php new file mode 100644 index 0000000..ec2a873 --- /dev/null +++ b/optimizers/TensorCovarianceWithMeanOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/linear_algebra', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_covariance_with_mean($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]}, {$resolvedParams[3]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorDeg2radOptimizer.php b/optimizers/TensorDeg2radOptimizer.php new file mode 100644 index 0000000..6eae1ef --- /dev/null +++ b/optimizers/TensorDeg2radOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_deg2rad($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorDivideColOptimizer.php b/optimizers/TensorDivideColOptimizer.php new file mode 100644 index 0000000..c63e47d --- /dev/null +++ b/optimizers/TensorDivideColOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_divide_col($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorDivideColReverseOptimizer.php b/optimizers/TensorDivideColReverseOptimizer.php new file mode 100644 index 0000000..e3f2660 --- /dev/null +++ b/optimizers/TensorDivideColReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_divide_col_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorDivideRowOptimizer.php b/optimizers/TensorDivideRowOptimizer.php new file mode 100644 index 0000000..329462c --- /dev/null +++ b/optimizers/TensorDivideRowOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_divide_row($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorDivideRowReverseOptimizer.php b/optimizers/TensorDivideRowReverseOptimizer.php new file mode 100644 index 0000000..db3d290 --- /dev/null +++ b/optimizers/TensorDivideRowReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_divide_row_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorEigOptimizer.php b/optimizers/TensorEigOptimizer.php index ce41d01..6965554 100644 --- a/optimizers/TensorEigOptimizer.php +++ b/optimizers/TensorEigOptimizer.php @@ -24,9 +24,9 @@ public function optimize(array $expression, Call $call, CompilationContext $cont return false; } - if (count($expression['parameters']) !== 1) { + if (count($expression['parameters']) !== 2) { throw new CompilerException( - 'Eig accepts exactly one argument, ' . count($expression['parameters']) . 'given.', + 'Eig accepts exactly two arguments, ' . count($expression['parameters']) . 'given.', $expression ); } @@ -64,7 +64,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont $symbol = $context->backend->getVariableCode($symbolVariable); $context->codePrinter->output( - "tensor_eig($symbol, {$resolvedParams[0]});" + "tensor_eig($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" ); return new CompiledExpression( diff --git a/optimizers/TensorEigSymmetricOptimizer.php b/optimizers/TensorEigSymmetricOptimizer.php index 1f9d970..e1f770d 100644 --- a/optimizers/TensorEigSymmetricOptimizer.php +++ b/optimizers/TensorEigSymmetricOptimizer.php @@ -24,9 +24,9 @@ public function optimize(array $expression, Call $call, CompilationContext $cont return false; } - if (count($expression['parameters']) !== 1) { + if (count($expression['parameters']) !== 2) { throw new CompilerException( - 'Eig symmetric accepts exactly one argument, ' . count($expression['parameters']) . 'given.', + 'Eig symmetric accepts exactly two arguments, ' . count($expression['parameters']) . 'given.', $expression ); } @@ -64,7 +64,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont $symbol = $context->backend->getVariableCode($symbolVariable); $context->codePrinter->output( - "tensor_eig_symmetric($symbol, {$resolvedParams[0]});" + "tensor_eig_symmetric($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" ); return new CompiledExpression( diff --git a/optimizers/TensorEqualColOptimizer.php b/optimizers/TensorEqualColOptimizer.php new file mode 100644 index 0000000..2f2aee7 --- /dev/null +++ b/optimizers/TensorEqualColOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_equal_col($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorEqualRowOptimizer.php b/optimizers/TensorEqualRowOptimizer.php new file mode 100644 index 0000000..7086326 --- /dev/null +++ b/optimizers/TensorEqualRowOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_equal_row($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorExpOptimizer.php b/optimizers/TensorExpOptimizer.php new file mode 100644 index 0000000..de3e7d7 --- /dev/null +++ b/optimizers/TensorExpOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_exp($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorExpm1Optimizer.php b/optimizers/TensorExpm1Optimizer.php new file mode 100644 index 0000000..c3e26d5 --- /dev/null +++ b/optimizers/TensorExpm1Optimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_expm1($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorFloorOptimizer.php b/optimizers/TensorFloorOptimizer.php new file mode 100644 index 0000000..53307e5 --- /dev/null +++ b/optimizers/TensorFloorOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_floor($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorGreaterColOptimizer.php b/optimizers/TensorGreaterColOptimizer.php new file mode 100644 index 0000000..5fad60a --- /dev/null +++ b/optimizers/TensorGreaterColOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_greater_col($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorGreaterColReverseOptimizer.php b/optimizers/TensorGreaterColReverseOptimizer.php new file mode 100644 index 0000000..8184338 --- /dev/null +++ b/optimizers/TensorGreaterColReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_greater_col_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorGreaterEqualColOptimizer.php b/optimizers/TensorGreaterEqualColOptimizer.php new file mode 100644 index 0000000..0c1fa78 --- /dev/null +++ b/optimizers/TensorGreaterEqualColOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_greater_equal_col($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorGreaterEqualColReverseOptimizer.php b/optimizers/TensorGreaterEqualColReverseOptimizer.php new file mode 100644 index 0000000..ddc1b09 --- /dev/null +++ b/optimizers/TensorGreaterEqualColReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_greater_equal_col_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorGreaterEqualRowOptimizer.php b/optimizers/TensorGreaterEqualRowOptimizer.php new file mode 100644 index 0000000..8428194 --- /dev/null +++ b/optimizers/TensorGreaterEqualRowOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_greater_equal_row($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorGreaterEqualRowReverseOptimizer.php b/optimizers/TensorGreaterEqualRowReverseOptimizer.php new file mode 100644 index 0000000..8bf5e48 --- /dev/null +++ b/optimizers/TensorGreaterEqualRowReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_greater_equal_row_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorGreaterRowOptimizer.php b/optimizers/TensorGreaterRowOptimizer.php new file mode 100644 index 0000000..9a9a458 --- /dev/null +++ b/optimizers/TensorGreaterRowOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_greater_row($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorGreaterRowReverseOptimizer.php b/optimizers/TensorGreaterRowReverseOptimizer.php new file mode 100644 index 0000000..5006a52 --- /dev/null +++ b/optimizers/TensorGreaterRowReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_greater_row_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorInfNormOptimizer.php b/optimizers/TensorInfNormOptimizer.php new file mode 100644 index 0000000..9fc5ba6 --- /dev/null +++ b/optimizers/TensorInfNormOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_inf_norm($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorInverseOptimizer.php b/optimizers/TensorInverseOptimizer.php index 39dd7c0..d63eea7 100644 --- a/optimizers/TensorInverseOptimizer.php +++ b/optimizers/TensorInverseOptimizer.php @@ -24,9 +24,9 @@ public function optimize(array $expression, Call $call, CompilationContext $cont return false; } - if (count($expression['parameters']) !== 1) { + if (count($expression['parameters']) !== 2) { throw new CompilerException( - 'Inverse accepts exactly one argument, ' . count($expression['parameters']) . 'given.', + 'Inverse accepts exactly two arguments, ' . count($expression['parameters']) . 'given.', $expression ); } @@ -64,7 +64,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont $symbol = $context->backend->getVariableCode($symbolVariable); $context->codePrinter->output( - "tensor_inverse($symbol, {$resolvedParams[0]});" + "tensor_inverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" ); return new CompiledExpression( diff --git a/optimizers/TensorIsSymmetricOptimizer.php b/optimizers/TensorIsSymmetricOptimizer.php new file mode 100644 index 0000000..b8c5086 --- /dev/null +++ b/optimizers/TensorIsSymmetricOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/linear_algebra', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_is_symmetric($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorLessColOptimizer.php b/optimizers/TensorLessColOptimizer.php new file mode 100644 index 0000000..67fb35d --- /dev/null +++ b/optimizers/TensorLessColOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_less_col($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorLessColReverseOptimizer.php b/optimizers/TensorLessColReverseOptimizer.php new file mode 100644 index 0000000..268e988 --- /dev/null +++ b/optimizers/TensorLessColReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_less_col_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorLessEqualColOptimizer.php b/optimizers/TensorLessEqualColOptimizer.php new file mode 100644 index 0000000..f4334e5 --- /dev/null +++ b/optimizers/TensorLessEqualColOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_less_equal_col($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorLessEqualColReverseOptimizer.php b/optimizers/TensorLessEqualColReverseOptimizer.php new file mode 100644 index 0000000..e596805 --- /dev/null +++ b/optimizers/TensorLessEqualColReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_less_equal_col_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorLessEqualRowOptimizer.php b/optimizers/TensorLessEqualRowOptimizer.php new file mode 100644 index 0000000..d27cfee --- /dev/null +++ b/optimizers/TensorLessEqualRowOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_less_equal_row($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorLessEqualRowReverseOptimizer.php b/optimizers/TensorLessEqualRowReverseOptimizer.php new file mode 100644 index 0000000..71e36f7 --- /dev/null +++ b/optimizers/TensorLessEqualRowReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_less_equal_row_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorLessRowOptimizer.php b/optimizers/TensorLessRowOptimizer.php new file mode 100644 index 0000000..101d6dd --- /dev/null +++ b/optimizers/TensorLessRowOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_less_row($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorLessRowReverseOptimizer.php b/optimizers/TensorLessRowReverseOptimizer.php new file mode 100644 index 0000000..ca2f45a --- /dev/null +++ b/optimizers/TensorLessRowReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_less_row_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorLog1pOptimizer.php b/optimizers/TensorLog1pOptimizer.php new file mode 100644 index 0000000..a8dfa8d --- /dev/null +++ b/optimizers/TensorLog1pOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_log1p($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorLogBaseOptimizer.php b/optimizers/TensorLogBaseOptimizer.php new file mode 100644 index 0000000..ce150bd --- /dev/null +++ b/optimizers/TensorLogBaseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_log_base($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorLogOptimizer.php b/optimizers/TensorLogOptimizer.php new file mode 100644 index 0000000..4377415 --- /dev/null +++ b/optimizers/TensorLogOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_log($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorLuOptimizer.php b/optimizers/TensorLuOptimizer.php index 762720e..6559bf8 100644 --- a/optimizers/TensorLuOptimizer.php +++ b/optimizers/TensorLuOptimizer.php @@ -24,9 +24,9 @@ public function optimize(array $expression, Call $call, CompilationContext $cont return false; } - if (count($expression['parameters']) !== 1) { + if (count($expression['parameters']) !== 2) { throw new CompilerException( - 'Lu accepts exactly one argument, ' . count($expression['parameters']) . 'given.', + 'Lu accepts exactly two arguments, ' . count($expression['parameters']) . 'given.', $expression ); } @@ -64,7 +64,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont $symbol = $context->backend->getVariableCode($symbolVariable); $context->codePrinter->output( - "tensor_lu($symbol, {$resolvedParams[0]});" + "tensor_lu($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" ); return new CompiledExpression( diff --git a/optimizers/TensorMatL1NormOptimizer.php b/optimizers/TensorMatL1NormOptimizer.php new file mode 100644 index 0000000..bbe0a7e --- /dev/null +++ b/optimizers/TensorMatL1NormOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_mat_l1_norm($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorMatL2NormOptimizer.php b/optimizers/TensorMatL2NormOptimizer.php new file mode 100644 index 0000000..0f2f006 --- /dev/null +++ b/optimizers/TensorMatL2NormOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_mat_l2_norm($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorMatMaxNormOptimizer.php b/optimizers/TensorMatMaxNormOptimizer.php new file mode 100644 index 0000000..1cbc41d --- /dev/null +++ b/optimizers/TensorMatMaxNormOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_mat_max_norm($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorMatmulOptimizer.php b/optimizers/TensorMatmulOptimizer.php index 64a84e7..7d433e6 100644 --- a/optimizers/TensorMatmulOptimizer.php +++ b/optimizers/TensorMatmulOptimizer.php @@ -24,9 +24,9 @@ public function optimize(array $expression, Call $call, CompilationContext $cont return false; } - if (count($expression['parameters']) !== 2) { + if (count($expression['parameters']) !== 5) { throw new CompilerException( - 'Dot accepts exactly two arguments, ' . count($expression['parameters']) . 'given.', + 'Matmul accepts exactly five arguments, ' . count($expression['parameters']) . 'given.', $expression ); } @@ -64,7 +64,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont $symbol = $context->backend->getVariableCode($symbolVariable); $context->codePrinter->output( - "tensor_matmul($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + "tensor_matmul($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]}, {$resolvedParams[3]}, {$resolvedParams[4]});" ); return new CompiledExpression( diff --git a/optimizers/TensorMatrixDotOptimizer.php b/optimizers/TensorMatrixDotOptimizer.php new file mode 100644 index 0000000..9d1ca25 --- /dev/null +++ b/optimizers/TensorMatrixDotOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/linear_algebra', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_matrix_dot($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]}, {$resolvedParams[3]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorMatrixMeanOptimizer.php b/optimizers/TensorMatrixMeanOptimizer.php new file mode 100644 index 0000000..63f2206 --- /dev/null +++ b/optimizers/TensorMatrixMeanOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_matrix_mean($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorMatrixRepeatOptimizer.php b/optimizers/TensorMatrixRepeatOptimizer.php new file mode 100644 index 0000000..6391538 --- /dev/null +++ b/optimizers/TensorMatrixRepeatOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_matrix_repeat($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]}, {$resolvedParams[3]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorMatrixToArrayOptimizer.php b/optimizers/TensorMatrixToArrayOptimizer.php new file mode 100644 index 0000000..fef4b82 --- /dev/null +++ b/optimizers/TensorMatrixToArrayOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_matrix_to_array($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorMatrixTransposeOptimizer.php b/optimizers/TensorMatrixTransposeOptimizer.php new file mode 100644 index 0000000..86a962c --- /dev/null +++ b/optimizers/TensorMatrixTransposeOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/shape', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_matrix_transpose($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorMatrixVarianceOptimizer.php b/optimizers/TensorMatrixVarianceOptimizer.php new file mode 100644 index 0000000..76cd19b --- /dev/null +++ b/optimizers/TensorMatrixVarianceOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_matrix_variance($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorMatrixVarianceWithMeanOptimizer.php b/optimizers/TensorMatrixVarianceWithMeanOptimizer.php new file mode 100644 index 0000000..358fb67 --- /dev/null +++ b/optimizers/TensorMatrixVarianceWithMeanOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_matrix_variance_with_mean($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]}, {$resolvedParams[3]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorMedianOptimizer.php b/optimizers/TensorMedianOptimizer.php new file mode 100644 index 0000000..849f852 --- /dev/null +++ b/optimizers/TensorMedianOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_median($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorModColOptimizer.php b/optimizers/TensorModColOptimizer.php new file mode 100644 index 0000000..c69e61f --- /dev/null +++ b/optimizers/TensorModColOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_mod_col($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorModColReverseOptimizer.php b/optimizers/TensorModColReverseOptimizer.php new file mode 100644 index 0000000..4c83adc --- /dev/null +++ b/optimizers/TensorModColReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_mod_col_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorModRowOptimizer.php b/optimizers/TensorModRowOptimizer.php new file mode 100644 index 0000000..f2f5247 --- /dev/null +++ b/optimizers/TensorModRowOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_mod_row($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorModRowReverseOptimizer.php b/optimizers/TensorModRowReverseOptimizer.php new file mode 100644 index 0000000..44ea67d --- /dev/null +++ b/optimizers/TensorModRowReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_mod_row_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorMultiplyColOptimizer.php b/optimizers/TensorMultiplyColOptimizer.php new file mode 100644 index 0000000..55bc247 --- /dev/null +++ b/optimizers/TensorMultiplyColOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_multiply_col($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorMultiplyRowOptimizer.php b/optimizers/TensorMultiplyRowOptimizer.php new file mode 100644 index 0000000..8a81d91 --- /dev/null +++ b/optimizers/TensorMultiplyRowOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_multiply_row($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorNegateOptimizer.php b/optimizers/TensorNegateOptimizer.php new file mode 100644 index 0000000..a9b92b8 --- /dev/null +++ b/optimizers/TensorNegateOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_negate($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorNotEqualColOptimizer.php b/optimizers/TensorNotEqualColOptimizer.php new file mode 100644 index 0000000..c2fdcbd --- /dev/null +++ b/optimizers/TensorNotEqualColOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_not_equal_col($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorNotEqualRowOptimizer.php b/optimizers/TensorNotEqualRowOptimizer.php new file mode 100644 index 0000000..0533dad --- /dev/null +++ b/optimizers/TensorNotEqualRowOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/comparison', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_not_equal_row($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorOuterOptimizer.php b/optimizers/TensorOuterOptimizer.php new file mode 100644 index 0000000..a6d66dd --- /dev/null +++ b/optimizers/TensorOuterOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/linear_algebra', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_outer($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]}, {$resolvedParams[3]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorPNormOptimizer.php b/optimizers/TensorPNormOptimizer.php new file mode 100644 index 0000000..95ddbe9 --- /dev/null +++ b/optimizers/TensorPNormOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_p_norm($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorPowColOptimizer.php b/optimizers/TensorPowColOptimizer.php new file mode 100644 index 0000000..070a342 --- /dev/null +++ b/optimizers/TensorPowColOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_pow_col($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorPowColReverseOptimizer.php b/optimizers/TensorPowColReverseOptimizer.php new file mode 100644 index 0000000..95eb163 --- /dev/null +++ b/optimizers/TensorPowColReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_pow_col_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorPowRowOptimizer.php b/optimizers/TensorPowRowOptimizer.php new file mode 100644 index 0000000..bb341b1 --- /dev/null +++ b/optimizers/TensorPowRowOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_pow_row($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorPowRowReverseOptimizer.php b/optimizers/TensorPowRowReverseOptimizer.php new file mode 100644 index 0000000..b2bd104 --- /dev/null +++ b/optimizers/TensorPowRowReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_pow_row_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorPseudoinverseOptimizer.php b/optimizers/TensorPseudoinverseOptimizer.php index 8f9b7f6..03b2dfb 100644 --- a/optimizers/TensorPseudoinverseOptimizer.php +++ b/optimizers/TensorPseudoinverseOptimizer.php @@ -24,9 +24,9 @@ public function optimize(array $expression, Call $call, CompilationContext $cont return false; } - if (count($expression['parameters']) !== 1) { + if (count($expression['parameters']) !== 3) { throw new CompilerException( - 'Pseudo inverse accepts exactly one argument, ' . count($expression['parameters']) . 'given.', + 'Pseudo inverse accepts exactly three arguments, ' . count($expression['parameters']) . 'given.', $expression ); } @@ -64,7 +64,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont $symbol = $context->backend->getVariableCode($symbolVariable); $context->codePrinter->output( - "tensor_pseudoinverse($symbol, {$resolvedParams[0]});" + "tensor_pseudoinverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" ); return new CompiledExpression( diff --git a/optimizers/TensorQuantileOptimizer.php b/optimizers/TensorQuantileOptimizer.php new file mode 100644 index 0000000..0c36863 --- /dev/null +++ b/optimizers/TensorQuantileOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_quantile($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorRad2degOptimizer.php b/optimizers/TensorRad2degOptimizer.php new file mode 100644 index 0000000..5eb8c0f --- /dev/null +++ b/optimizers/TensorRad2degOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_rad2deg($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorRankOptimizer.php b/optimizers/TensorRankOptimizer.php new file mode 100644 index 0000000..dce61f4 --- /dev/null +++ b/optimizers/TensorRankOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/linear_algebra', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_rank($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorReciprocalOptimizer.php b/optimizers/TensorReciprocalOptimizer.php new file mode 100644 index 0000000..a8c8a99 --- /dev/null +++ b/optimizers/TensorReciprocalOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_reciprocal($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorReduceArgmaxOptimizer.php b/optimizers/TensorReduceArgmaxOptimizer.php new file mode 100644 index 0000000..d8dacce --- /dev/null +++ b/optimizers/TensorReduceArgmaxOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_reduce_argmax($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorReduceArgminOptimizer.php b/optimizers/TensorReduceArgminOptimizer.php new file mode 100644 index 0000000..07c0e2f --- /dev/null +++ b/optimizers/TensorReduceArgminOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_reduce_argmin($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorReduceMaxOptimizer.php b/optimizers/TensorReduceMaxOptimizer.php new file mode 100644 index 0000000..6f0976a --- /dev/null +++ b/optimizers/TensorReduceMaxOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_reduce_max($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorReduceMinOptimizer.php b/optimizers/TensorReduceMinOptimizer.php new file mode 100644 index 0000000..8beb832 --- /dev/null +++ b/optimizers/TensorReduceMinOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_reduce_min($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorReduceProductOptimizer.php b/optimizers/TensorReduceProductOptimizer.php new file mode 100644 index 0000000..86398d0 --- /dev/null +++ b/optimizers/TensorReduceProductOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_reduce_product($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorReduceSumOptimizer.php b/optimizers/TensorReduceSumOptimizer.php new file mode 100644 index 0000000..01db3ad --- /dev/null +++ b/optimizers/TensorReduceSumOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_reduce_sum($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorRefOptimizer.php b/optimizers/TensorRefOptimizer.php index 7fddde5..372fa13 100644 --- a/optimizers/TensorRefOptimizer.php +++ b/optimizers/TensorRefOptimizer.php @@ -24,9 +24,9 @@ public function optimize(array $expression, Call $call, CompilationContext $cont return false; } - if (count($expression['parameters']) !== 1) { + if (count($expression['parameters']) !== 3) { throw new CompilerException( - 'REF accepts exactly one argument, ' . count($expression['parameters']) . 'given.', + 'REF accepts exactly three arguments, ' . count($expression['parameters']) . 'given.', $expression ); } @@ -64,7 +64,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont $symbol = $context->backend->getVariableCode($symbolVariable); $context->codePrinter->output( - "tensor_ref($symbol, {$resolvedParams[0]});" + "tensor_ref($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" ); return new CompiledExpression( diff --git a/optimizers/TensorRoundOptimizer.php b/optimizers/TensorRoundOptimizer.php new file mode 100644 index 0000000..d2c2e22 --- /dev/null +++ b/optimizers/TensorRoundOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_round($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorRrefOptimizer.php b/optimizers/TensorRrefOptimizer.php new file mode 100644 index 0000000..9001dbc --- /dev/null +++ b/optimizers/TensorRrefOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/linear_algebra', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_rref($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorSignOptimizer.php b/optimizers/TensorSignOptimizer.php new file mode 100644 index 0000000..852c3ba --- /dev/null +++ b/optimizers/TensorSignOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_sign($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorSinOptimizer.php b/optimizers/TensorSinOptimizer.php new file mode 100644 index 0000000..ec3f2e3 --- /dev/null +++ b/optimizers/TensorSinOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_sin($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorSqrtOptimizer.php b/optimizers/TensorSqrtOptimizer.php new file mode 100644 index 0000000..7c161a6 --- /dev/null +++ b/optimizers/TensorSqrtOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_sqrt($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorSubtractColOptimizer.php b/optimizers/TensorSubtractColOptimizer.php new file mode 100644 index 0000000..c745b34 --- /dev/null +++ b/optimizers/TensorSubtractColOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_subtract_col($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorSubtractColReverseOptimizer.php b/optimizers/TensorSubtractColReverseOptimizer.php new file mode 100644 index 0000000..39207a4 --- /dev/null +++ b/optimizers/TensorSubtractColReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_subtract_col_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorSubtractRowOptimizer.php b/optimizers/TensorSubtractRowOptimizer.php new file mode 100644 index 0000000..5bb785b --- /dev/null +++ b/optimizers/TensorSubtractRowOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_subtract_row($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorSubtractRowReverseOptimizer.php b/optimizers/TensorSubtractRowReverseOptimizer.php new file mode 100644 index 0000000..06b35bf --- /dev/null +++ b/optimizers/TensorSubtractRowReverseOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/arithmetic', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_subtract_row_reverse($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorSvdOptimizer.php b/optimizers/TensorSvdOptimizer.php index 3dd8529..ebde30e 100644 --- a/optimizers/TensorSvdOptimizer.php +++ b/optimizers/TensorSvdOptimizer.php @@ -24,9 +24,9 @@ public function optimize(array $expression, Call $call, CompilationContext $cont return false; } - if (count($expression['parameters']) !== 1) { + if (count($expression['parameters']) !== 3) { throw new CompilerException( - 'SVD accepts exactly one argument, ' . count($expression['parameters']) . 'given.', + 'SVD accepts exactly three arguments, ' . count($expression['parameters']) . 'given.', $expression ); } @@ -64,7 +64,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont $symbol = $context->backend->getVariableCode($symbolVariable); $context->codePrinter->output( - "tensor_svd($symbol, {$resolvedParams[0]});" + "tensor_svd($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" ); return new CompiledExpression( diff --git a/optimizers/TensorTanOptimizer.php b/optimizers/TensorTanOptimizer.php new file mode 100644 index 0000000..db24ab1 --- /dev/null +++ b/optimizers/TensorTanOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_tan($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorVecL1NormOptimizer.php b/optimizers/TensorVecL1NormOptimizer.php new file mode 100644 index 0000000..48b8c46 --- /dev/null +++ b/optimizers/TensorVecL1NormOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_vec_l1_norm($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorVecL2NormOptimizer.php b/optimizers/TensorVecL2NormOptimizer.php new file mode 100644 index 0000000..cb12588 --- /dev/null +++ b/optimizers/TensorVecL2NormOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_vec_l2_norm($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorVecMaxNormOptimizer.php b/optimizers/TensorVecMaxNormOptimizer.php new file mode 100644 index 0000000..039883d --- /dev/null +++ b/optimizers/TensorVecMaxNormOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_vec_max_norm($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorVecMeanOptimizer.php b/optimizers/TensorVecMeanOptimizer.php new file mode 100644 index 0000000..a7147a7 --- /dev/null +++ b/optimizers/TensorVecMeanOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_vec_mean($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorVecVarianceOptimizer.php b/optimizers/TensorVecVarianceOptimizer.php new file mode 100644 index 0000000..f19cd66 --- /dev/null +++ b/optimizers/TensorVecVarianceOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_vec_variance($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorVecVarianceWithMeanOptimizer.php b/optimizers/TensorVecVarianceWithMeanOptimizer.php new file mode 100644 index 0000000..58ad40c --- /dev/null +++ b/optimizers/TensorVecVarianceWithMeanOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/reductions', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_vec_variance_with_mean($symbol, {$resolvedParams[0]}, {$resolvedParams[1]}, {$resolvedParams[2]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/phpstan.neon b/phpstan.neon deleted file mode 100644 index 7b2d639..0000000 --- a/phpstan.neon +++ /dev/null @@ -1,5 +0,0 @@ -parameters: - level: 8 - paths: - - 'tests' - - 'benchmarks' diff --git a/phpunit.xml b/phpunit.xml index 55f90f6..b20fb1b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,5 @@ - + tests diff --git a/scripts/compare-serialization.php b/scripts/compare-serialization.php new file mode 100755 index 0000000..3e7aa13 --- /dev/null +++ b/scripts/compare-serialization.php @@ -0,0 +1,265 @@ +#!/usr/bin/env php + Buffer -> TensorBuffer -> Vector / ColumnVector / Matrix + * + * For every representation the script reports: + * - byte size of serialize() (and ratio vs the plain-array baseline) + * - structure: class, own properties with their visibility, __serialize presence + * - round-trip fidelity: unserialize -> class survived -> values match + * + * It then sweeps array size to separate the fixed wrapper overhead from the + * per-element cost, and exercises the empty-buffer edge case. + * + * Usage: + * php scripts/compare-serialization.php + * + * The `tensor` extension must be loaded. If it is not, the exact command to + * load a locally built shared object is printed. + */ +if (!class_exists('\Tensor\Vector')) { + fwrite(STDERR, "The 'tensor' extension is not loaded.\n"); + + $localSo = __DIR__ . '/../ext/modules/tensor.so'; + + if (file_exists($localSo)) { + fwrite( + STDERR, + "Try again with:\n" . + ' php -n -d extension=' . $localSo . ' ' . __FILE__ . "\n" + ); + } + + exit(1); +} + +echo 'PHP ' . phpversion() . ' | ', "\n"; +$extName = extension_loaded('tensor') ? 'tensor' : 'tensor_ext'; +echo 'extension: ', $extName, "\n\n"; + +/* + * The canonical payload: the same four doubles reused at every layer so that + * only representation overhead varies, never the data. + */ +$elements = [1.5, -2.25, 3.0, 4.75]; +$matrixRows = [ + [1.5, -2.25], + [3.0, 4.75], +]; + +$maxDelta = 1e-8; + +/** + * The own properties of an object, with their visibility. + * + * @param object $subject + * + * @return array + */ +function ownProperties(object $subject) : array +{ + $reflection = new ReflectionObject($subject); + + $properties = []; + + foreach ($reflection->getProperties() as $property) { + if ($property->isStatic()) { + continue; + } + + $visibility = $property->isPrivate() + ? 'private' + : ($property->isProtected() ? 'protected' : 'public'); + + $properties[] = ['name' => $property->getName(), 'visibility' => $visibility]; + } + + return $properties; +} + +function declaresSerialize(object $subject) : bool +{ + return $subject instanceof Tensor\Buffer || method_exists($subject, '__serialize'); +} + +/** + * Extract the element values from a tensor or plain array, for round-trip checks. + * + * @param object|array|array> $subject + * + * @return array + */ +function elementValues($subject) : array +{ + if (is_array($subject)) { + return $subject; + } + + if (method_exists($subject, 'toArray')) { + return $subject->toArray(); + } + + if (method_exists($subject, 'asArray')) { + return $subject->asArray(); + } + + throw new LogicException('Unable to read values from ' . get_class($subject)); +} + +function valuesEqual(array $a, array $b, float $delta) : bool +{ + $a = array_map('floatval', array_values($a)); + $b = array_map('floatval', array_values($b)); + + $count = count($a); + + if ($count !== count($b)) { + return false; + } + + for ($i = 0; $i < $count; ++$i) { + if (abs($a[$i] - $b[$i]) > $delta) { + return false; + } + } + + return true; +} + +/** + * @param object|array $subject + * @param float $maxDelta + * @return array{class: string, ok: bool} + */ +function roundTrip($subject, float $maxDelta) : array +{ + $originalClass = is_object($subject) ? get_class($subject) : 'array'; + $expected = elementValues($subject); + + $deserialized = unserialize(serialize($subject)); + + $newClass = is_object($deserialized) ? get_class($deserialized) : 'array'; + + return [ + 'class' => $newClass, + 'ok' => $newClass === $originalClass && valuesEqual(elementValues($deserialized), $expected, $maxDelta), + ]; +} + +function bytes($payload) : int +{ + return strlen(serialize($payload)); +} + +echo "=== A. Size, structure and round-trip ===\n\n"; + +$representations = [ + 'array (baseline)' => fn () => $elements, + 'Buffer::fromArray()' => fn () => Tensor\Buffer::fromArray($elements), + 'new TensorBuffer()' => fn () => new Tensor\TensorBuffer(Tensor\Buffer::fromArray($elements)), + 'Vector::fromArray()' => fn () => Tensor\Vector::fromArray($elements), + 'ColumnVector::fromArray()' => fn () => Tensor\ColumnVector::fromArray($elements), + 'Matrix::fromArray() 2x2' => fn () => Tensor\Matrix::fromArray($matrixRows), +]; + +$arrayBytes = bytes($elements); + +foreach ($representations as $label => $build) { + $object = $build(); + $size = bytes($object); + $ratio = round($size / $arrayBytes, 2); + + echo str_pad($label, 24) . " {$size} B ({$ratio}x)\n"; + + if (is_object($object)) { + $properties = ownProperties($object); + $propertyList = $properties + ? implode(', ', array_map(static fn ($p) => $p['visibility'] . ' ' . $p['name'], $properties)) + : '(none)'; + + echo ' class: ', get_class($object), "\n"; + echo " properties: {$propertyList}\n"; + echo ' __serialize:', declaresSerialize($object) ? 'yes' : 'no', "\n"; + } else { + echo " class: array\n"; + echo " __serialize: n/a\n"; + } + + $raw = serialize($object); + echo ' raw: ', substr($raw, 0, 120), (strlen($raw) > 120 ? '...' : ''), "\n"; + + $result = roundTrip($object, $maxDelta); + echo ' round-trip: ', $result['ok'] ? 'OK' : 'FAILED', " (as {$result['class']})\n\n"; +} + +echo "=== B. Size vs element count (wrapper overhead vs per-element cost) ===\n\n"; + +echo " n array Buffer Vector Matrix ratio(V/array)\n"; + +foreach ([4, 64, 1024, 8192] as $n) { + $data = array_map(fn (int $i) => ($i % 9) - 4.0, range(0, $n - 1)); + + $arraySize = strlen(serialize($data)); + $bufferSize = bytes(Tensor\Buffer::fromArray($data)); + $vectorSize = bytes(new Tensor\Vector($data)); + $matrixSize = $n % 2 === 0 ? bytes(Tensor\Matrix::fromArray(array_chunk($data, $n / 2))) : null; + $ratio = round($vectorSize / $arraySize, 2); + + $matrixCell = $matrixSize === null ? ' n/a' : (string) $matrixSize; + + printf( + " %-11d %-10d %-11d %-11d %-11s %s\n", + $n, + $arraySize, + $bufferSize, + $vectorSize, + $matrixCell, + $ratio . 'x' + ); +} + +echo "\n"; +echo " As n grows, the fixed wrapper (class name, property keys, shape ints)\n"; +echo " amortises and the ratio converges toward ~1x (the raw element array).\n\n"; + +echo "=== C. Empty-buffer edge case ===\n\n"; + +$empty = []; + +foreach ([ + 'array' => static fn () => $empty, + 'Buffer' => static function () use ($empty) { + return Tensor\Buffer::fromArray($empty); + }, + 'TensorBuffer' => static function () use ($empty) { + return new Tensor\TensorBuffer(Tensor\Buffer::fromArray($empty)); + }, + 'Vector' => static function () use ($empty) { + return new Tensor\Vector($empty); + }, +] as $label => $build) { + $object = $build(); + $size = bytes($object); + $result = roundTrip($object, $maxDelta); + + echo ' ', str_pad($label, 14), ' ', $size, ' B round-trip: ', $result['ok'] ? 'OK' : 'FAILED', "\n"; +} + +echo "\n"; +echo "=== Summary (canonical payload: {$elements[0]}, {$elements[1]}, {$elements[2]}, {$elements[3]}) ===\n\n"; + +echo ' Array ', str_pad((string) strlen(serialize($elements)), 8), "B (baseline)\n"; +echo ' Buffer ', str_pad((string) bytes(Tensor\Buffer::fromArray($elements)), 8), "B\n"; +echo ' TensorBuffer ', str_pad((string) bytes(new Tensor\TensorBuffer(Tensor\Buffer::fromArray($elements))), 8), "B\n"; +echo ' Vector ', str_pad((string) bytes(new Tensor\Vector($elements)), 8), "B\n"; +echo ' ColumnVector ', str_pad((string) bytes(new Tensor\ColumnVector($elements)), 8), "B\n"; +echo ' Matrix 2x2 ', str_pad((string) bytes(Tensor\Matrix::fromArray($matrixRows)), 8), "B\n\n"; + +echo " Overhead: a plain array and the raw Buffer carry a little per-element\n"; +echo " overhead. Vector, ColumnVector and Matrix declare __serialize/__unserialize,\n"; +echo " so the element payload is written value-only (a nested array) and rebuilt\n"; +echo " into a TensorBuffer on unserialize - only the object envelope remains.\n"; diff --git a/stubs/TensorBuffer.php b/stubs/TensorBuffer.php new file mode 100644 index 0000000..55d095e --- /dev/null +++ b/stubs/TensorBuffer.php @@ -0,0 +1,136 @@ +a); + return new Vector(this->a); } /** @@ -74,7 +52,14 @@ class ColumnVector extends Vector */ public function matmul(const b) -> { - return this->asColumnMatrix()->matmul(b); + if unlikely b->m() !== 1 { + throw new DimensionalityMismatch("Matrix A requires" + . " 1 rows but Matrix B has " . (string) b->m() . "."); + } + + var product = tensor_outer(this->a, b->asTensorBuffer(), this->m(), b->n()); + + return new Matrix(product, this->m(), b->n()); } /** @@ -92,24 +77,13 @@ class ColumnVector extends Vector . (string) b->m() . "."); } - var i, rowB, valueB, valueA; - - array c = []; - array rowC = []; - - for i, rowB in b->asArray() { - let valueA = this->a[i]; + var bHat, result; - let rowC = []; + let bHat = b->asTensorBuffer(); - for valueB in rowB { - let rowC[] = valueA * valueB; - } + let result = tensor_multiply_col(bHat, this->a, b->n()); - let c[] = rowC; - } - - return Matrix::quick(c); + return new Matrix(result, b->m(), b->n()); } /** @@ -127,24 +101,13 @@ class ColumnVector extends Vector . (string) b->m() . "."); } - var i, rowB, valueB, valueA; - - array c = []; - array rowC = []; - - for i, rowB in b->asArray() { - let valueA = this->a[i]; + var bHat, result; - let rowC = []; + let bHat = b->asTensorBuffer(); - for valueB in rowB { - let rowC[] = valueA / valueB; - } + let result = tensor_divide_col_reverse(bHat, this->a, b->n()); - let c[] = rowC; - } - - return Matrix::quick(c); + return new Matrix(result, b->m(), b->n()); } /** @@ -162,24 +125,13 @@ class ColumnVector extends Vector . (string) b->m() . "."); } - var i, rowB, valueB, valueA; - - array c = []; - array rowC = []; - - for i, rowB in b->asArray() { - let valueA = this->a[i]; + var bHat, result; - let rowC = []; + let bHat = b->asTensorBuffer(); - for valueB in rowB { - let rowC[] = valueA + valueB; - } + let result = tensor_add_col(bHat, this->a, b->n()); - let c[] = rowC; - } - - return Matrix::quick(c); + return new Matrix(result, b->m(), b->n()); } /** @@ -197,24 +149,13 @@ class ColumnVector extends Vector . (string) b->m() . "."); } - var i, rowB, valueB, valueA; - - array c = []; - array rowC = []; - - for i, rowB in b->asArray() { - let valueA = this->a[i]; + var bHat, result; - let rowC = []; + let bHat = b->asTensorBuffer(); - for valueB in rowB { - let rowC[] = valueA - valueB; - } + let result = tensor_subtract_col_reverse(bHat, this->a, b->n()); - let c[] = rowC; - } - - return Matrix::quick(c); + return new Matrix(result, b->m(), b->n()); } /** @@ -232,24 +173,13 @@ class ColumnVector extends Vector . (string) b->m() . "."); } - var i, rowB, valueB, valueA; - - array c = []; - array rowC = []; - - for i, rowB in b->asArray() { - let valueA = this->a[i]; + var bHat, result; - let rowC = []; + let bHat = b->asTensorBuffer(); - for valueB in rowB { - let rowC[] = pow(valueA, valueB); - } + let result = tensor_pow_col_reverse(bHat, this->a, b->n()); - let c[] = rowC; - } - - return Matrix::quick(c); + return new Matrix(result, b->m(), b->n()); } /** @@ -267,24 +197,13 @@ class ColumnVector extends Vector . (string) b->m() . "."); } - var i, rowB, valueB, valueA; - - array c = []; - array rowC = []; - - for i, rowB in b->asArray() { - let valueA = this->a[i]; + var bHat, result; - let rowC = []; + let bHat = b->asTensorBuffer(); - for valueB in rowB { - let rowC[] = valueA % valueB; - } + let result = tensor_mod_col_reverse(bHat, this->a, b->n()); - let c[] = rowC; - } - - return Matrix::quick(c); + return new Matrix(result, b->m(), b->n()); } /** @@ -302,24 +221,13 @@ class ColumnVector extends Vector . (string) b->m() . "."); } - var i, rowB, valueB, valueA; - - array c = []; - array rowC = []; - - for i, rowB in b->asArray() { - let valueA = this->a[i]; + var bHat, result; - let rowC = []; + let bHat = b->asTensorBuffer(); - for valueB in rowB { - let rowC[] = valueA == valueB ? 1 : 0; - } + let result = tensor_equal_col(bHat, this->a, b->n()); - let c[] = rowC; - } - - return Matrix::quick(c); + return new Matrix(result, b->m(), b->n()); } /** @@ -337,24 +245,13 @@ class ColumnVector extends Vector . (string) b->m() . "."); } - var i, rowB, valueB, valueA; - - array c = []; - array rowC = []; - - for i, rowB in b->asArray() { - let valueA = this->a[i]; + var bHat, result; - let rowC = []; + let bHat = b->asTensorBuffer(); - for valueB in rowB { - let rowC[] = valueA != valueB ? 1 : 0; - } + let result = tensor_not_equal_col(bHat, this->a, b->n()); - let c[] = rowC; - } - - return Matrix::quick(c); + return new Matrix(result, b->m(), b->n()); } /** @@ -372,24 +269,13 @@ class ColumnVector extends Vector . (string) b->m() . "."); } - var i, rowB, valueB, valueA; - - array c = []; - array rowC = []; - - for i, rowB in b->asArray() { - let valueA = this->a[i]; + var bHat, result; - let rowC = []; + let bHat = b->asTensorBuffer(); - for valueB in rowB { - let rowC[] = valueA > valueB ? 1 : 0; - } + let result = tensor_greater_col_reverse(bHat, this->a, b->n()); - let c[] = rowC; - } - - return Matrix::quick(c); + return new Matrix(result, b->m(), b->n()); } /** @@ -407,24 +293,13 @@ class ColumnVector extends Vector . (string) b->m() . "."); } - var i, rowB, valueB, valueA; - - array c = []; - array rowC = []; - - for i, rowB in b->asArray() { - let valueA = this->a[i]; + var bHat, result; - let rowC = []; + let bHat = b->asTensorBuffer(); - for valueB in rowB { - let rowC[] = valueA >= valueB ? 1 : 0; - } + let result = tensor_greater_equal_col_reverse(bHat, this->a, b->n()); - let c[] = rowC; - } - - return Matrix::quick(c); + return new Matrix(result, b->m(), b->n()); } /** @@ -442,24 +317,13 @@ class ColumnVector extends Vector . (string) b->m() . "."); } - var i, rowB, valueB, valueA; - - array c = []; - array rowC = []; - - for i, rowB in b->asArray() { - let valueA = this->a[i]; + var bHat, result; - let rowC = []; + let bHat = b->asTensorBuffer(); - for valueB in rowB { - let rowC[] = valueA < valueB ? 1 : 0; - } + let result = tensor_less_col_reverse(bHat, this->a, b->n()); - let c[] = rowC; - } - - return Matrix::quick(c); + return new Matrix(result, b->m(), b->n()); } /** @@ -477,23 +341,12 @@ class ColumnVector extends Vector . (string) b->m() . "."); } - var i, rowB, valueB, valueA; - - array c = []; - array rowC = []; - - for i, rowB in b->asArray() { - let valueA = this->a[i]; + var bHat, result; - let rowC = []; - - for valueB in rowB { - let rowC[] = valueA <= valueB ? 1 : 0; - } - - let c[] = rowC; - } + let bHat = b->asTensorBuffer(); + + let result = tensor_less_equal_col_reverse(bHat, this->a, b->n()); - return Matrix::quick(c); + return new Matrix(result, b->m(), b->n()); } } \ No newline at end of file diff --git a/tensor/decompositions/cholesky.zep b/tensor/decompositions/cholesky.zep index e3dbf1c..28f1048 100644 --- a/tensor/decompositions/cholesky.zep +++ b/tensor/decompositions/cholesky.zep @@ -37,13 +37,13 @@ class Cholesky . " square, " . $a->shapeString() . " given."); } - var l = tensor_cholesky(a->asArray()); + var l = tensor_cholesky(a->asTensorBuffer(), a->n()); if is_null(l) { throw new RuntimeException("Failed to decompose matrix."); } - return new self(Matrix::quick(l)); + return new self(new Matrix(l, a->n(), a->n())); } /** diff --git a/tensor/decompositions/eigen.zep b/tensor/decompositions/eigen.zep index 528f7da..eb1794d 100644 --- a/tensor/decompositions/eigen.zep +++ b/tensor/decompositions/eigen.zep @@ -51,9 +51,9 @@ class Eigen var result; if symmetric { - let result = tensor_eig_symmetric(a->asArray()); + let result = tensor_eig_symmetric(a->asTensorBuffer(), a->n()); } else { - let result = tensor_eig(a->asArray()); + let result = tensor_eig(a->asTensorBuffer(), a->n()); } if is_null(result) { @@ -64,8 +64,8 @@ class Eigen let eig = (array) result; - var eigenvalues = eig[0]; - var eigenvectors = Matrix::quick(eig[1])->transpose(); + var eigenvalues = (array) eig[0]; + var eigenvectors = new Matrix(eig[1], a->n(), a->n())->transpose(); return new self(eigenvalues, eigenvectors); } diff --git a/tensor/decompositions/lu.zep b/tensor/decompositions/lu.zep index 07d5e44..f253c38 100644 --- a/tensor/decompositions/lu.zep +++ b/tensor/decompositions/lu.zep @@ -52,7 +52,7 @@ class Lu . " square, " . $a->shapeString() . " given."); } - var result = tensor_lu(a->asArray()); + var result = tensor_lu(a->asTensorBuffer(), a->n()); if is_null(result) { throw new RuntimeException("Failed to decompose matrix."); @@ -62,9 +62,9 @@ class Lu let lup = (array) result; - var l = Matrix::quick(lup[0]); - var u = Matrix::quick(lup[1]); - var p = Matrix::quick(lup[2]); + var l = new Matrix(lup[0], a->n(), a->n()); + var u = new Matrix(lup[1], a->n(), a->n()); + var p = new Matrix(lup[2], a->n(), a->n()); return new self(l, u, p); } diff --git a/tensor/decompositions/svd.zep b/tensor/decompositions/svd.zep index 321e130..97bf5a7 100644 --- a/tensor/decompositions/svd.zep +++ b/tensor/decompositions/svd.zep @@ -42,7 +42,7 @@ class Svd */ public static function decompose(const a) -> { - var result = tensor_svd(a->asArray()); + var result = tensor_svd(a->asTensorBuffer(), a->m(), a->n()); if is_null(result) { throw new RuntimeException("Failed to decompose matrix."); @@ -52,9 +52,9 @@ class Svd let usvT = (array) result; - var u = Matrix::quick(usvT[0]); - var singularValues = usvT[1]; - var vT = Matrix::quick(usvT[2]); + var u = new Matrix(usvT[0], a->m(), a->m()); + var singularValues = (array) usvT[1]; + var vT = new Matrix(usvT[2], a->n(), a->n()); return new self(u, singularValues, vT); } diff --git a/tensor/matrix.zep b/tensor/matrix.zep index 83fe8ac..fc58e7d 100644 --- a/tensor/matrix.zep +++ b/tensor/matrix.zep @@ -23,9 +23,9 @@ use ArrayIterator; class Matrix implements Tensor { /** - * A 2-dimensional sequential array that holds the values of the matrix. + * A contiguous row-major buffer holding the elements of the matrix. * - * @var list> + * @var \Tensor\TensorBuffer */ protected a; @@ -43,28 +43,6 @@ class Matrix implements Tensor */ protected n; - /** - * Factory method to build a new matrix from an array. - * - * @param array[] a - * @return self - */ - public static function build(const array a = []) -> - { - return new self(a, true); - } - - /** - * Build a new matrix foregoing any validation for quicker instantiation. - * - * @param array[] a - * @return self - */ - public static function quick(const array a = []) -> - { - return new self(a, false); - } - /** * Return an identity matrix with dimensionality n x n. * @@ -94,7 +72,7 @@ class Matrix implements Tensor let a[] = rowA; } - return self::quick(a); + return self::fromArray(a, false); } /** @@ -151,7 +129,7 @@ class Matrix implements Tensor let a[] = rowA; } - return self::quick(a); + return self::fromArray(a, false); } /** @@ -175,7 +153,7 @@ class Matrix implements Tensor . " greater than 0, " . strval(n) . " given."); } - return self::quick(array_fill(0, m, array_fill(0, n, value))); + return self::fromArray(array_fill(0, m, array_fill(0, n, value)), false); } /** @@ -213,7 +191,7 @@ class Matrix implements Tensor let a[] = rowA; } - return self::quick(a); + return self::fromArray(a, false); } /** @@ -267,7 +245,7 @@ class Matrix implements Tensor let a[] = rowA; } - return self::quick(a); + return self::fromArray(a, false); } /** @@ -328,7 +306,7 @@ class Matrix implements Tensor let a[] = rowA; } - return self::quick(a); + return self::fromArray(a, false); } /** @@ -366,47 +344,83 @@ class Matrix implements Tensor let a[] = rowA; } - return self::quick(a); + return self::fromArray(a, false); } /** + * Build a new matrix from a PHP array of rows, each row being a PHP array + * of numeric elements. + * * @param array[] a * @param bool validate * @throws \Tensor\Exceptions\InvalidArgumentException + * @return self */ - public function __construct(array a, const bool validate = true) + public static function fromArray(const array a, const bool validate = true) -> { - var i, rowA, valueA; + int rows = count(a); - int m = count(a); - int n = count(current(a) ?: []); - - if validate { - array b = []; - array rowB = []; - - let a = array_values(a); - - for i, rowA in a { - if unlikely count(rowA) !== n { - throw new InvalidArgumentException("The number of columns" - . " must be equal for all rows, " . strval(n) - . " needed but " . count(rowA) . " given" - . " at row offset " . i . "."); + if unlikely rows < 1 { + var buffer = tensor_buffer_from_array([]); + + return new self(buffer, 0, 0); + } + + var rowA, valueA; + + array flat = []; + + int n = 0; + bool found = false; + + for rowA in a { + if unlikely !found { + if unlikely !is_array(rowA) { + throw new InvalidArgumentException("Matrix requires an" + . " array of arrays."); } - let rowB = []; + let n = count(rowA); - for valueA in rowA { - let rowB[] = is_float(valueA) ? valueA : (float) valueA; + let found = true; + } else { + if unlikely validate && !is_array(rowA) { + throw new InvalidArgumentException("Matrix requires an" + . " array of arrays."); } - let b[] = rowB; + if unlikely validate && count(rowA) !== n { + throw new InvalidArgumentException("The number of" + . " columns must be equal for all rows, " + . strval(n) . " needed but " . count(rowA) . " given."); + } } - let a = b; + for valueA in rowA { + let flat[] = valueA; + } } - + + var buffer = tensor_buffer_from_array(flat); + + return new self(buffer, rows, n); + } + + /** + * Construct a matrix from a single TensorBuffer holding the elements in + * row-major order together with the target dimensionality. + * + * @param \Tensor\TensorBuffer a + * @param int m + * @param int n + */ + public function __construct( a, const int m, const int n) + { + if unlikely m < 0 || n < 0 { + throw new InvalidArgumentException("Matrix dimensions must be" + . " non-negative."); + } + let this->a = a; let this->m = m; let this->n = n; @@ -477,10 +491,16 @@ class Matrix implements Tensor * * @param int index * @return \Tensor\Vector + * @throws \InvalidArgumentException */ public function rowAsVector(const int index) -> { - return this->offsetGet(index); + if unlikely index < 0 || index >= this->m { + throw new InvalidArgumentException("Row offset out of" + . " bounds."); + } + + return new Vector(this->a->slice(index * this->n, this->n)); } /** @@ -488,82 +508,153 @@ class Matrix implements Tensor * * @param int index * @return \Tensor\ColumnVector + * @throws \InvalidArgumentException */ public function columnAsVector(const int index) -> { - return ColumnVector::quick(array_column(this->a, index)); + if unlikely index < 0 || index >= this->n { + throw new InvalidArgumentException("Column offset out of" + . " bounds."); + } + + return new ColumnVector(this->a->sliceStrided(index, this->m, this->n)); } /** * Return the diagonal elements of a square matrix as a vector. * - * @throws \Tensor\Exceptions\InvalidArgumentException * @return \Tensor\Vector + * @throws \Tensor\Exceptions\InvalidArgumentException */ public function diagonalAsVector() -> { if unlikely !this->isSquare() { throw new InvalidArgumentException("Matrix must be" - . " square, " . this->shapeString() . " given."); + . " square, " . this->shapeString() . " given."); } - var i, rowA; + return new Vector(this->a->sliceStrided(0, this->m, this->n + 1)); + } + + /** + * Return the rows of the matrix as an array of Vector objects. + * + * @return \Tensor\Vector[] + */ + public function asVectors() -> array + { + var rowBuffer; array b = []; - for i, rowA in this->a { - let b[] = rowA[i]; + if unlikely this->n < 1 { + return []; + } + + for rowBuffer in this->a->split(this->n) { + let b[] = new Vector(rowBuffer); } - return Vector::quick(b); + return b; } /** - * Return the elements of the matrix in a 2-d array. + * Return the columns of the matrix as an array of ColumnVector objects. * - * @return list> + * @return \Tensor\ColumnVector[] */ - public function asArray() -> array + public function asColumnVectors() -> array { - return this->a; + var columnBuffer; + + array b = []; + + if unlikely this->n < 1 { + return []; + } + + for columnBuffer in this->asColumnBuffers() { + let b[] = new ColumnVector(columnBuffer); + } + + return b; } /** - * Return each row as a vector in an array. + * Return the elements of the matrix as a vector taken in row-major order. * - * @return \Tensor\Vector[] + * @return \Tensor\Vector */ - public function asVectors() -> array + public function flatten() -> { - return array_map(["Tensor\\Vector", "quick"], this->a); + return new Vector(this->a); } + /** - * Return each column as a column vector in an array. + * Return the matrix as an array of arrays. * - * @return \Tensor\ColumnVector[] + * @return array[] */ - public function asColumnVectors() -> array + public function asArray() -> array { - int i; + if unlikely this->n < 1 { + return []; + } - array vectors = []; + return tensor_matrix_to_array(this->a, this->n); + } - for i in range(0, this->n - 1) { - let vectors[] = this->columnAsVector(i); + /** + * Return the underlying TensorBuffer of the matrix. + * + * @internal + * + * @return \Tensor\TensorBuffer + */ + public function asTensorBuffer() -> + { + return this->a; + } + + /** + * Return each row of the matrix as a TensorBuffer. + * + * @internal + * + * @return \Tensor\TensorBuffer[] + */ + public function asRowBuffers() -> array + { + if unlikely this->n < 1 { + return []; } - return vectors; + return this->a->split(this->n); } /** - * Flatten i.e unravel the matrix into a vector. + * Return each column of the matrix as a TensorBuffer. * - * @return \Tensor\Vector + * @internal + * + * @return \Tensor\TensorBuffer[] */ - public function flatten() -> + public function asColumnBuffers() -> array { - return Vector::quick(call_user_func_array("array_merge", this->a)); + var i; + + array b = []; + + if unlikely this->n < 1 { + return []; + } + + for i in range(0, this->n - 1) { + let b[] = this->a->sliceStrided(i, this->m, this->n); + } + + return b; } /** @@ -576,17 +667,13 @@ class Matrix implements Tensor */ public function map(const var callback) -> { - var rowA; + var b = array_map(callback, this->a->toArray()); - array b = []; - - for rowA in this->a { - let b[] = array_map(callback, rowA); - } - - return self::quick(b); + var buffer = tensor_buffer_from_array(b); + + return new self(buffer, this->m, this->n); } - + /** * Reduce the matrix down to a scalar using a callback function. * @@ -598,17 +685,7 @@ class Matrix implements Tensor */ public function reduce(const var callback, float initial = 0.0) -> float { - var rowA, valueA; - - var carry = initial; - - for rowA in this->a { - for valueA in rowA { - let carry = {callback}(carry, valueA); - } - } - - return carry; + return array_reduce(this->a->toArray(), callback, initial); } /** @@ -618,15 +695,13 @@ class Matrix implements Tensor */ public function transpose() -> { - int i; - - array b = []; - - for i in range(0, this->n - 1) { - let b[] = array_column(this->a, i); + if unlikely this->n < 1 { + return self::fromArray([], false); } - - return self::quick(b); + + var result = tensor_matrix_transpose(this->a, this->m, this->n); + + return new self(result, this->n, this->m); } /** @@ -647,14 +722,14 @@ class Matrix implements Tensor . " of a singular matrix."); } - var result = tensor_inverse(this->a); + var result = tensor_inverse(this->a, this->n); if is_null(result) { throw new RuntimeException("Failed to compute the inverse" . " of a singular matrix."); } - return self::quick(result); + return new self(result, this->n, this->n); } /** @@ -664,14 +739,14 @@ class Matrix implements Tensor */ public function pseudoinverse() -> { - var result = tensor_pseudoinverse(this->a); + var result = tensor_pseudoinverse(this->a, this->m, this->n); if is_null(result) { throw new RuntimeException("Failed to compute the pseudoinverse" . " of the matrix."); } - return self::quick(result); + return new self(result, this->n, this->m); } /** @@ -711,35 +786,9 @@ class Matrix implements Tensor */ public function rank() -> int { - var rowA, valueA; - - array a = []; - - let a = (array) this->rref()->a()->asArray(); - - int pivots = 0; - - bool stop; - - float epsilon = (float) self::EPSILON; - - for rowA in a { - let stop = false; - - for valueA in rowA { - if stop { - continue; - } - - if abs(valueA) >= epsilon { - let pivots++; + var rref = this->rref()->a(); - let stop = true; - } - } - } - - return pivots; + return tensor_rank(rref->asTensorBuffer(), rref->m(), rref->n()); } /** @@ -763,21 +812,7 @@ class Matrix implements Tensor return false; } - int i, j; - - var rowA; - - for i in range(0, this->m - 2) { - let rowA = this->a[i]; - - for j in range(i + 1, this->n - 1) { - if rowA[j] != this->a[j][i] { - return false; - } - } - } - - return true; + return tensor_is_symmetric(this->a, this->n); } /** @@ -795,7 +830,9 @@ class Matrix implements Tensor . (string) b->m() . "."); } - return self::quick(tensor_matmul(this->a, b->asArray())); + var result = tensor_matmul(this->a, b->a, this->m, this->n, b->n()); + + return new self(result, this->m, b->n()); } /** @@ -813,7 +850,7 @@ class Matrix implements Tensor . (string) b->size() . "."); } - return this->matmul(b->asColumnMatrix())->columnAsVector(0); + return new ColumnVector(tensor_matrix_dot(this->a, b->asTensorBuffer(), this->m, this->n)); } /** @@ -836,7 +873,12 @@ class Matrix implements Tensor . " less than 1, " . strval(stride) . " given."); } - return self::quick(tensor_convolve_2d(this->a, b->asArray(), stride)); + var result = tensor_convolve_2d(this->a, b->a, stride, this->m, this->n, b->m(), b->n()); + + int outM = (int) intdiv(this->m + stride - 1, stride); + int outN = (int) intdiv(this->n + stride - 1, stride); + + return new self(result, outM, outN); } /** @@ -1355,8 +1397,7 @@ class Matrix implements Tensor */ public function reciprocal() -> { - return self::ones(this->m, this->n) - ->divideMatrix(this); + return self::ones(this->m, this->n)->divideMatrix(this); } /** @@ -1366,7 +1407,7 @@ class Matrix implements Tensor */ public function abs() -> { - return this->map("abs"); + return new self(tensor_abs(this->a), this->m, this->n); } /** @@ -1386,9 +1427,9 @@ class Matrix implements Tensor */ public function sqrt() -> { - return this->map("sqrt"); + return new self(tensor_sqrt(this->a), this->m, this->n); } - + /** * Return the exponential of the matrix. * @@ -1396,7 +1437,7 @@ class Matrix implements Tensor */ public function exp() -> { - return this->map("exp"); + return new self(tensor_exp(this->a), this->m, this->n); } /** @@ -1406,7 +1447,7 @@ class Matrix implements Tensor */ public function expm1() -> { - return this->map("expm1"); + return new self(tensor_expm1(this->a), this->m, this->n); } /** @@ -1418,25 +1459,12 @@ class Matrix implements Tensor public function log(const float base = self::M_E) -> { if base === self::M_E { - return this->map("log"); + return new self(tensor_log(this->a), this->m, this->n); } - var rowA, valueA; - - array rowB = []; - array b = []; - - for rowA in this->a { - let rowB = []; - - for valueA in rowA { - let rowB[] = log(valueA, base); - } - - let b[] = rowB; - } - - return self::quick(b); + return new self( + tensor_log_base(this->a, (double) base), this->m, this->n + ); } /** @@ -1446,7 +1474,7 @@ class Matrix implements Tensor */ public function log1p() -> { - return this->map("log1p"); + return new self(tensor_log1p(this->a), this->m, this->n); } /** @@ -1456,7 +1484,7 @@ class Matrix implements Tensor */ public function sin() -> { - return this->map("sin"); + return new self(tensor_sin(this->a), this->m, this->n); } /** @@ -1466,7 +1494,7 @@ class Matrix implements Tensor */ public function asin() -> { - return this->map("asin"); + return new self(tensor_asin(this->a), this->m, this->n); } /** @@ -1476,7 +1504,7 @@ class Matrix implements Tensor */ public function cos() -> { - return this->map("cos"); + return new self(tensor_cos(this->a), this->m, this->n); } /** @@ -1486,7 +1514,7 @@ class Matrix implements Tensor */ public function acos() -> { - return this->map("acos"); + return new self(tensor_acos(this->a), this->m, this->n); } /** @@ -1496,7 +1524,7 @@ class Matrix implements Tensor */ public function tan() -> { - return this->map("tan"); + return new self(tensor_tan(this->a), this->m, this->n); } /** @@ -1506,7 +1534,7 @@ class Matrix implements Tensor */ public function atan() -> { - return this->map("atan"); + return new self(tensor_atan(this->a), this->m, this->n); } /** @@ -1516,7 +1544,7 @@ class Matrix implements Tensor */ public function rad2deg() -> { - return this->map("rad2deg"); + return new self(tensor_rad2deg(this->a), this->m, this->n); } /** @@ -1526,7 +1554,7 @@ class Matrix implements Tensor */ public function deg2rad() -> { - return this->map("deg2rad"); + return new self(tensor_deg2rad(this->a), this->m, this->n); } /** @@ -1536,7 +1564,7 @@ class Matrix implements Tensor */ public function sum() -> { - return ColumnVector::quick(array_map("array_sum", this->a)); + return new ColumnVector(tensor_reduce_sum(this->a, this->m, this->n)); } /** @@ -1546,7 +1574,7 @@ class Matrix implements Tensor */ public function product() -> { - return ColumnVector::quick(array_map("array_product", this->a)); + return new ColumnVector(tensor_reduce_product(this->a, this->m, this->n)); } /** @@ -1556,7 +1584,7 @@ class Matrix implements Tensor */ public function min() -> { - return ColumnVector::quick(array_map("min", this->a)); + return new ColumnVector(tensor_reduce_min(this->a, this->m, this->n)); } /** @@ -1566,7 +1594,27 @@ class Matrix implements Tensor */ public function max() -> { - return ColumnVector::quick(array_map("max", this->a)); + return new ColumnVector(tensor_reduce_max(this->a, this->m, this->n)); + } + + /** + * Return the index of the minimum of each row in the matrix. + * + * @return \Tensor\ColumnVector + */ + public function argmin() -> + { + return new ColumnVector(tensor_reduce_argmin(this->a, this->m, this->n)); + } + + /** + * Return the index of the maximum of each row in the matrix. + * + * @return \Tensor\ColumnVector + */ + public function argmax() -> + { + return new ColumnVector(tensor_reduce_argmax(this->a, this->m, this->n)); } /** @@ -1586,26 +1634,7 @@ class Matrix implements Tensor */ public function median() -> { - var rowA, median; - array b = []; - - int mid = (int) intdiv(this->n, 2); - - bool odd = this->n % 2 === 1; - - for rowA in this->a { - sort(rowA); - - if odd { - let median = rowA[mid]; - } else { - let median = (rowA[mid - 1] + rowA[mid]) / 2.0; - } - - let b[] = median; - } - - return ColumnVector::quick(b); + return new ColumnVector(tensor_median(this->a, this->n)); } /** @@ -1622,32 +1651,7 @@ class Matrix implements Tensor . " 0 and 1, " . strval(q) . " given."); } - float t; - var rowA; - - array b = []; - - float x = q * (this->n - 1) + 1; - - int xHat = (int) x; - - float remainder = x - xHat; - - for rowA in this->a { - sort(rowA); - - if xHat >= this->n { - let b[] = (float) rowA[this->n - 1]; - - continue; - } - - let t = (float) rowA[xHat - 1]; - - let b[] = t + remainder * (rowA[xHat] - t); - } - - return ColumnVector::quick(b); + return new ColumnVector(tensor_quantile(this->a, this->n, q)); } /** @@ -1702,8 +1706,7 @@ class Matrix implements Tensor var b = this->subtractColumnVector(mean); - return b->matmul(b->transpose()) - ->divideScalar(this->n); + return b->matmul(b->transpose())->divideScalar(this->n); } /** @@ -1714,31 +1717,12 @@ class Matrix implements Tensor */ public function round(const int precision = 0) -> { - if precision === 0 { - return this->map("round"); - } - if unlikely precision < 0 { throw new InvalidArgumentException("Decimal precision cannot" . " be less than 0, ". strval(precision) . " given."); } - var rowA, valueA; - - array b = []; - array rowB = []; - - for rowA in this->a { - let rowB = []; - - for valueA in rowA { - let rowB[] = round(valueA, precision); - } - - let b[] = rowB; - } - - return self::quick(b); + return new self(tensor_round(this->a, precision), this->m, this->n); } /** @@ -1748,7 +1732,7 @@ class Matrix implements Tensor */ public function floor() -> { - return this->map("floor"); + return new self(tensor_floor(this->a), this->m, this->n); } /** @@ -1758,7 +1742,7 @@ class Matrix implements Tensor */ public function ceil() -> { - return this->map("ceil"); + return new self(tensor_ceil(this->a), this->m, this->n); } /** @@ -1777,34 +1761,9 @@ class Matrix implements Tensor . " greater than maximum."); } - var rowA, valueA; - - array b = []; - array rowB = []; - - for rowA in this->a { - let rowB = []; - - for valueA in rowA { - if valueA > max { - let rowB[] = max; - - continue; - } - - if valueA < min { - let rowB[] = min; - - continue; - } - - let rowB[] = valueA; - } - - let b[] = rowB; - } - - return self::quick(b); + return new self( + tensor_clip(this->a, (double) min, (double) max), this->m, this->n + ); } /** @@ -1815,28 +1774,9 @@ class Matrix implements Tensor */ public function clipLower(const float min) -> { - var rowA, valueA; - - array b = []; - array rowB = []; - - for rowA in this->a { - let rowB = []; - - for valueA in rowA { - if valueA < min { - let rowB[] = min; - - continue; - } - - let rowB[] = valueA; - } - - let b[] = rowB; - } - - return self::quick(b); + return new self( + tensor_clip_lower(this->a, (double) min), this->m, this->n + ); } /** @@ -1847,28 +1787,9 @@ class Matrix implements Tensor */ public function clipUpper(const float max) -> { - var rowA, valueA; - - array b = []; - array rowB = []; - - for rowA in this->a { - let rowB = []; - - for valueA in rowA { - if valueA > max { - let rowB[] = max; - - continue; - } - - let rowB[] = valueA; - } - - let b[] = rowB; - } - - return self::quick(b); + return new self( + tensor_clip_upper(this->a, (double) max), this->m, this->n + ); } /** @@ -1878,28 +1799,7 @@ class Matrix implements Tensor */ public function sign() -> { - var rowA, valueA; - - array b = []; - array rowB = []; - - for rowA in this->a { - let rowB = []; - - for valueA in rowA { - if valueA > 0 { - let rowB[] = 1.0; - } elseif valueA < 0 { - let rowB[] = -1.0; - } else { - let rowB[] = 0.0; - } - } - - let b[] = rowB; - } - - return self::quick(b); + return new self(tensor_sign(this->a), this->m, this->n); } /** @@ -1909,22 +1809,7 @@ class Matrix implements Tensor */ public function negate() -> { - var rowA, valueA; - - array b = []; - array rowB = []; - - for rowA in this->a { - let rowB = []; - - for valueA in rowA { - let rowB[] = -valueA; - } - - let b[] = rowB; - } - - return self::quick(b); + return new self(tensor_negate(this->a), this->m, this->n); } /** @@ -1942,7 +1827,9 @@ class Matrix implements Tensor . (string) b->n() . "."); } - return self::quick(array_merge(b->asArray(), this->a)); + var buffer = b->a->concat([this->a]); + + return new self(buffer, b->m() + this->m, this->n); } /** @@ -1960,7 +1847,9 @@ class Matrix implements Tensor . (string) b->n() . "."); } - return self::quick(array_merge(this->a, b->asArray())); + var buffer = this->a->concat([b->a]); + + return new self(buffer, this->m + b->m(), this->n); } /** @@ -1978,7 +1867,21 @@ class Matrix implements Tensor . (string) b->m() . "."); } - return self::quick(array_map("array_merge", b->asArray(), this->a)); + var i; + + var bufferB, bufferA; + + array c = []; + + for i in range(0, this->m - 1) { + let bufferB = b->a->slice(i * b->n(), b->n()); + + let bufferA = this->a->slice(i * this->n, this->n); + + let c[] = bufferB->concat([bufferA]); + } + + return new self(TensorBuffer::fromBuffers(c), this->m, this->n + b->n()); } /** @@ -1996,7 +1899,21 @@ class Matrix implements Tensor . (string) b->m() . "."); } - return self::quick(array_map("array_merge", this->a, b->asArray())); + var i; + + var bufferA, bufferB; + + array c = []; + + for i in range(0, this->m - 1) { + let bufferA = this->a->slice(i * this->n, this->n); + + let bufferB = b->a->slice(i * b->n(), b->n()); + + let c[] = bufferA->concat([bufferB]); + } + + return new self(TensorBuffer::fromBuffers(c), this->m, this->n + b->n()); } /** @@ -2009,29 +1926,22 @@ class Matrix implements Tensor */ public function repeat(const int m, const int n) -> { - var rowA; - array b = []; - array temp = []; - - if n > 0 { - for rowA in this->a { - let temp = []; - - while count(temp) <= n { - let temp[] = rowA; - } - - let b[] = call_user_func_array("array_merge", temp); - } + if unlikely n < 1 { + return self::fromArray([], false); } - let temp = []; + if unlikely this->n < 1 { + throw new InvalidArgumentException("Chunk length must be" + . " greater than 0, 0 given."); + } - while count(temp) <= m { - let temp[] = b; + if unlikely this->m < 1 { + return self::fromArray([], false); } - return self::quick(call_user_func_array("array_merge", temp)); + var result = tensor_matrix_repeat(this->a, this->n, m, n); + + return new self(result, this->m * (m + 1), this->n * (n + 1)); } /** @@ -2048,15 +1958,9 @@ class Matrix implements Tensor . " matrix expected but " . b->shapeString() . " given."); } - var i, rowB; + var result = tensor_multiply(this->a, b->a); - array c = []; - - for i, rowB in b->asArray() { - let c[] = tensor_multiply(this->a[i], rowB); - } - - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2073,15 +1977,9 @@ class Matrix implements Tensor . " matrix expected but " . b->shapeString() . " given."); } - var i, rowB; - - array c = []; - - for i, rowB in b->asArray() { - let c[] = tensor_divide(this->a[i], rowB); - } + var result = tensor_divide(this->a, b->a); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2098,15 +1996,9 @@ class Matrix implements Tensor . " matrix expected but " . b->shapeString() . " given."); } - var i, rowB; - - array c = []; - - for i, rowB in b->asArray() { - let c[] = tensor_add(this->a[i], rowB); - } + var result = tensor_add(this->a, b->a); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2123,15 +2015,9 @@ class Matrix implements Tensor . " matrix expected but " . b->shapeString() . " given."); } - var i, rowB; - - array c = []; - - for i, rowB in b->asArray() { - let c[] = tensor_subtract(this->a[i], rowB); - } + var result = tensor_subtract(this->a, b->a); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2149,15 +2035,9 @@ class Matrix implements Tensor . " matrix expected but " . b->shapeString() . " given."); } - var i, rowB; - - array c = []; - - for i, rowB in b->asArray() { - let c[] = tensor_pow(this->a[i], rowB); - } + var result = tensor_pow(this->a, b->a); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2175,15 +2055,9 @@ class Matrix implements Tensor . " matrix expected but " . b->shapeString() . " given."); } - var i, rowB; - - array c = []; - - for i, rowB in b->asArray() { - let c[] = tensor_mod(this->a[i], rowB); - } + var result = tensor_mod(this->a, b->a); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2201,15 +2075,9 @@ class Matrix implements Tensor . " matrix expected but " . b->shapeString() . " given."); } - var i, rowB; - - array c = []; - - for i, rowB in b->asArray() { - let c[] = tensor_equal(this->a[i], rowB); - } + var result = tensor_equal(this->a, b->a); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2226,15 +2094,9 @@ class Matrix implements Tensor . " matrix expected but " . b->shapeString() . " given."); } - var i, rowB; - - array c = []; - - for i, rowB in b->asArray() { - let c[] = tensor_not_equal(this->a[i], rowB); - } + var result = tensor_not_equal(this->a, b->a); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2252,15 +2114,9 @@ class Matrix implements Tensor . " matrix expected but " . b->shapeString() . " given."); } - var i, rowB; - - array c = []; - - for i, rowB in b->asArray() { - let c[] = tensor_greater(this->a[i], rowB); - } + var result = tensor_greater(this->a, b->a); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2278,15 +2134,9 @@ class Matrix implements Tensor . " matrix expected but " . b->shapeString() . " given."); } - var i, rowB; - - array c = []; - - for i, rowB in b->asArray() { - let c[] = tensor_greater_equal(this->a[i], rowB); - } + var result = tensor_greater_equal(this->a, b->a); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2303,15 +2153,9 @@ class Matrix implements Tensor . " matrix expected but " . b->shapeString() . " given."); } - var i, rowB; - - array c = []; - - for i, rowB in b->asArray() { - let c[] = tensor_less(this->a[i], rowB); - } + var result = tensor_less(this->a, b->a); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2328,15 +2172,9 @@ class Matrix implements Tensor . " matrix expected but " . b->shapeString() . " given."); } - var i, rowB; - - array c = []; - - for i, rowB in b->asArray() { - let c[] = tensor_less_equal(this->a[i], rowB); - } + var result = tensor_less_equal(this->a, b->a); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2354,17 +2192,13 @@ class Matrix implements Tensor . (string) b->n() . "."); } - var rowA; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - var bHat = b->asArray(); - - for rowA in this->a { - let c[] = tensor_multiply(rowA, bHat); - } - - return self::quick(c); + let result = tensor_multiply_row(this->a, bHat, this->n); + + return new self(result, this->m, this->n); } /** @@ -2382,17 +2216,13 @@ class Matrix implements Tensor . (string) b->n() . "."); } - var rowA; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - var bHat = b->asArray(); - - for rowA in this->a { - let c[] = tensor_divide(rowA, bHat); - } - - return self::quick(c); + let result = tensor_divide_row(this->a, bHat, this->n); + + return new self(result, this->m, this->n); } /** @@ -2410,17 +2240,13 @@ class Matrix implements Tensor . (string) b->n() . "."); } - var rowA; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - var bHat = b->asArray(); - - for rowA in this->a { - let c[] = tensor_add(rowA, bHat); - } - - return self::quick(c); + let result = tensor_add_row(this->a, bHat, this->n); + + return new self(result, this->m, this->n); } /** @@ -2438,17 +2264,13 @@ class Matrix implements Tensor . (string) b->n() . "."); } - var rowA; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - var bHat = b->asArray(); - - for rowA in this->a { - let c[] = tensor_subtract(rowA, bHat); - } - - return self::quick(c); + let result = tensor_subtract_row(this->a, bHat, this->n); + + return new self(result, this->m, this->n); } /** @@ -2466,17 +2288,13 @@ class Matrix implements Tensor . (string) b->n() . "."); } - var rowA; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - var bHat = b->asArray(); - - for rowA in this->a { - let c[] = tensor_pow(rowA, bHat); - } - - return self::quick(c); + let result = tensor_pow_row(this->a, bHat, this->n); + + return new self(result, this->m, this->n); } /** @@ -2494,17 +2312,13 @@ class Matrix implements Tensor . (string) b->n() . "."); } - var rowA; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - var bHat = b->asArray(); - - for rowA in this->a { - let c[] = tensor_mod(rowA, bHat); - } - - return self::quick(c); + let result = tensor_mod_row(this->a, bHat, this->n); + + return new self(result, this->m, this->n); } /** @@ -2523,17 +2337,13 @@ class Matrix implements Tensor . (string) b->n() . "."); } - var rowA; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - var bHat = b->asArray(); - - for rowA in this->a { - let c[] = tensor_equal(rowA, bHat); - } - - return self::quick(c); + let result = tensor_equal_row(this->a, bHat, this->n); + + return new self(result, this->m, this->n); } /** @@ -2551,17 +2361,13 @@ class Matrix implements Tensor . (string) b->n() . "."); } - var rowA; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - var bHat = b->asArray(); - - for rowA in this->a { - let c[] = tensor_not_equal(rowA, bHat); - } - - return self::quick(c); + let result = tensor_not_equal_row(this->a, bHat, this->n); + + return new self(result, this->m, this->n); } /** @@ -2579,17 +2385,13 @@ class Matrix implements Tensor . (string) b->n() . "."); } - var rowA; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - var bHat = b->asArray(); - - for rowA in this->a { - let c[] = tensor_greater(rowA, bHat); - } - - return self::quick(c); + let result = tensor_greater_row(this->a, bHat, this->n); + + return new self(result, this->m, this->n); } /** @@ -2607,17 +2409,13 @@ class Matrix implements Tensor . (string) b->n() . "."); } - var rowA; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - var bHat = b->asArray(); - - for rowA in this->a { - let c[] = tensor_greater_equal(rowA, bHat); - } - - return self::quick(c); + let result = tensor_greater_equal_row(this->a, bHat, this->n); + + return new self(result, this->m, this->n); } /** @@ -2635,17 +2433,13 @@ class Matrix implements Tensor . (string) b->n() . "."); } - var rowA; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - var bHat = b->asArray(); - - for rowA in this->a { - let c[] = tensor_less(rowA, bHat); - } - - return self::quick(c); + let result = tensor_less_row(this->a, bHat, this->n); + + return new self(result, this->m, this->n); } /** @@ -2664,17 +2458,13 @@ class Matrix implements Tensor . (string) b->n() . "."); } - var rowA; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - var bHat = b->asArray(); - - for rowA in this->a { - let c[] = tensor_less_equal(rowA, bHat); - } - - return self::quick(c); + let result = tensor_less_equal_row(this->a, bHat, this->n); + + return new self(result, this->m, this->n); } /** @@ -2692,15 +2482,13 @@ class Matrix implements Tensor . (string) b->m() . "."); } - var i, valueB; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - for i, valueB in b->asArray() { - let c[] = tensor_multiply_scalar(this->a[i], valueB); - } + let result = tensor_multiply_col(this->a, bHat, this->n); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2718,15 +2506,13 @@ class Matrix implements Tensor . (string) b->m() . "."); } - var i, valueB; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - for i, valueB in b->asArray() { - let c[] = tensor_divide_scalar(this->a[i], valueB); - } + let result = tensor_divide_col(this->a, bHat, this->n); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2744,15 +2530,13 @@ class Matrix implements Tensor . (string) b->m() . "."); } - var i, valueB; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - for i, valueB in b->asArray() { - let c[] = tensor_add_scalar(this->a[i], valueB); - } + let result = tensor_add_col(this->a, bHat, this->n); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2770,15 +2554,13 @@ class Matrix implements Tensor . (string) b->m() . "."); } - var i, valueB; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - for i, valueB in b->asArray() { - let c[] = tensor_subtract_scalar(this->a[i], valueB); - } + let result = tensor_subtract_col(this->a, bHat, this->n); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2796,15 +2578,13 @@ class Matrix implements Tensor . (string) b->m() . "."); } - var i, valueB; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - for i, valueB in b->asArray() { - let c[] = tensor_pow_scalar(this->a[i], valueB); - } + let result = tensor_pow_col(this->a, bHat, this->n); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2822,15 +2602,13 @@ class Matrix implements Tensor . (string) b->m() . "."); } - var i, valueB; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - for i, valueB in b->asArray() { - let c[] = tensor_mod_scalar(this->a[i], valueB); - } + let result = tensor_mod_col(this->a, bHat, this->n); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2848,15 +2626,13 @@ class Matrix implements Tensor . (string) b->m() . "."); } - var i, valueB; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - for i, valueB in b->asArray() { - let c[] = tensor_equal_scalar(this->a[i], valueB); - } + let result = tensor_equal_col(this->a, bHat, this->n); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2874,15 +2650,13 @@ class Matrix implements Tensor . (string) b->m() . "."); } - var i, valueB; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - for i, valueB in b->asArray() { - let c[] = tensor_not_equal_scalar(this->a[i], valueB); - } + let result = tensor_not_equal_col(this->a, bHat, this->n); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2900,15 +2674,13 @@ class Matrix implements Tensor . (string) b->m() . "."); } - var i, valueB; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - for i, valueB in b->asArray() { - let c[] = tensor_greater_scalar(this->a[i], valueB); - } + let result = tensor_greater_col(this->a, bHat, this->n); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2926,15 +2698,13 @@ class Matrix implements Tensor . (string) b->m() . "."); } - var i, valueB; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - for i, valueB in b->asArray() { - let c[] = tensor_greater_equal_scalar(this->a[i], valueB); - } + let result = tensor_greater_equal_col(this->a, bHat, this->n); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2952,15 +2722,13 @@ class Matrix implements Tensor . (string) b->m() . "."); } - var i, valueB; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - for i, valueB in b->asArray() { - let c[] = tensor_less_scalar(this->a[i], valueB); - } + let result = tensor_less_col(this->a, bHat, this->n); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2978,15 +2746,13 @@ class Matrix implements Tensor . (string) b->m() . "."); } - var i, valueB; + var bHat, result; - array c = []; + let bHat = b->asTensorBuffer(); - for i, valueB in b->asArray() { - let c[] = tensor_less_equal_scalar(this->a[i], valueB); - } + let result = tensor_less_equal_col(this->a, bHat, this->n); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -2997,15 +2763,9 @@ class Matrix implements Tensor */ public function multiplyScalar(const float b) -> { - var rowA; - - array c = []; - - for rowA in this->a { - let c[] = tensor_multiply_scalar(rowA, b); - } + var result = tensor_multiply_scalar(this->a, b); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -3016,15 +2776,9 @@ class Matrix implements Tensor */ public function divideScalar(const float b) -> { - var rowA; + var result = tensor_divide_scalar(this->a, b); - array c = []; - - for rowA in this->a { - let c[] = tensor_divide_scalar(rowA, b); - } - - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -3035,15 +2789,9 @@ class Matrix implements Tensor */ public function addScalar(const float b) -> { - var rowA; - - array c = []; - - for rowA in this->a { - let c[] = tensor_add_scalar(rowA, b); - } + var result = tensor_add_scalar(this->a, b); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -3054,15 +2802,9 @@ class Matrix implements Tensor */ public function subtractScalar(const float b) -> { - var rowA; + var result = tensor_subtract_scalar(this->a, b); - array c = []; - - for rowA in this->a { - let c[] = tensor_subtract_scalar(rowA, b); - } - - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -3073,15 +2815,9 @@ class Matrix implements Tensor */ public function powScalar(const float b) -> { - var rowA; - - array c = []; - - for rowA in this->a { - let c[] = tensor_pow_scalar(rowA, b); - } + var result = tensor_pow_scalar(this->a, b); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -3092,15 +2828,9 @@ class Matrix implements Tensor */ public function modScalar(const float b) -> { - var rowA; + var result = tensor_mod_scalar(this->a, b); - array c = []; - - for rowA in this->a { - let c[] = tensor_mod_scalar(rowA, b); - } - - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -3111,15 +2841,9 @@ class Matrix implements Tensor */ public function equalScalar(const float b) -> { - var rowA; - - array c = []; - - for rowA in this->a { - let c[] = tensor_equal_scalar(rowA, b); - } + var result = tensor_equal_scalar(this->a, b); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -3130,15 +2854,9 @@ class Matrix implements Tensor */ public function notEqualScalar(const float b) -> { - var rowA; + var result = tensor_not_equal_scalar(this->a, b); - array c = []; - - for rowA in this->a { - let c[] = tensor_not_equal_scalar(rowA, b); - } - - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -3149,15 +2867,9 @@ class Matrix implements Tensor */ public function greaterScalar(const float b) -> { - var rowA; - - array c = []; - - for rowA in this->a { - let c[] = tensor_greater_scalar(rowA, b); - } + var result = tensor_greater_scalar(this->a, b); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -3169,15 +2881,9 @@ class Matrix implements Tensor */ public function greaterEqualScalar(const float b) -> { - var rowA; + var result = tensor_greater_equal_scalar(this->a, b); - array c = []; - - for rowA in this->a { - let c[] = tensor_greater_equal_scalar(rowA, b); - } - - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -3188,15 +2894,9 @@ class Matrix implements Tensor */ public function lessScalar(const float b) -> { - var rowA; - - array c = []; - - for rowA in this->a { - let c[] = tensor_less_scalar(rowA, b); - } + var result = tensor_less_scalar(this->a, b); - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -3208,15 +2908,9 @@ class Matrix implements Tensor */ public function lessEqualScalar(const float b) -> { - var rowA; + var result = tensor_less_equal_scalar(this->a, b); - array c = []; - - for rowA in this->a { - let c[] = tensor_less_equal_scalar(rowA, b); - } - - return self::quick(c); + return new self(result, this->m, this->n); } /** @@ -3245,7 +2939,11 @@ class Matrix implements Tensor */ public function offsetExists(const var index) -> bool { - return isset this->a[index]; + if typeof index != "int" { + return false; + } + + return index >= 0 && index < this->m; } /** @@ -3266,14 +2964,17 @@ class Matrix implements Tensor */ public function offsetGet(const var index) -> { - var row; + if unlikely typeof index != "int" { + throw new InvalidArgumentException("Row offset must be" + . " an integer, " . gettype(index) . " given."); + } - if likely fetch row, this->a[index] { - return Vector::quick(row); + if unlikely index < 0 || index >= this->m { + throw new InvalidArgumentException("Row offset out of" + . " bounds, " . (string) index . " given."); } - throw new InvalidArgumentException("Element not found at" - . " offset " . (string) index . "."); + return new Vector(this->a->slice(index * this->n, this->n)); } /** @@ -3285,4 +2986,38 @@ class Matrix implements Tensor { return new ArrayIterator(this->asVectors()); } + + /** + * Return the elements of the matrix as a plain PHP array of rows so that + * only the values, and not the object structure, appear in the + * serialized form. + * + * @return array[] + */ + public function __serialize() -> array + { + return [ + "data": this->asArray(), + "m": this->m, + "n": this->n + ]; + } + + /** + * Restore the matrix from the plain array of rows produced by + * __serialize() by rebuilding its TensorBuffer and shape. + * + * @param array> data + * @throws \Tensor\Exceptions\InvalidArgumentException + */ + public function __unserialize(const array data) + { + var rebuilt; + + let rebuilt = Matrix::fromArray(data["data"], false); + + let this->a = rebuilt->asTensorBuffer(); + let this->m = data["m"]; + let this->n = data["n"]; + } } \ No newline at end of file diff --git a/tensor/reductions/ref.zep b/tensor/reductions/ref.zep index 2f003bb..b30cbed 100644 --- a/tensor/reductions/ref.zep +++ b/tensor/reductions/ref.zep @@ -38,7 +38,7 @@ class Ref */ public static function reduce(const a) -> { - var result = tensor_ref(a->asArray()); + var result = tensor_ref(a->asTensorBuffer(), a->m(), a->n()); if is_null(result) { throw new RuntimeException("Failed to decompose matrix."); @@ -48,8 +48,8 @@ class Ref let ref = (array) result; - var b = Matrix::quick(ref[0]); - var swaps = ref[1]; + var b = new Matrix(ref[0], a->m(), a->n()); + var swaps = (int) ref[1]; return new self(b, swaps); } diff --git a/tensor/reductions/rref.zep b/tensor/reductions/rref.zep index 50f0a13..a908747 100644 --- a/tensor/reductions/rref.zep +++ b/tensor/reductions/rref.zep @@ -1,9 +1,8 @@ namespace Tensor\Reductions; use Tensor\Matrix; -use Tensor\Tensor; -use InvalidArgumentException; -use RuntimeException; +use Tensor\Exceptions\InvalidArgumentException; +use Tensor\Exceptions\RuntimeException; /** * RREF @@ -31,83 +30,13 @@ class Rref */ public static function reduce(const a) -> { - int i, j; - float scale, divisor; - bool hasPivot; - float epsilon = (float) Tensor::EPSILON; - - array b = []; - array rowB = []; - array t = []; + var result = tensor_rref(a->asTensorBuffer(), a->m(), a->n()); - int m = (int) a->m(); - int n = (int) a->n(); - - int row = 0; - int col = 0; - - let b = (array) a->ref()->a()->asArray(); - - while row < m && col < n { - let t = (array) b[row]; - - if abs(t[col]) < epsilon { - let hasPivot = false; - - for i in range(col, n - 1) { - if abs(t[i]) >= epsilon { - let hasPivot = true; - - break; - } - } - - if hasPivot == false { - for i in range(col, n - 1) { - let t[i] = 0.0; - } - - let b[row] = t; - - let row++; - - continue; - } - - let col++; - - continue; - } - - let divisor = (float) t[col]; - - if divisor !== 1.0 { - for i in range(0, n - 1) { - let t[i] = t[i] / divisor; - } - } - - for i in reverse range(0, row - 1) { - let rowB = (array) b[i]; - - let scale = (float) rowB[col]; - - if abs(scale) >= epsilon { - for j in range(0, n - 1) { - let rowB[j] = rowB[j] - scale * t[j]; - } - } - - let b[i] = rowB; - } - - let b[row] = t; - - let row++; - let col++; + if is_null(result) { + throw new RuntimeException("Failed to reduce matrix."); } - return new self(Matrix::quick(b)); + return new self(new Matrix(result, a->m(), a->n())); } /** diff --git a/tensor/special.zep b/tensor/special.zep index f0ab1af..094f4f0 100644 --- a/tensor/special.zep +++ b/tensor/special.zep @@ -30,6 +30,20 @@ interface Special */ public function max(); + /** + * Return the index (or per-row indices) of the minimum of the tensor. + * + * @return mixed + */ + public function argmin(); + + /** + * Return the index (or per-row indices) of the maximum of the tensor. + * + * @return mixed + */ + public function argmax(); + /** * Clip the tensor to be between the given minimum and maximum. * diff --git a/tensor/tensorbuffer.zep b/tensor/tensorbuffer.zep new file mode 100644 index 0000000..0ecc735 --- /dev/null +++ b/tensor/tensorbuffer.zep @@ -0,0 +1,283 @@ +namespace Tensor; + +use Tensor\Exceptions\InvalidArgumentException; + +/** + * TensorBuffer + * + * A decorator that wraps the kernel Buffer class and provides structural + * operations such as sorting, slicing, splitting, concatenating, and + * repeating. + * + * @internal + * + * @category Scientific Computing + * @package Rubix/Tensor + * @author Andrew DalPino + */ +class TensorBuffer +{ + /** + * The underlying buffer being decorated. + * + * @var \Tensor\Buffer + */ + protected buffer; + + /** + * Build a buffer by concatenating an array of buffers into a single + * contiguous buffer. + * + * @param \Tensor\TensorBuffer[] buffers + * @return self + */ + public static function fromBuffers(const array buffers) -> + { + int rows = count(buffers); + + if unlikely rows < 1 { + return tensor_buffer_from_array([]); + } + + if unlikely rows == 1 { + return buffers[0]; + } + + return buffers[0]->concat(array_slice(buffers, 1)); + } + + /** + * @param \Tensor\Buffer buffer + */ + public function __construct( buffer) + { + let this->buffer = buffer; + } + + /** + * Return the element type of the buffer. + * + * @return int + */ + public function type() -> int + { + return this->buffer->type(); + } + + /** + * Return the element at the given index. + * + * @param int index + * @return mixed + */ + public function get(const int index) + { + return this->buffer[index]; + } + + /** + * Set the element at the given index. + * + * @param int index + * @param mixed value + * @return void + */ + public function set(const int index, const var value) -> void + { + let this->buffer[index] = value; + } + + /** + * Sort the buffer in place. + * + * @param bool ascending + * @return void + */ + public function sort(const bool ascending = true) -> void + { + var status = tensor_buffer_sort(this->buffer, ascending); + } + + /** + * Return a slice of the buffer as a new decorator. + * + * @param int offset + * @param int length + * @throws \Tensor\Exceptions\InvalidArgumentException + * @return self + */ + public function slice(const int offset, const int length) -> + { + if unlikely offset < 0 || length < 0 || offset > this->buffer->count() - length { + throw new InvalidArgumentException("Offset and length" + . " must be within the bounds of the buffer."); + } + + var b = tensor_buffer_slice(this->buffer, offset, length); + + return new TensorBuffer( b); + } + + /** + * Return a slice of the buffer with a given stride as a new decorator. + * + * @param int offset + * @param int length + * @param int stride + * @throws \Tensor\Exceptions\InvalidArgumentException + * @return self + */ + public function sliceStrided(const int offset, const int length, const int stride) -> + { + int limit = 0; + int a = 0; + int acc = 0; + int product = 0; + bool invalid = offset < 0 || length < 0 || stride < 1; + + if likely !invalid && length > 0 { + let limit = this->buffer->count() - 1 - offset; + + let invalid = limit < 0 || (length > 1 && stride > limit); + + if likely !invalid { + let a = length - 1; + + let acc = stride; + + while a > 0 { + if (a & 1) { + let product += acc; + + if product > limit { + let invalid = true; + + break; + } + } + + let a = a >> 1; + + if a > 0 { + if acc > (limit >> 1) { + let invalid = true; + + break; + } + + let acc = acc << 1; + } + } + } + } + + if unlikely invalid { + throw new InvalidArgumentException("Offset, length, and" + . " stride must be within the bounds of the buffer."); + } + + var b = tensor_buffer_slice_strided(this->buffer, offset, length, stride); + + return new TensorBuffer( b); + } + + /** + * Return a new decorator wrapping a new buffer containing the elements of + * this buffer concatenated with the given buffers. + * + * @param \Tensor\TensorBuffer[] buffers + * @return self + */ + public function concat(const array buffers) -> + { + var buffer; + + array unwrapped = []; + + for buffer in buffers { + let unwrapped[] = buffer->asBuffer(); + } + + var b = tensor_buffer_concat(this->buffer, unwrapped); + + return new TensorBuffer( b); + } + + /** + * Return an array of new decorators each wrapping a chunk of this buffer + * of the given length. + * + * @param int chunkLength + * @throws \Tensor\Exceptions\InvalidArgumentException + * @return \Tensor\TensorBuffer[] + */ + public function split(const int chunkLength) -> array + { + if unlikely chunkLength < 1 { + throw new InvalidArgumentException("Chunk length must be" + . " greater than 0, " . strval(chunkLength) . " given."); + } + + var buffer; + + var buffers = tensor_buffer_split(this->buffer, chunkLength); + + array tensorBuffers = []; + + for buffer in buffers { + let tensorBuffers[] = new TensorBuffer( buffer); + } + + return tensorBuffers; + } + + /** + * Return a new decorator wrapping a new buffer with the elements of this + * buffer repeated the given number of times. + * + * @param int times + * @throws \Tensor\Exceptions\InvalidArgumentException + * @return self + */ + public function repeat(const int times) -> + { + if unlikely times < 1 { + throw new InvalidArgumentException("Times must be" + . " greater than 0, " . strval(times) . " given."); + } + + var b = tensor_buffer_repeat(this->buffer, times); + + return new TensorBuffer( b); + } + + /** + * Return the underlying buffer. + * + * @return \Tensor\Buffer + */ + public function asBuffer() -> + { + return this->buffer; + } + + /** + * Return the number of elements in the buffer. + * + * @return int + */ + public function count() -> int + { + return this->buffer->count(); + } + + /** + * Return the buffer as a PHP array. + * + * @return list + */ + public function toArray() -> array + { + return this->buffer->toArray(); + } +} \ No newline at end of file diff --git a/tensor/vector.zep b/tensor/vector.zep index bf9fb76..08ed74f 100644 --- a/tensor/vector.zep +++ b/tensor/vector.zep @@ -17,9 +17,9 @@ use ArrayIterator; class Vector implements Tensor { /** - * A 1-d sequential array holding the elements of the vector. + * A 1-d contiguous buffer holding the elements of the vector. * - * @var list + * @var \Tensor\TensorBuffer */ protected a; @@ -30,28 +30,6 @@ class Vector implements Tensor */ protected n; - /** - * Factory method to build a new vector from an array. - * - * @param float[] a - * @return self - */ - public static function build(const array a = []) - { - return new self(a, true); - } - - /** - * Build a vector foregoing any validation for quicker instantiation. - * - * @param float[] a - * @return self - */ - public static function quick(const array a = []) - { - return new self(a, false); - } - /** * Build a vector of zeros with n elements. * @@ -97,7 +75,7 @@ class Vector implements Tensor . " greater than 0, " . strval(n) . " given."); } - return static::quick(array_fill(0, n, value)); + return static::fromArray(array_fill(0, n, value), false); } /** @@ -122,7 +100,7 @@ class Vector implements Tensor let a[] = rand() / max; } - return static::quick(a); + return static::fromArray(a, false); } /** @@ -159,7 +137,7 @@ class Vector implements Tensor array_pop(a); } - return static::quick(a); + return static::fromArray(a, false); } /** @@ -207,7 +185,7 @@ class Vector implements Tensor let a[] = k - 1.0; } - return static::quick(a); + return static::fromArray(a, false); } /** @@ -232,7 +210,7 @@ class Vector implements Tensor let a[] = rand(-max, max) / max; } - return static::quick(a); + return static::fromArray(a, false); } /** @@ -245,7 +223,7 @@ class Vector implements Tensor */ public static function range(const float start, const float end, const float interval = 1.0) -> { - return static::quick(range(start, end, interval)); + return static::fromArray(range(start, end, interval), false); } /** @@ -280,29 +258,45 @@ class Vector implements Tensor let a[] = max; - return self::quick(a); + return self::fromArray(a, false); } /** - * @param float[] a + * Build a new vector from a flat PHP array of numeric elements. + * + * @param array a * @param bool validate + * @throws \Tensor\Exceptions\InvalidArgumentException + * @return self */ - public function __construct(array a, const bool validate = true) + public static function fromArray(const array a, const bool validate = true) -> { - var valueA; - - if validate { - array b = []; + var buffer, valueA; - for valueA in a { - let b[] = is_float(valueA) ? valueA : (float) valueA; + if unlikely validate { + for valueA in (array) a { + if unlikely is_array(valueA) { + throw new InvalidArgumentException("Vector requires a" + . " flat array of numeric elements."); + } } - - let a = b; } + let buffer = tensor_buffer_from_array(a); + + return new static(buffer); + } + + /** + * Construct a new vector from a TensorBuffer holding its elements. + * + * @param \Tensor\TensorBuffer a + * @throws \Tensor\Exceptions\InvalidArgumentException + */ + public function __construct( a) + { let this->a = a; - let this->n = count(a); + let this->n = this->a->count(); } /** @@ -361,6 +355,16 @@ class Vector implements Tensor * @return list */ public function asArray() -> array + { + return this->a->toArray(); + } + + /** + * Return the underlying TensorBuffer of the vector. + * + * @return \Tensor\TensorBuffer + */ + public function asTensorBuffer() -> { return this->a; } @@ -372,7 +376,7 @@ class Vector implements Tensor */ public function asRowMatrix() -> { - return Matrix::quick([this->a]); + return new Matrix(this->a, 1, this->n); } /** @@ -382,15 +386,7 @@ class Vector implements Tensor */ public function asColumnMatrix() -> { - var valueA; - - array b = []; - - for valueA in this->a { - let b[] = [valueA]; - } - - return Matrix::quick(b); + return new Matrix(this->a, this->n, 1); } /** @@ -415,24 +411,7 @@ class Vector implements Tensor . " are needed but vector only has " . this->n . "."); } - int i = 0; - - array b = []; - array rowB = []; - - while count(b) < m { - let rowB = []; - - while count(rowB) < n { - let rowB[] = this->a[i]; - - let i++; - } - - let b[] = rowB; - } - - return Matrix::quick(b); + return new Matrix(this->a, m, n); } /** @@ -442,7 +421,7 @@ class Vector implements Tensor */ public function transpose() { - return ColumnVector::quick(this->a); + return new ColumnVector(this->a); } /** @@ -455,7 +434,7 @@ class Vector implements Tensor */ public function map(const var callback) -> { - return static::quick(array_map(callback, this->a)); + return static::fromArray(array_map(callback, this->a->toArray()), false); } /** @@ -469,7 +448,7 @@ class Vector implements Tensor */ public function reduce(const var callback, float initial = 0.0) -> float { - return array_reduce(this->a, callback, initial); + return array_reduce(this->a->toArray(), callback, initial); } /** @@ -487,7 +466,7 @@ class Vector implements Tensor . (string) b->size() . "."); } - return tensor_dot(this->a, b->asArray()); + return tensor_dot(this->a, b->a); } /** @@ -510,7 +489,7 @@ class Vector implements Tensor . " less than 1, " . strval(stride). " given."); } - return static::quick(tensor_convolve_1d(this->a, b->asArray(), stride)); + return new static(tensor_convolve_1d(this->a, b->a, stride)); } /** @@ -543,25 +522,9 @@ class Vector implements Tensor */ public function outer(const b) -> { - var j, valueA, valueB; - - array bHat = []; - array c = []; - array rowC = []; - - let bHat = (array) b->asArray(); + var result = tensor_outer(this->a, b->asTensorBuffer(), this->n, b->n()); - for valueA in this->a { - let rowC = []; - - for j, valueB in bHat { - let rowC[] = valueA * valueB; - } - - let c[] = rowC; - } - - return Matrix::quick(c); + return new Matrix(result, this->n, b->n()); } /** @@ -999,7 +962,7 @@ class Vector implements Tensor */ public function abs() -> { - return this->map("abs"); + return new static(tensor_abs(this->a)); } /** @@ -1019,7 +982,7 @@ class Vector implements Tensor */ public function sqrt() -> { - return this->map("sqrt"); + return new static(tensor_sqrt(this->a)); } /** @@ -1029,7 +992,7 @@ class Vector implements Tensor */ public function exp() -> { - return this->map("exp"); + return new static(tensor_exp(this->a)); } /** @@ -1039,7 +1002,7 @@ class Vector implements Tensor */ public function expm1() -> { - return this->map("expm1"); + return new static(tensor_expm1(this->a)); } /** @@ -1050,19 +1013,16 @@ class Vector implements Tensor */ public function log(const float base = self::M_E) -> { - if base === self::M_E { - return this->map("log"); + if unlikely base <= 0.0 { + throw new InvalidArgumentException("Log base must be greater" + . " than 0, " . strval(base) . " given."); } - var valueA; - - array b = []; - - for valueA in this->a { - let b[] = log(valueA, base); + if base === self::M_E { + return new static(tensor_log(this->a)); } - return static::quick(b); + return new static(tensor_log_base(this->a, (double) base)); } /** @@ -1072,7 +1032,7 @@ class Vector implements Tensor */ public function log1p() -> { - return this->map("log1p"); + return new static(tensor_log1p(this->a)); } /** @@ -1082,7 +1042,7 @@ class Vector implements Tensor */ public function sin() -> { - return this->map("sin"); + return new static(tensor_sin(this->a)); } /** @@ -1092,7 +1052,7 @@ class Vector implements Tensor */ public function asin() -> { - return this->map("asin"); + return new static(tensor_asin(this->a)); } /** @@ -1102,7 +1062,7 @@ class Vector implements Tensor */ public function cos() -> { - return this->map("cos"); + return new static(tensor_cos(this->a)); } /** @@ -1112,7 +1072,7 @@ class Vector implements Tensor */ public function acos() -> { - return this->map("acos"); + return new static(tensor_acos(this->a)); } /** @@ -1122,7 +1082,7 @@ class Vector implements Tensor */ public function tan() -> { - return this->map("tan"); + return new static(tensor_tan(this->a)); } /** @@ -1132,7 +1092,7 @@ class Vector implements Tensor */ public function atan() -> { - return this->map("atan"); + return new static(tensor_atan(this->a)); } /** @@ -1142,7 +1102,7 @@ class Vector implements Tensor */ public function rad2deg() -> { - return this->map("rad2deg"); + return new static(tensor_rad2deg(this->a)); } /** @@ -1152,7 +1112,7 @@ class Vector implements Tensor */ public function deg2rad() -> { - return this->map("deg2rad"); + return new static(tensor_deg2rad(this->a)); } /** @@ -1162,7 +1122,9 @@ class Vector implements Tensor */ public function sum() -> float { - return (float) array_sum(this->a); + var result = tensor_reduce_sum(this->a, 1, this->n); + + return (double) result->get(0); } /** @@ -1172,7 +1134,9 @@ class Vector implements Tensor */ public function product() -> float { - return (float) array_product(this->a); + var result = tensor_reduce_product(this->a, 1, this->n); + + return (double) result->get(0); } /** @@ -1182,7 +1146,14 @@ class Vector implements Tensor */ public function min() -> float { - return (float) min(this->a); + if unlikely this->n < 1 { + throw new InvalidArgumentException("Cannot compute" + . " the minimum of an empty vector."); + } + + var result = tensor_reduce_min(this->a, 1, this->n); + + return (double) result->get(0); } /** @@ -1192,7 +1163,48 @@ class Vector implements Tensor */ public function max() -> float { - return (float) max(this->a); + if unlikely this->n < 1 { + throw new InvalidArgumentException("Cannot compute" + . " the maximum of an empty vector."); + } + + var result = tensor_reduce_max(this->a, 1, this->n); + + return (double) result->get(0); + } + + /** + * Return the index of the minimum element in the vector. + * + * @return int + */ + public function argmin() -> int + { + if unlikely this->n < 1 { + throw new InvalidArgumentException("Cannot compute" + . " the argmin of an empty vector."); + } + + var result = tensor_reduce_argmin(this->a, 1, this->n); + + return (int) result->get(0); + } + + /** + * Return the index of the maximum element in the vector. + * + * @return int + */ + public function argmax() -> int + { + if unlikely this->n < 1 { + throw new InvalidArgumentException("Cannot compute" + . " the argmax of an empty vector."); + } + + var result = tensor_reduce_argmax(this->a, 1, this->n); + + return (int) result->get(0); } /** @@ -1212,21 +1224,14 @@ class Vector implements Tensor */ public function median() -> float { - var median; - - int mid = (int) intdiv(this->n, 2); - - var a = this->a; - - sort(a); - - if this->n % 2 === 1 { - let median = a[mid]; - } else { - let median = (a[mid - 1] + a[mid]) / 2.0; + if unlikely this->n < 1 { + throw new InvalidArgumentException("Cannot compute" + . " the median of an empty vector."); } - return median; + var result = tensor_median(this->a, this->n); + + return (float) result->get(0); } /** @@ -1243,23 +1248,14 @@ class Vector implements Tensor . " between 0 and 1, " . strval(q) . " given."); } - var a = this->a; - - sort(a); - - float x = q * (this->n - 1) + 1; - - int xHat = (int) x; - - if xHat >= this->n { - return (float) a[this->n - 1]; + if unlikely this->n < 1 { + throw new InvalidArgumentException("Cannot compute" + . " the quantile of an empty vector."); } - float remainder = x - xHat; - - float t = (float) a[xHat - 1]; + var result = tensor_quantile(this->a, this->n, q); - return t + remainder * (a[xHat] - t); + return (float) result->get(0); } /** @@ -1296,24 +1292,12 @@ class Vector implements Tensor */ public function round(const int precision = 0) -> { - if precision === 0 { - return this->map("round"); - } - if unlikely precision < 0 { throw new InvalidArgumentException("Decimal precision cannot" . " be less than 0, " . strval(precision) . " given."); } - var valueA; - - array b = []; - - for valueA in this->a { - let b[] = round(valueA, precision); - } - - return static::quick(b); + return new static(tensor_round(this->a, (int) precision)); } /** @@ -1323,7 +1307,7 @@ class Vector implements Tensor */ public function floor() -> { - return this->map("floor"); + return new static(tensor_floor(this->a)); } /** @@ -1333,7 +1317,7 @@ class Vector implements Tensor */ public function ceil() -> { - return this->map("ceil"); + return new static(tensor_ceil(this->a)); } /** @@ -1352,27 +1336,7 @@ class Vector implements Tensor . " greater than maximum."); } - var valueA; - - array b = []; - - for valueA in this->a { - if valueA > max { - let b[] = max; - - continue; - } - - if valueA < min { - let b[] = min; - - continue; - } - - let b[] = valueA; - } - - return static::quick(b); + return new static(tensor_clip(this->a, (double) min, (double) max)); } /** @@ -1383,21 +1347,7 @@ class Vector implements Tensor */ public function clipLower(const float min) -> { - var valueA; - - array b = []; - - for valueA in this->a { - if valueA < min { - let b[] = min; - - continue; - } - - let b[] = valueA; - } - - return static::quick(b); + return new static(tensor_clip_lower(this->a, (double) min)); } /** @@ -1408,21 +1358,7 @@ class Vector implements Tensor */ public function clipUpper(const float max) -> { - var valueA; - - array b = []; - - for valueA in this->a { - if valueA > max { - let b[] = max; - - continue; - } - - let b[] = valueA; - } - - return static::quick(b); + return new static(tensor_clip_upper(this->a, (double) max)); } /** @@ -1432,21 +1368,7 @@ class Vector implements Tensor */ public function sign() -> { - var valueA; - - array b = []; - - for valueA in this->a { - if valueA > 0 { - let b[] = 1.0; - } elseif valueA < 0 { - let b[] = -1.0; - } else { - let b[] = 0.0; - } - } - - return static::quick(b); + return new static(tensor_sign(this->a)); } /** @@ -1456,15 +1378,7 @@ class Vector implements Tensor */ public function negate() -> { - var valueA; - - array b = []; - - for valueA in this->a { - let b[] = -valueA; - } - - return static::quick(b); + return new static(tensor_negate(this->a)); } /** @@ -1481,16 +1395,14 @@ class Vector implements Tensor . (string) this->n . " columns but Matrix B has " . (string) b->n() . "."); } - - var rowB; - array c = []; - - for rowB in b->asArray() { - let c[] = tensor_multiply(this->a, rowB); - } - - return Matrix::quick(c); + var bHat, result; + + let bHat = b->asTensorBuffer(); + + let result = tensor_multiply_row(bHat, this->a, this->n); + + return new Matrix(result, b->m(), b->n()); } /** @@ -1508,15 +1420,13 @@ class Vector implements Tensor . (string) b->n() . "."); } - var rowB; + var bHat, result; - array c = []; - - for rowB in b->asArray() { - let c[] = tensor_divide(this->a, rowB); - } - - return Matrix::quick(c); + let bHat = b->asTensorBuffer(); + + let result = tensor_divide_row_reverse(bHat, this->a, this->n); + + return new Matrix(result, b->m(), b->n()); } /** @@ -1534,15 +1444,13 @@ class Vector implements Tensor . (string) b->n() . "."); } - var rowB; + var bHat, result; - array c = []; - - for rowB in b->asArray() { - let c[] = tensor_add(this->a, rowB); - } - - return Matrix::quick(c); + let bHat = b->asTensorBuffer(); + + let result = tensor_add_row(bHat, this->a, this->n); + + return new Matrix(result, b->m(), b->n()); } /** @@ -1560,15 +1468,13 @@ class Vector implements Tensor . (string) b->n() . "."); } - var rowB; + var bHat, result; - array c = []; - - for rowB in b->asArray() { - let c[] = tensor_subtract(this->a, rowB); - } - - return Matrix::quick(c); + let bHat = b->asTensorBuffer(); + + let result = tensor_subtract_row_reverse(bHat, this->a, this->n); + + return new Matrix(result, b->m(), b->n()); } /** @@ -1586,15 +1492,13 @@ class Vector implements Tensor . (string) b->n() . "."); } - var rowB; + var bHat, result; - array c = []; - - for rowB in b->asArray() { - let c[] = tensor_pow(this->a, rowB); - } - - return Matrix::quick(c); + let bHat = b->asTensorBuffer(); + + let result = tensor_pow_row_reverse(bHat, this->a, this->n); + + return new Matrix(result, b->m(), b->n()); } /** @@ -1612,15 +1516,13 @@ class Vector implements Tensor . (string) b->n() . "."); } - var rowB; + var bHat, result; - array c = []; - - for rowB in b->asArray() { - let c[] = tensor_mod(this->a, rowB); - } - - return Matrix::quick(c); + let bHat = b->asTensorBuffer(); + + let result = tensor_mod_row_reverse(bHat, this->a, this->n); + + return new Matrix(result, b->m(), b->n()); } /** @@ -1638,15 +1540,13 @@ class Vector implements Tensor . (string) b->n() . "."); } - var rowB; + var bHat, result; - array c = []; - - for rowB in b->asArray() { - let c[] = tensor_equal(this->a, rowB); - } - - return Matrix::quick(c); + let bHat = b->asTensorBuffer(); + + let result = tensor_equal_row(bHat, this->a, this->n); + + return new Matrix(result, b->m(), b->n()); } /** @@ -1664,15 +1564,13 @@ class Vector implements Tensor . (string) b->n() . "."); } - var rowB; + var bHat, result; - array c = []; - - for rowB in b->asArray() { - let c[] = tensor_not_equal(this->a, rowB); - } - - return Matrix::quick(c); + let bHat = b->asTensorBuffer(); + + let result = tensor_not_equal_row(bHat, this->a, this->n); + + return new Matrix(result, b->m(), b->n()); } /** @@ -1690,15 +1588,13 @@ class Vector implements Tensor . (string) b->n() . "."); } - var rowB; + var bHat, result; - array c = []; - - for rowB in b->asArray() { - let c[] = tensor_greater(this->a, rowB); - } - - return Matrix::quick(c); + let bHat = b->asTensorBuffer(); + + let result = tensor_greater_row_reverse(bHat, this->a, this->n); + + return new Matrix(result, b->m(), b->n()); } /** @@ -1716,15 +1612,13 @@ class Vector implements Tensor . (string) b->n() . "."); } - var rowB; + var bHat, result; - array c = []; - - for rowB in b->asArray() { - let c[] = tensor_greater_equal(this->a, rowB); - } - - return Matrix::quick(c); + let bHat = b->asTensorBuffer(); + + let result = tensor_greater_equal_row_reverse(bHat, this->a, this->n); + + return new Matrix(result, b->m(), b->n()); } /** @@ -1742,15 +1636,13 @@ class Vector implements Tensor . (string) b->n() . "."); } - var rowB; + var bHat, result; - array c = []; - - for rowB in b->asArray() { - let c[] = tensor_less(this->a, rowB); - } - - return Matrix::quick(c); + let bHat = b->asTensorBuffer(); + + let result = tensor_less_row_reverse(bHat, this->a, this->n); + + return new Matrix(result, b->m(), b->n()); } /** @@ -1768,15 +1660,13 @@ class Vector implements Tensor . (string) b->n() . "."); } - var rowB; + var bHat, result; - array c = []; - - for rowB in b->asArray() { - let c[] = tensor_less_equal(this->a, rowB); - } - - return Matrix::quick(c); + let bHat = b->asTensorBuffer(); + + let result = tensor_less_equal_row_reverse(bHat, this->a, this->n); + + return new Matrix(result, b->m(), b->n()); } /** @@ -1794,7 +1684,7 @@ class Vector implements Tensor . (string) b->size() . "."); } - return static::quick(tensor_multiply(this->a, b->asArray())); + return new static(tensor_multiply(this->a, b->a)); } /** @@ -1812,7 +1702,7 @@ class Vector implements Tensor . (string) b->size() . "."); } - return static::quick(tensor_divide(this->a, b->asArray())); + return new static(tensor_divide(this->a, b->a)); } /** @@ -1830,7 +1720,7 @@ class Vector implements Tensor . (string) b->size() . "."); } - return static::quick(tensor_add(this->a, b->asArray())); + return new static(tensor_add(this->a, b->a)); } /** @@ -1848,7 +1738,7 @@ class Vector implements Tensor . (string) b->size() . "."); } - return static::quick(tensor_subtract(this->a, b->asArray())); + return new static(tensor_subtract(this->a, b->a)); } /** @@ -1866,7 +1756,7 @@ class Vector implements Tensor . (string) b->size() . "."); } - return static::quick(tensor_pow(this->a, b->asArray())); + return new static(tensor_pow(this->a, b->a)); } /** @@ -1884,7 +1774,7 @@ class Vector implements Tensor . (string) b->size() . "."); } - return static::quick(tensor_mod(this->a, b->asArray())); + return new static(tensor_mod(this->a, b->a)); } /** @@ -1903,7 +1793,7 @@ class Vector implements Tensor . (string) b->size() . "."); } - return static::quick(tensor_equal(this->a, b->asArray())); + return new static(tensor_equal(this->a, b->a)); } /** @@ -1921,7 +1811,7 @@ class Vector implements Tensor . (string) b->size() . "."); } - return static::quick(tensor_not_equal(this->a, b->asArray())); + return new static(tensor_not_equal(this->a, b->a)); } /** @@ -1939,7 +1829,7 @@ class Vector implements Tensor . (string) b->size() . "."); } - return static::quick(tensor_greater(this->a, b->asArray())); + return new static(tensor_greater(this->a, b->a)); } /** @@ -1957,7 +1847,7 @@ class Vector implements Tensor . (string) b->size() . "."); } - return static::quick(tensor_greater_equal(this->a, b->asArray())); + return new static(tensor_greater_equal(this->a, b->a)); } /** @@ -1975,7 +1865,7 @@ class Vector implements Tensor . (string) b->size() . "."); } - return static::quick(tensor_less(this->a, b->asArray())); + return new static(tensor_less(this->a, b->a)); } /** @@ -1993,7 +1883,7 @@ class Vector implements Tensor . (string) b->size() . "."); } - return static::quick(tensor_less_equal(this->a, b->asArray())); + return new static(tensor_less_equal(this->a, b->a)); } /** @@ -2004,7 +1894,7 @@ class Vector implements Tensor */ public function multiplyScalar(const float b) -> { - return static::quick(tensor_multiply_scalar(this->a, b)); + return new static(tensor_multiply_scalar(this->a, b)); } /** @@ -2015,7 +1905,7 @@ class Vector implements Tensor */ public function divideScalar(const float b) -> { - return static::quick(tensor_divide_scalar(this->a, b)); + return new static(tensor_divide_scalar(this->a, b)); } /** @@ -2026,7 +1916,7 @@ class Vector implements Tensor */ public function addScalar(const float b) -> { - return static::quick(tensor_add_scalar(this->a, b)); + return new static(tensor_add_scalar(this->a, b)); } /** @@ -2037,7 +1927,7 @@ class Vector implements Tensor */ public function subtractScalar(const float b) -> { - return static::quick(tensor_subtract_scalar(this->a, b)); + return new static(tensor_subtract_scalar(this->a, b)); } /** @@ -2048,7 +1938,7 @@ class Vector implements Tensor */ public function powScalar(const float b) -> { - return static::quick(tensor_pow_scalar(this->a, b)); + return new static(tensor_pow_scalar(this->a, b)); } /** @@ -2059,7 +1949,7 @@ class Vector implements Tensor */ public function modScalar(const float b) -> { - return static::quick(tensor_mod_scalar(this->a, b)); + return new static(tensor_mod_scalar(this->a, b)); } /** @@ -2070,7 +1960,7 @@ class Vector implements Tensor */ public function equalScalar(const float b) -> { - return static::quick(tensor_equal_scalar(this->a, b)); + return new static(tensor_equal_scalar(this->a, b)); } /** @@ -2081,7 +1971,7 @@ class Vector implements Tensor */ public function notEqualScalar(const float b) -> { - return static::quick(tensor_not_equal_scalar(this->a, b)); + return new static(tensor_not_equal_scalar(this->a, b)); } /** @@ -2092,7 +1982,7 @@ class Vector implements Tensor */ public function greaterScalar(const float b) -> { - return static::quick(tensor_greater_scalar(this->a, b)); + return new static(tensor_greater_scalar(this->a, b)); } /** @@ -2104,7 +1994,7 @@ class Vector implements Tensor */ public function greaterEqualScalar(const float b) -> { - return static::quick(tensor_greater_equal_scalar(this->a, b)); + return new static(tensor_greater_equal_scalar(this->a, b)); } /** @@ -2115,7 +2005,7 @@ class Vector implements Tensor */ public function lessScalar(const float b) -> { - return static::quick(tensor_less_scalar(this->a, b)); + return new static(tensor_less_scalar(this->a, b)); } /** @@ -2127,7 +2017,7 @@ class Vector implements Tensor */ public function lessEqualScalar(const float b) -> { - return static::quick(tensor_less_equal_scalar(this->a, b)); + return new static(tensor_less_equal_scalar(this->a, b)); } /** @@ -2151,14 +2041,18 @@ class Vector implements Tensor } /** - * Does a given column exist in the matrix. + * Does a given element exist in the vector. * * @param mixed index * @return bool */ public function offsetExists(const var index) -> bool { - return isset(this->a[index]); + if unlikely !is_int(index) { + return false; + } + + return index >= 0 && index < this->n; } /** @@ -2171,7 +2065,7 @@ class Vector implements Tensor } /** - * Return a row from the matrix at the given index. + * Return an element from the vector at the given index. * * @param mixed index * @throws \Tensor\Exceptions\InvalidArgumentException @@ -2179,23 +2073,52 @@ class Vector implements Tensor */ public function offsetGet(const var index) -> mixed { - var value; - - if likely fetch value, this->a[index] { - return value; + if unlikely !is_int(index) || (index < 0 || index >= this->n) { + throw new InvalidArgumentException("Element not found at" + . " offset " . (string) index . "."); } - throw new InvalidArgumentException("Element not found at" - . " offset " . (string) index . "."); + return this->a->get(index); } /** - * Get an iterator for the rows in the matrix. + * Get an iterator for the items in the vector. * * @return \ArrayIterator */ public function getIterator() -> <\Traversable> { - return new ArrayIterator(this->a); + return new ArrayIterator(this->a->toArray()); + } + + /** + * Return the elements of the vector as a plain PHP array so that only the + * values, and not the object structure, appear in the serialized form. + * + * @return list + */ + public function __serialize() -> array + { + return [ + "data": this->asArray(), + "n": this->n + ]; + } + + /** + * Restore the vector from the plain array of elements produced by + * __serialize() by rebuilding its TensorBuffer. + * + * @param float[] data + * @throws \Tensor\Exceptions\InvalidArgumentException + */ + public function __unserialize(const array data) + { + var rebuilt; + + let rebuilt = self::fromArray(data["data"], false); + + let this->a = rebuilt->a; + let this->n = data["n"]; } } \ No newline at end of file diff --git a/tests/ColumnVectorTest.php b/tests/ColumnVectorTest.php index cd6d0e7..f57dad8 100644 --- a/tests/ColumnVectorTest.php +++ b/tests/ColumnVectorTest.php @@ -33,7 +33,7 @@ class ColumnVectorTest extends TestCase */ public function build() : void { - $vector = ColumnVector::build([-15, 25, 35]); + $vector = ColumnVector::fromArray([-15.0, 25.0, 35.0]); $this->assertInstanceOf(ColumnVector::class, $vector); $this->assertInstanceOf(Tensor::class, $vector); @@ -51,7 +51,7 @@ public function build() : void */ public function shape() : void { - $vector = ColumnVector::quick([-15, 25, 35]); + $vector = ColumnVector::fromArray([-15.0, 25.0, 35.0]); $this->assertEquals([3], $vector->shape()); } @@ -61,7 +61,7 @@ public function shape() : void */ public function shapeString() : void { - $vector = ColumnVector::quick([-15, 25, 35]); + $vector = ColumnVector::fromArray([-15.0, 25.0, 35.0]); $this->assertEquals('3', $vector->shapeString()); } @@ -71,17 +71,35 @@ public function shapeString() : void */ public function size() : void { - $vector = ColumnVector::quick([-15, 25, 35]); + $vector = ColumnVector::fromArray([-15.0, 25.0, 35.0]); $this->assertEquals(3, $vector->size()); } + /** + * @test + */ + public function serialization() : void + { + $vector = ColumnVector::fromArray([-15.0, 25.0, 35.0]); + + $serialized = serialize($vector); + + $this->assertStringNotContainsString('TensorBuffer', $serialized); + + $restored = unserialize($serialized); + + $this->assertInstanceOf(ColumnVector::class, $restored); + $this->assertEquals([-15.0, 25.0, 35.0], $restored->asArray()); + $this->assertSame(serialize($vector), serialize($restored)); + } + /** * @test */ public function m() : void { - $vector = ColumnVector::quick([-15, 25, 35]); + $vector = ColumnVector::fromArray([-15.0, 25.0, 35.0]); $this->assertEquals(3, $vector->m()); } @@ -91,7 +109,7 @@ public function m() : void */ public function n() : void { - $vector = ColumnVector::quick([-15, 25, 35]); + $vector = ColumnVector::fromArray([-15.0, 25.0, 35.0]); $this->assertEquals(1, $vector->n()); } @@ -101,23 +119,23 @@ public function n() : void */ public function multiply() : void { - $a = ColumnVector::quick([-15, 25, 35]); + $a = ColumnVector::fromArray([-15.0, 25.0, 35.0]); - $b = Matrix::quick([ - [6.23, -1, 0.03], - [0.01, 2.01, 1], - [1.1, 5, -5], + $b = Matrix::fromArray([ + [6.23, -1.0, 0.03], + [0.01, 2.01, 1.0], + [1.1, 5.0, -5.0], ]); $c = $a->multiply($b); - $expected = Matrix::quick([ - [-93.45, 15, -0.44999999999999996], - [0.25, 50.24999999999999, 25], - [38.5, 175, -175], + $expected = Matrix::fromArray([ + [-93.45, 15.0, -0.44999999999999996], + [0.25, 50.24999999999999, 25.0], + [38.5, 175.0, -175.0], ]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -125,23 +143,23 @@ public function multiply() : void */ public function divide() : void { - $a = ColumnVector::quick([-15, 25, 35]); + $a = ColumnVector::fromArray([-15.0, 25.0, 35.0]); - $b = Matrix::quick([ - [6.23, -1, 0.03], - [0.01, 2.01, 1], - [1.1, 5, -5], + $b = Matrix::fromArray([ + [6.23, -1.0, 0.03], + [0.01, 2.01, 1.0], + [1.1, 5.0, -5.0], ]); $c = $a->divide($b); - $expected = Matrix::quick([ - [-2.407704654895666, 15, -500.], - [2500.0, 12.437810945273633, 25], - [31.818181818181817, 7, -7], + $expected = Matrix::fromArray([ + [-2.407704654895666, 15.0, -500.], + [2500.0, 12.437810945273633, 25.0], + [31.818181818181817, 7.0, -7.0], ]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -149,23 +167,23 @@ public function divide() : void */ public function add() : void { - $a = ColumnVector::quick([-15, 25, 35]); + $a = ColumnVector::fromArray([-15.0, 25.0, 35.0]); - $b = Matrix::quick([ - [6.23, -1, 0.03], - [0.01, 2.01, 1], - [1.1, 5, -5], + $b = Matrix::fromArray([ + [6.23, -1.0, 0.03], + [0.01, 2.01, 1.0], + [1.1, 5.0, -5.0], ]); $c = $a->add($b); - $expected = Matrix::quick([ - [-8.77, -16, -14.97], - [25.01, 27.009999999999998, 26], - [36.1, 40, 30], + $expected = Matrix::fromArray([ + [-8.77, -16.0, -14.97], + [25.01, 27.009999999999998, 26.0], + [36.1, 40.0, 30.0], ]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -173,23 +191,23 @@ public function add() : void */ public function subtract() : void { - $a = ColumnVector::quick([-15, 25, 35]); + $a = ColumnVector::fromArray([-15.0, 25.0, 35.0]); - $b = Matrix::quick([ - [6.23, -1, 0.03], - [0.01, 2.01, 1], - [1.1, 5, -5], + $b = Matrix::fromArray([ + [6.23, -1.0, 0.03], + [0.01, 2.01, 1.0], + [1.1, 5.0, -5.0], ]); $c = $a->subtract($b); - $expected = Matrix::quick([ - [-21.23, -14, -15.03], - [24.99, 22.990000000000002, 24], - [33.9, 30, 40], + $expected = Matrix::fromArray([ + [-21.23, -14.0, -15.03], + [24.99, 22.990000000000002, 24.0], + [33.9, 30.0, 40.0], ]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -197,23 +215,23 @@ public function subtract() : void */ public function equal() : void { - $a = ColumnVector::quick([-15, 25, 35]); + $a = ColumnVector::fromArray([-15.0, 25.0, 35.0]); - $b = Matrix::quick([ - [6.23, -1, 0.03], - [0.01, 2.01, 1], - [1.1, 5, -5], + $b = Matrix::fromArray([ + [6.23, -1.0, 0.03], + [0.01, 2.01, 1.0], + [1.1, 5.0, -5.0], ]); $c = $a->equal($b); - $expected = Matrix::quick([ - [0, 0, 0], - [0, 0, 0], - [0, 0, 0], + $expected = Matrix::fromArray([ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], ]); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -221,23 +239,23 @@ public function equal() : void */ public function notEqual() : void { - $a = ColumnVector::quick([-15, 25, 35]); + $a = ColumnVector::fromArray([-15.0, 25.0, 35.0]); - $b = Matrix::quick([ - [6.23, -1, 0.03], - [0.01, 2.01, 1], - [1.1, 5, -5], + $b = Matrix::fromArray([ + [6.23, -1.0, 0.03], + [0.01, 2.01, 1.0], + [1.1, 5.0, -5.0], ]); $c = $a->notEqual($b); - $expected = Matrix::quick([ - [1, 1, 1], - [1, 1, 1], - [1, 1, 1], + $expected = Matrix::fromArray([ + [1.0, 1.0, 1.0], + [1.0, 1.0, 1.0], + [1.0, 1.0, 1.0], ]); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -245,23 +263,23 @@ public function notEqual() : void */ public function greater() : void { - $a = ColumnVector::quick([-15, 25, 35]); + $a = ColumnVector::fromArray([-15.0, 25.0, 35.0]); - $b = Matrix::quick([ - [6.23, -1, 0.03], - [0.01, 2.01, 1], - [1.1, 5, -5], + $b = Matrix::fromArray([ + [6.23, -1.0, 0.03], + [0.01, 2.01, 1.0], + [1.1, 5.0, -5.0], ]); $c = $a->greater($b); - $expected = Matrix::quick([ - [0, 0, 0], - [1, 1, 1], - [1, 1, 1], + $expected = Matrix::fromArray([ + [0.0, 0.0, 0.0], + [1.0, 1.0, 1.0], + [1.0, 1.0, 1.0], ]); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -269,23 +287,23 @@ public function greater() : void */ public function greaterEqual() : void { - $a = ColumnVector::quick([-15, 25, 35]); + $a = ColumnVector::fromArray([-15.0, 25.0, 35.0]); - $b = Matrix::quick([ - [6.23, -1, 0.03], - [0.01, 2.01, 1], - [1.1, 5, -5], + $b = Matrix::fromArray([ + [6.23, -1.0, 0.03], + [0.01, 2.01, 1.0], + [1.1, 5.0, -5.0], ]); $c = $a->greaterEqual($b); - $expected = Matrix::quick([ - [0, 0, 0], - [1, 1, 1], - [1, 1, 1], + $expected = Matrix::fromArray([ + [0.0, 0.0, 0.0], + [1.0, 1.0, 1.0], + [1.0, 1.0, 1.0], ]); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -293,23 +311,23 @@ public function greaterEqual() : void */ public function less() : void { - $a = ColumnVector::quick([-15, 25, 35]); + $a = ColumnVector::fromArray([-15.0, 25.0, 35.0]); - $b = Matrix::quick([ - [6.23, -1, 0.03], - [0.01, 2.01, 1], - [1.1, 5, -5], + $b = Matrix::fromArray([ + [6.23, -1.0, 0.03], + [0.01, 2.01, 1.0], + [1.1, 5.0, -5.0], ]); $c = $a->less($b); - $expected = Matrix::quick([ - [1, 1, 1], - [0, 0, 0], - [0, 0, 0], + $expected = Matrix::fromArray([ + [1.0, 1.0, 1.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], ]); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -317,23 +335,23 @@ public function less() : void */ public function lessEqual() : void { - $a = ColumnVector::quick([-15, 25, 35]); + $a = ColumnVector::fromArray([-15.0, 25.0, 35.0]); - $b = Matrix::quick([ - [6.23, -1, 0.03], - [0.01, 2.01, 1], - [1.1, 5, -5], + $b = Matrix::fromArray([ + [6.23, -1.0, 0.03], + [0.01, 2.01, 1.0], + [1.1, 5.0, -5.0], ]); $c = $a->lessEqual($b); - $expected = Matrix::quick([ - [1, 1, 1], - [0, 0, 0], - [0, 0, 0], + $expected = Matrix::fromArray([ + [1.0, 1.0, 1.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], ]); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -341,12 +359,12 @@ public function lessEqual() : void */ public function transposeReturnsVector() : void { - $a = ColumnVector::quick([1.0, 2.0, 3.0]); + $a = ColumnVector::fromArray([1.0, 2.0, 3.0]); $b = $a->transpose(); $this->assertInstanceOf(Vector::class, $b); - $this->assertEquals(Vector::quick([1.0, 2.0, 3.0]), $b); + $this->assertEquals(Vector::fromArray([1.0, 2.0, 3.0])->asArray(), $b->asArray()); } /** @@ -354,7 +372,7 @@ public function transposeReturnsVector() : void */ public function sizes() : void { - $a = ColumnVector::quick([1.0, 2.0, 3.0]); + $a = ColumnVector::fromArray([1.0, 2.0, 3.0]); $this->assertEquals(3, $a->m()); $this->assertEquals(1, $a->n()); @@ -366,21 +384,21 @@ public function sizes() : void */ public function matmul() : void { - $a = ColumnVector::quick([1.0, 2.0, 3.0]); + $a = ColumnVector::fromArray([1.0, 2.0, 3.0]); - $b = Matrix::quick([ + $b = Matrix::fromArray([ [1.0, 2.0, 3.0], ]); $c = $a->matmul($b); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [1.0, 2.0, 3.0], [2.0, 4.0, 6.0], [3.0, 6.0, 9.0], ]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -390,7 +408,7 @@ public function matmulDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - ColumnVector::quick([1.0, 2.0, 3.0])->matmul(Matrix::quick([ + (ColumnVector::fromArray([1.0, 2.0, 3.0]))->matmul(Matrix::fromArray([ [1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0], [9.0, 10.0, 11.0, 12.0], @@ -402,9 +420,9 @@ public function matmulDimensionMismatchThrows() : void */ public function powMatrix() : void { - $a = ColumnVector::quick([2.0, 3.0, 4.0]); + $a = ColumnVector::fromArray([2.0, 3.0, 4.0]); - $b = Matrix::quick([ + $b = Matrix::fromArray([ [1.0, 2.0, 3.0], [1.0, 1.0, 1.0], [2.0, 0.0, 1.0], @@ -412,13 +430,13 @@ public function powMatrix() : void $c = $a->powMatrix($b); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [2.0, 4.0, 8.0], [3.0, 3.0, 3.0], [16.0, 1.0, 4.0], ]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -428,7 +446,7 @@ public function powMatrixDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - ColumnVector::quick([1.0, 2.0, 3.0])->powMatrix(Matrix::quick([ + (ColumnVector::fromArray([1.0, 2.0, 3.0]))->powMatrix(Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], ])); @@ -439,9 +457,9 @@ public function powMatrixDimensionMismatchThrows() : void */ public function modMatrix() : void { - $a = ColumnVector::quick([10.0, 12.0, 15.0]); + $a = ColumnVector::fromArray([10.0, 12.0, 15.0]); - $b = Matrix::quick([ + $b = Matrix::fromArray([ [3.0, 4.0, 5.0], [2.0, 3.0, 4.0], [5.0, 6.0, 7.0], @@ -449,13 +467,13 @@ public function modMatrix() : void $c = $a->modMatrix($b); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [1.0, 2.0, 0.0], [0.0, 0.0, 0.0], [0.0, 3.0, 1.0], ]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -465,7 +483,7 @@ public function modMatrixDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - ColumnVector::quick([1.0, 2.0, 3.0])->modMatrix(Matrix::quick([ + (ColumnVector::fromArray([1.0, 2.0, 3.0]))->modMatrix(Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], ])); @@ -478,7 +496,7 @@ public function multiplyMatrixDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - ColumnVector::quick([1.0, 2.0, 3.0])->multiplyMatrix(Matrix::quick([ + (ColumnVector::fromArray([1.0, 2.0, 3.0]))->multiplyMatrix(Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], ])); @@ -491,7 +509,7 @@ public function divideMatrixDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - ColumnVector::quick([1.0, 2.0, 3.0])->divideMatrix(Matrix::quick([ + (ColumnVector::fromArray([1.0, 2.0, 3.0]))->divideMatrix(Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], ])); diff --git a/tests/Decompositions/CholeskyTest.php b/tests/Decompositions/CholeskyTest.php index 6dc819d..e3998b7 100644 --- a/tests/Decompositions/CholeskyTest.php +++ b/tests/Decompositions/CholeskyTest.php @@ -25,24 +25,24 @@ class CholeskyTest extends TestCase */ public function decompose2x2() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [9.0, 3.0], [3.0, 5.0], ]); $ch = Cholesky::decompose($a); - $l = Matrix::quick([ + $l = Matrix::fromArray([ [3.0, 0.0], [1.0, 2.0], ]); $expected = new Cholesky($l); - $this->assertEqualsWithDelta($expected, $ch, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->l()->asArray(), $ch->l()->asArray(), self::MAX_DELTA); // Cross-check: L * L^T reconstructs A. - $this->assertEqualsWithDelta($a, $ch->l()->matmul($ch->lT()), self::MAX_DELTA); + $this->assertEqualsWithDelta($a->asArray(), $ch->l()->matmul($ch->lT())->asArray(), self::MAX_DELTA); } /** @@ -50,7 +50,7 @@ public function decompose2x2() : void */ public function decompose3x3() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [2.0, -1.0, 0.0], [-1.0, 2.0, -1.0], [0.0, -1.0, 2.0], @@ -58,15 +58,15 @@ public function decompose3x3() : void $ch = Cholesky::decompose($a); - $l = Matrix::quick([ - [1.4142135623730951, 0, 0], - [-0.7071067811865475, 1.224744871391589, 0], - [0, -0.8164965809277261, 1.1547005383792515], + $l = Matrix::fromArray([ + [1.4142135623730951, 0.0, 0.0], + [-0.7071067811865475, 1.224744871391589, 0.0], + [0.0, -0.8164965809277261, 1.1547005383792515], ]); $expected = new Cholesky($l); - $this->assertEqualsWithDelta($expected, $ch, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->l()->asArray(), $ch->l()->asArray(), self::MAX_DELTA); } /** @@ -74,15 +74,15 @@ public function decompose3x3() : void */ public function decompose1x1() : void { - $a = Matrix::quick([[9.0]]); + $a = Matrix::fromArray([[9.0]]); $ch = Cholesky::decompose($a); - $l = Matrix::quick([[3.0]]); + $l = Matrix::fromArray([[3.0]]); $expected = new Cholesky($l); - $this->assertEqualsWithDelta($expected, $ch, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->l()->asArray(), $ch->l()->asArray(), self::MAX_DELTA); } /** @@ -90,7 +90,7 @@ public function decompose1x1() : void */ public function decomposeDiagonal() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [4.0, 0.0, 0.0], [0.0, 9.0, 0.0], [0.0, 0.0, 16.0], @@ -98,7 +98,7 @@ public function decomposeDiagonal() : void $ch = Cholesky::decompose($a); - $l = Matrix::quick([ + $l = Matrix::fromArray([ [2.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 4.0], @@ -106,7 +106,7 @@ public function decomposeDiagonal() : void $expected = new Cholesky($l); - $this->assertEqualsWithDelta($expected, $ch, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->l()->asArray(), $ch->l()->asArray(), self::MAX_DELTA); } /** @@ -116,7 +116,7 @@ public function decomposeNonSquareThrows() : void { $this->expectException(InvalidArgumentException::class); - Cholesky::decompose(Matrix::quick([ + Cholesky::decompose(Matrix::fromArray([ [1.0, 2.0, 3.0], [4.0, 5.0, 6.0], ])); @@ -129,7 +129,7 @@ public function decomposeIndefiniteThrows() : void { $this->expectException(RuntimeException::class); - Cholesky::decompose(Matrix::quick([ + Cholesky::decompose(Matrix::fromArray([ [1.0, 2.0], [2.0, 1.0], ])); @@ -142,7 +142,7 @@ public function decomposeZeroPivotThrows() : void { $this->expectException(RuntimeException::class); - Cholesky::decompose(Matrix::quick([ + Cholesky::decompose(Matrix::fromArray([ [0.0, 1.0], [1.0, 1.0], ])); @@ -155,7 +155,7 @@ public function decomposeSingularThrows() : void { $this->expectException(RuntimeException::class); - Cholesky::decompose(Matrix::quick([ + Cholesky::decompose(Matrix::fromArray([ [1.0, 2.0], [2.0, 4.0], ])); @@ -166,14 +166,14 @@ public function decomposeSingularThrows() : void */ public function lTIsTranspose() : void { - $l = Matrix::quick([ + $l = Matrix::fromArray([ [3.0, 0.0], [1.0, 2.0], ]); $ch = new Cholesky($l); - $this->assertEqualsWithDelta($l->transpose(), $ch->lT(), self::MAX_DELTA); + $this->assertEqualsWithDelta($l->transpose()->asArray(), $ch->lT()->asArray(), self::MAX_DELTA); } /** @@ -181,20 +181,20 @@ public function lTIsTranspose() : void */ public function accessorsReturnMatrices() : void { - $l = Matrix::quick([ + $l = Matrix::fromArray([ [1.0, 0.0], [0.5, 1.0], ]); $ch = new Cholesky($l); - $this->assertEquals($l, $ch->l()); + $this->assertEquals($l->asArray(), $ch->l()->asArray()); - $expectedT = Matrix::quick([ + $expectedT = Matrix::fromArray([ [1.0, 0.5], [0.0, 1.0], ]); - $this->assertEqualsWithDelta($expectedT, $ch->lT(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expectedT->asArray(), $ch->lT()->asArray(), self::MAX_DELTA); } } diff --git a/tests/Decompositions/EigenTest.php b/tests/Decompositions/EigenTest.php index efe9104..a7f4cb0 100644 --- a/tests/Decompositions/EigenTest.php +++ b/tests/Decompositions/EigenTest.php @@ -24,7 +24,7 @@ class EigenTest extends TestCase */ public function decomposeGeneral3x3() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -52,7 +52,7 @@ public function decomposeGeneral3x3() : void */ public function decomposeSymmetric3x3() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [3.0, -1.0, 0.0], [-1.0, 2.0, -1.0], [0.0, -1.0, 3.0], @@ -72,7 +72,7 @@ public function decomposeSymmetric3x3() : void */ public function decomposeSymmetric2x2() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [9.0, 3.0], [3.0, 5.0], ]); @@ -89,7 +89,7 @@ public function decomposeSymmetric2x2() : void */ public function decomposeGeneralAndSymmetricAgree() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [3.0, -1.0, 0.0], [-1.0, 2.0, -1.0], [0.0, -1.0, 3.0], @@ -112,7 +112,7 @@ public function decomposeGeneralAndSymmetricAgree() : void */ public function decompose1x1() : void { - $a = Matrix::quick([[9.0]]); + $a = Matrix::fromArray([[9.0]]); $eig = Eigen::decompose($a); @@ -120,7 +120,7 @@ public function decompose1x1() : void $this->assertEquals([9.0], $eig->eigenvalues()); - $this->assertEqualsWithDelta(Matrix::quick([[1.0]]), $eig->eigenvectors(), self::MAX_DELTA); + $this->assertEqualsWithDelta(Matrix::fromArray([[1.0]])->asArray(), $eig->eigenvectors()->asArray(), self::MAX_DELTA); } /** @@ -128,7 +128,7 @@ public function decompose1x1() : void */ public function decomposeDiagonal() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [2.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 5.0], @@ -148,7 +148,7 @@ public function decomposeNonSquareThrows() : void { $this->expectException(InvalidArgumentException::class); - Eigen::decompose(Matrix::quick([ + Eigen::decompose(Matrix::fromArray([ [1.0, 2.0, 3.0], [4.0, 5.0, 6.0], ])); @@ -161,7 +161,7 @@ public function constructAndAccess() : void { $eigenvalues = [1.0, 2.0, 3.0]; - $eigenvectors = Matrix::quick([ + $eigenvectors = Matrix::fromArray([ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], @@ -170,7 +170,7 @@ public function constructAndAccess() : void $eig = new Eigen($eigenvalues, $eigenvectors); $this->assertEquals($eigenvalues, $eig->eigenvalues()); - $this->assertEqualsWithDelta($eigenvectors, $eig->eigenvectors(), self::MAX_DELTA); + $this->assertEqualsWithDelta($eigenvectors->asArray(), $eig->eigenvectors()->asArray(), self::MAX_DELTA); } /** @@ -180,7 +180,7 @@ public function constructAndAccess() : void */ public function decomposeComplexPair() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [0.0, -1.0], [1.0, 0.0], ]); @@ -226,7 +226,7 @@ public function decomposeComplexPair() : void */ public function decomposeComplexPairWithReal() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [0.0, -1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 2.0], diff --git a/tests/Decompositions/LUTest.php b/tests/Decompositions/LUTest.php index 3f79c46..066027d 100644 --- a/tests/Decompositions/LUTest.php +++ b/tests/Decompositions/LUTest.php @@ -25,7 +25,7 @@ class LUTest extends TestCase */ public function decompose3x3() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -33,33 +33,35 @@ public function decompose3x3() : void $lu = LU::decompose($a); - $l = Matrix::quick([ - [1.0, 0, 0], - [0.18181818181818182, 1.0, 0], + $l = Matrix::fromArray([ + [1.0, 0.0, 0.0], + [0.18181818181818182, 1.0, 0.0], [0.9090909090909091, 0.6709677419354838, 1.0], ]); - $u = Matrix::quick([ + $u = Matrix::fromArray([ [22.0, -17.0, 12.0], [0.0, 14.09090909090909, -4.181818181818182], [0.0, 0.0, -17.10322580645161], ]); - $p = Matrix::quick([ - [1.0, 0, 0], - [0.0, 1.0, 0], + $p = Matrix::fromArray([ + [1.0, 0.0, 0.0], + [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], ]); $expected = new LU($l, $u, $p); - $this->assertEqualsWithDelta($expected, $lu, self::MAX_DELTA); + $this->assertEqualsWithDelta($l->asArray(), $lu->l()->asArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta($u->asArray(), $lu->u()->asArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta($p->asArray(), $lu->p()->asArray(), self::MAX_DELTA); // And, cross-check the factors are consistent: P * A == L * U. $pa = $lu->p()->matmul($a); $luProd = $lu->l()->matmul($lu->u()); - $this->assertEqualsWithDelta($pa, $luProd, self::MAX_DELTA); + $this->assertEqualsWithDelta($pa->asArray(), $luProd->asArray(), self::MAX_DELTA); } /** @@ -67,7 +69,7 @@ public function decompose3x3() : void */ public function decomposeRequiresPivoting() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [0.0, 1.0, 0.0, 0.0], [-1.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 2.0], @@ -80,7 +82,7 @@ public function decomposeRequiresPivoting() : void $pa = $lu->p()->matmul($a); $luProd = $lu->l()->matmul($lu->u()); - $this->assertEqualsWithDelta($pa, $luProd, self::MAX_DELTA); + $this->assertEqualsWithDelta($pa->asArray(), $luProd->asArray(), self::MAX_DELTA); } /** @@ -88,17 +90,19 @@ public function decomposeRequiresPivoting() : void */ public function decompose1x1() : void { - $a = Matrix::quick([[9.0]]); + $a = Matrix::fromArray([[9.0]]); $lu = LU::decompose($a); - $l = Matrix::quick([[1.0]]); - $u = Matrix::quick([[9.0]]); - $p = Matrix::quick([[1.0]]); + $l = Matrix::fromArray([[1.0]]); + $u = Matrix::fromArray([[9.0]]); + $p = Matrix::fromArray([[1.0]]); $expected = new LU($l, $u, $p); - $this->assertEqualsWithDelta($expected, $lu, self::MAX_DELTA); + $this->assertEqualsWithDelta($l->asArray(), $lu->l()->asArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta($u->asArray(), $lu->u()->asArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta($p->asArray(), $lu->p()->asArray(), self::MAX_DELTA); } /** @@ -106,31 +110,33 @@ public function decompose1x1() : void */ public function decomposeDiagonal() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [2.0, 0.0], [0.0, 3.0], ]); $lu = LU::decompose($a); - $l = Matrix::quick([ + $l = Matrix::fromArray([ [1.0, 0.0], [0.0, 1.0], ]); - $u = Matrix::quick([ + $u = Matrix::fromArray([ [2.0, 0.0], [0.0, 3.0], ]); - $p = Matrix::quick([ + $p = Matrix::fromArray([ [1.0, 0.0], [0.0, 1.0], ]); $expected = new LU($l, $u, $p); - $this->assertEqualsWithDelta($expected, $lu, self::MAX_DELTA); + $this->assertEqualsWithDelta($l->asArray(), $lu->l()->asArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta($u->asArray(), $lu->u()->asArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta($p->asArray(), $lu->p()->asArray(), self::MAX_DELTA); } /** @@ -140,7 +146,7 @@ public function decomposeNonSquareThrows() : void { $this->expectException(InvalidArgumentException::class); - LU::decompose(Matrix::quick([ + LU::decompose(Matrix::fromArray([ [1.0, 2.0, 3.0], [4.0, 5.0, 6.0], ])); @@ -153,7 +159,7 @@ public function decomposeSingularThrows() : void { $this->expectException(RuntimeException::class); - LU::decompose(Matrix::quick([ + LU::decompose(Matrix::fromArray([ [1.0, 2.0], [2.0, 4.0], ])); @@ -164,25 +170,25 @@ public function decomposeSingularThrows() : void */ public function accessorsReturnMatrices() : void { - $l = Matrix::quick([ + $l = Matrix::fromArray([ [1.0, 0.0], [0.5, 1.0], ]); - $u = Matrix::quick([ + $u = Matrix::fromArray([ [2.0, 3.0], [0.0, 4.0], ]); - $p = Matrix::quick([ + $p = Matrix::fromArray([ [0.0, 1.0], [1.0, 0.0], ]); $lu = new LU($l, $u, $p); - $this->assertEquals($l, $lu->l()); - $this->assertEquals($u, $lu->u()); - $this->assertEquals($p, $lu->p()); + $this->assertEquals($l->asArray(), $lu->l()->asArray()); + $this->assertEquals($u->asArray(), $lu->u()->asArray()); + $this->assertEquals($p->asArray(), $lu->p()->asArray()); } } diff --git a/tests/Decompositions/SVDTest.php b/tests/Decompositions/SVDTest.php index 57d36ff..5c1d946 100644 --- a/tests/Decompositions/SVDTest.php +++ b/tests/Decompositions/SVDTest.php @@ -23,7 +23,7 @@ class SVDTest extends TestCase */ public function decomposeSquare3x3() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -38,11 +38,11 @@ public function decomposeSquare3x3() : void $this->assertEqualsWithDelta(8.929610580306822, $svd->singularValues()[2], self::MAX_DELTA); // The decomposition must reconstruct the original matrix. - $this->assertEqualsWithDelta($a, $this->reconstruct($svd, 3, 3), self::MAX_DELTA); + $this->assertEqualsWithDelta($a->asArray(), $this->reconstruct($svd, 3, 3)->asArray(), self::MAX_DELTA); // Both U and V must be orthogonal matrices. - $this->assertEqualsWithDelta(Matrix::identity(3), $svd->u()->transpose()->matmul($svd->u()), self::MAX_DELTA); - $this->assertEqualsWithDelta(Matrix::identity(3), $svd->vT()->matmul($svd->vT()->transpose()), self::MAX_DELTA); + $this->assertEqualsWithDelta(Matrix::identity(3)->asArray(), $svd->u()->transpose()->matmul($svd->u())->asArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta(Matrix::identity(3)->asArray(), $svd->vT()->matmul($svd->vT()->transpose())->asArray(), self::MAX_DELTA); } /** @@ -50,7 +50,7 @@ public function decomposeSquare3x3() : void */ public function decomposeSquare2x2() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], ]); @@ -59,10 +59,10 @@ public function decomposeSquare2x2() : void $this->assertCount(2, $svd->singularValues()); - $this->assertEqualsWithDelta($a, $this->reconstruct($svd, 2, 2), self::MAX_DELTA); + $this->assertEqualsWithDelta($a->asArray(), $this->reconstruct($svd, 2, 2)->asArray(), self::MAX_DELTA); - $this->assertEqualsWithDelta(Matrix::identity(2), $svd->u()->transpose()->matmul($svd->u()), self::MAX_DELTA); - $this->assertEqualsWithDelta(Matrix::identity(2), $svd->vT()->matmul($svd->vT()->transpose()), self::MAX_DELTA); + $this->assertEqualsWithDelta(Matrix::identity(2)->asArray(), $svd->u()->transpose()->matmul($svd->u())->asArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta(Matrix::identity(2)->asArray(), $svd->vT()->matmul($svd->vT()->transpose())->asArray(), self::MAX_DELTA); } /** @@ -70,7 +70,7 @@ public function decomposeSquare2x2() : void */ public function decomposeTall() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], [5.0, 6.0], @@ -84,10 +84,10 @@ public function decomposeTall() : void $this->assertSame([4, 4], $svd->u()->shape()); $this->assertSame([2, 2], $svd->vT()->shape()); - $this->assertEqualsWithDelta($a, $this->reconstruct($svd, 4, 2), self::MAX_DELTA); + $this->assertEqualsWithDelta($a->asArray(), $this->reconstruct($svd, 4, 2)->asArray(), self::MAX_DELTA); - $this->assertEqualsWithDelta(Matrix::identity(4), $svd->u()->transpose()->matmul($svd->u()), self::MAX_DELTA); - $this->assertEqualsWithDelta(Matrix::identity(2), $svd->vT()->matmul($svd->vT()->transpose()), self::MAX_DELTA); + $this->assertEqualsWithDelta(Matrix::identity(4)->asArray(), $svd->u()->transpose()->matmul($svd->u())->asArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta(Matrix::identity(2)->asArray(), $svd->vT()->matmul($svd->vT()->transpose())->asArray(), self::MAX_DELTA); } /** @@ -95,7 +95,7 @@ public function decomposeTall() : void */ public function decomposeWide() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 2.0, 3.0], [4.0, 5.0, 6.0], ]); @@ -107,10 +107,10 @@ public function decomposeWide() : void $this->assertSame([2, 2], $svd->u()->shape()); $this->assertSame([3, 3], $svd->vT()->shape()); - $this->assertEqualsWithDelta($a, $this->reconstruct($svd, 2, 3), self::MAX_DELTA); + $this->assertEqualsWithDelta($a->asArray(), $this->reconstruct($svd, 2, 3)->asArray(), self::MAX_DELTA); - $this->assertEqualsWithDelta(Matrix::identity(2), $svd->u()->transpose()->matmul($svd->u()), self::MAX_DELTA); - $this->assertEqualsWithDelta(Matrix::identity(3), $svd->vT()->matmul($svd->vT()->transpose()), self::MAX_DELTA); + $this->assertEqualsWithDelta(Matrix::identity(2)->asArray(), $svd->u()->transpose()->matmul($svd->u())->asArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta(Matrix::identity(3)->asArray(), $svd->vT()->matmul($svd->vT()->transpose())->asArray(), self::MAX_DELTA); } /** @@ -118,13 +118,13 @@ public function decomposeWide() : void */ public function decompose1x1() : void { - $a = Matrix::quick([[9.0]]); + $a = Matrix::fromArray([[9.0]]); $svd = SVD::decompose($a); $this->assertEqualsWithDelta([9.0], $svd->singularValues(), self::MAX_DELTA); - $this->assertEqualsWithDelta($a, $this->reconstruct($svd, 1, 1), self::MAX_DELTA); + $this->assertEqualsWithDelta($a->asArray(), $this->reconstruct($svd, 1, 1)->asArray(), self::MAX_DELTA); } /** @@ -132,7 +132,7 @@ public function decompose1x1() : void */ public function decomposeRankDeficient() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 1.0], [2.0, 2.0], ]); @@ -144,10 +144,10 @@ public function decomposeRankDeficient() : void $this->assertEqualsWithDelta(sqrt(10.0), $svd->singularValues()[0], self::MAX_DELTA); $this->assertEqualsWithDelta(0.0, $svd->singularValues()[1], self::MAX_DELTA); - $this->assertEqualsWithDelta($a, $this->reconstruct($svd, 2, 2), self::MAX_DELTA); + $this->assertEqualsWithDelta($a->asArray(), $this->reconstruct($svd, 2, 2)->asArray(), self::MAX_DELTA); - $this->assertEqualsWithDelta(Matrix::identity(2), $svd->u()->transpose()->matmul($svd->u()), self::MAX_DELTA); - $this->assertEqualsWithDelta(Matrix::identity(2), $svd->vT()->matmul($svd->vT()->transpose()), self::MAX_DELTA); + $this->assertEqualsWithDelta(Matrix::identity(2)->asArray(), $svd->u()->transpose()->matmul($svd->u())->asArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta(Matrix::identity(2)->asArray(), $svd->vT()->matmul($svd->vT()->transpose())->asArray(), self::MAX_DELTA); } /** @@ -155,7 +155,7 @@ public function decomposeRankDeficient() : void */ public function decomposePreservesTinySingularValues() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 0.0, 0.0], [0.0, 1e-9, 0.0], [0.0, 0.0, 0.0], @@ -169,7 +169,7 @@ public function decomposePreservesTinySingularValues() : void $this->assertEqualsWithDelta(1e-9, $svd->singularValues()[1], self::MAX_DELTA); $this->assertEqualsWithDelta(0.0, $svd->singularValues()[2], self::MAX_DELTA); - $this->assertEqualsWithDelta($a, $this->reconstruct($svd, 3, 3), self::MAX_DELTA); + $this->assertEqualsWithDelta($a->asArray(), $this->reconstruct($svd, 3, 3)->asArray(), self::MAX_DELTA); } /** @@ -177,36 +177,36 @@ public function decomposePreservesTinySingularValues() : void */ public function constructAndAccess() : void { - $u = Matrix::quick([ + $u = Matrix::fromArray([ [1.0, 0.0], [0.0, 1.0], ]); $singularValues = [5.0, 3.0]; - $vT = Matrix::quick([ + $vT = Matrix::fromArray([ [1.0, 0.0], [0.0, 1.0], ]); $svd = new SVD($u, $singularValues, $vT); - $this->assertEqualsWithDelta($u, $svd->u(), self::MAX_DELTA); + $this->assertEqualsWithDelta($u->asArray(), $svd->u()->asArray(), self::MAX_DELTA); $this->assertEquals($singularValues, $svd->singularValues()); - $this->assertEqualsWithDelta($vT, $svd->vT(), self::MAX_DELTA); + $this->assertEqualsWithDelta($vT->asArray(), $svd->vT()->asArray(), self::MAX_DELTA); // v is the transpose of vT. - $this->assertEqualsWithDelta($vT->transpose(), $svd->v(), self::MAX_DELTA); + $this->assertEqualsWithDelta($vT->transpose()->asArray(), $svd->v()->asArray(), self::MAX_DELTA); // The singular value matrix is an m by n matrix with the singular values on the diagonal. $this->assertSame([2, 2], $svd->s()->shape()); - $expectedS = Matrix::quick([ + $expectedS = Matrix::fromArray([ [5.0, 0.0], [0.0, 3.0], ]); - $this->assertEqualsWithDelta($expectedS, $svd->s(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expectedS->asArray(), $svd->s()->asArray(), self::MAX_DELTA); } /** @@ -225,6 +225,6 @@ private function reconstruct(SVD $svd, int $m, int $n) : Matrix $s[$i][$i] = $value; } - return $svd->u()->matmul(Matrix::quick($s))->matmul($svd->vT()); + return $svd->u()->matmul(Matrix::fromArray($s))->matmul($svd->vT()); } } diff --git a/tests/MatrixTest.php b/tests/MatrixTest.php index 449b19d..5049861 100644 --- a/tests/MatrixTest.php +++ b/tests/MatrixTest.php @@ -42,10 +42,10 @@ class MatrixTest extends TestCase */ public function build() : void { - $matrix = Matrix::build([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $matrix = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); $this->assertInstanceOf(Matrix::class, $matrix); @@ -64,9 +64,9 @@ public function build() : void */ public function buildCastsIntegersToFloatsAndPreservesShape() : void { - $matrix = Matrix::build([ - [1, 2, 3], - [4, 5, 6], + $matrix = Matrix::fromArray([ + [1.0, 2.0, 3.0], + [4.0, 5.0, 6.0], ]); $this->assertSame([2, 3], $matrix->shape()); @@ -90,6 +90,46 @@ public function buildCastsIntegersToFloatsAndPreservesShape() : void ], $result, self::MAX_DELTA); } + /** + * @test + */ + public function fromArrayThrowsOnNonArrayRow() : void + { + $this->expectException(InvalidArgumentException::class); + + Matrix::fromArray([ + [1.0, 2.0], + 3.0, + ]); + } + + /** + * @test + */ + public function fromArrayThrowsOnRaggedColumns() : void + { + $this->expectException(InvalidArgumentException::class); + + Matrix::fromArray([ + [1.0, 2.0], + [3.0], + ]); + } + + /** + * @test + */ + public function fromArraySkipsValidationWhenValidateFalse() : void + { + $matrix = Matrix::fromArray([ + [1.0, 2.0], + [3.0], + ], false); + + $this->assertInstanceOf(Matrix::class, $matrix); + $this->assertSame([2, 2], $matrix->shape()); + } + /** * @test */ @@ -97,14 +137,14 @@ public function identity() : void { $matrix = Matrix::identity(4); - $expected = Matrix::quick([ - [1, 0, 0, 0], - [0, 1, 0, 0], - [0, 0, 1, 0], - [0, 0, 0, 1], + $expected = Matrix::fromArray([ + [1.0, 0.0, 0.0, 0.0], + [0.0, 1.0, 0.0, 0.0], + [0.0, 0.0, 1.0, 0.0], + [0.0, 0.0, 0.0, 1.0], ]); - $this->assertEquals($expected, $matrix); + $this->assertEquals($expected->asArray(), $matrix->asArray()); } /** @@ -114,12 +154,12 @@ public function zeros() : void { $matrix = Matrix::zeros(2, 4); - $expected = Matrix::quick([ - [0, 0, 0, 0], - [0, 0, 0, 0], + $expected = Matrix::fromArray([ + [0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0], ]); - $this->assertEquals($expected, $matrix); + $this->assertEquals($expected->asArray(), $matrix->asArray()); } /** @@ -129,14 +169,14 @@ public function ones() : void { $matrix = Matrix::ones(4, 2); - $expected = Matrix::quick([ - [1, 1], - [1, 1], - [1, 1], - [1, 1], + $expected = Matrix::fromArray([ + [1.0, 1.0], + [1.0, 1.0], + [1.0, 1.0], + [1.0, 1.0], ]); - $this->assertEquals($expected, $matrix); + $this->assertEquals($expected->asArray(), $matrix->asArray()); } /** @@ -144,16 +184,16 @@ public function ones() : void */ public function diagonal() : void { - $matrix = Matrix::diagonal([0, 1, 4, 5]); + $matrix = Matrix::diagonal([0.0, 1.0, 4.0, 5.0]); - $expected = Matrix::quick([ - [0, 0, 0, 0], - [0, 1, 0, 0], - [0, 0, 4, 0], - [0, 0, 0, 5], + $expected = Matrix::fromArray([ + [0.0, 0.0, 0.0, 0.0], + [0.0, 1.0, 0.0, 0.0], + [0.0, 0.0, 4.0, 0.0], + [0.0, 0.0, 0.0, 5.0], ]); - $this->assertEquals($expected, $matrix); + $this->assertEquals($expected->asArray(), $matrix->asArray()); } /** @@ -161,16 +201,16 @@ public function diagonal() : void */ public function fill() : void { - $matrix = Matrix::fill(5, 4, 4); + $matrix = Matrix::fill(5.0, 4, 4); - $expected = Matrix::quick([ - [5, 5, 5, 5], - [5, 5, 5, 5], - [5, 5, 5, 5], - [5, 5, 5, 5], + $expected = Matrix::fromArray([ + [5.0, 5.0, 5.0, 5.0], + [5.0, 5.0, 5.0, 5.0], + [5.0, 5.0, 5.0, 5.0], + [5.0, 5.0, 5.0, 5.0], ]); - $this->assertEquals($expected, $matrix); + $this->assertEquals($expected->asArray(), $matrix->asArray()); } /** @@ -212,7 +252,7 @@ public function poissonZeroLambdaIsZero() : void $expected = Matrix::fill(0.0, 3, 3); - $this->assertEquals($expected, $matrix); + $this->assertEquals($expected->asArray(), $matrix->asArray()); } /** @@ -240,10 +280,10 @@ public function uniform() : void */ public function shape() : void { - $matrix = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $matrix = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); $this->assertEquals([3, 3], $matrix->shape()); @@ -254,9 +294,9 @@ public function shape() : void */ public function shapeString() : void { - $matrix = Matrix::quick([ - [22, -17, 12, 16], - [4, 11, -2, 18], + $matrix = Matrix::fromArray([ + [22.0, -17.0, 12.0, 16.0], + [4.0, 11.0, -2.0, 18.0], ]); $this->assertEquals('2 x 4', $matrix->shapeString()); @@ -280,18 +320,18 @@ public function isSquare(Matrix $matrix, $expected) : void public function isSquareProvider() : Generator { yield [ - Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]), true, ]; yield [ - Matrix::quick([ - [22, -17, 12, 16], - [4, 11, -2, 18], + Matrix::fromArray([ + [22.0, -17.0, 12.0, 16.0], + [4.0, 11.0, -2.0, 18.0], ]), false, ]; @@ -302,10 +342,10 @@ public function isSquareProvider() : Generator */ public function size() : void { - $matrix = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $matrix = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); $this->assertEquals(9, $matrix->size()); @@ -316,10 +356,10 @@ public function size() : void */ public function m() : void { - $matrix = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $matrix = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); $this->assertEquals(3, $matrix->m()); @@ -330,10 +370,10 @@ public function m() : void */ public function n() : void { - $matrix = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $matrix = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); $this->assertEquals(3, $matrix->n()); @@ -344,17 +384,17 @@ public function n() : void */ public function rowAsVector() : void { - $a = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $a = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); $b = $a->rowAsVector(1); - $expected = Vector::quick([4, 11, -2]); + $expected = Vector::fromArray([4.0, 11.0, -2.0]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -362,17 +402,17 @@ public function rowAsVector() : void */ public function columnAsVector() : void { - $a = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $a = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); $b = $a->columnAsVector(1); - $expected = ColumnVector::quick([-17, 11, -6]); + $expected = ColumnVector::fromArray([-17.0, 11.0, -6.0]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -380,17 +420,17 @@ public function columnAsVector() : void */ public function diagonalAsVector() : void { - $a = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $a = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); $b = $a->diagonalAsVector(); - $expected = Vector::quick([22, 11, -9]); + $expected = Vector::fromArray([22.0, 11.0, -9.0]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -398,41 +438,69 @@ public function diagonalAsVector() : void */ public function asArray() : void { - $matrix = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $matrix = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); $expected = [ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]; $this->assertEquals($expected, $matrix->asArray()); } + /** + * @test + */ + public function serialization() : void + { + $matrix = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + ]); + + $serialized = serialize($matrix); + + $this->assertStringNotContainsString('TensorBuffer', $serialized); + + $restored = unserialize($serialized); + + $this->assertInstanceOf(Matrix::class, $restored); + $this->assertEquals([2, 3], $restored->shape()); + $this->assertEquals([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + ], $restored->asArray()); + $this->assertSame(serialize($matrix), serialize($restored)); + } + /** * @test */ public function asVectors() : void { - $matrix = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $matrix = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); $vectors = $matrix->asVectors(); $expected = [ - Vector::quick([22, -17, 12]), - Vector::quick([4, 11, -2]), - Vector::quick([20, -6, -9]), + Vector::fromArray([22.0, -17.0, 12.0]), + Vector::fromArray([4.0, 11.0, -2.0]), + Vector::fromArray([20.0, -6.0, -9.0]), ]; - $this->assertEquals($expected, $vectors); + $this->assertEquals( + array_map(static fn (Vector $vector) => $vector->asArray(), $expected), + array_map(static fn (Vector $vector) => $vector->asArray(), $vectors) + ); } /** @@ -440,21 +508,24 @@ public function asVectors() : void */ public function asColumnVectors() : void { - $matrix = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $matrix = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); $vectors = $matrix->asColumnVectors(); $expected = [ - ColumnVector::quick([22, 4, 20]), - ColumnVector::quick([-17, 11, -6]), - ColumnVector::quick([12, -2, -9]), + ColumnVector::fromArray([22.0, 4.0, 20.0]), + ColumnVector::fromArray([-17.0, 11.0, -6.0]), + ColumnVector::fromArray([12.0, -2.0, -9.0]), ]; - $this->assertEquals($expected, $vectors); + $this->assertEquals( + array_map(static fn (ColumnVector $vector) => $vector->asArray(), $expected), + array_map(static fn (ColumnVector $vector) => $vector->asArray(), $vectors) + ); } /** @@ -462,17 +533,17 @@ public function asColumnVectors() : void */ public function flatten() : void { - $a = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $a = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); $b = $a->flatten(); - $expected = Vector::quick([22, -17, 12, 4, 11, -2, 20, -6, -9]); + $expected = Vector::fromArray([22.0, -17.0, 12.0, 4.0, 11.0, -2.0, 20.0, -6.0, -9.0]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -480,21 +551,86 @@ public function flatten() : void */ public function transpose() : void { - $a = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $a = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); $b = $a->transpose(); - $expected = Matrix::quick([ - [22, 4, 20], - [-17, 11, -6], - [12, -2, -9], + $expected = Matrix::fromArray([ + [22.0, 4.0, 20.0], + [-17.0, 11.0, -6.0], + [12.0, -2.0, -9.0], + ]); + + $this->assertEquals($expected->asArray(), $b->asArray()); + } + + /** + * Regression test: passing an array callable [instance, 'method'] to + * Matrix::map() must not segfault. The previous Zephir dynamic + * user-callback dispatch inside TensorBuffer::map() was triggered only + * for arrays holding a non-static instance and crashed on the second + * and later elements. + * + * @test + */ + public function mapWithInstanceArrayCallable() : void + { + $helper = new class() { + public float $slope = 0.1; + + public function activate(float $v) : float + { + return $v > 0.0 ? $v : $v * $this->slope; + } + }; + + $a = Matrix::fromArray([ + [1.0, -2.0], + [-3.0, 4.0], + ]); + + $b = $a->map([$helper, 'activate']); + + $expected = Matrix::fromArray([ + [1.0, -0.2], + [-0.3, 4.0], ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); + } + + /** + * A static array callable [Class::class, 'method'] must also work on + * Matrix::map() over a multi-element matrix. + * + * @test + */ + public function mapWithStaticArrayCallable() : void + { + $a = Matrix::fromArray([ + [7.0, -2.5], + [-3.0, 4.25], + ]); + + $helper = new class() { + public static function square(float $v) : float + { + return $v * $v; + } + }; + + $b = $a->map([get_class($helper), 'square']); + + $expected = Matrix::fromArray([ + [49.0, 6.25], + [9.0, 18.0625], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -502,21 +638,21 @@ public function transpose() : void */ public function inverse() : void { - $a = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $a = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); $b = $a->inverse(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [0.02093549603923048, 0.042436816295737464, 0.018483591097698978], [0.0007544322897019996, 0.08261033572236892, -0.017351942663145988], [0.04602036967182196, 0.03923047906450396, -0.05846850245190495], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -526,7 +662,7 @@ public function inverseNonSquareThrows() : void { $this->expectException(InvalidArgumentException::class); - Matrix::quick([ + Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], [5.0, 6.0], @@ -541,7 +677,7 @@ public function inverseSingularThrows() : void // Exactly singular (column 3 = column 0 - column 1 + column 2); the // inverse must be rejected rather than return a magnitude ~1e15 matrix // that does not satisfy A * A^-1 = I. - $a = Matrix::quick([ + $a = Matrix::fromArray([ [2.0, 1.0, 0.0, 1.0], [1.0, 2.0, 1.0, 0.0], [0.0, 1.0, 2.0, 1.0], @@ -555,24 +691,23 @@ public function inverseSingularThrows() : void /** * @test - * @requires extension tensor */ public function pseudoinverse() : void { - $a = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], + $a = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], ]); $b = $a->pseudoinverse(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [0.03147992432205172, 0.05583000490505223], [-0.009144418751313844, 0.07003713825239999], [0.01266554551187723, -0.0031357298016957483], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -580,10 +715,10 @@ public function pseudoinverse() : void */ public function det() : void { - $a = Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + $a = Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]); $this->assertEqualsWithDelta(-544.0, $a->det(), self::MAX_DELTA); @@ -596,7 +731,7 @@ public function detSingularIsZero() : void { // Exactly singular (column 3 = column 0 - column 1 + column 2); the // determinant must be ~0 rather than a spurious ~1e-15 value. - $a = Matrix::quick([ + $a = Matrix::fromArray([ [2.0, 1.0, 0.0, 1.0], [1.0, 2.0, 1.0, 0.0], [0.0, 1.0, 2.0, 1.0], @@ -611,10 +746,10 @@ public function detSingularIsZero() : void */ public function trace() : void { - $a = Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + $a = Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]); $this->assertEquals(21.0, $a->trace()); @@ -638,19 +773,31 @@ public function symmetric(Matrix $matrix, $expected) : void public function symmetricProvider() : Generator { yield [ - Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]), false, ]; yield [ - Matrix::quick([ - [1, 5, 2], - [5, 1, 3], - [2, 3, 1], + Matrix::fromArray([ + [1.0, 5.0, 2.0], + [5.0, 1.0, 3.0], + [2.0, 3.0, 1.0], + ]), + true, + ]; + + yield [ + Matrix::fromArray([]), + true, + ]; + + yield [ + Matrix::fromArray([ + [5.0], ]), true, ]; @@ -661,7 +808,7 @@ public function symmetricProvider() : Generator */ public function rank() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -669,7 +816,7 @@ public function rank() : void $this->assertEquals(3, $a->rank()); - $b = Matrix::quick([ + $b = Matrix::fromArray([ [1.0, 2.0, 3.0], [4.0, 5.0, 6.0], ]); @@ -679,7 +826,7 @@ public function rank() : void // Exactly singular (column 3 = column 0 - column 1 + column 2); the // rank must be 3, not 4, even though floating point leaves a ~1e-16 // residual on the diagonal. - $c = Matrix::quick([ + $c = Matrix::fromArray([ [2.0, 1.0, 0.0, 1.0], [1.0, 2.0, 1.0, 0.0], [0.0, 1.0, 2.0, 1.0], @@ -694,7 +841,7 @@ public function rank() : void */ public function fullRank() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -702,7 +849,7 @@ public function fullRank() : void $this->assertTrue($a->fullRank()); - $b = Matrix::quick([ + $b = Matrix::fromArray([ [1.0, 2.0, 3.0], [4.0, 5.0, 6.0], ]); @@ -710,7 +857,7 @@ public function fullRank() : void $this->assertTrue($b->fullRank()); // Exactly singular 4x4 (see rank() above); fullRank() must be false. - $c = Matrix::quick([ + $c = Matrix::fromArray([ [2.0, 1.0, 0.0, 1.0], [1.0, 2.0, 1.0, 0.0], [0.0, 1.0, 2.0, 1.0], @@ -725,7 +872,7 @@ public function fullRank() : void */ public function reciprocal() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -733,13 +880,13 @@ public function reciprocal() : void $b = $a->reciprocal(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [0.045454545454545456, -0.058823529411764705, 0.08333333333333333], [0.25, 0.09090909090909091, -0.5], [0.05, -0.16666666666666666, -0.1111111111111111], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -747,7 +894,7 @@ public function reciprocal() : void */ public function map() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -759,13 +906,13 @@ public function map() : void $b = $a->map($sign); - $expected = Matrix::quick([ - [1, -1, 1], - [1, 1, -1], - [1, -1, -1], + $expected = Matrix::fromArray([ + [1.0, -1.0, 1.0], + [1.0, 1.0, -1.0], + [1.0, -1.0, -1.0], ]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -773,7 +920,7 @@ public function map() : void */ public function reduce() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], ]); @@ -793,7 +940,7 @@ public function reduce() : void $this->assertEqualsWithDelta(-8.0, $a->reduce($subtract, 2.0), self::MAX_DELTA); // Must match Vector::reduce() for the same data and callback. - $v = Vector::quick([1.0, 2.0, 3.0, 4.0]); + $v = Vector::fromArray([1.0, 2.0, 3.0, 4.0]); $this->assertEqualsWithDelta($v->reduce($subtract), $a->reduce($subtract), self::MAX_DELTA); } @@ -803,7 +950,7 @@ public function reduce() : void */ public function ref() : void { - $matrix = Matrix::quick([ + $matrix = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -811,15 +958,16 @@ public function ref() : void $ref = $matrix->ref(); - $a = Matrix::quick([ - [22, -17, 12], - [0, 14.09090909090909, -4.181818181818182], - [0, 0, -17.10322580645161], + $a = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [0.0, 14.09090909090909, -4.181818181818182], + [0.0, 0.0, -17.10322580645161], ]); $expected = new REF($a, 0); - $this->assertEqualsWithDelta($expected, $ref, self::MAX_DELTA); + $this->assertEqualsWithDelta($a->asArray(), $ref->a()->asArray(), self::MAX_DELTA); + $this->assertEquals(0, $ref->swaps()); } /** @@ -827,7 +975,7 @@ public function ref() : void */ public function rref() : void { - $matrix = Matrix::quick([ + $matrix = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -835,15 +983,15 @@ public function rref() : void $rref = $matrix->rref(); - $a = Matrix::quick([ - [1, 0, 0], - [0, 1, 0], - [0, 0, 1], + $a = Matrix::fromArray([ + [1.0, 0.0, 0.0], + [0.0, 1.0, 0.0], + [0.0, 0.0, 1.0], ]); $expected = new RREF($a); - $this->assertEqualsWithDelta($expected, $rref, self::MAX_DELTA); + $this->assertEqualsWithDelta($a->asArray(), $rref->a()->asArray(), self::MAX_DELTA); } /** @@ -851,7 +999,7 @@ public function rref() : void */ public function lu() : void { - $matrix = Matrix::quick([ + $matrix = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -859,27 +1007,29 @@ public function lu() : void $lu = $matrix->lu(); - $l = Matrix::quick([ - [1.0, 0, 0], - [0.18181818181818182, 1.0, 0], + $l = Matrix::fromArray([ + [1.0, 0.0, 0.0], + [0.18181818181818182, 1.0, 0.0], [0.9090909090909091, 0.6709677419354838, 1.0], ]); - $u = Matrix::quick([ - [22, -17, 12], - [0, 14.09090909090909, -4.181818181818182], - [0, 0, -17.10322580645161], + $u = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [0.0, 14.09090909090909, -4.181818181818182], + [0.0, 0.0, -17.10322580645161], ]); - $p = Matrix::quick([ - [1, 0, 0], - [0, 1, 0], - [0, 0, 1], + $p = Matrix::fromArray([ + [1.0, 0.0, 0.0], + [0.0, 1.0, 0.0], + [0.0, 0.0, 1.0], ]); $expected = new LU($l, $u, $p); - $this->assertEqualsWithDelta($expected, $lu, self::MAX_DELTA); + $this->assertEqualsWithDelta($l->asArray(), $lu->l()->asArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta($u->asArray(), $lu->u()->asArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta($p->asArray(), $lu->p()->asArray(), self::MAX_DELTA); } /** @@ -887,7 +1037,7 @@ public function lu() : void */ public function luMultiPivot() : void { - $matrix = Matrix::quick([ + $matrix = Matrix::fromArray([ [0.0, 1.0, 0.0, 0.0], [-1.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 2.0], @@ -899,7 +1049,7 @@ public function luMultiPivot() : void $pa = $lu->p()->matmul($matrix); $luProd = $lu->l()->matmul($lu->u()); - $this->assertEqualsWithDelta($pa, $luProd, self::MAX_DELTA); + $this->assertEqualsWithDelta($pa->asArray(), $luProd->asArray(), self::MAX_DELTA); } /** @@ -907,7 +1057,7 @@ public function luMultiPivot() : void */ public function luNegativePivot() : void { - $matrix = Matrix::quick([ + $matrix = Matrix::fromArray([ [1.0, 2.0, 3.0, 4.0], [-9.0, 1.0, 0.0, 0.0], [0.5, 0.5, 1.0, 1.0], @@ -919,7 +1069,7 @@ public function luNegativePivot() : void $pa = $lu->p()->matmul($matrix); $luProd = $lu->l()->matmul($lu->u()); - $this->assertEqualsWithDelta($pa, $luProd, self::MAX_DELTA); + $this->assertEqualsWithDelta($pa->asArray(), $luProd->asArray(), self::MAX_DELTA); } /** @@ -929,7 +1079,7 @@ public function luSingular() : void { $this->expectException(RuntimeException::class); - $matrix = Matrix::quick([ + $matrix = Matrix::fromArray([ [1.0, 2.0, 0.0, 0.0], [0.0, 1.0, 1.0, 0.0], [2.0, 4.0, 0.0, 1.0], @@ -944,28 +1094,27 @@ public function luSingular() : void */ public function cholesky() : void { - $matrix = Matrix::quick([ - [2, -1, 0], - [-1, 2, -1], - [0, -1, 2], + $matrix = Matrix::fromArray([ + [2.0, -1.0, 0.0], + [-1.0, 2.0, -1.0], + [0.0, -1.0, 2.0], ]); $cholesky = $matrix->cholesky(); - $l = Matrix::quick([ - [1.4142135623730951, 0, 0], - [-0.7071067811865475, 1.224744871391589, 0], - [0, -0.8164965809277261, 1.1547005383792515], + $l = Matrix::fromArray([ + [1.4142135623730951, 0.0, 0.0], + [-0.7071067811865475, 1.224744871391589, 0.0], + [0.0, -0.8164965809277261, 1.1547005383792515], ]); $expected = new Cholesky($l); - $this->assertEqualsWithDelta($expected, $cholesky, self::MAX_DELTA); + $this->assertEqualsWithDelta($l->asArray(), $cholesky->l()->asArray(), self::MAX_DELTA); } /** * @test - * @requires extension tensor * @dataProvider eigProvider * * @param Matrix $matrix @@ -975,7 +1124,8 @@ public function eig(Matrix $matrix, Eigen $expected) : void { $eig = $matrix->eig(false); - $this->assertEqualsWithDelta($expected, $eig, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->eigenvalues(), $eig->eigenvalues(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->eigenvectors()->asArray(), $eig->eigenvectors()->asArray(), self::MAX_DELTA); } /** @@ -984,7 +1134,7 @@ public function eig(Matrix $matrix, Eigen $expected) : void public function eigProvider() : Generator { yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -993,7 +1143,7 @@ public function eigProvider() : Generator [ -15.096331148319537, 25.108706520450326, 13.9876246278692, ], - Matrix::quick([ + Matrix::fromArray([ [0.25848694820886425, -0.11314537870318066, -0.9593657388523845], [-0.8622719261400653, -0.17721179605718698, -0.47442924101375483], [-0.6684472200177011, -0.6126879076802705, -0.42165369894378907], @@ -1004,11 +1154,10 @@ public function eigProvider() : Generator /** * @test - * @requires extension tensor */ public function eigSymmetric() : void { - $matrix = Matrix::quick([ + $matrix = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -1018,7 +1167,7 @@ public function eigSymmetric() : void $values = [-366.30071669298195, 335.92000012383926, 1084.3807165691428]; - $vectors = Matrix::quick([ + $vectors = Matrix::fromArray([ [0.5423765325213931, 0.8162941265260668, -0.19872492538460218], [-0.04667292577741032, 0.26544998308386847, 0.9629942598375911], [-0.8388380862654284, 0.5130304137961217, -0.1820726765627782], @@ -1026,16 +1175,16 @@ public function eigSymmetric() : void $expected = new Eigen($values, $vectors); - $this->assertEqualsWithDelta($expected, $eig, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->eigenvalues(), $eig->eigenvalues(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->eigenvectors()->asArray(), $eig->eigenvectors()->asArray(), self::MAX_DELTA); } /** * @test - * @requires extension tensor */ public function svd() : void { - $matrix = Matrix::quick([ + $matrix = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -1043,7 +1192,7 @@ public function svd() : void $svd = $matrix->svd(); - $u = Matrix::quick([ + $u = Matrix::fromArray([ [-0.8436018806559158, 0.4252547343454771, -0.3278631999333884], [0.08179499775610413, -0.5016868397437385, -0.8611735557772425], [-0.5307027843302525, -0.7533052009276842, 0.38844025146657923], @@ -1053,7 +1202,7 @@ public function svd() : void 34.66917512262571, 17.12630582468919, 8.929610580306822, ]; - $vT = Matrix::quick([ + $vT = Matrix::fromArray([ [-0.8320393250771425, 0.531457514846513, -0.15894486917903863], [-0.4506078135544562, -0.48043370238236727, 0.7524201326246152], [-0.3235168618307952, -0.6976649392999047, -0.6392186422366096], @@ -1061,7 +1210,9 @@ public function svd() : void $expected = new SVD($u, $singularValues, $vT); - $this->assertEqualsWithDelta($expected, $svd, self::MAX_DELTA); + $this->assertEqualsWithDelta($u->asArray(), $svd->u()->asArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta($singularValues, $svd->singularValues(), self::MAX_DELTA); + $this->assertEqualsWithDelta($vT->asArray(), $svd->vT()->asArray(), self::MAX_DELTA); } /** @@ -1069,25 +1220,25 @@ public function svd() : void */ public function matmul() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]); - $b = Matrix::quick([ - [13], - [11], - [9], + $b = Matrix::fromArray([ + [13.0], + [11.0], + [9.0], ]); $c = $a->matmul($b); - $expected = Matrix::quick([ - [207], [155], [113], + $expected = Matrix::fromArray([ + [207.0], [155.0], [113.0], ]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -1095,19 +1246,19 @@ public function matmul() : void */ public function dotVector() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]); - $b = Vector::quick([2, 10, -1]); + $b = Vector::fromArray([2.0, 10.0, -1.0]); $c = $a->dot($b); - $expected = ColumnVector::quick([-138, 120, -11]); + $expected = ColumnVector::fromArray([-138.0, 120.0, -11.0]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -1115,33 +1266,33 @@ public function dotVector() : void */ public function convolve() : void { - $a = Matrix::quick([ - [3, 27, 66, 29, 42, 5], - [5, 9, 15, 42, 45, 16], - [1, 5, 10, 22, 66, 5], - [0, 1, 4, 9, 10, 22, 2], - [0, 0, 3, 19, 21, 25], - [0, 0, 0, 5, 2, 33, 35], + $a = Matrix::fromArray([ + [3.0, 27.0, 66.0, 29.0, 42.0, 5.0], + [5.0, 9.0, 15.0, 42.0, 45.0, 16.0], + [1.0, 5.0, 10.0, 22.0, 66.0, 5.0], + [0.0, 1.0, 4.0, 9.0, 10.0, 22.0], + [0.0, 0.0, 3.0, 19.0, 21.0, 25.0], + [0.0, 0.0, 0.0, 5.0, 2.0, 33.0], ]); - $b = Matrix::quick([ - [0, 0, 1], - [0, 1, 0], - [1, 0, 0], + $b = Matrix::fromArray([ + [0.0, 0.0, 1.0], + [0.0, 1.0, 0.0], + [1.0, 0.0, 0.0], ]); $c = $a->convolve($b, 1); - $expected = Matrix::quick([ - [3, 32, 75, 44, 84, 50], - [32, 76, 49, 94, 72, 82], - [10, 20, 53, 71, 91, 15], - [5, 11, 26, 78, 34, 43], - [1, 4, 12, 29, 48, 27], - [0, 3, 19, 26, 27, 33], + $expected = Matrix::fromArray([ + [3.0, 32.0, 75.0, 44.0, 84.0, 50.0], + [32.0, 76.0, 49.0, 94.0, 72.0, 82.0], + [10.0, 20.0, 53.0, 71.0, 91.0, 15.0], + [5.0, 11.0, 26.0, 78.0, 34.0, 43.0], + [1.0, 4.0, 12.0, 29.0, 48.0, 27.0], + [0.0, 3.0, 19.0, 26.0, 27.0, 33.0], ]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -1152,27 +1303,27 @@ public function convolve() : void */ public function convolveStrideTwo() : void { - $a = Matrix::quick([ - [1, 2, 3, 4, 5, 6, 7, 8], - [9, 10, 11, 12, 13, 14, 15, 16], - [17, 18, 19, 20, 21, 22, 23, 24], - [25, 26, 27, 28, 29, 30, 31, 32], - [33, 34, 35, 36, 37, 38, 39, 40], + $a = Matrix::fromArray([ + [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0], + [9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0], + [17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0], + [25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0], + [33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0], ]); - $b = Matrix::quick([ - [1], + $b = Matrix::fromArray([ + [1.0], ]); $c = $a->convolve($b, 2); - $expected = Matrix::quick([ - [1, 3, 5, 7], - [17, 19, 21, 23], - [33, 35, 37, 39], + $expected = Matrix::fromArray([ + [1.0, 3.0, 5.0, 7.0], + [17.0, 19.0, 21.0, 23.0], + [33.0, 35.0, 37.0, 39.0], ]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -1180,26 +1331,26 @@ public function convolveStrideTwo() : void */ public function convolveStrideThree() : void { - $a = Matrix::quick([ - [1, 2, 3, 4, 5, 6, 7, 8], - [9, 10, 11, 12, 13, 14, 15, 16], - [17, 18, 19, 20, 21, 22, 23, 24], - [25, 26, 27, 28, 29, 30, 31, 32], - [33, 34, 35, 36, 37, 38, 39, 40], + $a = Matrix::fromArray([ + [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0], + [9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0], + [17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0], + [25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0], + [33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0], ]); - $b = Matrix::quick([ - [1], + $b = Matrix::fromArray([ + [1.0], ]); $c = $a->convolve($b, 3); - $expected = Matrix::quick([ - [1, 4, 7], - [25, 28, 31], + $expected = Matrix::fromArray([ + [1.0, 4.0, 7.0], + [25.0, 28.0, 31.0], ]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -1214,7 +1365,7 @@ public function multiply(Matrix $a, $b, $expected) : void { $c = $a->multiply($b); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -1223,62 +1374,62 @@ public function multiply(Matrix $a, $b, $expected) : void public function multiplyProvider() : Generator { yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]), - Matrix::quick([ - [88, -102, -144], - [4, 33, -10], - [-200, 6, -126], + Matrix::fromArray([ + [88.0, -102.0, -144.0], + [4.0, 33.0, -10.0], + [-200.0, 6.0, -126.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Vector::quick([2, 10, -1]), - Matrix::quick([ - [44, -170, -12], - [8, 110, 2], - [40, -60, 9], + Vector::fromArray([2.0, 10.0, -1.0]), + Matrix::fromArray([ + [44.0, -170.0, -12.0], + [8.0, 110.0, 2.0], + [40.0, -60.0, 9.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - ColumnVector::quick([2.5, -1, 4.8]), - Matrix::quick([ - [55.0, -42.5, 30.], - [-4, -11, 2], - [96.0, -28.799999999999997, -43.199999999999996], + ColumnVector::fromArray([2.5, -1.0, 4.8]), + Matrix::fromArray([ + [55.0, -42.5, 30.0], + [-4.0, -11.0, 2.0], + [96.0, -28.8, -43.2], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), 2.5, - Matrix::quick([ - [55, -42.5, 30], - [10.0, 27.5, -5.], - [50, -15, -22.5], + Matrix::fromArray([ + [55.0, -42.5, 30.0], + [10.0, 27.5, -5.0], + [50.0, -15.0, -22.5], ]), ]; } @@ -1295,7 +1446,7 @@ public function divide(Matrix $a, $b, $expected) : void { $c = $a->divide($b); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -1304,61 +1455,61 @@ public function divide(Matrix $a, $b, $expected) : void public function divideProvider() : Generator { yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]), - Matrix::quick([ - [5.5, -2.8333333333333335, -1], - [4, 3.6666666666666665, -0.4], - [-2, 6, -0.6428571428571429], + Matrix::fromArray([ + [5.5, -2.8333333333333335, -1.0], + [4.0, 3.6666666666666665, -0.4], + [-2.0, 6.0, -0.6428571428571429], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Vector::quick([2, 10, -1]), - Matrix::quick([ - [11, -1.7, -12], - [2, 1.1, 2], - [10, -0.6, 9], + Vector::fromArray([2.0, 10.0, -1.0]), + Matrix::fromArray([ + [11.0, -1.7, -12.0], + [2.0, 1.1, 2.0], + [10.0, -0.6, 9.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - ColumnVector::quick([2.5, -1, 4.8]), - Matrix::quick([ + ColumnVector::fromArray([2.5, -1.0, 4.8]), + Matrix::fromArray([ [8.8, -6.8, 4.8], - [-4, -11, 2], + [-4.0, -11.0, 2.0], [4.166666666666667, -1.25, -1.875], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), 2.0, - Matrix::quick([ - [11.0, -8.5, 6.], - [2.0, 5.5, -1.], + Matrix::fromArray([ + [11.0, -8.5, 6.0], + [2.0, 5.5, -1.0], [10.0, -3.0, -4.5], ]), ]; @@ -1376,7 +1527,7 @@ public function add(Matrix $a, $b, $expected) : void { $c = $a->add($b); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -1385,62 +1536,62 @@ public function add(Matrix $a, $b, $expected) : void public function addProvider() : Generator { yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]), - Matrix::quick([ - [26, -11, 0], - [5, 14, 3], - [10, -7, 5], + Matrix::fromArray([ + [26.0, -11.0, 0.0], + [5.0, 14.0, 3.0], + [10.0, -7.0, 5.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Vector::quick([2, 10, -1]), - Matrix::quick([ - [24, -7, 11], - [6, 21, -3], - [22, 4, -10], + Vector::fromArray([2.0, 10.0, -1.0]), + Matrix::fromArray([ + [24.0, -7.0, 11.0], + [6.0, 21.0, -3.0], + [22.0, 4.0, -10.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - ColumnVector::quick([2.5, -1, 4.8]), - Matrix::quick([ + ColumnVector::fromArray([2.5, -1.0, 4.8]), + Matrix::fromArray([ [24.5, -14.5, 14.5], - [3, 10, -3], + [3.0, 10.0, -3.0], [24.8, -1.2000000000000002, -4.2], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), 1.0, - Matrix::quick([ - [23, -16, 13], - [5, 12, -1], - [21, -5, -8], + Matrix::fromArray([ + [23.0, -16.0, 13.0], + [5.0, 12.0, -1.0], + [21.0, -5.0, -8.0], ]), ]; } @@ -1457,7 +1608,7 @@ public function subtract(Matrix $a, $b, $expected) : void { $c = $a->subtract($b); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -1466,62 +1617,62 @@ public function subtract(Matrix $a, $b, $expected) : void public function subtractProvider() : Generator { yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]), - Matrix::quick([ - [18, -23, 24], - [3, 8, -7], - [30, -5, -23], + Matrix::fromArray([ + [18.0, -23.0, 24.0], + [3.0, 8.0, -7.0], + [30.0, -5.0, -23.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Vector::quick([2, 10, -1]), - Matrix::quick([ - [20, -27, 13], - [2, 1, -1], - [18, -16, -8], + Vector::fromArray([2.0, 10.0, -1.0]), + Matrix::fromArray([ + [20.0, -27.0, 13.0], + [2.0, 1.0, -1.0], + [18.0, -16.0, -8.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - ColumnVector::quick([2.5, -1, 4.8]), - Matrix::quick([ + ColumnVector::fromArray([2.5, -1.0, 4.8]), + Matrix::fromArray([ [19.5, -19.5, 9.5], - [5, 12, -1], + [5.0, 12.0, -1.0], [15.2, -10.8, -13.8], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), 10.0, - Matrix::quick([ - [12, -27, 2], - [-6, 1, -12], - [10, -16, -19], + Matrix::fromArray([ + [12.0, -27.0, 2.0], + [-6.0, 1.0, -12.0], + [10.0, -16.0, -19.0], ]), ]; } @@ -1538,7 +1689,7 @@ public function pow(Matrix $a, $b, $expected) : void { $c = $a->pow($b); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -1547,48 +1698,48 @@ public function pow(Matrix $a, $b, $expected) : void public function powProvider() : Generator { yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]), - Matrix::quick([ - [234256, 24137569, 1.1215665478461509E-13], - [4, 1331, -32], - [9.765625E-14, -0.16666666666666666, 22876792454961], + Matrix::fromArray([ + [234256.0, 24137569.0, 1.1215665478461509E-13], + [4.0, 1331.0, -32.0], + [9.765625E-14, -0.16666666666666666, 22876792454961.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Vector::quick([2, 10, -1]), - Matrix::quick([ - [484, 2015993900449, 0.08333333333333333], - [16, 25937424601, -0.5], - [400, 60466176, -0.1111111111111111], + Vector::fromArray([2.0, 10.0, -1.0]), + Matrix::fromArray([ + [484.0, 2015993900449.0, 0.08333333333333333], + [16.0, 25937424601.0, -0.5], + [400.0, 60466176.0, -0.1111111111111111], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), 3.0, - Matrix::quick([ - [10648, -4913, 1728], - [64, 1331, -8], - [8000, -216, -729], + Matrix::fromArray([ + [10648.0, -4913.0, 1728.0], + [64.0, 1331.0, -8.0], + [8000.0, -216.0, -729.0], ]), ]; } @@ -1605,7 +1756,7 @@ public function mod(Matrix $a, $b, $expected) : void { $c = $a->mod($b); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -1614,62 +1765,62 @@ public function mod(Matrix $a, $b, $expected) : void public function modProvider() : Generator { yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]), - Matrix::quick([ - [2, -5, 0], - [0, 2, -2], - [0, 0, -9], + Matrix::fromArray([ + [2.0, -5.0, 0.0], + [0.0, 2.0, -2.0], + [0.0, 0.0, -9.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Vector::quick([2, 10, -1]), - Matrix::quick([ - [0, -7, 0], - [0, 1, 0], - [0, -6, 0], + Vector::fromArray([2.0, 10.0, -1.0]), + Matrix::fromArray([ + [0.0, -7.0, 0.0], + [0.0, 1.0, 0.0], + [0.0, -6.0, 0.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - ColumnVector::quick([2.5, -1, 4.8]), - Matrix::quick([ - [0, -1, 0], - [0, 0, 0], - [0, -2, -1] + ColumnVector::fromArray([2.5, -1.0, 4.0]), + Matrix::fromArray([ + [2.0, -2.0, 2.0], + [0.0, 0.0, 0.0], + [0.0, -2.0, -1.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), 10.0, - Matrix::quick([ - [2, -7, 2], - [4, 1, -2], - [0, -6, -9], + Matrix::fromArray([ + [2.0, -7.0, 2.0], + [4.0, 1.0, -2.0], + [0.0, -6.0, -9.0], ]), ]; } @@ -1686,7 +1837,7 @@ public function equal(Matrix $a, $b, $expected) : void { $c = $a->equal($b); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -1695,62 +1846,62 @@ public function equal(Matrix $a, $b, $expected) : void public function equalProvider() : Generator { yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]), - Matrix::quick([ - [0, 0, 0], - [0, 0, 0], - [0, 0, 0], + Matrix::fromArray([ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Vector::quick([2, 10, -1]), - Matrix::quick([ - [0, 0, 0], - [0, 0, 0], - [0, 0, 0], + Vector::fromArray([2.0, 10.0, -1.0]), + Matrix::fromArray([ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - ColumnVector::quick([2.5, -1, 4.8]), - Matrix::quick([ - [0, 0, 0], - [0, 0, 0], - [0, 0, 0], + ColumnVector::fromArray([2.5, -1.0, 4.8]), + Matrix::fromArray([ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), 4.0, - Matrix::quick([ - [0, 0, 0], - [1, 0, 0], - [0, 0, 0], + Matrix::fromArray([ + [0.0, 0.0, 0.0], + [1.0, 0.0, 0.0], + [0.0, 0.0, 0.0], ]), ]; } @@ -1767,7 +1918,7 @@ public function notEqual(Matrix $a, $b, $expected) : void { $c = $a->notEqual($b); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -1776,62 +1927,62 @@ public function notEqual(Matrix $a, $b, $expected) : void public function notEqualProvider() : Generator { yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]), - Matrix::quick([ - [1, 1, 1], - [1, 1, 1], - [1, 1, 1], + Matrix::fromArray([ + [1.0, 1.0, 1.0], + [1.0, 1.0, 1.0], + [1.0, 1.0, 1.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Vector::quick([2, 10, -1]), - Matrix::quick([ - [1, 1, 1], - [1, 1, 1], - [1, 1, 1], + Vector::fromArray([2.0, 10.0, -1.0]), + Matrix::fromArray([ + [1.0, 1.0, 1.0], + [1.0, 1.0, 1.0], + [1.0, 1.0, 1.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - ColumnVector::quick([2.5, -1, 4.8]), - Matrix::quick([ - [1, 1, 1], - [1, 1, 1], - [1, 1, 1], + ColumnVector::fromArray([2.5, -1.0, 4.8]), + Matrix::fromArray([ + [1.0, 1.0, 1.0], + [1.0, 1.0, 1.0], + [1.0, 1.0, 1.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), 4.0, - Matrix::quick([ - [1, 1, 1], - [0, 1, 1], - [1, 1, 1], + Matrix::fromArray([ + [1.0, 1.0, 1.0], + [0.0, 1.0, 1.0], + [1.0, 1.0, 1.0], ]), ]; } @@ -1848,7 +1999,7 @@ public function greater(Matrix $a, $b, $expected) : void { $c = $a->greater($b); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -1857,62 +2008,62 @@ public function greater(Matrix $a, $b, $expected) : void public function greaterProvider() : Generator { yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]), - Matrix::quick([ - [1, 0, 1], - [1, 1, 0], - [1, 0, 0], + Matrix::fromArray([ + [1.0, 0.0, 1.0], + [1.0, 1.0, 0.0], + [1.0, 0.0, 0.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Vector::quick([2, 10, -1]), - Matrix::quick([ - [1, 0, 1], - [1, 1, 0], - [1, 0, 0], + Vector::fromArray([2.0, 10.0, -1.0]), + Matrix::fromArray([ + [1.0, 0.0, 1.0], + [1.0, 1.0, 0.0], + [1.0, 0.0, 0.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - ColumnVector::quick([2.5, -1, 4.8]), - Matrix::quick([ - [1, 0, 1], - [1, 1, 0], - [1, 0, 0], + ColumnVector::fromArray([2.5, -1.0, 4.8]), + Matrix::fromArray([ + [1.0, 0.0, 1.0], + [1.0, 1.0, 0.0], + [1.0, 0.0, 0.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), 4.0, - Matrix::quick([ - [1, 0, 1], - [0, 1, 0], - [1, 0, 0], + Matrix::fromArray([ + [1.0, 0.0, 1.0], + [0.0, 1.0, 0.0], + [1.0, 0.0, 0.0], ]), ]; } @@ -1929,7 +2080,7 @@ public function greaterEqual(Matrix $a, $b, $expected) : void { $c = $a->greaterEqual($b); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -1938,62 +2089,62 @@ public function greaterEqual(Matrix $a, $b, $expected) : void public function greaterEqualProvider() : Generator { yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]), - Matrix::quick([ - [1, 0, 1], - [1, 1, 0], - [1, 0, 0], + Matrix::fromArray([ + [1.0, 0.0, 1.0], + [1.0, 1.0, 0.0], + [1.0, 0.0, 0.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Vector::quick([2, 10, -1]), - Matrix::quick([ - [1, 0, 1], - [1, 1, 0], - [1, 0, 0], + Vector::fromArray([2.0, 10.0, -1.0]), + Matrix::fromArray([ + [1.0, 0.0, 1.0], + [1.0, 1.0, 0.0], + [1.0, 0.0, 0.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - ColumnVector::quick([2.5, -1, 4.8]), - Matrix::quick([ - [1, 0, 1], - [1, 1, 0], - [1, 0, 0], + ColumnVector::fromArray([2.5, -1.0, 4.8]), + Matrix::fromArray([ + [1.0, 0.0, 1.0], + [1.0, 1.0, 0.0], + [1.0, 0.0, 0.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), 4.0, - Matrix::quick([ - [1, 0, 1], - [1, 1, 0], - [1, 0, 0], + Matrix::fromArray([ + [1.0, 0.0, 1.0], + [1.0, 1.0, 0.0], + [1.0, 0.0, 0.0], ]), ]; } @@ -2010,7 +2161,7 @@ public function less(Matrix $a, $b, $expected) : void { $c = $a->less($b); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -2019,62 +2170,62 @@ public function less(Matrix $a, $b, $expected) : void public function lessProvider() : Generator { yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]), - Matrix::quick([ - [0, 1, 0], - [0, 0, 1], - [0, 1, 1], + Matrix::fromArray([ + [0.0, 1.0, 0.0], + [0.0, 0.0, 1.0], + [0.0, 1.0, 1.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Vector::quick([2, 10, -1]), - Matrix::quick([ - [0, 1, 0], - [0, 0, 1], - [0, 1, 1], + Vector::fromArray([2.0, 10.0, -1.0]), + Matrix::fromArray([ + [0.0, 1.0, 0.0], + [0.0, 0.0, 1.0], + [0.0, 1.0, 1.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - ColumnVector::quick([2.5, -1, 4.8]), - Matrix::quick([ - [0, 1, 0], - [0, 0, 1], - [0, 1, 1], + ColumnVector::fromArray([2.5, -1.0, 4.8]), + Matrix::fromArray([ + [0.0, 1.0, 0.0], + [0.0, 0.0, 1.0], + [0.0, 1.0, 1.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), 10.0, - Matrix::quick([ - [0, 1, 0], - [1, 0, 1], - [0, 1, 1], + Matrix::fromArray([ + [0.0, 1.0, 0.0], + [1.0, 0.0, 1.0], + [0.0, 1.0, 1.0], ]), ]; } @@ -2091,7 +2242,7 @@ public function lessEqual(Matrix $a, $b, $expected) : void { $c = $a->lessEqual($b); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -2100,62 +2251,62 @@ public function lessEqual(Matrix $a, $b, $expected) : void public function lessEqualProvider() : Generator { yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]), - Matrix::quick([ - [0, 1, 0], - [0, 0, 1], - [0, 1, 1], + Matrix::fromArray([ + [0.0, 1.0, 0.0], + [0.0, 0.0, 1.0], + [0.0, 1.0, 1.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - Vector::quick([2, 10, -1]), - Matrix::quick([ - [0, 1, 0], - [0, 0, 1], - [0, 1, 1], + Vector::fromArray([2.0, 10.0, -1.0]), + Matrix::fromArray([ + [0.0, 1.0, 0.0], + [0.0, 0.0, 1.0], + [0.0, 1.0, 1.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), - ColumnVector::quick([2.5, -1, 4.8]), - Matrix::quick([ - [0, 1, 0], - [0, 0, 1], - [0, 1, 1], + ColumnVector::fromArray([2.5, -1.0, 4.8]), + Matrix::fromArray([ + [0.0, 1.0, 0.0], + [0.0, 0.0, 1.0], + [0.0, 1.0, 1.0], ]), ]; yield [ - Matrix::quick([ + Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]), 10.0, - Matrix::quick([ - [0, 1, 0], - [1, 0, 1], - [0, 1, 1], + Matrix::fromArray([ + [0.0, 1.0, 0.0], + [1.0, 0.0, 1.0], + [0.0, 1.0, 1.0], ]), ]; } @@ -2165,7 +2316,7 @@ public function lessEqualProvider() : Generator */ public function abs() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2173,13 +2324,13 @@ public function abs() : void $b = $a->abs(); - $expected = Matrix::quick([ - [22, 17, 12], - [4, 11, 2], - [20, 6, 9], + $expected = Matrix::fromArray([ + [22.0, 17.0, 12.0], + [4.0, 11.0, 2.0], + [20.0, 6.0, 9.0], ]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -2187,7 +2338,7 @@ public function abs() : void */ public function square() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2195,13 +2346,13 @@ public function square() : void $b = $a->square(); - $expected = Matrix::quick([ - [484, 289, 144], - [16, 121, 4], - [400, 36, 81], + $expected = Matrix::fromArray([ + [484.0, 289.0, 144.0], + [16.0, 121.0, 4.0], + [400.0, 36.0, 81.0], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2209,21 +2360,21 @@ public function square() : void */ public function sqrt() : void { - $a = Matrix::quick([ - [13], - [11], - [9], + $a = Matrix::fromArray([ + [13.0], + [11.0], + [9.0], ]); $b = $a->sqrt(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [3.605551275463989], [3.3166247903554], - [3], + [3.0], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2231,21 +2382,21 @@ public function sqrt() : void */ public function exp() : void { - $a = Matrix::quick([ - [13], - [11], - [9], + $a = Matrix::fromArray([ + [13.0], + [11.0], + [9.0], ]); $b = $a->exp(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [442413.3920089205], [59874.14171519778], [8103.08392757538], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2253,21 +2404,21 @@ public function exp() : void */ public function expm1() : void { - $a = Matrix::quick([ - [13], - [11], - [9], + $a = Matrix::fromArray([ + [13.0], + [11.0], + [9.0], ]); $b = $a->expm1(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [442412.3920089205], [59873.14171519782], [8102.083927575384], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2275,21 +2426,21 @@ public function expm1() : void */ public function log() : void { - $a = Matrix::quick([ - [13], - [11], - [9], + $a = Matrix::fromArray([ + [13.0], + [11.0], + [9.0], ]); $b = $a->log(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [2.5649493574615367], [2.3978952727983707], [2.1972245773362196], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2297,21 +2448,21 @@ public function log() : void */ public function log1p() : void { - $a = Matrix::quick([ - [13], - [11], - [9], + $a = Matrix::fromArray([ + [13.0], + [11.0], + [9.0], ]); $b = $a->log1p(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [2.6390573296152584], [2.4849066497880004], [2.302585092994046], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2319,21 +2470,21 @@ public function log1p() : void */ public function sin() : void { - $a = Matrix::quick([ - [13], - [11], - [9], + $a = Matrix::fromArray([ + [13.0], + [11.0], + [9.0], ]); $b = $a->sin(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [0.4201670368266409], [-0.9999902065507035], [0.4121184852417566], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2341,7 +2492,7 @@ public function sin() : void */ public function asin() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [0.32], [-0.5], [0.01], @@ -2349,13 +2500,13 @@ public function asin() : void $b = $a->asin(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [0.3257294872946302], [-0.5235987755982989], [0.010000166674167114], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2363,21 +2514,21 @@ public function asin() : void */ public function cos() : void { - $a = Matrix::quick([ - [13], - [11], - [9], + $a = Matrix::fromArray([ + [13.0], + [11.0], + [9.0], ]); $b = $a->cos(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [0.9074467814501962], [0.004425697988050785], [-0.9111302618846769], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2385,7 +2536,7 @@ public function cos() : void */ public function acos() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [0.32], [-0.5], [0.01], @@ -2393,13 +2544,13 @@ public function acos() : void $b = $a->acos(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [1.2450668395002664], [2.0943951023931957], [1.5607961601207294], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2407,21 +2558,21 @@ public function acos() : void */ public function tan() : void { - $a = Matrix::quick([ - [13], - [11], - [9], + $a = Matrix::fromArray([ + [13.0], + [11.0], + [9.0], ]); $b = $a->tan(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [0.4630211329364896], [-225.95084645419513], [-0.45231565944180985], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2429,21 +2580,21 @@ public function tan() : void */ public function atan() : void { - $a = Matrix::quick([ - [13], - [11], - [9], + $a = Matrix::fromArray([ + [13.0], + [11.0], + [9.0], ]); $b = $a->atan(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [1.4940244355251187], [1.4801364395941514], [1.460139105621001], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2451,21 +2602,21 @@ public function atan() : void */ public function rad2deg() : void { - $a = Matrix::quick([ - [13], - [11], - [9], + $a = Matrix::fromArray([ + [13.0], + [11.0], + [9.0], ]); $b = $a->rad2deg(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [744.8451336700701], [630.2535746439056], [515.6620156177408], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2473,21 +2624,21 @@ public function rad2deg() : void */ public function deg2rad() : void { - $a = Matrix::quick([ - [13], - [11], - [9], + $a = Matrix::fromArray([ + [13.0], + [11.0], + [9.0], ]); $b = $a->deg2rad(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [0.22689280275926282], [0.19198621771937624], [0.15707963267948966], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2495,7 +2646,7 @@ public function deg2rad() : void */ public function sum() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2503,9 +2654,9 @@ public function sum() : void $b = $a->sum(); - $expected = ColumnVector::quick([17, 13, 5]); + $expected = ColumnVector::fromArray([17.0, 13.0, 5.0]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2513,7 +2664,7 @@ public function sum() : void */ public function product() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2521,9 +2672,9 @@ public function product() : void $b = $a->product(); - $expected = ColumnVector::quick([-4488.0, -88.0, 1080.0]); + $expected = ColumnVector::fromArray([-4488.0, -88.0, 1080.0]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2531,7 +2682,7 @@ public function product() : void */ public function min() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2539,9 +2690,9 @@ public function min() : void $b = $a->min(); - $expected = ColumnVector::quick([-17, -2, -9]); + $expected = ColumnVector::fromArray([-17.0, -2.0, -9.0]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -2549,7 +2700,7 @@ public function min() : void */ public function max() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2557,9 +2708,45 @@ public function max() : void $b = $a->max(); - $expected = ColumnVector::quick([22, 11, 20]); + $expected = ColumnVector::fromArray([22.0, 11.0, 20.0]); + + $this->assertEquals($expected->asArray(), $b->asArray()); + } + + /** + * @test + */ + public function argmin() : void + { + $a = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], + ]); + + $b = $a->argmin(); + + $expected = ColumnVector::fromArray([1, 2, 2]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); + } + + /** + * @test + */ + public function argmax() : void + { + $a = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], + ]); + + $b = $a->argmax(); + + $expected = ColumnVector::fromArray([0, 1, 0]); + + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -2567,7 +2754,7 @@ public function max() : void */ public function mean() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2575,9 +2762,9 @@ public function mean() : void $b = $a->mean(); - $expected = ColumnVector::quick([5.666666666666667, 4.333333333333333, 1.6666666666666667]); + $expected = ColumnVector::fromArray([5.666666666666667, 4.333333333333333, 1.6666666666666667]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2585,7 +2772,7 @@ public function mean() : void */ public function median() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2593,9 +2780,9 @@ public function median() : void $b = $a->median(); - $expected = ColumnVector::quick([12, 4, -6]); + $expected = ColumnVector::fromArray([12.0, 4.0, -6.0]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -2603,7 +2790,7 @@ public function median() : void */ public function quantile() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2611,27 +2798,27 @@ public function quantile() : void $b = $a->quantile(0.4); - $expected = ColumnVector::quick([6.200000000000001, 2.8000000000000003, -6.6]); + $expected = ColumnVector::fromArray([6.200000000000001, 2.8000000000000003, -6.6]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); $max = $a->quantile(1.0); - $maxExpected = ColumnVector::quick([22.0, 11.0, 20.0]); + $maxExpected = ColumnVector::fromArray([22.0, 11.0, 20.0]); - $this->assertEqualsWithDelta($maxExpected, $max, self::MAX_DELTA); + $this->assertEqualsWithDelta($maxExpected->asArray(), $max->asArray(), self::MAX_DELTA); - $single = Matrix::quick([ + $single = Matrix::fromArray([ [5.0], [3.0], [8.0], ]); - $singleExpected = ColumnVector::quick([5.0, 3.0, 8.0]); + $singleExpected = ColumnVector::fromArray([5.0, 3.0, 8.0]); $this->assertEqualsWithDelta( - $singleExpected, - $single->quantile(0.5), + $singleExpected->asArray(), + $single->quantile(0.5)->asArray(), self::MAX_DELTA ); } @@ -2641,7 +2828,7 @@ public function quantile() : void */ public function variance() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2649,9 +2836,9 @@ public function variance() : void $b = $a->variance(); - $expected = ColumnVector::quick([273.55555555555554, 28.222222222222225, 169.55555555555554]); + $expected = ColumnVector::fromArray([273.55555555555554, 28.222222222222225, 169.55555555555554]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2659,16 +2846,16 @@ public function variance() : void */ public function varianceRowNonSquare() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 2.0, 3.0], [10.0, 20.0, 30.0], ]); $b = $a->variance(); - $expected = ColumnVector::quick([0.6666666666666666, 66.66666666666667]); + $expected = ColumnVector::fromArray([0.6666666666666666, 66.66666666666667]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -2676,7 +2863,7 @@ public function varianceRowNonSquare() : void */ public function covariance() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2684,27 +2871,27 @@ public function covariance() : void $b = $a->covariance(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [273.55555555555554, -65.55555555555556, 135.2222222222222], [-65.55555555555556, 28.222222222222225, 3.4444444444444406], [135.2222222222222, 3.4444444444444406, 169.55555555555554], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); - $c = Matrix::quick([ + $c = Matrix::fromArray([ [1.0, 2.0, 3.0], [4.0, 5.0, 6.0], ]); $d = $c->covariance(); - $expectedC = Matrix::quick([ + $expectedC = Matrix::fromArray([ [2.0 / 3.0, 2.0 / 3.0], [2.0 / 3.0, 2.0 / 3.0], ]); - $this->assertEqualsWithDelta($expectedC, $d, self::MAX_DELTA); + $this->assertEqualsWithDelta($expectedC->asArray(), $d->asArray(), self::MAX_DELTA); } /** @@ -2712,7 +2899,7 @@ public function covariance() : void */ public function round() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2720,13 +2907,51 @@ public function round() : void $b = $a->round(2); - $expected = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $expected = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function roundFractions() : void + { + $a = Matrix::fromArray([ + [1.2345, 2.675, -0.125], + [0.125, 1.005, 12.345], + [-12.345, 2.5, -2.5], + ]); + + $b = $a->round(2); + + $expected = Matrix::fromArray([ + [round(1.2345, 2), round(2.675, 2), round(-0.125, 2)], + [round(0.125, 2), round(1.005, 2), round(12.345, 2)], + [round(-12.345, 2), round(2.5, 2), round(-2.5, 2)], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function roundNegativePrecisionThrows() : void + { + $a = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->expectException(InvalidArgumentException::class); + + $a->round(-1); } /** @@ -2734,7 +2959,7 @@ public function round() : void */ public function floor() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2742,13 +2967,13 @@ public function floor() : void $b = $a->floor(); - $expected = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $expected = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -2756,7 +2981,7 @@ public function floor() : void */ public function ceil() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2764,13 +2989,13 @@ public function ceil() : void $b = $a->ceil(); - $expected = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $expected = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -2778,13 +3003,13 @@ public function ceil() : void */ public function l1Norm() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]); - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2798,7 +3023,7 @@ public function l1Norm() : void */ public function l2Norm() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2812,7 +3037,7 @@ public function l2Norm() : void */ public function infinityNorm() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2826,7 +3051,7 @@ public function infinityNorm() : void */ public function maxNorm() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2840,7 +3065,7 @@ public function maxNorm() : void */ public function clip() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2848,13 +3073,13 @@ public function clip() : void $b = $a->clip(0.0, INF); - $expected = Matrix::quick([ - [22, 0.0, 12], - [4, 11, 0.], - [20, 0.0, 0.], + $expected = Matrix::fromArray([ + [22.0, 0.0, 12.0], + [4.0, 11.0, 0.], + [20.0, 0.0, 0.], ]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -2862,7 +3087,7 @@ public function clip() : void */ public function clipLower() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2870,13 +3095,13 @@ public function clipLower() : void $b = $a->clipLower(5.); - $expected = Matrix::quick([ - [22, 5.0, 12], - [5.0, 11, 5.], - [20, 5.0, 5.], + $expected = Matrix::fromArray([ + [22.0, 5.0, 12.0], + [5.0, 11.0, 5.], + [20.0, 5.0, 5.], ]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -2884,7 +3109,7 @@ public function clipLower() : void */ public function clipUpper() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2892,13 +3117,13 @@ public function clipUpper() : void $b = $a->clipUpper(16.0); - $expected = Matrix::quick([ - [16.0, -17.0, 12], - [4, 11, -2.0], - [16, -6.0, -9.0], + $expected = Matrix::fromArray([ + [16.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [16.0, -6.0, -9.0], ]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -2906,7 +3131,7 @@ public function clipUpper() : void */ public function sign() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2914,13 +3139,13 @@ public function sign() : void $b = $a->sign(); - $expected = Matrix::quick([ - [1, -1, 1], - [1, 1, -1], - [1, -1, -1], + $expected = Matrix::fromArray([ + [1.0, -1.0, 1.0], + [1.0, 1.0, -1.0], + [1.0, -1.0, -1.0], ]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -2928,7 +3153,7 @@ public function sign() : void */ public function negate() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -2936,13 +3161,13 @@ public function negate() : void $b = $a->negate(); - $expected = Matrix::quick([ - [-22, 17, -12], - [-4, -11, 2], - [-20, 6, 9], + $expected = Matrix::fromArray([ + [-22.0, 17.0, -12.0], + [-4.0, -11.0, 2.0], + [-20.0, 6.0, 9.0], ]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -2950,30 +3175,30 @@ public function negate() : void */ public function augmentAbove() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]); - $b = Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + $b = Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]); $c = $a->augmentAbove($b); - $expected = Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], + $expected = Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], ]); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -2981,30 +3206,30 @@ public function augmentAbove() : void */ public function augmentBelow() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]); - $b = Matrix::quick([ - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + $b = Matrix::fromArray([ + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]); $c = $a->augmentBelow($b); - $expected = Matrix::quick([ - [22, -17, 12], - [4, 11, -2], - [20, -6, -9], - [4, 6, -12], - [1, 3, 5], - [-10, -1, 14], + $expected = Matrix::fromArray([ + [22.0, -17.0, 12.0], + [4.0, 11.0, -2.0], + [20.0, -6.0, -9.0], + [4.0, 6.0, -12.0], + [1.0, 3.0, 5.0], + [-10.0, -1.0, 14.0], ]); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -3012,27 +3237,27 @@ public function augmentBelow() : void */ public function augmentLeft() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]); - $b = Matrix::quick([ - [13], - [11], - [9], + $b = Matrix::fromArray([ + [13.0], + [11.0], + [9.0], ]); $c = $a->augmentLeft($b); - $expected = Matrix::quick([ - [13, 22, -17, 12], - [11, 4, 11, -2], - [9, 20, -6, -9], + $expected = Matrix::fromArray([ + [13.0, 22.0, -17.0, 12.0], + [11.0, 4.0, 11.0, -2.0], + [9.0, 20.0, -6.0, -9.0], ]); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -3040,27 +3265,27 @@ public function augmentLeft() : void */ public function augmentRight() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], ]); - $b = Matrix::quick([ - [13], - [11], - [9], + $b = Matrix::fromArray([ + [13.0], + [11.0], + [9.0], ]); $c = $a->augmentRight($b); - $expected = Matrix::quick([ - [22, -17, 12, 13], - [4, 11, -2, 11], - [20, -6, -9, 9], + $expected = Matrix::fromArray([ + [22.0, -17.0, 12.0, 13.0], + [4.0, 11.0, -2.0, 11.0], + [20.0, -6.0, -9.0, 9.0], ]); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -3068,24 +3293,24 @@ public function augmentRight() : void */ public function repeat() : void { - $a = Matrix::quick([ - [13], - [11], - [9], + $a = Matrix::fromArray([ + [13.0], + [11.0], + [9.0], ]); $b = $a->repeat(1, 3); - $expected = Matrix::quick([ - [13, 13, 13, 13], - [11, 11, 11, 11], - [9, 9, 9, 9], - [13, 13, 13, 13], - [11, 11, 11, 11], - [9, 9, 9, 9], + $expected = Matrix::fromArray([ + [13.0, 13.0, 13.0, 13.0], + [11.0, 11.0, 11.0, 11.0], + [9.0, 9.0, 9.0, 9.0], + [13.0, 13.0, 13.0, 13.0], + [11.0, 11.0, 11.0, 11.0], + [9.0, 9.0, 9.0, 9.0], ]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -3125,7 +3350,7 @@ public function detNonSquareThrows() : void { $this->expectException(InvalidArgumentException::class); - Matrix::quick([ + Matrix::fromArray([ [1.0, 2.0, 3.0], [4.0, 5.0, 6.0], ])->det(); @@ -3138,10 +3363,10 @@ public function matmulDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - Matrix::quick([ + Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], - ])->matmul(Matrix::quick([ + ])->matmul(Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], [5.0, 6.0], @@ -3155,10 +3380,10 @@ public function dotDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - Matrix::quick([ + Matrix::fromArray([ [1.0, 2.0, 3.0], [4.0, 5.0, 6.0], - ])->dot(Vector::quick([1.0, 2.0])); + ])->dot(Vector::fromArray([1.0, 2.0])); } /** @@ -3168,9 +3393,9 @@ public function augmentAboveDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - Matrix::quick([ + Matrix::fromArray([ [1.0, 2.0], - ])->augmentAbove(Matrix::quick([ + ])->augmentAbove(Matrix::fromArray([ [1.0, 2.0, 3.0], ])); } @@ -3182,9 +3407,9 @@ public function augmentBelowDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - Matrix::quick([ + Matrix::fromArray([ [1.0, 2.0], - ])->augmentBelow(Matrix::quick([ + ])->augmentBelow(Matrix::fromArray([ [1.0, 2.0, 3.0], ])); } @@ -3196,9 +3421,9 @@ public function augmentLeftDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - Matrix::quick([ + Matrix::fromArray([ [1.0, 2.0], - ])->augmentLeft(Matrix::quick([ + ])->augmentLeft(Matrix::fromArray([ [1.0], [2.0], [3.0], @@ -3212,9 +3437,9 @@ public function augmentRightDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - Matrix::quick([ + Matrix::fromArray([ [1.0, 2.0], - ])->augmentRight(Matrix::quick([ + ])->augmentRight(Matrix::fromArray([ [1.0], [2.0], [3.0], @@ -3228,7 +3453,7 @@ public function offsetSetThrows() : void { $this->expectException(RuntimeException::class); - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], ]); @@ -3243,7 +3468,7 @@ public function offsetUnsetThrows() : void { $this->expectException(RuntimeException::class); - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], ]); @@ -3258,7 +3483,7 @@ public function offsetGetOutOfBoundsThrows() : void { $this->expectException(InvalidArgumentException::class); - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], ]); @@ -3273,7 +3498,7 @@ public function luNonSquareThrows() : void { $this->expectException(InvalidArgumentException::class); - Matrix::quick([ + Matrix::fromArray([ [1.0, 2.0, 3.0], [4.0, 5.0, 6.0], ])->lu(); @@ -3286,7 +3511,7 @@ public function choleskyNonSquareThrows() : void { $this->expectException(InvalidArgumentException::class); - Matrix::quick([ + Matrix::fromArray([ [1.0, 2.0, 3.0], [4.0, 5.0, 6.0], ])->cholesky(); @@ -3297,7 +3522,7 @@ public function choleskyNonSquareThrows() : void */ public function eigReturnsEigen() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], ]); @@ -3326,7 +3551,7 @@ public function eigReturnsEigen() : void */ public function eigSymmetricReturnsEigen() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [9.0, 3.0], [3.0, 5.0], ]); @@ -3343,16 +3568,16 @@ public function eigSymmetricReturnsEigen() : void */ public function pseudoinversePreservesTinySingularValues() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 0.0], [0.0, 1e-9], ]); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [1.0, 0.0], [0.0, 1.0 / 1e-9], ]); - $this->assertEqualsWithDelta($expected, $a->pseudoinverse(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $a->pseudoinverse()->asArray(), self::MAX_DELTA); } } diff --git a/tests/Reductions/REFTest.php b/tests/Reductions/REFTest.php index e7122af..1585ec5 100644 --- a/tests/Reductions/REFTest.php +++ b/tests/Reductions/REFTest.php @@ -24,7 +24,7 @@ class REFTest extends TestCase */ public function reduce2x2() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], ]); @@ -33,13 +33,13 @@ public function reduce2x2() : void // Partial pivoting selects the largest magnitude in each column, so the // rows are swapped to bring 3 (col 0) to the top and 4 (col 1) to the right. - $expectedA = Matrix::quick([ + $expectedA = Matrix::fromArray([ [3.0, 4.0], [0.0, 2.0 / 3.0], ]); $this->assertEquals(1, $ref->swaps()); - $this->assertEqualsWithDelta($expectedA, $ref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expectedA->asArray(), $ref->a()->asArray(), self::MAX_DELTA); } /** @@ -47,7 +47,7 @@ public function reduce2x2() : void */ public function reduce3x3() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [22.0, -17.0, 12.0], [4.0, 11.0, -2.0], [20.0, -6.0, -9.0], @@ -55,13 +55,13 @@ public function reduce3x3() : void $ref = REF::reduce($a); - $expectedA = Matrix::quick([ + $expectedA = Matrix::fromArray([ [22.0, -17.0, 12.0], [0.0, 14.09090909090909, -4.181818181818182], [0.0, 0.0, -17.10322580645161], ]); - $this->assertEqualsWithDelta($expectedA, $ref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expectedA->asArray(), $ref->a()->asArray(), self::MAX_DELTA); } /** @@ -69,7 +69,7 @@ public function reduce3x3() : void */ public function reduce2x3Rectangular() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 2.0, 3.0], [4.0, 5.0, 6.0], ]); @@ -77,13 +77,13 @@ public function reduce2x3Rectangular() : void $ref = REF::reduce($a); // Partial pivoting brings 4 to the top of column 0. - $expectedA = Matrix::quick([ + $expectedA = Matrix::fromArray([ [4.0, 5.0, 6.0], [0.0, 0.75, 1.5], ]); $this->assertEquals(1, $ref->swaps()); - $this->assertEqualsWithDelta($expectedA, $ref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expectedA->asArray(), $ref->a()->asArray(), self::MAX_DELTA); } /** @@ -92,7 +92,7 @@ public function reduce2x3Rectangular() : void public function reduceRequiresPivoting() : void { // First column is [0, 5] - a row swap is required to pivot. - $a = Matrix::quick([ + $a = Matrix::fromArray([ [0.0, 1.0], [5.0, 2.0], ]); @@ -103,12 +103,12 @@ public function reduceRequiresPivoting() : void // should be used as the pivot, and the first row below it zeroed. $this->assertGreaterThanOrEqual(1, $ref->swaps()); - $expectedA = Matrix::quick([ + $expectedA = Matrix::fromArray([ [5.0, 2.0], [0.0, 1.0], ]); - $this->assertEqualsWithDelta($expectedA, $ref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expectedA->asArray(), $ref->a()->asArray(), self::MAX_DELTA); } /** @@ -116,14 +116,14 @@ public function reduceRequiresPivoting() : void */ public function reduce1x1() : void { - $a = Matrix::quick([[7.0]]); + $a = Matrix::fromArray([[7.0]]); $ref = REF::reduce($a); - $expectedA = Matrix::quick([[7.0]]); + $expectedA = Matrix::fromArray([[7.0]]); $this->assertEquals(0, $ref->swaps()); - $this->assertEqualsWithDelta($expectedA, $ref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expectedA->asArray(), $ref->a()->asArray(), self::MAX_DELTA); } /** @@ -131,7 +131,7 @@ public function reduce1x1() : void */ public function reduceDiagonal() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [2.0, 0.0], [0.0, 3.0], ]); @@ -139,13 +139,13 @@ public function reduceDiagonal() : void $ref = REF::reduce($a); // Diagonal is already in row echelon form. - $expectedA = Matrix::quick([ + $expectedA = Matrix::fromArray([ [2.0, 0.0], [0.0, 3.0], ]); $this->assertEquals(0, $ref->swaps()); - $this->assertEqualsWithDelta($expectedA, $ref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expectedA->asArray(), $ref->a()->asArray(), self::MAX_DELTA); } /** @@ -154,7 +154,7 @@ public function reduceDiagonal() : void public function reduceZeroRow() : void { // One zero row at the top, non-zero row at the bottom. - $a = Matrix::quick([ + $a = Matrix::fromArray([ [0.0, 0.0], [1.0, 2.0], ]); @@ -177,19 +177,19 @@ public function reduceSingularKeepsPivotScale() : void // A rank-1 matrix is singular: Gaussian elimination must fail and the // row reduction fallback must produce the same (non-normalised) REF // convention as Gaussian elimination - the pivot keeps its value. - $a = Matrix::quick([ + $a = Matrix::fromArray([ [2.0, 4.0], [1.0, 2.0], ]); $ref = REF::reduce($a); - $expectedA = Matrix::quick([ + $expectedA = Matrix::fromArray([ [2.0, 4.0], [0.0, 0.0], ]); - $this->assertEqualsWithDelta($expectedA, $ref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expectedA->asArray(), $ref->a()->asArray(), self::MAX_DELTA); } /** @@ -199,7 +199,7 @@ public function constructorWithNegativeSwapsThrows() : void { $this->expectException(InvalidArgumentException::class); - new REF(Matrix::quick([[1.0]]), -1); + new REF(Matrix::fromArray([[1.0]]), -1); } /** @@ -207,11 +207,11 @@ public function constructorWithNegativeSwapsThrows() : void */ public function constructorWithZeroSwaps() : void { - $a = Matrix::quick([[1.0]]); + $a = Matrix::fromArray([[1.0]]); $ref = new REF($a, 0); - $this->assertEqualsWithDelta($a, $ref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta($a->asArray(), $ref->a()->asArray(), self::MAX_DELTA); $this->assertEquals(0, $ref->swaps()); } @@ -220,14 +220,14 @@ public function constructorWithZeroSwaps() : void */ public function constructorWithPositiveSwaps() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 0.0], [0.0, 1.0], ]); $ref = new REF($a, 2); - $this->assertEqualsWithDelta($a, $ref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta($a->asArray(), $ref->a()->asArray(), self::MAX_DELTA); $this->assertEquals(2, $ref->swaps()); } diff --git a/tests/Reductions/RREFTest.php b/tests/Reductions/RREFTest.php index 0aec1da..1fa265d 100644 --- a/tests/Reductions/RREFTest.php +++ b/tests/Reductions/RREFTest.php @@ -24,7 +24,7 @@ class RREFTest extends TestCase public function reduceDiagonalIsIdentity() : void { // A non-singular diagonal matrix reduces to the identity. - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 3.0], @@ -32,13 +32,13 @@ public function reduceDiagonalIsIdentity() : void $rref = RREF::reduce($a); - $expectedA = Matrix::quick([ + $expectedA = Matrix::fromArray([ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], ]); - $this->assertEqualsWithDelta($expectedA, $rref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expectedA->asArray(), $rref->a()->asArray(), self::MAX_DELTA); } /** @@ -46,19 +46,19 @@ public function reduceDiagonalIsIdentity() : void */ public function reduce2x2() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], ]); $rref = RREF::reduce($a); - $expectedA = Matrix::quick([ + $expectedA = Matrix::fromArray([ [1.0, 0.0], [0.0, 1.0], ]); - $this->assertEqualsWithDelta($expectedA, $rref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expectedA->asArray(), $rref->a()->asArray(), self::MAX_DELTA); } /** @@ -66,19 +66,19 @@ public function reduce2x2() : void */ public function reduceDiagonal2x2() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [2.0, 0.0], [0.0, 3.0], ]); $rref = RREF::reduce($a); - $expectedA = Matrix::quick([ + $expectedA = Matrix::fromArray([ [1.0, 0.0], [0.0, 1.0], ]); - $this->assertEqualsWithDelta($expectedA, $rref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expectedA->asArray(), $rref->a()->asArray(), self::MAX_DELTA); } /** @@ -86,11 +86,11 @@ public function reduceDiagonal2x2() : void */ public function reduce1x1() : void { - $a = Matrix::quick([[7.0]]); + $a = Matrix::fromArray([[7.0]]); $rref = RREF::reduce($a); - $this->assertEqualsWithDelta(Matrix::quick([[1.0]]), $rref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta(Matrix::fromArray([[1.0]])->asArray(), $rref->a()->asArray(), self::MAX_DELTA); } /** @@ -99,19 +99,19 @@ public function reduce1x1() : void public function reduceSingular2x2() : void { // A rank-1 matrix has a zero row and one free variable. - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 2.0], [2.0, 4.0], ]); $rref = RREF::reduce($a); - $expectedA = Matrix::quick([ + $expectedA = Matrix::fromArray([ [1.0, 2.0], [0.0, 0.0], ]); - $this->assertEqualsWithDelta($expectedA, $rref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expectedA->asArray(), $rref->a()->asArray(), self::MAX_DELTA); $aOut = $rref->a()->asArray(); @@ -124,19 +124,19 @@ public function reduceSingular2x2() : void public function reduceZeroRow() : void { // A leading zero row is swapped down; the result has a zero row. - $a = Matrix::quick([ + $a = Matrix::fromArray([ [0.0, 0.0], [1.0, 2.0], ]); $rref = RREF::reduce($a); - $expectedA = Matrix::quick([ + $expectedA = Matrix::fromArray([ [1.0, 2.0], [0.0, 0.0], ]); - $this->assertEqualsWithDelta($expectedA, $rref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta($expectedA->asArray(), $rref->a()->asArray(), self::MAX_DELTA); } /** @@ -144,7 +144,7 @@ public function reduceZeroRow() : void */ public function rankMatchesNumberNonZeroRows() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 2.0, 3.0], [2.0, 4.0, 6.0], [4.0, 8.0, 12.0], @@ -185,7 +185,7 @@ public function reduceExactlySingular4x4Has3NonZeroRows() : void // RREF must contain exactly three non-zero rows, the fourth being zero. // Before the float-tolerance fix, floating-point residual of ~1e-16 // on the diagonal would cause RREF to report a fourth non-zero row. - $a = Matrix::quick([ + $a = Matrix::fromArray([ [2.0, 1.0, 0.0, 1.0], [1.0, 2.0, 1.0, 0.0], [0.0, 1.0, 2.0, 1.0], @@ -222,7 +222,7 @@ public function reduceExactlySingular4x4Has3NonZeroRows() : void */ public function accessorsReturnMatrices() : void { - $a = Matrix::quick([ + $a = Matrix::fromArray([ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], @@ -230,6 +230,6 @@ public function accessorsReturnMatrices() : void $rref = new RREF($a); - $this->assertEqualsWithDelta($a, $rref->a(), self::MAX_DELTA); + $this->assertEqualsWithDelta($a->asArray(), $rref->a()->asArray(), self::MAX_DELTA); } } diff --git a/tests/TensorBufferTest.php b/tests/TensorBufferTest.php new file mode 100644 index 0000000..cf9f1d6 --- /dev/null +++ b/tests/TensorBufferTest.php @@ -0,0 +1,479 @@ +assertInstanceOf(TensorBuffer::class, $decorator); + $this->assertSame($buffer, $decorator->asBuffer()); + $this->assertSame(3, $decorator->count()); + $this->assertSame(Buffer::TYPE_DOUBLE, $decorator->type()); + } + + /** + * @test + */ + public function toArray() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1, 2, 3])); + + $expected = [1.0, 2.0, 3.0]; + + $this->assertEqualsWithDelta($expected, $decorator->toArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function longType() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1, 2, 3], Buffer::TYPE_LONG)); + + $this->assertSame(Buffer::TYPE_LONG, $decorator->type()); + $this->assertSame([1, 2, 3], $decorator->toArray()); + } + + /** + * @test + */ + public function get() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([3.0, 1.0, 2.0])); + + $this->assertSame(1.0, $decorator->get(1)); + } + + /** + * @test + */ + public function set() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([3.0, 1.0, 2.0])); + + $decorator->set(0, 4.0); + + $this->assertEqualsWithDelta([4.0, 1.0, 2.0], $decorator->toArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function sortAscending() : void + { + $buffer = Buffer::fromArray([3.0, 1.0, 2.0]); + + $decorator = new TensorBuffer($buffer); + + $decorator->sort(); + + $this->assertSame($buffer, $decorator->asBuffer()); + $this->assertEqualsWithDelta([1.0, 2.0, 3.0], $decorator->toArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function sortDescending() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([3.0, 1.0, 2.0])); + + $decorator->sort(false); + + $this->assertEqualsWithDelta([3.0, 2.0, 1.0], $decorator->toArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function sortLongBuffer() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([3, 1, 2], Buffer::TYPE_LONG)); + + $decorator->sort(); + + $this->assertSame(Buffer::TYPE_LONG, $decorator->type()); + $this->assertSame([1, 2, 3], $decorator->toArray()); + } + + /** + * @test + */ + public function slice() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0])); + + $slice = $decorator->slice(1, 2); + + $this->assertInstanceOf(TensorBuffer::class, $slice); + $this->assertNotSame($decorator->asBuffer(), $slice->asBuffer()); + $this->assertEqualsWithDelta([2.0, 3.0], $slice->toArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta([1.0, 2.0, 3.0], $decorator->toArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function sliceIsACopy() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0])); + + $slice = $decorator->slice(0, 3); + + $slice->set(0, 100.0); + + $this->assertEqualsWithDelta([1.0, 2.0, 3.0], $decorator->toArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta([100.0, 2.0, 3.0], $slice->toArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function sliceZeroLength() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0])); + + $slice = $decorator->slice(2, 0); + + $this->assertSame(0, $slice->count()); + } + + /** + * @test + */ + public function slicePreservesType() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1, 2, 3], Buffer::TYPE_LONG)); + + $slice = $decorator->slice(1, 1); + + $this->assertSame(Buffer::TYPE_LONG, $slice->type()); + $this->assertSame([2], $slice->toArray()); + } + + /** + * @test + */ + public function sliceOutOfRange() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0])); + + $this->expectException(InvalidArgumentException::class); + + $decorator->slice(2, 2); + } + + /** + * @test + */ + public function sliceNegativeOffset() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0])); + + $this->expectException(InvalidArgumentException::class); + + $decorator->slice(-1, 1); + } + + /** + * @test + */ + public function sliceNegativeLength() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0])); + + $this->expectException(InvalidArgumentException::class); + + $decorator->slice(0, -1); + } + + /** + * @test + */ + public function sliceStrided() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0, 4.0, 5.0])); + + $slice = $decorator->sliceStrided(1, 2, 2); + + $this->assertInstanceOf(TensorBuffer::class, $slice); + $this->assertNotSame($decorator->asBuffer(), $slice->asBuffer()); + $this->assertEqualsWithDelta([2.0, 4.0], $slice->toArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta([1.0, 2.0, 3.0, 4.0, 5.0], $decorator->toArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function sliceStridedPreservesType() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1, 2, 3, 4, 5], Buffer::TYPE_LONG)); + + $slice = $decorator->sliceStrided(0, 3, 2); + + $this->assertSame(Buffer::TYPE_LONG, $slice->type()); + $this->assertSame([1, 3, 5], $slice->toArray()); + } + + /** + * @test + */ + public function sliceStridedZeroLength() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0, 4.0, 5.0])); + + $slice = $decorator->sliceStrided(4, 0, 2); + + $this->assertSame(0, $slice->count()); + } + + /** + * @test + */ + public function sliceStridedOutOfRange() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0, 4.0, 5.0])); + + $this->expectException(InvalidArgumentException::class); + + $decorator->sliceStrided(4, 2, 2); + } + + /** + * @test + */ + public function sliceStridedInvalidStride() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0, 4.0, 5.0])); + + $this->expectException(InvalidArgumentException::class); + + $decorator->sliceStrided(0, 2, 0); + } + + /** + * @test + */ + public function sliceStridedRejectsOverflowingRange() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0, 4.0, 5.0])); + + $this->expectException(InvalidArgumentException::class); + + $decorator->sliceStrided(0, 4097, 4503599627370496); + } + + /** + * @test + */ + public function sliceStridedRejectsHugeStride() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0, 4.0, 5.0])); + + $this->expectException(InvalidArgumentException::class); + + $decorator->sliceStrided(0, 10, 4611686018427387904); + } + + /** + * @test + */ + public function sliceStridedSingleElementHugeStride() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0, 4.0, 5.0])); + + $slice = $decorator->sliceStrided(4, 1, PHP_INT_MAX); + + $this->assertSame([5.0], $slice->toArray()); + } + + /** + * @test + */ + public function concat() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0])); + $other = new TensorBuffer(Buffer::fromArray([3.0, 4.0])); + + $concat = $decorator->concat([$other]); + + $this->assertInstanceOf(TensorBuffer::class, $concat); + $this->assertEqualsWithDelta([1.0, 2.0, 3.0, 4.0], $concat->toArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta([1.0, 2.0], $decorator->toArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function concatMany() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0])); + + $concat = $decorator->concat([ + new TensorBuffer(Buffer::fromArray([2.0])), + new TensorBuffer(Buffer::fromArray([3.0])), + ]); + + $this->assertEqualsWithDelta([1.0, 2.0, 3.0], $concat->toArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function concatPreservesType() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1, 2], Buffer::TYPE_LONG)); + $other = new TensorBuffer(Buffer::fromArray([3, 4], Buffer::TYPE_LONG)); + + $concat = $decorator->concat([$other]); + + $this->assertSame(Buffer::TYPE_LONG, $concat->type()); + $this->assertSame([1, 2, 3, 4], $concat->toArray()); + } + + /** + * @test + */ + public function concatEmptyList() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0])); + + $concat = $decorator->concat([]); + + $this->assertEqualsWithDelta([1.0, 2.0], $concat->toArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function split() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0, 4.0, 5.0])); + + $chunks = $decorator->split(2); + + $this->assertCount(3, $chunks); + + foreach ($chunks as $chunk) { + $this->assertInstanceOf(TensorBuffer::class, $chunk); + } + + $this->assertEqualsWithDelta([1.0, 2.0], $chunks[0]->toArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta([3.0, 4.0], $chunks[1]->toArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta([5.0], $chunks[2]->toArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta([1.0, 2.0, 3.0, 4.0, 5.0], $decorator->toArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function splitPreservesType() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1, 2, 3], Buffer::TYPE_LONG)); + + $chunks = $decorator->split(2); + + $this->assertSame(Buffer::TYPE_LONG, $chunks[0]->type()); + $this->assertSame([1, 2], $chunks[0]->toArray()); + $this->assertSame([3], $chunks[1]->toArray()); + } + + /** + * @test + */ + public function splitInvalidChunkLength() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0])); + + $this->expectException(InvalidArgumentException::class); + + $decorator->split(0); + } + + /** + * @test + */ + public function repeat() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0])); + + $repeated = $decorator->repeat(3); + + $this->assertInstanceOf(TensorBuffer::class, $repeated); + $this->assertEqualsWithDelta([1.0, 2.0, 1.0, 2.0, 1.0, 2.0], $repeated->toArray(), self::MAX_DELTA); + $this->assertEqualsWithDelta([1.0, 2.0], $decorator->toArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function repeatPreservesType() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1, 2], Buffer::TYPE_LONG)); + + $repeated = $decorator->repeat(2); + + $this->assertSame(Buffer::TYPE_LONG, $repeated->type()); + $this->assertSame([1, 2, 1, 2], $repeated->toArray()); + } + + /** + * @test + */ + public function repeatInvalidTimes() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0])); + + $this->expectException(InvalidArgumentException::class); + + $decorator->repeat(0); + } + + /** + * @test + */ + public function repeatRejectsOverflowingTimes() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0])); + + $this->expectException(InvalidArgumentException::class); + + $decorator->repeat(PHP_INT_MAX); + } + + /** + * @test + */ + public function splitChunkLargerThanBuffer() : void + { + $decorator = new TensorBuffer(Buffer::fromArray([1.0, 2.0, 3.0])); + + $chunks = $decorator->split(PHP_INT_MAX); + + $this->assertCount(1, $chunks); + $this->assertEqualsWithDelta([1.0, 2.0, 3.0], $chunks[0]->toArray(), self::MAX_DELTA); + } +} diff --git a/tests/VectorTest.php b/tests/VectorTest.php index 52c5ea9..215d7e7 100644 --- a/tests/VectorTest.php +++ b/tests/VectorTest.php @@ -36,7 +36,7 @@ class VectorTest extends TestCase */ public function build() : void { - $vector = Vector::build([1, 2, 3, 4, 5]); + $vector = Vector::fromArray([1.0, 2.0, 3.0, 4.0, 5.0]); $this->assertInstanceOf(Vector::class, $vector); $this->assertInstanceOf(Tensor::class, $vector); @@ -54,7 +54,7 @@ public function build() : void */ public function buildCastsIntegersToFloats() : void { - $vector = Vector::build([1, 2, 3, 4, 5]); + $vector = Vector::fromArray([1.0, 2.0, 3.0, 4.0, 5.0]); $this->assertSame(5, $vector->size()); @@ -69,6 +69,39 @@ public function buildCastsIntegersToFloats() : void $this->assertEqualsWithDelta([1.0, 2.0, 3.0, 4.0, 5.0], $result, self::MAX_DELTA); } + /** + * @test + */ + public function fromArrayThrowsOnNestedArray() : void + { + $this->expectException(InvalidArgumentException::class); + + Vector::fromArray([1.0, [2.0], 3.0]); + } + + /** + * @test + */ + public function fromArraySkipsValidationWhenValidateFalse() : void + { + $expected = Vector::fromArray([1.0, 2.0, 3.0]); + + $a = Vector::fromArray([1.0, 2.0, 3.0], false); + + $this->assertInstanceOf(Vector::class, $a); + $this->assertEquals($expected->asArray(), $a->asArray()); + } + + /** + * @test + */ + public function fromArrayDiscardsKeysPositionally() : void + { + $vector = Vector::fromArray([1 => 1.5, 0 => 2.5, 3 => 4.0]); + + $this->assertEqualsWithDelta([1.5, 2.5, 4.0], $vector->asArray(), self::MAX_DELTA); + } + /** * @test */ @@ -76,9 +109,9 @@ public function zeros() : void { $zeros = Vector::zeros(4); - $expected = Vector::quick([0, 0, 0, 0]); + $expected = Vector::fromArray([0.0, 0.0, 0.0, 0.0]); - $this->assertEquals($expected, $zeros); + $this->assertEquals($expected->asArray(), $zeros->asArray()); } /** @@ -88,9 +121,9 @@ public function ones() : void { $ones = Vector::ones(4); - $expected = Vector::quick([1, 1, 1, 1]); + $expected = Vector::fromArray([1.0, 1.0, 1.0, 1.0]); - $this->assertEquals($expected, $ones); + $this->assertEquals($expected->asArray(), $ones->asArray()); } /** @@ -98,11 +131,11 @@ public function ones() : void */ public function fill() : void { - $vector = Vector::fill(16, 4); + $vector = Vector::fill(16.0, 4); - $expected = Vector::quick([16, 16, 16, 16]); + $expected = Vector::fromArray([16.0, 16.0, 16.0, 16.0]); - $this->assertEquals($expected, $vector); + $this->assertEquals($expected->asArray(), $vector->asArray()); } /** @@ -280,9 +313,9 @@ public function range() : void { $vector = Vector::range(5.0, 12.0, 2.0); - $expected = Vector::quick([5.0, 7.0, 9.0, 11.0]); + $expected = Vector::fromArray([5.0, 7.0, 9.0, 11.0]); - $this->assertEquals($expected, $vector); + $this->assertEquals($expected->asArray(), $vector->asArray()); } /** @@ -292,12 +325,12 @@ public function linspace() : void { $vector = Vector::linspace(-5.0, 5.0, 10); - $expected = Vector::quick([ + $expected = Vector::fromArray([ -5.0, -3.888888888888889, -2.7777777777777777, -1.6666666666666665, -0.5555555555555554, 0.5555555555555558, 1.666666666666667, 2.777777777777778, 3.8888888888888893, 5.0, ]); - $this->assertEquals($expected, $vector); + $this->assertEquals($expected->asArray(), $vector->asArray()); } /** @@ -317,11 +350,11 @@ public function shape(Vector $vector, array $expected) : void */ public function shapeProvider() : Generator { - yield [Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), [8]]; + yield [Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), [8]]; - yield [Vector::quick([0.25]), [1]]; + yield [Vector::fromArray([0.25]), [1]]; - yield [Vector::quick([]), [0]]; + yield [Vector::fromArray([]), [0]]; } /** @@ -329,7 +362,7 @@ public function shapeProvider() : Generator */ public function shapeString() : void { - $vector = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $vector = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $this->assertEquals('8', $vector->shapeString()); } @@ -339,7 +372,7 @@ public function shapeString() : void */ public function size() : void { - $vector = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $vector = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $this->assertEquals(8, $vector->size()); } @@ -349,7 +382,7 @@ public function size() : void */ public function m() : void { - $vector = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $vector = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $this->assertEquals(1, $vector->m()); } @@ -359,7 +392,7 @@ public function m() : void */ public function n() : void { - $vector = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $vector = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $this->assertEquals(8, $vector->n()); } @@ -369,27 +402,45 @@ public function n() : void */ public function asArray() : void { - $vector = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $vector = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $expected = [-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]; $this->assertEquals($expected, $vector->asArray()); } + /** + * @test + */ + public function serialization() : void + { + $vector = Vector::fromArray([-15.0, 25.0, 35.0, -36.0]); + + $serialized = serialize($vector); + + $this->assertStringNotContainsString('TensorBuffer', $serialized); + + $restored = unserialize($serialized); + + $this->assertInstanceOf(Vector::class, $restored); + $this->assertEquals([-15.0, 25.0, 35.0, -36.0], $restored->asArray()); + $this->assertSame(serialize($vector), serialize($restored)); + } + /** * @test */ public function asRowMatrix() : void { - $vector = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $vector = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $matrix = $vector->asRowMatrix(); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0], ]); - $this->assertEquals($expected, $matrix); + $this->assertEquals($expected->asArray(), $matrix->asArray()); } /** @@ -397,13 +448,13 @@ public function asRowMatrix() : void */ public function asColumnMatrix() : void { - $vector = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $vector = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $matrix = $vector->asColumnMatrix(); - $expected = Matrix::quick([[-15.0], [25.0], [35.0], [-36.0], [-72.0], [89.0], [106.0], [45.0]]); + $expected = Matrix::fromArray([[-15.0], [25.0], [35.0], [-36.0], [-72.0], [89.0], [106.0], [45.0]]); - $this->assertEquals($expected, $matrix); + $this->assertEquals($expected->asArray(), $matrix->asArray()); } /** @@ -411,18 +462,18 @@ public function asColumnMatrix() : void */ public function reshape() : void { - $vector = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $vector = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $matrix = $vector->reshape(4, 2); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [-15.0, 25.0], [35.0, -36.0], [-72.0, 89.0], [106.0, 45.0], ]); - $this->assertEquals($expected, $matrix); + $this->assertEquals($expected->asArray(), $matrix->asArray()); } /** @@ -430,13 +481,13 @@ public function reshape() : void */ public function transpose() : void { - $vector = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $vector = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $vector = $vector->transpose(); - $expected = ColumnVector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $expected = ColumnVector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $this->assertEquals($expected, $vector); + $this->assertEquals($expected->asArray(), $vector->asArray()); } /** @@ -444,7 +495,7 @@ public function transpose() : void */ public function map() : void { - $vector = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $vector = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $sign = function ($value) { return $value >= 0.0 ? 1 : 0; @@ -452,9 +503,9 @@ public function map() : void $vector = $vector->map($sign); - $expected = Vector::quick([0, 1, 1, 0, 0, 1, 1, 1]); + $expected = Vector::fromArray([0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0]); - $this->assertEquals($expected, $vector); + $this->assertEquals($expected->asArray(), $vector->asArray()); } /** @@ -462,7 +513,7 @@ public function map() : void */ public function reduce() : void { - $vector = Vector::quick([1.0, 2.0, 3.0]); + $vector = Vector::fromArray([1.0, 2.0, 3.0]); $sum = function ($carry, $value) { return $carry + $value; @@ -479,7 +530,7 @@ public function reduce() : void $this->assertEqualsWithDelta(-4.0, $vector->reduce($subtract, 2.0), self::MAX_DELTA); // Must match Matrix::reduce() for the same data and callback. - $matrix = Matrix::quick([[1.0, 2.0, 3.0]]); + $matrix = Matrix::fromArray([[1.0, 2.0, 3.0]]); $this->assertEqualsWithDelta($vector->reduce($subtract), $matrix->reduce($subtract), self::MAX_DELTA); } @@ -489,16 +540,16 @@ public function reduce() : void */ public function reciprocal() : void { - $vector = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $vector = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $vector = $vector->reciprocal(); - $expected = Vector::quick([ + $expected = Vector::fromArray([ -0.06666666666666667, 0.04, 0.02857142857142857, -0.027777777777777776, -0.013888888888888888, 0.011235955056179775, 0.009433962264150943, 0.022222222222222223, ]); - $this->assertEqualsWithDelta($expected, $vector, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $vector->asArray(), self::MAX_DELTA); } /** @@ -506,20 +557,23 @@ public function reciprocal() : void */ public function dot() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $b = Vector::quick([0.25, 0.1, 2.0, -0.5, -1.0, -3.0, 3.3, 2.0]); + $b = Vector::fromArray([0.25, 0.1, 2.0, -0.5, -1.0, -3.0, 3.3, 2.0]); $c = $a->dot($b); $this->assertEqualsWithDelta(331.54999999999995, $c, self::MAX_DELTA); } + /** + * @test + */ public function matmul() : void { - $a = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); - $b = Matrix::quick([ + $b = Matrix::fromArray([ [1.1, 0.01, 6.23], [5.0, 2.01, -1.0], [-5.0, 1.0, 0.03], @@ -530,11 +584,11 @@ public function matmul() : void $c = $a->matmul($b); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [622.3751, 4.634999999999993, 40.807], ]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -542,9 +596,9 @@ public function matmul() : void */ public function inner() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $b = Vector::quick([0.25, 0.1, 2.0, -0.5, -1.0, -3.0, 3.3, 2.0]); + $b = Vector::fromArray([0.25, 0.1, 2.0, -0.5, -1.0, -3.0, 3.3, 2.0]); $c = $a->inner($b); @@ -556,13 +610,13 @@ public function inner() : void */ public function outer() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $b = Vector::quick([0.25, 0.1, 2.0, -0.5, -1.0, -3.0, 3.3, 2.0]); + $b = Vector::fromArray([0.25, 0.1, 2.0, -0.5, -1.0, -3.0, 3.3, 2.0]); $c = $a->outer($b); - $expected = Matrix::quick([ + $expected = Matrix::fromArray([ [-3.75, -1.5, -30.0, 7.5, 15.0, 45.0, -49.5, -30.], [6.25, 2.5, 50.0, -12.5, -25.0, -75.0, 82.5, 50.], [8.75, 3.5, 70.0, -17.5, -35.0, -105.0, 115.5, 70.], @@ -573,7 +627,7 @@ public function outer() : void [11.25, 4.5, 90.0, -22.5, -45.0, -135.0, 148.5, 90.], ]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -581,18 +635,18 @@ public function outer() : void */ public function convolve() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $b = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + $b = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); $c = $a->convolve($b, 1); - $expected = Vector::quick([ + $expected = Vector::fromArray([ -60.0, 2.5, 259.0, -144.0, 40.5, 370.1, 462.20000000000005, 10.000000000000114, 1764.3000000000002, 1625.1, 2234.7, 1378.4, 535.5, ]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -604,15 +658,15 @@ public function convolve() : void */ public function convolveFullReadsNoOutOfBounds() : void { - $a = Vector::quick([5.0, 2.0, 7.0, 1.0, 9.0, 3.0]); + $a = Vector::fromArray([5.0, 2.0, 7.0, 1.0, 9.0, 3.0]); - $b = Vector::quick([1.0, 2.0, 3.0]); + $b = Vector::fromArray([1.0, 2.0, 3.0]); $c = $a->convolve($b, 1); - $expected = Vector::quick([5.0, 12.0, 26.0, 21.0, 32.0, 24.0, 33.0, 9.0]); + $expected = Vector::fromArray([5.0, 12.0, 26.0, 21.0, 32.0, 24.0, 33.0, 9.0]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -620,15 +674,15 @@ public function convolveFullReadsNoOutOfBounds() : void */ public function convolveStrideTwo() : void { - $a = Vector::quick([5.0, 2.0, 7.0, 1.0, 9.0, 3.0]); + $a = Vector::fromArray([5.0, 2.0, 7.0, 1.0, 9.0, 3.0]); - $b = Vector::quick([1.0, 2.0, 3.0]); + $b = Vector::fromArray([1.0, 2.0, 3.0]); $c = $a->convolve($b, 2); - $expected = Vector::quick([5.0, 26.0, 32.0, 33.0]); + $expected = Vector::fromArray([5.0, 26.0, 32.0, 33.0]); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -643,7 +697,7 @@ public function multiply(Vector $a, $b, $expected) : void { $c = $a->multiply($b); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -652,13 +706,13 @@ public function multiply(Vector $a, $b, $expected) : void public function multiplyProvider() : Generator { yield [ - Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), - Matrix::quick([ + Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), + Matrix::fromArray([ [6.23, -1.0, 0.03, -0.01, -0.5, 2.0], [0.01, 2.01, 1.0, 0.02, 0.05, -1.0], - [1.1, 5.0, -5.0, 30, -0.005, -0.001], + [1.1, 5.0, -5.0, 30.0, -0.005, -0.001], ]), - Matrix::quick([ + Matrix::fromArray([ [24.92, -6.5, 0.087, -0.2, -1.3, 23.8], [0.04, 13.064999999999998, 2.9, 0.4, 0.13, -11.9], [4.4, 32.5, -14.5, 600.0, -0.013000000000000001, -0.0119], @@ -666,15 +720,15 @@ public function multiplyProvider() : Generator ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), - Vector::quick([0.25, 0.1, 2.0, -0.5, -1.0, -3.0, 3.3, 2.0]), - Vector::quick([-3.75, 2.5, 70.0, 18.0, 72.0, -267.0, 349.79999999999995, 90.0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([0.25, 0.1, 2.0, -0.5, -1.0, -3.0, 3.3, 2.0]), + Vector::fromArray([-3.75, 2.5, 70.0, 18.0, 72.0, -267.0, 349.79999999999995, 90.0]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), 2.0, - Vector::quick([-30.0, 50.0, 70.0, -72.0, -144.0, 178.0, 212.0, 90.0]), + Vector::fromArray([-30.0, 50.0, 70.0, -72.0, -144.0, 178.0, 212.0, 90.0]), ]; } @@ -690,7 +744,7 @@ public function divide(Vector $a, $b, $expected) : void { $c = $a->divide($b); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -699,13 +753,13 @@ public function divide(Vector $a, $b, $expected) : void public function divideProvider() : Generator { yield [ - Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), - Matrix::quick([ + Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), + Matrix::fromArray([ [6.23, -1.0, 0.03, -0.01, -0.5, 2.0], [0.01, 2.01, 1.0, 0.02, 0.05, -1.0], - [1.1, 5.0, -5.0, 30, -0.005, -0.001], + [1.1, 5.0, -5.0, 30.0, -0.005, -0.001], ]), - Matrix::quick([ + Matrix::fromArray([ [0.6420545746388443, -6.5, 96.66666666666667, -2000.0, -5.2, 5.95], [400.0, 3.2338308457711444, 2.9, 1000.0, 52.0, -11.9], [3.6363636363636362, 1.3, -0.58, 0.6666666666666666, -520.0, -11900.], @@ -713,15 +767,15 @@ public function divideProvider() : Generator ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), - Vector::quick([0.25, 0.1, 2.0, -0.5, -1.0, -3.0, 3.3, 2.0]), - Vector::quick([-60.0, 250.0, 17.5, 72.0, 72.0, -29.666666666666668, 32.121212121212125, 22.5]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([0.25, 0.1, 2.0, -0.5, -1.0, -3.0, 3.3, 2.0]), + Vector::fromArray([-60.0, 250.0, 17.5, 72.0, 72.0, -29.666666666666668, 32.121212121212125, 22.5]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), 2.0, - Vector::quick([-7.5, 12.5, 17.5, -18.0, -36.0, 44.5, 53, 22.5]), + Vector::fromArray([-7.5, 12.5, 17.5, -18.0, -36.0, 44.5, 53.0, 22.5]), ]; } @@ -737,7 +791,7 @@ public function add(Vector $a, $b, $expected) : void { $c = $a->add($b); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -746,13 +800,13 @@ public function add(Vector $a, $b, $expected) : void public function addProvider() : Generator { yield [ - Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), - Matrix::quick([ + Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), + Matrix::fromArray([ [6.23, -1.0, 0.03, -0.01, -0.5, 2.0], [0.01, 2.01, 1.0, 0.02, 0.05, -1.0], - [1.1, 5.0, -5.0, 30, -0.005, -0.001], + [1.1, 5.0, -5.0, 30.0, -0.005, -0.001], ]), - Matrix::quick([ + Matrix::fromArray([ [10.23, 5.5, 2.9299999999999997, 19.99, 2.1, 13.9], [4.01, 8.51, 3.9, 20.02, 2.65, 10.9], [5.1, 11.5, -2.1, 50.0, 2.595, 11.899000000000001], @@ -760,15 +814,15 @@ public function addProvider() : Generator ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), - Vector::quick([0.25, 0.1, 2.0, -0.5, -1.0, -3.0, 3.3, 2.0]), - Vector::quick([-14.75, 25.1, 37.0, -36.5, -73.0, 86.0, 109.3, 47.0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([0.25, 0.1, 2.0, -0.5, -1.0, -3.0, 3.3, 2.0]), + Vector::fromArray([-14.75, 25.1, 37.0, -36.5, -73.0, 86.0, 109.3, 47.0]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), 10.0, - Vector::quick([-5.0, 35.0, 45.0, -26.0, -62.0, 99.0, 116.0, 55.0]), + Vector::fromArray([-5.0, 35.0, 45.0, -26.0, -62.0, 99.0, 116.0, 55.0]), ]; } @@ -784,7 +838,7 @@ public function subtract(Vector $a, $b, $expected) : void { $c = $a->subtract($b); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -793,13 +847,13 @@ public function subtract(Vector $a, $b, $expected) : void public function subtractProvider() : Generator { yield [ - Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), - Matrix::quick([ + Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), + Matrix::fromArray([ [6.23, -1.0, 0.03, -0.01, -0.5, 2.0], [0.01, 2.01, 1.0, 0.02, 0.05, -1.0], - [1.1, 5.0, -5.0, 30, -0.005, -0.001], + [1.1, 5.0, -5.0, 30.0, -0.005, -0.001], ]), - Matrix::quick([ + Matrix::fromArray([ [-2.2300000000000004, 7.5, 2.87, 20.01, 3.1, 9.9], [3.99, 4.49, 1.9, 19.98, 2.5500000000000003, 12.9], [2.9, 1.5, 7.9, -10.0, 2.605, 11.901], @@ -807,15 +861,15 @@ public function subtractProvider() : Generator ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), - Vector::quick([0.25, 0.1, 2.0, -0.5, -1.0, -3.0, 3.3, 2.0]), - Vector::quick([-15.25, 24.9, 33.0, -35.5, -71.0, 92.0, 102.7, 43.0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([0.25, 0.1, 2.0, -0.5, -1.0, -3.0, 3.3, 2.0]), + Vector::fromArray([-15.25, 24.9, 33.0, -35.5, -71.0, 92.0, 102.7, 43.0]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), 10.0, - Vector::quick([-25.0, 15.0, 25.0, -46.0, -82.0, 79.0, 96.0, 35.0]), + Vector::fromArray([-25.0, 15.0, 25.0, -46.0, -82.0, 79.0, 96.0, 35.0]), ]; } @@ -831,7 +885,7 @@ public function power(Vector $a, $b, $expected) : void { $c = $a->pow($b); - $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); } /** @@ -840,13 +894,13 @@ public function power(Vector $a, $b, $expected) : void public function powProvider() : Generator { yield [ - Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), - Matrix::quick([ + Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), + Matrix::fromArray([ [6.23, -1.0, 0.03, -0.01, -0.5, 2.0], [0.01, 2.01, 1.0, 0.02, 0.05, -1.0], - [1.1, 5.0, -5.0, 30, -0.005, -0.001], + [1.1, 5.0, -5.0, 30.0, -0.005, -0.001], ]), - Matrix::quick([ + Matrix::fromArray([ [5634.219287100394, 0.15384615384615385, 1.0324569211337775, 0.9704869503929601, 0.6201736729460423, 141.61], [1.013959479790029, 43.048284263459465, 2.9, 1.0617459178549786, 1.0489352187366092, 0.08403361344537814], [4.59479341998814, 11602.90625, 0.004875397277841432, 1.073741824E+39, 0.9952338371484033, 0.9975265256911376], @@ -854,16 +908,16 @@ public function powProvider() : Generator ]; yield [ - Vector::quick([3.0, 6.0, 9.0]), - Vector::quick([3.0, 2.0, 1.0]), - Vector::quick([27.0, 36.0, 9.0]), + Vector::fromArray([3.0, 6.0, 9.0]), + Vector::fromArray([3.0, 2.0, 1.0]), + Vector::fromArray([27.0, 36.0, 9.0]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), 4.0, - Vector::quick([ - 50625, 390625, 1500625, 1679616, 26873856, 62742241, 126247696, 4100625 + Vector::fromArray([ + 50625.0, 390625.0, 1500625.0, 1679616.0, 26873856.0, 62742241.0, 126247696.0, 4100625.0 ]), ]; } @@ -880,7 +934,7 @@ public function equal(Vector $a, $b, $expected) : void { $c = $a->equal($b); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -889,29 +943,29 @@ public function equal(Vector $a, $b, $expected) : void public function equalProvider() : Generator { yield [ - Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), - Matrix::quick([ + Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), + Matrix::fromArray([ [4.0, -1.0, 0.03, -0.01, -0.5, 2.0], [0.01, 2.01, 1.0, 20.0, 0.05, -1.0], - [1.1, 5.0, -5.0, 30, -0.005, 11.9], + [1.1, 5.0, -5.0, 30.0, -0.005, 11.9], ]), - Matrix::quick([ - [1, 0, 0, 0, 0, 0], - [0, 0, 0, 1, 0, 0], - [0, 0, 0, 0, 0, 1], + Matrix::fromArray([ + [1.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 1.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 1.0], ]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), - Vector::quick([0.25, 0.1, 2.0, -36.0, -1.0, -3.0, 3.3, 2.0]), - Vector::quick([0, 0, 0, 1, 0, 0, 0, 0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([0.25, 0.1, 2.0, -36.0, -1.0, -3.0, 3.3, 2.0]), + Vector::fromArray([0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), 25.0, - Vector::quick([0, 1, 0, 0, 0, 0, 0, 0]), + Vector::fromArray([0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]), ]; } @@ -927,7 +981,7 @@ public function notEqual(Vector $a, $b, $expected) : void { $c = $a->notEqual($b); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -936,29 +990,29 @@ public function notEqual(Vector $a, $b, $expected) : void public function notEqualProvider() : Generator { yield [ - Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), - Matrix::quick([ + Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), + Matrix::fromArray([ [4.0, -1.0, 0.03, -0.01, -0.5, 2.0], [0.01, 2.01, 1.0, 20.0, 0.05, -1.0], - [1.1, 5.0, -5.0, 30, -0.005, 11.9], + [1.1, 5.0, -5.0, 30.0, -0.005, 11.9], ]), - Matrix::quick([ - [0, 1, 1, 1, 1, 1], - [1, 1, 1, 0, 1, 1], - [1, 1, 1, 1, 1, 0], + Matrix::fromArray([ + [0.0, 1.0, 1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 0.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0, 1.0, 0.0], ]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), - Vector::quick([0.25, 0.1, 2.0, -36.0, -1.0, -3.0, 3.3, 2.0]), - Vector::quick([1, 1, 1, 0, 1, 1, 1, 1]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([0.25, 0.1, 2.0, -36.0, -1.0, -3.0, 3.3, 2.0]), + Vector::fromArray([1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), 25.0, - Vector::quick([1, 0, 1, 1, 1, 1, 1, 1]), + Vector::fromArray([1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]), ]; } @@ -969,9 +1023,9 @@ public function notEqualMatrixDimensionMismatch() : void { $this->expectException(DimensionalityMismatch::class); - $a = Vector::quick([1.0, 2.0, 3.0]); + $a = Vector::fromArray([1.0, 2.0, 3.0]); - $b = Matrix::quick([ + $b = Matrix::fromArray([ [1.0, 2.0], [3.0, 4.0], ]); @@ -979,6 +1033,294 @@ public function notEqualMatrixDimensionMismatch() : void $a->notEqualMatrix($b); } + /** + * @test + */ + public function multiplyMatrix() : void + { + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + + $b = Matrix::fromArray([ + [4.0, -1.0, 0.03, -0.01, -0.5, 2.0], + [0.01, 2.01, 1.0, 20.0, 0.05, -1.0], + [1.1, 5.0, -5.0, 30.0, -0.005, 11.9], + ]); + + $c = $a->multiplyMatrix($b); + + $expected = Matrix::fromArray([ + [16.0, -6.5, 0.087, -0.2, -1.3, 23.8], + [0.04, 13.065, 2.9, 400.0, 0.13, -11.9], + [4.4, 32.5, -14.5, 600.0, -0.013, 141.61], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function divideMatrix() : void + { + $a = Vector::fromArray([10.0, 20.0, 30.0]); + + $b = Matrix::fromArray([ + [2.0, 4.0, 5.0], + [5.0, 10.0, 3.0], + [3.0, 2.0, 1.0], + ]); + + $c = $a->divideMatrix($b); + + $expected = Matrix::fromArray([ + [5.0, 5.0, 6.0], + [2.0, 2.0, 10.0], + [3.3333333333333335, 10.0, 30.0], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function addMatrix() : void + { + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + + $b = Matrix::fromArray([ + [4.0, -1.0, 0.03, -0.01, -0.5, 2.0], + [0.01, 2.01, 1.0, 20.0, 0.05, -1.0], + [1.1, 5.0, -5.0, 30.0, -0.005, 11.9], + ]); + + $c = $a->addMatrix($b); + + $expected = Matrix::fromArray([ + [8.0, 5.5, 2.93, 19.99, 2.1, 13.9], + [4.01, 8.51, 3.9, 40.0, 2.65, 10.9], + [5.1, 11.5, -2.1, 50.0, 2.595, 23.8], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function subtractMatrix() : void + { + $a = Vector::fromArray([10.0, 20.0, 30.0]); + + $b = Matrix::fromArray([ + [4.0, 15.0, 12.0], + [4.0, 15.0, 12.0], + [4.0, 15.0, 12.0], + ]); + + $c = $a->subtractMatrix($b); + + $expected = Matrix::fromArray([ + [6.0, 5.0, 18.0], + [6.0, 5.0, 18.0], + [6.0, 5.0, 18.0], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function powMatrix() : void + { + $a = Vector::fromArray([2.0, 10.0, 2.0]); + + $b = Matrix::fromArray([ + [1.0, 1.0, 1.5], + [2.0, 0.0, 1.0], + [3.0, 2.0, 0.5], + ]); + + $c = $a->powMatrix($b); + + $expected = Matrix::fromArray([ + [2.0, 10.0, 2.8284271247461903], + [4.0, 1.0, 2.0], + [8.0, 100.0, 1.4142135623730951], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function modMatrix() : void + { + $a = Vector::fromArray([1.0, 20.0, 7.5]); + + $b = Matrix::fromArray([ + [0.5, 5.0, 3.0], + [0.5, 10.0, 3.0], + [0.5, 7.5, 3.0], + ]); + + $c = $a->modMatrix($b); + + $expected = Matrix::fromArray([ + [0.0, 0.0, 1.5], + [0.0, 0.0, 1.5], + [0.0, 5.0, 1.5], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function equalMatrix() : void + { + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + + $b = Matrix::fromArray([ + [4.0, -1.0, 0.03, -0.01, -0.5, 2.0], + [0.01, 6.5, 2.9, 20.0, 2.6, 11.9], + [1.1, 5.0, -5.0, 30.0, -0.005, 11.9], + ]); + + $c = $a->equalMatrix($b); + + $expected = Matrix::fromArray([ + [1.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 1.0, 1.0, 1.0, 1.0, 1.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 1.0], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function notEqualMatrix() : void + { + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + + $b = Matrix::fromArray([ + [4.0, -1.0, 0.03, -0.01, -0.5, 2.0], + [0.01, 6.5, 2.9, 20.0, 2.6, 11.9], + [1.1, 5.0, -5.0, 30.0, -0.005, 11.9], + ]); + + $c = $a->notEqualMatrix($b); + + $expected = Matrix::fromArray([ + [0.0, 1.0, 1.0, 1.0, 1.0, 1.0], + [1.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [1.0, 1.0, 1.0, 1.0, 1.0, 0.0], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function greaterMatrix() : void + { + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + + $b = Matrix::fromArray([ + [4.0, -1.0, 0.03, -0.01, -0.5, 2.0], + [0.01, 6.5, 2.9, 20.0, 0.05, -1.0], + [1.1, 5.0, -5.0, 30.0, -0.005, 11.9], + ]); + + $c = $a->greaterMatrix($b); + + $expected = Matrix::fromArray([ + [0.0, 1.0, 1.0, 1.0, 1.0, 1.0], + [1.0, 0.0, 0.0, 0.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 0.0, 1.0, 0.0], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function greaterEqualMatrix() : void + { + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + + $b = Matrix::fromArray([ + [4.0, -1.0, 0.03, -0.01, -0.5, 2.0], + [0.01, 6.5, 2.9, 20.0, 0.05, -1.0], + [1.1, 5.0, -5.0, 30.0, -0.005, 11.9], + ]); + + $c = $a->greaterEqualMatrix($b); + + $expected = Matrix::fromArray([ + [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 0.0, 1.0, 1.0], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function lessMatrix() : void + { + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + + $b = Matrix::fromArray([ + [4.0, -1.0, 0.03, -0.01, -0.5, 2.0], + [0.01, 6.5, 2.9, 20.0, 0.05, -1.0], + [1.1, 5.0, -5.0, 30.0, -0.005, 11.9], + ]); + + $c = $a->lessMatrix($b); + + $expected = Matrix::fromArray([ + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 1.0, 0.0, 0.0], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); + } + + /** + * @test + */ + public function lessEqualMatrix() : void + { + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + + $b = Matrix::fromArray([ + [4.0, -1.0, 0.03, -0.01, -0.5, 2.0], + [0.01, 6.5, 2.9, 20.0, 0.05, -1.0], + [1.1, 5.0, -5.0, 30.0, -0.005, 11.9], + ]); + + $c = $a->lessEqualMatrix($b); + + $expected = Matrix::fromArray([ + [1.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 1.0, 1.0, 1.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 1.0, 0.0, 1.0], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $c->asArray(), self::MAX_DELTA); + } + /** * @test * @dataProvider greaterProvider @@ -991,7 +1333,7 @@ public function greater(Vector $a, $b, $expected) : void { $c = $a->greater($b); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -1000,29 +1342,29 @@ public function greater(Vector $a, $b, $expected) : void public function greaterProvider() : Generator { yield [ - Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), - Matrix::quick([ + Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), + Matrix::fromArray([ [4.0, -1.0, 0.03, -0.01, -0.5, 2.0], [0.01, 2.01, 1.0, 20.0, 0.05, -1.0], - [1.1, 5.0, -5.0, 30, -0.005, 11.9], + [1.1, 5.0, -5.0, 30.0, -0.005, 11.9], ]), - Matrix::quick([ - [0, 1, 1, 1, 1, 1], - [1, 1, 1, 0, 1, 1], - [1, 1, 1, 0, 1, 0], + Matrix::fromArray([ + [0.0, 1.0, 1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 0.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 0.0, 1.0, 0.0], ]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), - Vector::quick([0.25, 0.1, 2.0, -36.0, -1.0, -3.0, 3.3, 2.0]), - Vector::quick([0, 1, 1, 0, 0, 1, 1, 1]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([0.25, 0.1, 2.0, -36.0, -1.0, -3.0, 3.3, 2.0]), + Vector::fromArray([0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), 1.0, - Vector::quick([0, 1, 1, 0, 0, 1, 1, 1]), + Vector::fromArray([0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0]), ]; } @@ -1038,7 +1380,7 @@ public function greaterEqual(Vector $a, $b, $expected) : void { $c = $a->greaterEqual($b); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -1047,29 +1389,29 @@ public function greaterEqual(Vector $a, $b, $expected) : void public function greaterEqualProvider() : Generator { yield [ - Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), - Matrix::quick([ + Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), + Matrix::fromArray([ [4.0, -1.0, 0.03, -0.01, -0.5, 2.0], [0.01, 2.01, 1.0, 20.0, 0.05, -1.0], - [1.1, 5.0, -5.0, 30, -0.005, 11.9], + [1.1, 5.0, -5.0, 30.0, -0.005, 11.9], ]), - Matrix::quick([ - [1, 1, 1, 1, 1, 1], - [1, 1, 1, 1, 1, 1], - [1, 1, 1, 0, 1, 1], + Matrix::fromArray([ + [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 0.0, 1.0, 1.0], ]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), - Vector::quick([0.25, 0.1, 2.0, -36.0, -1.0, -3.0, 3.3, 2.0]), - Vector::quick([0, 1, 1, 1, 0, 1, 1, 1]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([0.25, 0.1, 2.0, -36.0, -1.0, -3.0, 3.3, 2.0]), + Vector::fromArray([0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), 25.0, - Vector::quick([0, 1, 1, 0, 0, 1, 1, 1]), + Vector::fromArray([0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0]), ]; } @@ -1085,7 +1427,7 @@ public function less(Vector $a, $b, $expected) : void { $c = $a->less($b); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -1094,29 +1436,29 @@ public function less(Vector $a, $b, $expected) : void public function lessProvider() : Generator { yield [ - Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), - Matrix::quick([ + Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), + Matrix::fromArray([ [4.0, -1.0, 0.03, -0.01, -0.5, 2.0], [0.01, 2.01, 1.0, 20.0, 0.05, -1.0], - [1.1, 5.0, -5.0, 30, -0.005, 11.9], + [1.1, 5.0, -5.0, 30.0, -0.005, 11.9], ]), - Matrix::quick([ - [0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0], - [0, 0, 0, 1, 0, 0], + Matrix::fromArray([ + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 1.0, 0.0, 0.0], ]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), - Vector::quick([0.25, 0.1, 2.0, -36.0, -1.0, -3.0, 3.3, 2.0]), - Vector::quick([1, 0, 0, 0, 1, 0, 0, 0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([0.25, 0.1, 2.0, -36.0, -1.0, -3.0, 3.3, 2.0]), + Vector::fromArray([1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), 25.0, - Vector::quick([1, 0, 0, 1, 1, 0, 0, 0]), + Vector::fromArray([1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0]), ]; } @@ -1132,7 +1474,7 @@ public function lessEqual(Vector $a, $b, $expected) : void { $c = $a->lessEqual($b); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -1141,30 +1483,30 @@ public function lessEqual(Vector $a, $b, $expected) : void public function lessEqualProvider() : Generator { yield [ - Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), - Matrix::quick([ + Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]), + Matrix::fromArray([ [4.0, -1.0, 0.03, -0.01, -0.5, 2.0], [0.01, 2.01, 1.0, 20.0, 0.05, -1.0], - [1.1, 5.0, -5.0, 30, -0.005, 11.9], + [1.1, 5.0, -5.0, 30.0, -0.005, 11.9], ]), - Matrix::quick([ - [1, 0, 0, 0, 0, 0], - [0, 0, 0, 1, 0, 0], - [0, 0, 0, 1, 0, 1], + Matrix::fromArray([ + [1.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 1.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 1.0, 0.0, 1.0], ]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), - Vector::quick([0.25, 0.1, 2.0, -36.0, -1.0, -3.0, 3.3, 2.0]), - Vector::quick([1, 0, 0, 1, 1, 0, 0, 0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([0.25, 0.1, 2.0, -36.0, -1.0, -3.0, 3.3, 2.0]), + Vector::fromArray([1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), 25.0, - Vector::quick([1, 1, 0, 1, 1, 0, 0, 0]), + Vector::fromArray([1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0]), ]; } @@ -1180,7 +1522,7 @@ public function mod(Vector $a, $b, $expected) : void { $c = $a->mod($b); - $this->assertEquals($expected, $c); + $this->assertEquals($expected->asArray(), $c->asArray()); } /** @@ -1189,15 +1531,15 @@ public function mod(Vector $a, $b, $expected) : void public function modProvider() : Generator { yield [ - Vector::quick([0.25, 0.1, 2.0, -0.5, -1.0, -3.0, 3.3, 2.0]), - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), - Vector::quick([0, 0, 2, 0, -1, -3, 3, 2]), + Vector::fromArray([3.5, -7.0, 12.75, 0.375, -1.5]), + Vector::fromArray([2.0, 3.0, 4.5, 0.5, 2.0]), + Vector::fromArray([1.5, -1.0, 3.75, 0.375, -1.5]), ]; yield [ - Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), - 4, - Vector::quick([-3, 1, 3, 0, 0, 1, 2, 1]), + Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]), + 4.0, + Vector::fromArray([-3.0, 1.0, 3.0, 0.0, 0.0, 1.0, 2.0, 1.0]), ]; } @@ -1206,13 +1548,13 @@ public function modProvider() : Generator */ public function abs() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $b = $a->abs(); - $expected = Vector::quick([15, 25, 35, 36, 72, 89, 106, 45]); + $expected = Vector::fromArray([15.0, 25.0, 35.0, 36.0, 72.0, 89.0, 106.0, 45.0]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -1220,13 +1562,13 @@ public function abs() : void */ public function square() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $b = $a->square(); - $expected = Vector::quick([225, 625, 1225, 1296, 5184, 7921, 11236, 2025]); + $expected = Vector::fromArray([225.0, 625.0, 1225.0, 1296.0, 5184.0, 7921.0, 11236.0, 2025.0]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -1234,13 +1576,13 @@ public function square() : void */ public function pow() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $b = $a->pow(3); + $b = $a->pow(3.0); - $expected = Vector::quick([-3375, 15625, 42875, -46656, -373248, 704969, 1191016, 91125]); + $expected = Vector::fromArray([-3375.0, 15625.0, 42875.0, -46656.0, -373248.0, 704969.0, 1191016.0, 91125.0]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -1248,16 +1590,16 @@ public function pow() : void */ public function sqrt() : void { - $a = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); $b = $a->sqrt(); - $expected = Vector::quick([ + $expected = Vector::fromArray([ 2.0, 2.5495097567963922, 1.70293863659264, 4.47213595499958, 1.61245154965971, 3.449637662132068, ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -1265,16 +1607,16 @@ public function sqrt() : void */ public function exp() : void { - $a = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); $b = $a->exp(); - $expected = Vector::quick([ + $expected = Vector::fromArray([ 54.598150033144236, 665.1416330443618, 18.17414536944306, 485165195.4097903, 13.463738035001692, 147266.6252405527, ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -1282,16 +1624,16 @@ public function exp() : void */ public function log() : void { - $a = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); $b = $a->log(); - $expected = Vector::quick([ + $expected = Vector::fromArray([ 1.3862943611198906, 1.8718021769015913, 1.0647107369924282, 2.995732273553991, 0.9555114450274363, 2.4765384001174837, ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -1299,16 +1641,16 @@ public function log() : void */ public function sin() : void { - $a = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); $b = $a->sin(); - $expected = Vector::quick([ + $expected = Vector::fromArray([ -0.7568024953079282, 0.21511998808781552, 0.23924932921398243, 0.9129452507276277, 0.5155013718214642, -0.6181371122370333, ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -1316,15 +1658,15 @@ public function sin() : void */ public function asin() : void { - $a = Vector::quick([0.1, 0.3, -0.5]); + $a = Vector::fromArray([0.1, 0.3, -0.5]); $b = $a->asin(); - $expected = Vector::quick([ + $expected = Vector::fromArray([ 0.1001674211615598, 0.3046926540153975, -0.5235987755982989, ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -1332,16 +1674,16 @@ public function asin() : void */ public function cos() : void { - $a = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); $b = $a->cos(); - $expected = Vector::quick([ + $expected = Vector::fromArray([ -0.6536436208636119, 0.9765876257280235, -0.9709581651495905, 0.40808206181339196, -0.8568887533689473, 0.7860702961410393, ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -1349,15 +1691,15 @@ public function cos() : void */ public function acos() : void { - $a = Vector::quick([0.1, 0.3, -0.5]); + $a = Vector::fromArray([0.1, 0.3, -0.5]); $b = $a->acos(); - $expected = Vector::quick([ + $expected = Vector::fromArray([ 1.4706289056333368, 1.2661036727794992, 2.0943951023931957, ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -1365,16 +1707,16 @@ public function acos() : void */ public function tan() : void { - $a = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); $b = $a->tan(); - $expected = Vector::quick([ + $expected = Vector::fromArray([ 1.1578212823495777, 0.22027720034589682, -0.24640539397196634, 2.237160944224742, -0.6015966130897586, -0.7863636563696398, ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -1382,16 +1724,16 @@ public function tan() : void */ public function atan() : void { - $a = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); $b = $a->atan(); - $expected = Vector::quick([ + $expected = Vector::fromArray([ 1.3258176636680326, 1.4181469983996315, 1.2387368592520112, 1.5208379310729538, 1.2036224929766774, 1.486959684726482, ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -1399,16 +1741,16 @@ public function atan() : void */ public function rad2deg() : void { - $a = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); $b = $a->rad2deg(); - $expected = Vector::quick([ + $expected = Vector::fromArray([ 229.1831180523293, 372.42256683503507, 166.15776058793872, 1145.9155902616465, 148.96902673401405, 681.8197762056797, ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -1416,16 +1758,16 @@ public function rad2deg() : void */ public function deg2rad() : void { - $a = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); $b = $a->deg2rad(); - $expected = Vector::quick([ + $expected = Vector::fromArray([ 0.06981317007977318, 0.11344640137963141, 0.05061454830783556, 0.3490658503988659, 0.04537856055185257, 0.2076941809873252, ]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -1433,7 +1775,7 @@ public function deg2rad() : void */ public function sum() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $this->assertEqualsWithDelta(177.0, $a->sum(), self::MAX_DELTA); } @@ -1443,7 +1785,7 @@ public function sum() : void */ public function product() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $this->assertEqualsWithDelta(-14442510600000.0, $a->product(), self::MAX_DELTA); } @@ -1453,9 +1795,9 @@ public function product() : void */ public function min() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $this->assertEquals(-72, $a->min()); + $this->assertEquals(-72.0, $a->min()); } /** @@ -1463,9 +1805,73 @@ public function min() : void */ public function max() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $this->assertEquals(106, $a->max()); + $this->assertEquals(106.0, $a->max()); + } + + /** + * @test + */ + public function argmin() : void + { + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + + $this->assertSame(4, $a->argmin()); + } + + /** + * @test + */ + public function argminTie() : void + { + $a = Vector::fromArray([2.0, 1.0, 1.0, 3.0]); + + $this->assertSame(1, $a->argmin()); + } + + /** + * @test + */ + public function argminEmptyVector() : void + { + $a = Vector::fromArray([], false); + + $this->expectException(\InvalidArgumentException::class); + + $a->argmin(); + } + + /** + * @test + */ + public function argmax() : void + { + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + + $this->assertSame(6, $a->argmax()); + } + + /** + * @test + */ + public function argmaxTie() : void + { + $a = Vector::fromArray([2.0, 3.0, 3.0, 1.0]); + + $this->assertSame(1, $a->argmax()); + } + + /** + * @test + */ + public function argmaxEmptyVector() : void + { + $a = Vector::fromArray([], false); + + $this->expectException(\InvalidArgumentException::class); + + $a->argmax(); } /** @@ -1473,7 +1879,7 @@ public function max() : void */ public function mean() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $this->assertEqualsWithDelta(22.125, $a->mean(), self::MAX_DELTA); } @@ -1483,35 +1889,59 @@ public function mean() : void */ public function median() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $this->assertEquals(30.0, $a->median()); } + /** + * @test + */ + public function medianEmptyVectorThrows() : void + { + $a = Vector::fromArray([], false); + + $this->expectException(InvalidArgumentException::class); + + $a->median(); + } + /** * @test */ public function quantile() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $this->assertEqualsWithDelta(30.0, $a->quantile(0.5), self::MAX_DELTA); $this->assertEqualsWithDelta(-72.0, $a->quantile(0.0), self::MAX_DELTA); $this->assertEqualsWithDelta(106.0, $a->quantile(1.0), self::MAX_DELTA); - $single = Vector::quick([5.0]); + $single = Vector::fromArray([5.0]); $this->assertEqualsWithDelta(5.0, $single->quantile(0.0), self::MAX_DELTA); $this->assertEqualsWithDelta(5.0, $single->quantile(0.5), self::MAX_DELTA); $this->assertEqualsWithDelta(5.0, $single->quantile(1.0), self::MAX_DELTA); } + /** + * @test + */ + public function quantileEmptyVectorThrows() : void + { + $a = Vector::fromArray([], false); + + $this->expectException(InvalidArgumentException::class); + + $a->quantile(0.5); + } + /** * @test */ public function variance() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $this->assertEqualsWithDelta(3227.609375, $a->variance(), self::MAX_DELTA); } @@ -1521,13 +1951,13 @@ public function variance() : void */ public function round() : void { - $a = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); $b = $a->round(2); - $expected = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + $expected = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); - $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } /** @@ -1535,13 +1965,13 @@ public function round() : void */ public function floor() : void { - $a = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); $b = $a->floor(); - $expected = Vector::quick([4.0, 6.0, 2.0, 20.0, 2.0, 11.0]); + $expected = Vector::fromArray([4.0, 6.0, 2.0, 20.0, 2.0, 11.0]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -1549,13 +1979,13 @@ public function floor() : void */ public function ceil() : void { - $a = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); $b = $a->ceil(); - $expected = Vector::quick([4.0, 7.0, 3.0, 20.0, 3.0, 12.0]); + $expected = Vector::fromArray([4.0, 7.0, 3.0, 20.0, 3.0, 12.0]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -1563,7 +1993,7 @@ public function ceil() : void */ public function l1Norm() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $this->assertEqualsWithDelta(423.0, $a->l1Norm(), self::MAX_DELTA); } @@ -1573,7 +2003,7 @@ public function l1Norm() : void */ public function l2Norm() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $this->assertEqualsWithDelta(172.4441938715247, $a->l2Norm(), self::MAX_DELTA); } @@ -1583,7 +2013,7 @@ public function l2Norm() : void */ public function pNorm() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $this->assertEqualsWithDelta(135.15554088861361, $a->pNorm(3.0), self::MAX_DELTA); } @@ -1593,7 +2023,7 @@ public function pNorm() : void */ public function maxNorm() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $this->assertEqualsWithDelta(106.0, $a->maxNorm(), self::MAX_DELTA); } @@ -1603,13 +2033,13 @@ public function maxNorm() : void */ public function clip() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $b = $a->clip(0.0, 100); + $b = $a->clip(0.0, 100.0); - $expected = Vector::quick([0.0, 25, 35, 0.0, 0.0, 89, 100.0, 45]); + $expected = Vector::fromArray([0.0, 25.0, 35.0, 0.0, 0.0, 89.0, 100.0, 45.0]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -1617,13 +2047,13 @@ public function clip() : void */ public function clipLower() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $b = $a->clipLower(60.0); - $expected = Vector::quick([60.0, 60.0, 60.0, 60.0, 60.0, 89, 106.0, 60.0]); + $expected = Vector::fromArray([60.0, 60.0, 60.0, 60.0, 60.0, 89.0, 106.0, 60.0]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -1631,13 +2061,13 @@ public function clipLower() : void */ public function clipUpper() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $b = $a->clipUpper(50.0); - $expected = Vector::quick([-15.0, 25, 35, -36.0, -72.0, 50.0, 50.0, 45]); + $expected = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 50.0, 50.0, 45.0]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -1645,13 +2075,13 @@ public function clipUpper() : void */ public function sign() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $b = $a->sign(); - $expected = Vector::quick([-1, 1, 1, -1, -1, 1, 1, 1]); + $expected = Vector::fromArray([-1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -1659,13 +2089,13 @@ public function sign() : void */ public function negate() : void { - $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); + $a = Vector::fromArray([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); $b = $a->negate(); - $expected = Vector::quick([15, -25, -35, 36, 72, -89, -106, -45]); + $expected = Vector::fromArray([15.0, -25.0, -35.0, 36.0, 72.0, -89.0, -106.0, -45.0]); - $this->assertEquals($expected, $b); + $this->assertEquals($expected->asArray(), $b->asArray()); } /** @@ -1765,7 +2195,7 @@ public function reshapeSizeMismatchThrows() : void { $this->expectException(InvalidArgumentException::class); - Vector::quick([1.0, 2.0, 3.0, 4.0])->reshape(2, 3); + (Vector::fromArray([1.0, 2.0, 3.0, 4.0]))->reshape(2, 3); } /** @@ -1775,7 +2205,7 @@ public function quantileOutOfRangeThrows() : void { $this->expectException(InvalidArgumentException::class); - Vector::quick([1.0, 2.0, 3.0])->quantile(-0.1); + (Vector::fromArray([1.0, 2.0, 3.0]))->quantile(-0.1); } /** @@ -1785,7 +2215,7 @@ public function quantileAboveOneThrows() : void { $this->expectException(InvalidArgumentException::class); - Vector::quick([1.0, 2.0, 3.0])->quantile(1.1); + (Vector::fromArray([1.0, 2.0, 3.0]))->quantile(1.1); } /** @@ -1795,7 +2225,7 @@ public function pNormNonPositiveThrows() : void { $this->expectException(InvalidArgumentException::class); - Vector::quick([1.0, 2.0, 3.0])->pNorm(0.0); + (Vector::fromArray([1.0, 2.0, 3.0]))->pNorm(0.0); } /** @@ -1805,7 +2235,7 @@ public function dotDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - Vector::quick([1.0, 2.0, 3.0])->dot(Vector::quick([1.0, 2.0])); + (Vector::fromArray([1.0, 2.0, 3.0]))->dot(Vector::fromArray([1.0, 2.0])); } /** @@ -1815,7 +2245,7 @@ public function multiplyDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - Vector::quick([1.0, 2.0, 3.0])->multiply(Vector::quick([1.0, 2.0])); + (Vector::fromArray([1.0, 2.0, 3.0]))->multiply(Vector::fromArray([1.0, 2.0])); } /** @@ -1825,7 +2255,7 @@ public function divideDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - Vector::quick([1.0, 2.0, 3.0])->divide(Vector::quick([1.0, 2.0])); + (Vector::fromArray([1.0, 2.0, 3.0]))->divide(Vector::fromArray([1.0, 2.0])); } /** @@ -1835,7 +2265,7 @@ public function addDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - Vector::quick([1.0, 2.0, 3.0])->add(Vector::quick([1.0, 2.0])); + (Vector::fromArray([1.0, 2.0, 3.0]))->add(Vector::fromArray([1.0, 2.0])); } /** @@ -1845,7 +2275,7 @@ public function subtractDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - Vector::quick([1.0, 2.0, 3.0])->subtract(Vector::quick([1.0, 2.0])); + (Vector::fromArray([1.0, 2.0, 3.0]))->subtract(Vector::fromArray([1.0, 2.0])); } /** @@ -1855,7 +2285,7 @@ public function powDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - Vector::quick([1.0, 2.0, 3.0])->pow(Vector::quick([1.0, 2.0])); + (Vector::fromArray([1.0, 2.0, 3.0]))->pow(Vector::fromArray([1.0, 2.0])); } /** @@ -1865,7 +2295,7 @@ public function modDimensionMismatchThrows() : void { $this->expectException(DimensionalityMismatch::class); - Vector::quick([1.0, 2.0, 3.0])->mod(Vector::quick([1.0, 2.0])); + (Vector::fromArray([1.0, 2.0, 3.0]))->mod(Vector::fromArray([1.0, 2.0])); } /** @@ -1886,51 +2316,51 @@ public function arithmeticWithWrongOperandTypeThrows(callable $operation) : void public function wrongOperandTypeProvider() : Generator { yield 'multiply' => [function () { - Vector::quick([1.0, 2.0, 3.0])->multiply('not a valid operand'); + (Vector::fromArray([1.0, 2.0, 3.0]))->multiply('not a valid operand'); }]; yield 'divide' => [function () { - Vector::quick([1.0, 2.0, 3.0])->divide('not a valid operand'); + (Vector::fromArray([1.0, 2.0, 3.0]))->divide('not a valid operand'); }]; yield 'add' => [function () { - Vector::quick([1.0, 2.0, 3.0])->add('not a valid operand'); + (Vector::fromArray([1.0, 2.0, 3.0]))->add('not a valid operand'); }]; yield 'subtract' => [function () { - Vector::quick([1.0, 2.0, 3.0])->subtract('not a valid operand'); + (Vector::fromArray([1.0, 2.0, 3.0]))->subtract('not a valid operand'); }]; yield 'pow' => [function () { - Vector::quick([1.0, 2.0, 3.0])->pow('not a valid operand'); + (Vector::fromArray([1.0, 2.0, 3.0]))->pow('not a valid operand'); }]; yield 'mod' => [function () { - Vector::quick([1.0, 2.0, 3.0])->mod('not a valid operand'); + (Vector::fromArray([1.0, 2.0, 3.0]))->mod('not a valid operand'); }]; yield 'equal' => [function () { - Vector::quick([1.0, 2.0, 3.0])->equal('not a valid operand'); + (Vector::fromArray([1.0, 2.0, 3.0]))->equal('not a valid operand'); }]; yield 'notEqual' => [function () { - Vector::quick([1.0, 2.0, 3.0])->notEqual('not a valid operand'); + (Vector::fromArray([1.0, 2.0, 3.0]))->notEqual('not a valid operand'); }]; yield 'greater' => [function () { - Vector::quick([1.0, 2.0, 3.0])->greater('not a valid operand'); + (Vector::fromArray([1.0, 2.0, 3.0]))->greater('not a valid operand'); }]; yield 'greaterEqual' => [function () { - Vector::quick([1.0, 2.0, 3.0])->greaterEqual('not a valid operand'); + (Vector::fromArray([1.0, 2.0, 3.0]))->greaterEqual('not a valid operand'); }]; yield 'less' => [function () { - Vector::quick([1.0, 2.0, 3.0])->less('not a valid operand'); + (Vector::fromArray([1.0, 2.0, 3.0]))->less('not a valid operand'); }]; yield 'lessEqual' => [function () { - Vector::quick([1.0, 2.0, 3.0])->lessEqual('not a valid operand'); + (Vector::fromArray([1.0, 2.0, 3.0]))->lessEqual('not a valid operand'); }]; } @@ -1941,7 +2371,7 @@ public function convolveStrideLessThanOneThrows() : void { $this->expectException(InvalidArgumentException::class); - Vector::quick([1.0, 2.0, 3.0])->convolve(Vector::quick([1.0, 1.0]), 0); + (Vector::fromArray([1.0, 2.0, 3.0]))->convolve(Vector::fromArray([1.0, 1.0]), 0); } /** @@ -1951,7 +2381,7 @@ public function convolveKernelLargerThanVectorThrows() : void { $this->expectException(InvalidArgumentException::class); - Vector::quick([1.0, 2.0])->convolve(Vector::quick([1.0, 2.0, 3.0])); + (Vector::fromArray([1.0, 2.0]))->convolve(Vector::fromArray([1.0, 2.0, 3.0])); } /** @@ -1961,7 +2391,7 @@ public function offsetSetThrows() : void { $this->expectException(RuntimeException::class); - $a = Vector::quick([1.0, 2.0, 3.0]); + $a = Vector::fromArray([1.0, 2.0, 3.0]); $a[0] = 4.0; } @@ -1973,7 +2403,7 @@ public function offsetUnsetThrows() : void { $this->expectException(RuntimeException::class); - $a = Vector::quick([1.0, 2.0, 3.0]); + $a = Vector::fromArray([1.0, 2.0, 3.0]); unset($a[0]); } @@ -1985,7 +2415,7 @@ public function offsetGetOutOfBoundsThrows() : void { $this->expectException(InvalidArgumentException::class); - $a = Vector::quick([1.0, 2.0, 3.0]); + $a = Vector::fromArray([1.0, 2.0, 3.0]); $this->assertEquals(0.0, $a[10]); }