├── .gitattributes ├── .github ├── FUNDING.yml └── workflows │ ├── ci-ext.sh │ ├── ci-ext.yml │ ├── ci.yml │ └── cla.yml ├── .gitignore ├── .php_cs.dist ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── benchmarks ├── Arithmetic │ ├── MatrixColumnVectorMultiplyBench.php │ ├── MatrixMatrixMultiplyBench.php │ ├── MatrixScalarMultiplyBench.php │ ├── MatrixSumBench.php │ ├── MatrixVectorMultiplyBench.php │ └── VectorVectorMultiplyBench.php ├── Comparison │ └── VectorVectorEqualBench.php ├── Decompositions │ ├── CholeskyBench.php │ ├── EigBench.php │ ├── LUBench.php │ └── SVDBench.php ├── Functions │ ├── AbsMatrixBench.php │ ├── ExpMatrixBench.php │ ├── LogMatrixBench.php │ ├── ProductVectorBench.php │ ├── SqrtMatrixBench.php │ ├── SquareMatrixBench.php │ ├── SumMatrixBench.php │ └── SumVectorBench.php ├── LinearAlgebra │ ├── MatmulBench.php │ ├── MatrixDeterminantBench.php │ ├── MatrixInfinityNormBench.php │ ├── MatrixInverseBench.php │ ├── MatrixL1NormBench.php │ ├── MatrixL2NormBench.php │ ├── MatrixMaxNormBench.php │ ├── MatrixPseudoInverseBench.php │ ├── VectorDotProductBench.php │ └── VectorOuterProductBench.php ├── Random │ ├── GaussianMatrixBench.php │ ├── GaussianVectorBench.php │ ├── PoissonMatrixBench.php │ ├── RandMatrixBench.php │ └── UniformMatrixBench.php ├── Reductions │ ├── REFBench.php │ └── RREFBench.php ├── SignalProcessing │ ├── MatrixConvolveBench.php │ └── VectorConvolveBench.php ├── Special │ └── MatrixClippingBench.php ├── Statistical │ ├── CovarianceBench.php │ ├── MatrixMeanBench.php │ ├── MatrixMedianBench.php │ ├── MatrixQuantileBench.php │ └── MatrixVarianceBench.php ├── Structural │ ├── AugmentMatrixBelowBench.php │ ├── AugmentMatrixLeftBench.php │ ├── FlattenMatrixBench.php │ ├── MatrixTransposeBench.php │ ├── RepeatMatrixBench.php │ └── ReshapeVectorBench.php └── Trigonometric │ ├── CosMatrixBench.php │ ├── CosVectorBench.php │ ├── SinMatrixBench.php │ └── TanMatrixBench.php ├── build-ext ├── build-ext.bat ├── composer.json ├── config.json ├── docs └── images │ ├── tensor-performance-benchmarks.png │ └── tensor-performance-mnist.png ├── ext ├── clean ├── config.m4 ├── config.w32 ├── ext.h ├── ext_config.h ├── include │ ├── arithmetic.c │ ├── arithmetic.h │ ├── comparison.c │ ├── comparison.h │ ├── linear_algebra.c │ ├── linear_algebra.h │ ├── settings.c │ ├── settings.h │ ├── signal_processing.c │ └── signal_processing.h ├── install ├── kernel │ ├── array.c │ ├── array.h │ ├── backtrace.c │ ├── backtrace.h │ ├── concat.c │ ├── concat.h │ ├── debug.c │ ├── debug.h │ ├── exception.c │ ├── exception.h │ ├── exit.c │ ├── exit.h │ ├── fcall.c │ ├── fcall.h │ ├── fcall_internal.h │ ├── file.c │ ├── file.h │ ├── filter.c │ ├── filter.h │ ├── globals.h │ ├── iterator.c │ ├── iterator.h │ ├── main.c │ ├── main.h │ ├── math.c │ ├── math.h │ ├── memory.c │ ├── memory.h │ ├── object.c │ ├── object.h │ ├── operators.c │ ├── operators.h │ ├── require.c │ ├── require.h │ ├── string.c │ ├── string.h │ ├── time.c │ ├── time.h │ ├── variables.c │ └── variables.h ├── php_ext.h ├── php_tensor.h ├── tensor.c ├── tensor.h └── tensor │ ├── algebraic.zep.c │ ├── algebraic.zep.h │ ├── arithmetic.zep.c │ ├── arithmetic.zep.h │ ├── arraylike.zep.c │ ├── arraylike.zep.h │ ├── columnvector.zep.c │ ├── columnvector.zep.h │ ├── comparable.zep.c │ ├── comparable.zep.h │ ├── decompositions │ ├── cholesky.zep.c │ ├── cholesky.zep.h │ ├── eigen.zep.c │ ├── eigen.zep.h │ ├── lu.zep.c │ ├── lu.zep.h │ ├── svd.zep.c │ └── svd.zep.h │ ├── exceptions │ ├── dimensionalitymismatch.zep.c │ ├── dimensionalitymismatch.zep.h │ ├── invalidargumentexception.zep.c │ ├── invalidargumentexception.zep.h │ ├── runtimeexception.zep.c │ ├── runtimeexception.zep.h │ ├── tensorexception.zep.c │ └── tensorexception.zep.h │ ├── functional.zep.c │ ├── functional.zep.h │ ├── matrix.zep.c │ ├── matrix.zep.h │ ├── reductions │ ├── ref.zep.c │ ├── ref.zep.h │ ├── rref.zep.c │ └── rref.zep.h │ ├── settings.zep.c │ ├── settings.zep.h │ ├── special.zep.c │ ├── special.zep.h │ ├── statistical.zep.c │ ├── statistical.zep.h │ ├── tensor.zep.c │ ├── tensor.zep.h │ ├── trigonometric.zep.c │ ├── trigonometric.zep.h │ ├── vector.zep.c │ └── vector.zep.h ├── optimizers ├── TensorAddOptimizer.php ├── TensorAddScalarOptimizer.php ├── TensorCholeskyOptimizer.php ├── TensorConvolve1dOptimizer.php ├── TensorConvolve2dOptimizer.php ├── TensorDivideOptimizer.php ├── TensorDivideScalarOptimizer.php ├── TensorDotOptimizer.php ├── TensorEigOptimizer.php ├── TensorEigSymmetricOptimizer.php ├── TensorEqualOptimizer.php ├── TensorEqualScalarOptimizer.php ├── TensorGetNumThreadsOptimizer.php ├── TensorGreaterEqualOptimizer.php ├── TensorGreaterEqualScalarOptimizer.php ├── TensorGreaterOptimizer.php ├── TensorGreaterScalarOptimizer.php ├── TensorInverseOptimizer.php ├── TensorLessEqualOptimizer.php ├── TensorLessEqualScalarOptimizer.php ├── TensorLessOptimizer.php ├── TensorLessScalarOptimizer.php ├── TensorLuOptimizer.php ├── TensorMatmulOptimizer.php ├── TensorModOptimizer.php ├── TensorModScalarOptimizer.php ├── TensorMultiplyOptimizer.php ├── TensorMultiplyScalarOptimizer.php ├── TensorNotEqualOptimizer.php ├── TensorNotEqualScalarOptimizer.php ├── TensorPowOptimizer.php ├── TensorPowScalarOptimizer.php ├── TensorPseudoinverseOptimizer.php ├── TensorRefOptimizer.php ├── TensorSetNumThreadsOptimizer.php ├── TensorSubtractOptimizer.php ├── TensorSubtractScalarOptimizer.php └── TensorSvdOptimizer.php ├── package.xml ├── phpbench.json.dist ├── phpstan.neon ├── phpunit.xml ├── src ├── Algebraic.php ├── Arithmetic.php ├── ArrayLike.php ├── ColumnVector.php ├── Comparable.php ├── Decompositions │ ├── Cholesky.php │ ├── Eigen.php │ ├── LU.php │ └── SVD.php ├── Exceptions │ ├── DimensionalityMismatch.php │ ├── InvalidArgumentException.php │ ├── NotImplemented.php │ ├── RuntimeException.php │ └── TensorException.php ├── Matrix.php ├── Reductions │ ├── REF.php │ └── RREF.php ├── Special.php ├── Statistical.php ├── Tensor.php ├── Trigonometric.php ├── Vector.php └── constants.php ├── tensor ├── algebraic.zep ├── arithmetic.zep ├── arraylike.zep ├── columnvector.zep ├── comparable.zep ├── decompositions │ ├── cholesky.zep │ ├── eigen.zep │ ├── lu.zep │ └── svd.zep ├── exceptions │ ├── DimensionalityMismatch.zep │ ├── InvalidArgumentException.zep │ ├── RuntimeException.zep │ └── TensorException.zep ├── matrix.zep ├── reductions │ ├── ref.zep │ └── rref.zep ├── settings.zep ├── special.zep ├── statistical.zep ├── tensor.zep ├── trigonometric.zep └── vector.zep └── tests ├── ColumnVectorTest.php ├── MatrixTest.php └── VectorTest.php /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.php text eol=lf 4 | *.zep text eol=lf 5 | *.zep.h linguist-language=C 6 | *.zep.c linguist-language=C -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [RubixML, andrewdalpino] 2 | -------------------------------------------------------------------------------- /.github/workflows/ci-ext.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -o nounset 4 | set -o errexit 5 | 6 | . /etc/os-release 7 | 8 | case "${ID:-}" in 9 | alpine) 10 | apk update 11 | apk add $PHPIZE_DEPS lapack-dev libexecinfo-dev openblas-dev 12 | ;; 13 | debian) 14 | apt-get update 15 | apt-get install -qy gfortran-8 liblapack-dev libopenblas-dev liblapacke-dev 16 | ;; 17 | *) 18 | echo 'Unsupported distribution' >&2 19 | exit 1 20 | esac 21 | 22 | cd /tmp 23 | pecl package /app/package.xml 24 | MAKE="make -j$(nproc)" pecl install tensor-*.tgz 25 | docker-php-ext-enable tensor 26 | php --ri tensor 27 | -------------------------------------------------------------------------------- /.github/workflows/ci-ext.yml: -------------------------------------------------------------------------------- 1 | name: Compile extension 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/ci-ext.*" 7 | - "ext/**" 8 | - package.xml 9 | push: 10 | branches: 11 | - "**" 12 | paths: 13 | - ".github/workflows/ci-ext.*" 14 | - "ext/**" 15 | - package.xml 16 | tags-ignore: 17 | - "**" 18 | 19 | jobs: 20 | compile: 21 | strategy: 22 | matrix: 23 | image: 24 | - php:7.4-cli 25 | - php:7.4-cli-alpine 26 | - php:8.0-cli 27 | - php:8.0-cli-alpine 28 | name: Image ${{ matrix.image }} 29 | runs-on: ubuntu-latest 30 | steps: 31 | - name: Pull docker image 32 | run: docker pull ${{ matrix.image }} 33 | 34 | - name: Checkout 35 | uses: actions/checkout@v2 36 | 37 | - name: Compile 38 | run: docker run --rm -v "$GITHUB_WORKSPACE:/app" ${{ matrix.image }} /app/.github/workflows/ci-ext.sh 39 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: "Code Checks" 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | name: PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }} 8 | runs-on: ${{ matrix.operating-system }} 9 | strategy: 10 | matrix: 11 | operating-system: [windows-latest, ubuntu-latest, macos-latest] 12 | php-versions: ['7.4', '8.0'] 13 | 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v2 17 | 18 | - name: Setup PHP 19 | uses: shivammathur/setup-php@v2 20 | with: 21 | php-version: ${{ matrix.php-versions }} 22 | tools: pecl 23 | extensions: fileinfo 24 | ini-values: memory_limit=-1 25 | 26 | - name: Validate composer.json 27 | run: composer validate 28 | 29 | - name: Install Dependencies 30 | run: composer install 31 | 32 | - name: Static Analysis 33 | run: composer analyze 34 | 35 | - name: Run Unit Tests 36 | run: composer test 37 | 38 | - name: Check Coding Style 39 | run: composer check 40 | -------------------------------------------------------------------------------- /.github/workflows/cla.yml: -------------------------------------------------------------------------------- 1 | name: "CLA Assistant" 2 | 3 | on: 4 | issue_comment: 5 | types: [created] 6 | pull_request_target: 7 | types: [opened, closed, synchronize] 8 | 9 | jobs: 10 | CLAssistant: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: "CLA Assistant" 14 | if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target' 15 | uses: cla-assistant/github-action@v2.0.2-alpha 16 | env: 17 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 18 | PERSONAL_ACCESS_TOKEN : ${{ secrets.CLA_BOT_TOKEN }} 19 | with: 20 | remote-organization-name: 'RubixML' 21 | remote-repository-name: 'Signatures' 22 | path-to-document: 'https://github.com/RubixML/Signatures/blob/master/CLA.md' 23 | path-to-signatures: 'cla-v1.json' 24 | branch: 'master' 25 | allowlist: bot* 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.o 3 | *.out 4 | *.lo 5 | *.la 6 | *.log 7 | *.loT 8 | *.gch 9 | *.h.ghc 10 | *.phc 11 | *.dSYM 12 | *.deps 13 | *.tgz 14 | 15 | zephir.phar 16 | autom4te.cache/ 17 | 18 | ext/ltmain.sh 19 | ext/Makefile 20 | ext/Makefile.fragments 21 | ext/Makefile.global 22 | ext/Makefile.objects 23 | ext/acinclude.m4 24 | ext/aclocal.m4 25 | ext/build/ 26 | ext/config.guess 27 | ext/config.h 28 | ext/config.h.in 29 | ext/config.nice 30 | ext/config.status 31 | ext/config.sub 32 | ext/configure 33 | ext/configure.ac 34 | ext/configure.in 35 | ext/install-sh 36 | ext/libtool 37 | ext/missing 38 | ext/mkinstalldirs 39 | ext/modules/ 40 | ext/run-tests.php 41 | 42 | /vendor 43 | composer.lock 44 | .phpunit.result.cache 45 | .php_cs.cache 46 | .zephir 47 | Thumbs.db 48 | .DS_Store 49 | .libs/ 50 | .log 51 | /.idea 52 | /.vscode 53 | /.vs 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Rubix ML 4 | Copyright (c) 2021 Andrew DalPino 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /benchmarks/Arithmetic/MatrixColumnVectorMultiplyBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(1000, 1000); 27 | 28 | $this->b = ColumnVector::uniform(1000); 29 | } 30 | 31 | /** 32 | * @Subject 33 | * @Iterations(5) 34 | * @OutputTimeUnit("seconds", precision=3) 35 | */ 36 | public function multiply() : void 37 | { 38 | $this->a->multiply($this->b); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /benchmarks/Arithmetic/MatrixMatrixMultiplyBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(1000, 1000); 26 | 27 | $this->b = Matrix::uniform(1000, 1000); 28 | } 29 | 30 | /** 31 | * @Subject 32 | * @Iterations(5) 33 | * @OutputTimeUnit("seconds", precision=3) 34 | */ 35 | public function multiply() : void 36 | { 37 | $this->a->multiply($this->b); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /benchmarks/Arithmetic/MatrixScalarMultiplyBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(1000, 1000); 26 | } 27 | 28 | /** 29 | * @Subject 30 | * @Iterations(5) 31 | * @OutputTimeUnit("seconds", precision=3) 32 | */ 33 | public function multiply() : void 34 | { 35 | $this->a->multiply($this->b); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /benchmarks/Arithmetic/MatrixSumBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function sum() : void 29 | { 30 | $this->a->sum(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Arithmetic/MatrixVectorMultiplyBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(1000, 1000); 27 | 28 | $this->b = Vector::uniform(1000); 29 | } 30 | 31 | /** 32 | * @Subject 33 | * @Iterations(5) 34 | * @OutputTimeUnit("seconds", precision=3) 35 | */ 36 | public function multiply() : void 37 | { 38 | $this->a->multiply($this->b); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /benchmarks/Arithmetic/VectorVectorMultiplyBench.php: -------------------------------------------------------------------------------- 1 | a = Vector::uniform(10000); 26 | 27 | $this->b = Vector::uniform(10000); 28 | } 29 | 30 | /** 31 | * @Subject 32 | * @Iterations(5) 33 | * @OutputTimeUnit("milliseconds", precision=3) 34 | */ 35 | public function multiply() : void 36 | { 37 | $this->a->multiply($this->b); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /benchmarks/Comparison/VectorVectorEqualBench.php: -------------------------------------------------------------------------------- 1 | a = Vector::uniform(10000); 26 | 27 | $this->b = Vector::uniform(10000); 28 | } 29 | 30 | /** 31 | * @Subject 32 | * @Iterations(5) 33 | * @OutputTimeUnit("milliseconds", precision=3) 34 | */ 35 | public function equal() : void 36 | { 37 | $this->a->equal($this->b); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /benchmarks/Decompositions/CholeskyBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::rand(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function cholesky() : void 29 | { 30 | $this->a->cholesky(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Decompositions/EigBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 20 | } 21 | 22 | /** 23 | * @Subject 24 | * @Iterations(5) 25 | * @BeforeMethods({"setUpGeneral"}) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function eigGeneral() : void 29 | { 30 | $this->a->eig(false); 31 | } 32 | 33 | public function setUpSymmetric() : void 34 | { 35 | $this->a = Matrix::uniform(500, 500); 36 | 37 | $this->a = $this->a->matmul($this->a); 38 | } 39 | 40 | /** 41 | * @Subject 42 | * @Iterations(5) 43 | * @BeforeMethods({"setUpSymmetric"}) 44 | * @OutputTimeUnit("seconds", precision=3) 45 | */ 46 | public function eigSymmetric() : void 47 | { 48 | $this->a->eig(true); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /benchmarks/Decompositions/LUBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function lu() : void 29 | { 30 | $this->a->lu(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Decompositions/SVDBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function eig() : void 29 | { 30 | $this->a->svd(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Functions/AbsMatrixBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function abs() : void 29 | { 30 | $this->a->abs(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Functions/ExpMatrixBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function exp() : void 29 | { 30 | $this->a->exp(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Functions/LogMatrixBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function log() : void 29 | { 30 | $this->a->log(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Functions/ProductVectorBench.php: -------------------------------------------------------------------------------- 1 | a = Vector::uniform(100000); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("milliseconds", precision=3) 27 | */ 28 | public function sum() : void 29 | { 30 | $this->a->product(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Functions/SqrtMatrixBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function sqrt() : void 29 | { 30 | $this->a->sqrt(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Functions/SquareMatrixBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function square() : void 29 | { 30 | $this->a->square(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Functions/SumMatrixBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("milliseconds", precision=3) 27 | */ 28 | public function sum() : void 29 | { 30 | $this->a->sum(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Functions/SumVectorBench.php: -------------------------------------------------------------------------------- 1 | a = Vector::uniform(100000); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("milliseconds", precision=3) 27 | */ 28 | public function sum() : void 29 | { 30 | $this->a->sum(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/LinearAlgebra/MatmulBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 26 | 27 | $this->b = Matrix::uniform(500, 500); 28 | } 29 | 30 | /** 31 | * @Subject 32 | * @Iterations(5) 33 | * @OutputTimeUnit("seconds", precision=3) 34 | */ 35 | public function matmul() : void 36 | { 37 | $this->a->matmul($this->b); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /benchmarks/LinearAlgebra/MatrixDeterminantBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function det() : void 29 | { 30 | $this->a->det(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/LinearAlgebra/MatrixInfinityNormBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function infinityNorm() : void 29 | { 30 | $this->a->infinityNorm(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/LinearAlgebra/MatrixInverseBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function inverse() : void 29 | { 30 | $this->a->inverse(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/LinearAlgebra/MatrixL1NormBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function l1Norm() : void 29 | { 30 | $this->a->l1Norm(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/LinearAlgebra/MatrixL2NormBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function l2Norm() : void 29 | { 30 | $this->a->l2Norm(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/LinearAlgebra/MatrixMaxNormBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function max_norm() : void 29 | { 30 | $this->a->maxNorm(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/LinearAlgebra/MatrixPseudoInverseBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function inverse() : void 29 | { 30 | $this->a->pseudoinverse(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/LinearAlgebra/VectorDotProductBench.php: -------------------------------------------------------------------------------- 1 | a = Vector::uniform(10000000); 26 | 27 | $this->b = Vector::uniform(10000000); 28 | } 29 | 30 | /** 31 | * @Subject 32 | * @Iterations(5) 33 | * @OutputTimeUnit("seconds", precision=3) 34 | */ 35 | public function dot() : void 36 | { 37 | $this->a->dot($this->b); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /benchmarks/LinearAlgebra/VectorOuterProductBench.php: -------------------------------------------------------------------------------- 1 | a = Vector::uniform(500); 26 | 27 | $this->b = Vector::uniform(500); 28 | } 29 | 30 | /** 31 | * @Subject 32 | * @Iterations(5) 33 | * @OutputTimeUnit("seconds", precision=3) 34 | */ 35 | public function outer() : void 36 | { 37 | $this->a->outer($this->b); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /benchmarks/Random/GaussianMatrixBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function ref() : void 29 | { 30 | $this->a->ref(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Reductions/RREFBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function rref() : void 29 | { 30 | $this->a->rref(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/SignalProcessing/MatrixConvolveBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 26 | 27 | $this->kernel = Matrix::uniform(10, 10); 28 | } 29 | 30 | /** 31 | * @Subject 32 | * @Iterations(5) 33 | * @OutputTimeUnit("seconds", precision=3) 34 | */ 35 | public function convolve() : void 36 | { 37 | $this->a->convolve($this->kernel); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /benchmarks/SignalProcessing/VectorConvolveBench.php: -------------------------------------------------------------------------------- 1 | a = Vector::uniform(250000); 26 | 27 | $this->kernel = Vector::uniform(100); 28 | } 29 | 30 | /** 31 | * @Subject 32 | * @Iterations(5) 33 | * @OutputTimeUnit("seconds", precision=3) 34 | */ 35 | public function convolve() : void 36 | { 37 | $this->a->convolve($this->kernel); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /benchmarks/Special/MatrixClippingBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(1000, 1000); 26 | } 27 | 28 | /** 29 | * @Subject 30 | * @Iterations(5) 31 | * @OutputTimeUnit("seconds", precision=3) 32 | */ 33 | public function clip() : void 34 | { 35 | $this->a->clip(0, 1); 36 | } 37 | 38 | /** 39 | * @Subject 40 | * @Iterations(5) 41 | * @OutputTimeUnit("seconds", precision=3) 42 | */ 43 | public function clipUpper() : void 44 | { 45 | $this->a->clipUpper(0); 46 | } 47 | 48 | /** 49 | * @Subject 50 | * @Iterations(5) 51 | * @OutputTimeUnit("seconds", precision=3) 52 | */ 53 | public function clipLower() : void 54 | { 55 | $this->a->clipLower(0); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /benchmarks/Statistical/CovarianceBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function covariance() : void 29 | { 30 | $this->a->covariance(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Statistical/MatrixMeanBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(1000, 1000); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("milliseconds", precision=3) 27 | */ 28 | public function mean() : void 29 | { 30 | $this->a->mean(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Statistical/MatrixMedianBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function median() : void 29 | { 30 | $this->a->median(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Statistical/MatrixQuantileBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function quantile() : void 29 | { 30 | $this->a->quantile(0.5); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Statistical/MatrixVarianceBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function variance() : void 29 | { 30 | $this->a->variance(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Structural/AugmentMatrixBelowBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 26 | 27 | $this->b = Matrix::uniform(500, 500); 28 | } 29 | 30 | /** 31 | * @Subject 32 | * @Iterations(5) 33 | * @OutputTimeUnit("seconds", precision=3) 34 | */ 35 | public function augmentBelow() : void 36 | { 37 | $this->a->augmentBelow($this->b); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /benchmarks/Structural/AugmentMatrixLeftBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 26 | 27 | $this->b = Matrix::uniform(500, 500); 28 | } 29 | 30 | /** 31 | * @Subject 32 | * @Iterations(5) 33 | * @OutputTimeUnit("seconds", precision=3) 34 | */ 35 | public function augmentLeft() : void 36 | { 37 | $this->a->augmentLeft($this->b); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /benchmarks/Structural/FlattenMatrixBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function flatten() : void 29 | { 30 | $this->a->flatten(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Structural/MatrixTransposeBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(1000, 1000); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function transpose() : void 29 | { 30 | $this->a->transpose(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Structural/RepeatMatrixBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(100, 100); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function repeat() : void 29 | { 30 | $this->a->repeat(100, 100); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Structural/ReshapeVectorBench.php: -------------------------------------------------------------------------------- 1 | a = Vector::uniform(250000); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function reshape() : void 29 | { 30 | $this->a->reshape(500, 500); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Trigonometric/CosMatrixBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function cosine() : void 29 | { 30 | $this->a->cos(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Trigonometric/CosVectorBench.php: -------------------------------------------------------------------------------- 1 | a = Vector::uniform(100000); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("milliseconds", precision=3) 27 | */ 28 | public function cosine() : void 29 | { 30 | $this->a->cos(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Trigonometric/SinMatrixBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function sine() : void 29 | { 30 | $this->a->sin(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/Trigonometric/TanMatrixBench.php: -------------------------------------------------------------------------------- 1 | a = Matrix::uniform(500, 500); 21 | } 22 | 23 | /** 24 | * @Subject 25 | * @Iterations(5) 26 | * @OutputTimeUnit("seconds", precision=3) 27 | */ 28 | public function tangent() : void 29 | { 30 | $this->a->tan(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /build-ext: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | 5 | 6 | void tensor_multiply(zval * return_value, zval * a, zval * b); 7 | void tensor_divide(zval * return_value, zval * a, zval * b); 8 | void tensor_add(zval * return_value, zval * a, zval * b); 9 | void tensor_subtract(zval * return_value, zval * a, zval * b); 10 | void tensor_pow(zval * return_value, zval * a, zval * b); 11 | void tensor_mod(zval * return_value, zval * a, zval * b); 12 | 13 | void tensor_multiply_scalar(zval * return_value, zval * a, zval * b); 14 | void tensor_divide_scalar(zval * return_value, zval * a, zval * b); 15 | void tensor_add_scalar(zval * return_value, zval * a, zval * b); 16 | void tensor_subtract_scalar(zval * return_value, zval * a, zval * b); 17 | void tensor_pow_scalar(zval * return_value, zval * a, zval * b); 18 | void tensor_mod_scalar(zval * return_value, zval * a, zval * b); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /ext/include/comparison.h: -------------------------------------------------------------------------------- 1 | #ifndef TENSOR_COMPARISON_H 2 | #define TENSOR_COMPARISON_H 3 | 4 | #include 5 | 6 | void tensor_equal(zval * return_value, zval * a, zval * b); 7 | void tensor_not_equal(zval * return_value, zval * a, zval * b); 8 | void tensor_greater(zval * return_value, zval * a, zval * b); 9 | void tensor_greater_equal(zval * return_value, zval * a, zval * b); 10 | void tensor_less(zval * return_value, zval * a, zval * b); 11 | void tensor_less_equal(zval * return_value, zval * a, zval * b); 12 | 13 | void tensor_equal_scalar(zval * return_value, zval * a, zval * b); 14 | void tensor_not_equal_scalar(zval * return_value, zval * a, zval * b); 15 | void tensor_greater_scalar(zval * return_value, zval * a, zval * b); 16 | void tensor_greater_equal_scalar(zval * return_value, zval * a, zval * b); 17 | void tensor_less_scalar(zval * return_value, zval * a, zval * b); 18 | void tensor_less_equal_scalar(zval * return_value, zval * a, zval * b); 19 | 20 | #endif -------------------------------------------------------------------------------- /ext/include/linear_algebra.h: -------------------------------------------------------------------------------- 1 | #ifndef TENSOR_LINEAR_ALGEBRA_H 2 | #define TENSOR_LINEAR_ALGEBRA_H 3 | 4 | #include 5 | 6 | void tensor_matmul(zval * return_value, zval * a, zval * b); 7 | void tensor_dot(zval * return_value, zval * a, zval * b); 8 | 9 | void tensor_inverse(zval * return_value, zval * a); 10 | void tensor_pseudoinverse(zval * return_value, zval * a); 11 | 12 | void tensor_ref(zval * return_value, zval * a); 13 | void tensor_cholesky(zval * return_value, zval * a); 14 | void tensor_lu(zval * return_value, zval * a); 15 | void tensor_eig(zval * return_value, zval * a); 16 | void tensor_eig_symmetric(zval * return_value, zval * a); 17 | void tensor_svd(zval * return_value, zval * a); 18 | 19 | #endif -------------------------------------------------------------------------------- /ext/include/settings.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | 5 | #include 6 | #include 7 | #include "kernel/operators.h" 8 | 9 | /** 10 | * Sets the number of threads to use when parallel processesing. 11 | * 12 | * @param return_value 13 | * @param threads 14 | */ 15 | void tensor_set_num_threads(zval * return_value, zval * threads) 16 | { 17 | int n = zephir_get_intval(threads); 18 | 19 | openblas_set_num_threads(n); 20 | 21 | RETURN_TRUE; 22 | } 23 | 24 | /** 25 | * Return the number of threads to use when parallel processesing. 26 | * 27 | * @param return_value 28 | */ 29 | void tensor_get_num_threads(zval * return_value) 30 | { 31 | long threads = openblas_get_num_threads(); 32 | 33 | RETURN_LONG(threads); 34 | } 35 | -------------------------------------------------------------------------------- /ext/include/settings.h: -------------------------------------------------------------------------------- 1 | #ifndef TENSOR_SETTINGS_H 2 | #define TENSOR_SETTINGS_H 3 | 4 | #include 5 | 6 | void tensor_set_num_threads(zval * return_value, zval * threads); 7 | void tensor_get_num_threads(zval * return_value); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /ext/include/signal_processing.h: -------------------------------------------------------------------------------- 1 | #ifndef TENSOR_SIGNAL_PROCESSING_H 2 | #define TENSOR_SIGNAL_PROCESSING_H 3 | 4 | #include 5 | 6 | void tensor_convolve_1d(zval * return_value, zval * a, zval * b, zval * stride); 7 | void tensor_convolve_2d(zval * return_value, zval * a, zval * b, zval * stride); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /ext/install: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # This file was generated automatically by Zephir. 4 | # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN 5 | # 6 | # (c) Phalcon Team 7 | # 8 | # For the full copyright and license information, please view 9 | # the LICENSE file that was distributed with this source code. 10 | 11 | export CC="gcc" 12 | export CFLAGS="-O2 -Wall -fvisibility=hidden -flto -DZEPHIR_RELEASE=1" 13 | 14 | IN_DOCKER=0 15 | 16 | if [[ -f /proc/1/cgroup ]] 17 | then 18 | if [[ -f /.dockerenv ]] || grep -Eq '/(lxc|docker)/[[:xdigit:]]{64}' /proc/1/cgroup 19 | then 20 | IN_DOCKER=1 21 | fi 22 | fi 23 | 24 | phpize="$(command -v phpize 2> /dev/null)" 25 | 26 | sudo="" 27 | test "$IN_DOCKER" -eq 0 && sudo="$(command -v sudo 2> /dev/null)" 28 | 29 | if [ -f Makefile ]; then 30 | $sudo make -s clean 31 | $sudo "${phpize}" --silent --clean 32 | fi 33 | 34 | ${phpize} --silent 35 | 36 | ./configure --silent --enable-tensor CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" 37 | 38 | make -s 39 | $sudo make -s install 40 | -------------------------------------------------------------------------------- /ext/kernel/backtrace.c: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Zephir. 3 | * 4 | * (c) Phalcon Team 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. If you did not receive 8 | * a copy of the license it is available through the world-wide-web at the 9 | * following url: https://docs.zephir-lang.com/en/latest/license 10 | */ 11 | 12 | #ifndef ZEPHIR_RELEASE 13 | #if defined(linux) || defined(DARWIN) || defined(__APPLE__) 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | /** 21 | * A buffer for backtrace. It is better to have it allocated statically 22 | * in order not to face out of memory conditions later 23 | */ 24 | void *backtrace_buf[4096]; 25 | 26 | void zephir_print_backtrace(void) 27 | { 28 | int i; 29 | int stack_size = backtrace(backtrace_buf, sizeof(backtrace_buf) / sizeof(void*)); 30 | char **stack_symbols = backtrace_symbols(backtrace_buf, stack_size); 31 | char buf[50]; 32 | smart_str s = {0}; 33 | 34 | for (i = 0; i < stack_size; ++i) { 35 | snprintf(buf, sizeof(buf), "#%d %p [", i, backtrace_buf[i]); 36 | smart_str_appends(&s, buf); 37 | smart_str_appends(&s, stack_symbols[i]); 38 | smart_str_appends(&s, "]\n"); 39 | } 40 | 41 | smart_str_0(&s); 42 | 43 | fprintf(stderr, "%s\n", ZSTR_VAL(s.s)); 44 | smart_str_free(&s); 45 | } 46 | 47 | #else 48 | 49 | void zephir_print_backtrace(void) 50 | { 51 | /** 52 | * Not implemented yet for anything other than Linux 53 | */ 54 | } 55 | 56 | #endif 57 | #endif /* ZEPHIR_RELEASE */ 58 | -------------------------------------------------------------------------------- /ext/kernel/backtrace.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Zephir. 3 | * 4 | * (c) Phalcon Team 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. If you did not receive 8 | * a copy of the license it is available through the world-wide-web at the 9 | * following url: https://docs.zephir-lang.com/en/latest/license 10 | */ 11 | 12 | #ifndef ZEPHIR_KERNEL_BACKTRACE_H 13 | #define ZEPHIR_KERNEL_BACKTRACE_H 14 | 15 | #ifndef ZEPHIR_RELEASE 16 | 17 | void zephir_print_backtrace(void); 18 | 19 | #else 20 | 21 | #ifndef zephir_print_backtrace 22 | #define zephir_print_backtrace() 23 | #endif 24 | 25 | #endif 26 | #endif /* ZEPHIR_KERNEL_BACKTRACE_H */ 27 | -------------------------------------------------------------------------------- /ext/kernel/debug.c: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Zephir. 3 | * 4 | * (c) Phalcon Team 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. If you did not receive 8 | * a copy of the license it is available through the world-wide-web at the 9 | * following url: https://docs.zephir-lang.com/en/latest/license 10 | */ 11 | 12 | #ifdef HAVE_CONFIG_H 13 | #include "config.h" 14 | #endif 15 | 16 | #include 17 | #include "php_ext.h" 18 | #include "kernel/debug.h" 19 | #include "kernel/main.h" 20 | #include "kernel/string.h" 21 | 22 | #ifndef ZEPHIR_RELEASE 23 | 24 | void zephir_vdump(zval *var, const char *func) 25 | { 26 | if (Z_TYPE_P(var) > IS_CALLABLE) { 27 | fprintf(stderr, "%s: (%p) has invalid type %u\n", func, var, Z_TYPE_P(var)); 28 | } 29 | 30 | if (!Z_REFCOUNTED_P(var)) { 31 | fprintf(stderr, "%s: (%p) is not reference-counted, type=%d\n", func, var, Z_TYPE_P(var)); 32 | return; 33 | } 34 | 35 | if (Z_REFCOUNT_P(var) == 0) { 36 | fprintf(stderr, "%s: (%p) has 0 references, type=%d\n", func, var, Z_TYPE_P(var)); 37 | } else { 38 | if (Z_REFCOUNT_P(var) >= 1000000) { 39 | fprintf(stderr, "%s: (%p) has too many references (%u), type=%d\n", func, var, Z_REFCOUNT_P(var), Z_TYPE_P(var)); 40 | } 41 | } 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /ext/kernel/exit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Zephir. 3 | * 4 | * (c) Phalcon Team 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. If you did not receive 8 | * a copy of the license it is available through the world-wide-web at the 9 | * following url: https://docs.zephir-lang.com/en/latest/license 10 | */ 11 | 12 | #ifdef HAVE_CONFIG_H 13 | #include "config.h" 14 | #endif 15 | 16 | #include "php.h" 17 | #include "php_ext.h" 18 | #include "php_main.h" 19 | 20 | #include "kernel/main.h" 21 | #include "kernel/exit.h" 22 | 23 | void zephir_exit_empty() 24 | { 25 | zend_bailout(); 26 | } 27 | 28 | void zephir_exit(zval *ptr) 29 | { 30 | if (Z_TYPE_P(ptr) == IS_LONG) { 31 | EG(exit_status) = Z_LVAL_P(ptr); 32 | } else { 33 | zend_print_variable(ptr); 34 | } 35 | zephir_exit_empty(); 36 | } 37 | -------------------------------------------------------------------------------- /ext/kernel/exit.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Zephir. 3 | * 4 | * (c) Phalcon Team 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. If you did not receive 8 | * a copy of the license it is available through the world-wide-web at the 9 | * following url: https://docs.zephir-lang.com/en/latest/license 10 | */ 11 | 12 | #ifndef ZEPHIR_KERNEL_EXIT_H 13 | #define ZEPHIR_KERNEL_EXIT_H 14 | 15 | #include 16 | 17 | void zephir_exit_empty(); 18 | void zephir_exit(zval *ptr); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /ext/kernel/fcall_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated automatically by Zephir. 3 | * DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN 4 | */ 5 | 6 | #ifndef ZEPHIR_KERNEL_FCALL_INTERNAL_H 7 | #define ZEPHIR_KERNEL_FCALL_INTERNAL_H 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /ext/kernel/file.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Zephir. 3 | * 4 | * (c) Phalcon Team 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. If you did not receive 8 | * a copy of the license it is available through the world-wide-web at the 9 | * following url: https://docs.zephir-lang.com/en/latest/license 10 | */ 11 | 12 | #ifndef ZEPHIR_KERNEL_FILE_H 13 | #define ZEPHIR_KERNEL_FILE_H 14 | 15 | #include 16 | 17 | int zephir_file_exists(zval *filename); 18 | 19 | void zephir_fwrite(zval *return_value, zval *stream_zval, zval *data); 20 | int zephir_feof(zval *stream_zval); 21 | int zephir_fclose(zval *stream_zval); 22 | void zephir_file_get_contents(zval *return_value, zval *filename); 23 | void zephir_file_put_contents(zval *return_value, zval *filename, zval *data); 24 | 25 | void zephir_basename(zval *return_value, zval *path); 26 | void zephir_filemtime(zval *return_value, zval *path); 27 | int zephir_compare_mtime(zval *filename1, zval *filename2); 28 | void zephir_prepare_virtual_path(zval *return_value, zval *path, zval *virtual_separator); 29 | void zephir_unique_path_key(zval *return_value, zval *path); 30 | 31 | #ifdef TSRM_WIN32 32 | #define ZEPHIR_DIRECTORY_SEPARATOR "\\" 33 | #else 34 | #define ZEPHIR_DIRECTORY_SEPARATOR "/" 35 | #endif 36 | 37 | #endif /* ZEPHIR_KERNEL_FILE_H */ 38 | -------------------------------------------------------------------------------- /ext/kernel/filter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Zephir. 3 | * 4 | * (c) Phalcon Team 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. If you did not receive 8 | * a copy of the license it is available through the world-wide-web at the 9 | * following url: https://docs.zephir-lang.com/en/latest/license 10 | */ 11 | 12 | #ifndef ZEPHIR_KERNEL_FILTER_H 13 | #define ZEPHIR_KERNEL_FILTER_H 14 | 15 | #include 16 | 17 | void zephir_filter_alphanum(zval *return_value, zval *param); 18 | void zephir_is_basic_charset(zval *return_value, const zval *param); 19 | void zephir_escape_multi(zval *return_value, zval *param, const char *escape_char, unsigned int escape_length, char escape_extra, int use_whitelist); 20 | void zephir_escape_js(zval *return_value, zval *param); 21 | void zephir_escape_css(zval *return_value, zval *param); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /ext/kernel/iterator.c: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Zephir. 3 | * 4 | * (c) Phalcon Team 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. If you did not receive 8 | * a copy of the license it is available through the world-wide-web at the 9 | * following url: https://docs.zephir-lang.com/en/latest/license 10 | */ 11 | 12 | #ifdef HAVE_CONFIG_H 13 | #include "config.h" 14 | #endif 15 | 16 | #include "php.h" 17 | #include "php_ext.h" 18 | 19 | #include "kernel/main.h" 20 | #include "kernel/memory.h" 21 | 22 | /** 23 | * Returns an iterator from the object 24 | */ 25 | zend_object_iterator *zephir_get_iterator(zval *iterator) 26 | { 27 | zend_class_entry *ce; 28 | zend_object_iterator *it; 29 | 30 | if (UNEXPECTED(Z_TYPE_P(iterator) != IS_OBJECT)) { 31 | return NULL; 32 | } 33 | 34 | ce = Z_OBJCE_P(iterator); 35 | it = ce->get_iterator(ce, iterator, 0); 36 | if (UNEXPECTED(!it || EG(exception))) { 37 | return NULL; 38 | } 39 | 40 | if (UNEXPECTED(it->funcs->get_current_key == NULL)) { 41 | return NULL; 42 | } 43 | 44 | if (UNEXPECTED(it->funcs->rewind == NULL)) { 45 | return NULL; 46 | } 47 | 48 | return it; 49 | } 50 | -------------------------------------------------------------------------------- /ext/kernel/iterator.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Zephir. 3 | * 4 | * (c) Phalcon Team 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. If you did not receive 8 | * a copy of the license it is available through the world-wide-web at the 9 | * following url: https://docs.zephir-lang.com/en/latest/license 10 | */ 11 | 12 | #ifndef ZEPHIR_KERNEL_ITERATOR_H 13 | #define ZEPHIR_KERNEL_ITERATOR_H 14 | 15 | #include 16 | #include 17 | 18 | zend_object_iterator *zephir_get_iterator(zval *iterator); 19 | 20 | #define ZEPHIR_ITERATOR_COPY(var, it) \ 21 | { \ 22 | zval *ZEPHIR_TMP_ITERATOR_PTR; \ 23 | ZEPHIR_TMP_ITERATOR_PTR = it->funcs->get_current_data(it); \ 24 | if (UNEXPECTED(EG(exception) != NULL)) { \ 25 | return; \ 26 | } \ 27 | ZEPHIR_INIT_NVAR(var); \ 28 | if (Z_ISREF_P(var)) { \ 29 | ZVAL_DUP(var, Z_REFVAL_P(var)); \ 30 | } else { \ 31 | ZVAL_COPY(var, ZEPHIR_TMP_ITERATOR_PTR); \ 32 | } \ 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /ext/kernel/math.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Zephir. 3 | * 4 | * (c) Phalcon Team 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. If you did not receive 8 | * a copy of the license it is available through the world-wide-web at the 9 | * following url: https://docs.zephir-lang.com/en/latest/license 10 | */ 11 | 12 | #ifndef ZEPHIR_KERNEL_MATH_H 13 | #define ZEPHIR_KERNEL_MATH_H 14 | 15 | #include 16 | #include 17 | 18 | double zephir_sin(zval *op1); 19 | double zephir_asin(zval *op1); 20 | double zephir_tan(zval *op1); 21 | double zephir_cos(zval *op1); 22 | double zephir_acos(zval *op1); 23 | double zephir_sqrt(zval *op1); 24 | 25 | double zephir_floor(zval *op1); 26 | zend_long zephir_mt_rand(zend_long min, zend_long max); 27 | double zephir_ceil(zval *op1); 28 | void zephir_round(zval *return_value, zval *op1, zval *op2, zval *op3); 29 | 30 | double zephir_ldexp(zval *value, zval *expval); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /ext/kernel/require.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Zephir. 3 | * 4 | * (c) Phalcon Team 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. If you did not receive 8 | * a copy of the license it is available through the world-wide-web at the 9 | * following url: https://docs.zephir-lang.com/en/latest/license 10 | */ 11 | 12 | #ifndef ZEPHIR_KERNEL_REQUIRE_H 13 | #define ZEPHIR_KERNEL_REQUIRE_H 14 | 15 | #include "php_ext.h" 16 | 17 | int zephir_require_ret(zval *return_value_ptr, const char *require_path) ZEPHIR_ATTR_NONNULL1(2); 18 | 19 | ZEPHIR_ATTR_NONNULL static inline int zephir_require(const char *require_path) 20 | { 21 | return zephir_require_ret(NULL, require_path); 22 | } 23 | 24 | ZEPHIR_ATTR_NONNULL static inline int zephir_require_zval(const zval *require_path) 25 | { 26 | return zephir_require_ret(NULL, Z_TYPE_P(require_path) == IS_STRING ? Z_STRVAL_P(require_path) : ""); 27 | } 28 | 29 | ZEPHIR_ATTR_NONNULL static inline int zephir_require_zval_ret(zval *return_value_ptr, const zval *require_path) 30 | { 31 | return zephir_require_ret(return_value_ptr, Z_TYPE_P(require_path) == IS_STRING ? Z_STRVAL_P(require_path) : ""); 32 | } 33 | 34 | #endif /* ZEPHIR_KERNEL_REQUIRE_H */ 35 | -------------------------------------------------------------------------------- /ext/kernel/time.c: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Zephir. 3 | * 4 | * (c) Phalcon Team 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. If you did not receive 8 | * a copy of the license it is available through the world-wide-web at the 9 | * following url: https://docs.zephir-lang.com/en/latest/license 10 | */ 11 | 12 | #ifdef HAVE_CONFIG_H 13 | #include "config.h" 14 | #endif 15 | 16 | #ifdef PHP_WIN32 17 | #include "win32/time.h" 18 | #elif defined(NETWARE) 19 | #include 20 | #include 21 | #else 22 | #include 23 | #endif 24 | 25 | #include 26 | 27 | #include "php.h" 28 | #include "php_ext.h" 29 | 30 | #include "kernel/main.h" 31 | #include "kernel/time.h" 32 | #include "kernel/operators.h" 33 | 34 | void zephir_time(zval *return_value) 35 | { 36 | RETURN_LONG(time(NULL)); 37 | } 38 | 39 | void zephir_microtime(zval *return_value, zval *get_as_float) 40 | { 41 | struct timeval tp = {0}; 42 | char ret[100]; 43 | 44 | if (gettimeofday(&tp, NULL)) { 45 | RETURN_FALSE; 46 | } 47 | 48 | if (get_as_float && ZEPHIR_IS_TRUE(get_as_float)) { 49 | RETURN_DOUBLE((double)(tp.tv_sec + tp.tv_usec / MICRO_IN_SEC)); 50 | } 51 | 52 | snprintf(ret, 100, "%.8F %ld", tp.tv_usec / MICRO_IN_SEC, tp.tv_sec); 53 | RETURN_STRING(ret); 54 | } 55 | -------------------------------------------------------------------------------- /ext/kernel/time.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Zephir. 3 | * 4 | * (c) Phalcon Team 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. If you did not receive 8 | * a copy of the license it is available through the world-wide-web at the 9 | * following url: https://docs.zephir-lang.com/en/latest/license 10 | */ 11 | 12 | #ifndef ZEPHIR_KERNEL_TIME_H 13 | #define ZEPHIR_KERNEL_TIME_H 14 | 15 | #include 16 | #include 17 | 18 | #define MICRO_IN_SEC 1000000.00 19 | 20 | void zephir_time(zval *return_value); 21 | #ifdef HAVE_GETTIMEOFDAY 22 | void zephir_microtime(zval *return_value, zval *get_as_float); 23 | #endif 24 | 25 | #endif /* ZEPHIR_KERNEL_TIME_H */ 26 | -------------------------------------------------------------------------------- /ext/kernel/variables.c: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Zephir. 3 | * 4 | * (c) Phalcon Team 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. If you did not receive 8 | * a copy of the license it is available through the world-wide-web at the 9 | * following url: https://docs.zephir-lang.com/en/latest/license 10 | */ 11 | 12 | #ifdef HAVE_CONFIG_H 13 | #include "config.h" 14 | #endif 15 | 16 | #include "php.h" 17 | #include "php_ext.h" 18 | 19 | #include "ext/standard/php_smart_string.h" 20 | #include "ext/standard/php_var.h" 21 | 22 | static zend_always_inline void zephir_smart_str_0(smart_str *str) 23 | { 24 | if (str->s) { 25 | ZSTR_VAL(str->s)[ZSTR_LEN(str->s)] = '\0'; 26 | } 27 | } 28 | 29 | /** 30 | * var_dump outputs php variables without using the PHP userland 31 | */ 32 | void zephir_var_dump(zval *var) 33 | { 34 | php_var_dump(var, 1); 35 | } 36 | 37 | /** 38 | * var_export outputs php variables without using the PHP userland 39 | */ 40 | void zephir_var_export(zval *var) 41 | { 42 | php_var_export(var, 1); 43 | } 44 | 45 | /** 46 | * var_export returns php variables without using the PHP userland 47 | */ 48 | void zephir_var_export_ex(zval *return_value, zval *var) 49 | { 50 | smart_str buf = { 0 }; 51 | 52 | php_var_export_ex(var, 1, &buf); 53 | zephir_smart_str_0(&buf); 54 | ZVAL_STR(return_value, buf.s); 55 | } 56 | 57 | void zephir_get_defined_vars(zval *return_value) 58 | { 59 | zend_array *symtable = zend_rebuild_symbol_table(); 60 | if (EXPECTED(symtable != NULL)) { 61 | RETURN_ARR(zend_array_dup(symtable)); 62 | } 63 | 64 | RETURN_NULL(); 65 | } 66 | -------------------------------------------------------------------------------- /ext/kernel/variables.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Zephir. 3 | * 4 | * (c) Phalcon Team 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. If you did not receive 8 | * a copy of the license it is available through the world-wide-web at the 9 | * following url: https://docs.zephir-lang.com/en/latest/license 10 | */ 11 | 12 | #ifndef ZEPHIR_KERNEL_VARIABLES_H 13 | #define ZEPHIR_KERNEL_VARIABLES_H 14 | 15 | #include 16 | #include 17 | 18 | void zephir_var_dump(zval *var); 19 | 20 | void zephir_var_export(zval *var); 21 | void zephir_var_export_ex(zval *return_value, zval *var); 22 | 23 | void zephir_get_defined_vars(zval *return_value); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /ext/php_ext.h: -------------------------------------------------------------------------------- 1 | 2 | /* This file was generated automatically by Zephir do not modify it! */ 3 | 4 | #include "php_tensor.h" -------------------------------------------------------------------------------- /ext/php_tensor.h: -------------------------------------------------------------------------------- 1 | 2 | /* This file was generated automatically by Zephir do not modify it! */ 3 | 4 | #ifndef PHP_TENSOR_H 5 | #define PHP_TENSOR_H 1 6 | 7 | #ifdef PHP_WIN32 8 | #define ZEPHIR_RELEASE 1 9 | #endif 10 | 11 | #include "kernel/globals.h" 12 | 13 | #define PHP_TENSOR_NAME "tensor" 14 | #define PHP_TENSOR_VERSION "3.0.0" 15 | #define PHP_TENSOR_EXTNAME "tensor" 16 | #define PHP_TENSOR_AUTHOR "Andrew DalPino" 17 | #define PHP_TENSOR_ZEPVERSION "0.13.5-$Id$" 18 | #define PHP_TENSOR_DESCRIPTION "A library and extension that provides objects for scientific computing in PHP." 19 | 20 | 21 | 22 | ZEND_BEGIN_MODULE_GLOBALS(tensor) 23 | 24 | int initialized; 25 | 26 | /** Function cache */ 27 | HashTable *fcache; 28 | 29 | zephir_fcall_cache_entry *scache[ZEPHIR_MAX_CACHE_SLOTS]; 30 | 31 | /* Cache enabled */ 32 | unsigned int cache_enabled; 33 | 34 | /* Max recursion control */ 35 | unsigned int recursive_lock; 36 | 37 | 38 | ZEND_END_MODULE_GLOBALS(tensor) 39 | 40 | #ifdef ZTS 41 | #include "TSRM.h" 42 | #endif 43 | 44 | ZEND_EXTERN_MODULE_GLOBALS(tensor) 45 | 46 | #ifdef ZTS 47 | #define ZEPHIR_GLOBAL(v) ZEND_MODULE_GLOBALS_ACCESSOR(tensor, v) 48 | #else 49 | #define ZEPHIR_GLOBAL(v) (tensor_globals.v) 50 | #endif 51 | 52 | #ifdef ZTS 53 | ZEND_TSRMLS_CACHE_EXTERN() 54 | #define ZEPHIR_VGLOBAL ((zend_tensor_globals *) (*((void ***) tsrm_get_ls_cache()))[TSRM_UNSHUFFLE_RSRC_ID(tensor_globals_id)]) 55 | #else 56 | #define ZEPHIR_VGLOBAL &(tensor_globals) 57 | #endif 58 | 59 | #define ZEPHIR_API ZEND_API 60 | 61 | #define zephir_globals_def tensor_globals 62 | #define zend_zephir_globals_def zend_tensor_globals 63 | 64 | extern zend_module_entry tensor_module_entry; 65 | #define phpext_tensor_ptr &tensor_module_entry 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /ext/tensor.h: -------------------------------------------------------------------------------- 1 | 2 | /* This file was generated automatically by Zephir do not modify it! */ 3 | 4 | #ifndef ZEPHIR_CLASS_ENTRIES_H 5 | #define ZEPHIR_CLASS_ENTRIES_H 6 | 7 | #include "tensor/algebraic.zep.h" 8 | #include "tensor/arithmetic.zep.h" 9 | #include "tensor/arraylike.zep.h" 10 | #include "tensor/comparable.zep.h" 11 | #include "tensor/special.zep.h" 12 | #include "tensor/statistical.zep.h" 13 | #include "tensor/trigonometric.zep.h" 14 | #include "tensor/exceptions/tensorexception.zep.h" 15 | #include "tensor/tensor.zep.h" 16 | #include "tensor/exceptions/invalidargumentexception.zep.h" 17 | #include "tensor/vector.zep.h" 18 | #include "tensor/columnvector.zep.h" 19 | #include "tensor/decompositions/cholesky.zep.h" 20 | #include "tensor/decompositions/eigen.zep.h" 21 | #include "tensor/decompositions/lu.zep.h" 22 | #include "tensor/decompositions/svd.zep.h" 23 | #include "tensor/exceptions/dimensionalitymismatch.zep.h" 24 | #include "tensor/exceptions/runtimeexception.zep.h" 25 | #include "tensor/matrix.zep.h" 26 | #include "tensor/reductions/ref.zep.h" 27 | #include "tensor/reductions/rref.zep.h" 28 | #include "tensor/settings.zep.h" 29 | 30 | #endif -------------------------------------------------------------------------------- /ext/tensor/algebraic.zep.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef HAVE_CONFIG_H 3 | #include "../ext_config.h" 4 | #endif 5 | 6 | #include 7 | #include "../php_ext.h" 8 | #include "../ext.h" 9 | 10 | #include 11 | 12 | #include "kernel/main.h" 13 | 14 | 15 | ZEPHIR_INIT_CLASS(Tensor_Algebraic) 16 | { 17 | ZEPHIR_REGISTER_INTERFACE(Tensor, Algebraic, tensor, algebraic, tensor_algebraic_method_entry); 18 | 19 | zephir_declare_class_constant_double(tensor_algebraic_ce, SL("M_E"), 2.7182818284590452354); 20 | 21 | return SUCCESS; 22 | } 23 | 24 | /** 25 | * Take the absolute value of the tensor. 26 | * 27 | * @return mixed 28 | */ 29 | ZEPHIR_DOC_METHOD(Tensor_Algebraic, abs); 30 | /** 31 | * Square the tensor. 32 | * 33 | * @return mixed 34 | */ 35 | ZEPHIR_DOC_METHOD(Tensor_Algebraic, square); 36 | /** 37 | * Return the square root of the tensor. 38 | * 39 | * @return mixed 40 | */ 41 | ZEPHIR_DOC_METHOD(Tensor_Algebraic, sqrt); 42 | /** 43 | * Return the exponential of the tensor. 44 | * 45 | * @return mixed 46 | */ 47 | ZEPHIR_DOC_METHOD(Tensor_Algebraic, exp); 48 | /** 49 | * Return the exponential of the tensor minus 1. 50 | * 51 | * @return mixed 52 | */ 53 | ZEPHIR_DOC_METHOD(Tensor_Algebraic, expm1); 54 | /** 55 | * Return the logarithm of the tensor in a specified base. 56 | * 57 | * @param float base 58 | * @return mixed 59 | */ 60 | ZEPHIR_DOC_METHOD(Tensor_Algebraic, log); 61 | /** 62 | * Return the log of 1 plus the tensor i.e. a transform. 63 | * 64 | * @return mixed 65 | */ 66 | ZEPHIR_DOC_METHOD(Tensor_Algebraic, log1p); 67 | /** 68 | * Round the elements in the tensor to a given decimal place. 69 | * 70 | * @param int precision 71 | * @return self 72 | */ 73 | ZEPHIR_DOC_METHOD(Tensor_Algebraic, round); 74 | /** 75 | * Round the tensor down to the nearest integer. 76 | * 77 | * @return mixed 78 | */ 79 | ZEPHIR_DOC_METHOD(Tensor_Algebraic, floor); 80 | /** 81 | * Round the tensor up to the nearest integer. 82 | * 83 | * @return mixed 84 | */ 85 | ZEPHIR_DOC_METHOD(Tensor_Algebraic, ceil); 86 | /** 87 | * Return the element-wise sign indication. 88 | * 89 | * @return mixed 90 | */ 91 | ZEPHIR_DOC_METHOD(Tensor_Algebraic, sign); 92 | /** 93 | * Negate the tensor i.e take the negative. 94 | * 95 | * @return mixed 96 | */ 97 | ZEPHIR_DOC_METHOD(Tensor_Algebraic, negate); 98 | -------------------------------------------------------------------------------- /ext/tensor/algebraic.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_algebraic_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Algebraic); 5 | 6 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_algebraic_abs, 0, 0, 0) 7 | ZEND_END_ARG_INFO() 8 | 9 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_algebraic_square, 0, 0, 0) 10 | ZEND_END_ARG_INFO() 11 | 12 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_algebraic_sqrt, 0, 0, 0) 13 | ZEND_END_ARG_INFO() 14 | 15 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_algebraic_exp, 0, 0, 0) 16 | ZEND_END_ARG_INFO() 17 | 18 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_algebraic_expm1, 0, 0, 0) 19 | ZEND_END_ARG_INFO() 20 | 21 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_algebraic_log, 0, 0, 0) 22 | ZEND_ARG_TYPE_INFO(0, base, IS_DOUBLE, 0) 23 | ZEND_END_ARG_INFO() 24 | 25 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_algebraic_log1p, 0, 0, 0) 26 | ZEND_END_ARG_INFO() 27 | 28 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_algebraic_round, 0, 0, 0) 29 | ZEND_ARG_TYPE_INFO(0, precision, IS_LONG, 0) 30 | ZEND_END_ARG_INFO() 31 | 32 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_algebraic_floor, 0, 0, 0) 33 | ZEND_END_ARG_INFO() 34 | 35 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_algebraic_ceil, 0, 0, 0) 36 | ZEND_END_ARG_INFO() 37 | 38 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_algebraic_sign, 0, 0, 0) 39 | ZEND_END_ARG_INFO() 40 | 41 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_algebraic_negate, 0, 0, 0) 42 | ZEND_END_ARG_INFO() 43 | 44 | ZEPHIR_INIT_FUNCS(tensor_algebraic_method_entry) { 45 | PHP_ABSTRACT_ME(Tensor_Algebraic, abs, arginfo_tensor_algebraic_abs) 46 | PHP_ABSTRACT_ME(Tensor_Algebraic, square, arginfo_tensor_algebraic_square) 47 | PHP_ABSTRACT_ME(Tensor_Algebraic, sqrt, arginfo_tensor_algebraic_sqrt) 48 | PHP_ABSTRACT_ME(Tensor_Algebraic, exp, arginfo_tensor_algebraic_exp) 49 | PHP_ABSTRACT_ME(Tensor_Algebraic, expm1, arginfo_tensor_algebraic_expm1) 50 | PHP_ABSTRACT_ME(Tensor_Algebraic, log, arginfo_tensor_algebraic_log) 51 | PHP_ABSTRACT_ME(Tensor_Algebraic, log1p, arginfo_tensor_algebraic_log1p) 52 | PHP_ABSTRACT_ME(Tensor_Algebraic, round, arginfo_tensor_algebraic_round) 53 | PHP_ABSTRACT_ME(Tensor_Algebraic, floor, arginfo_tensor_algebraic_floor) 54 | PHP_ABSTRACT_ME(Tensor_Algebraic, ceil, arginfo_tensor_algebraic_ceil) 55 | PHP_ABSTRACT_ME(Tensor_Algebraic, sign, arginfo_tensor_algebraic_sign) 56 | PHP_ABSTRACT_ME(Tensor_Algebraic, negate, arginfo_tensor_algebraic_negate) 57 | PHP_FE_END 58 | }; 59 | -------------------------------------------------------------------------------- /ext/tensor/arithmetic.zep.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef HAVE_CONFIG_H 3 | #include "../ext_config.h" 4 | #endif 5 | 6 | #include 7 | #include "../php_ext.h" 8 | #include "../ext.h" 9 | 10 | #include 11 | 12 | #include "kernel/main.h" 13 | 14 | 15 | ZEPHIR_INIT_CLASS(Tensor_Arithmetic) 16 | { 17 | ZEPHIR_REGISTER_INTERFACE(Tensor, Arithmetic, tensor, arithmetic, tensor_arithmetic_method_entry); 18 | 19 | return SUCCESS; 20 | } 21 | 22 | /** 23 | * A universal function to multiply this tensor with another tensor element-wise. 24 | * 25 | * @param mixed b 26 | * @return mixed 27 | */ 28 | ZEPHIR_DOC_METHOD(Tensor_Arithmetic, multiply); 29 | /** 30 | * A universal function to divide this tensor by another tensor element-wise. 31 | * 32 | * @param mixed b 33 | * @return mixed 34 | */ 35 | ZEPHIR_DOC_METHOD(Tensor_Arithmetic, divide); 36 | /** 37 | * A universal function to add this tensor with another tensor element-wise. 38 | * 39 | * @param mixed b 40 | * @return mixed 41 | */ 42 | ZEPHIR_DOC_METHOD(Tensor_Arithmetic, add); 43 | /** 44 | * A universal function to subtract this tensor from another tensor element-wise. 45 | * 46 | * @param mixed b 47 | * @return mixed 48 | */ 49 | ZEPHIR_DOC_METHOD(Tensor_Arithmetic, subtract); 50 | /** 51 | * A universal function to raise this tensor to the power of another tensor element-wise. 52 | * 53 | * @param mixed b 54 | * @return mixed 55 | */ 56 | ZEPHIR_DOC_METHOD(Tensor_Arithmetic, pow); 57 | /** 58 | * A universal function to compute the integer modulus of this tensor and another tensor element-wise. 59 | * 60 | * @param mixed b 61 | * @return mixed 62 | */ 63 | ZEPHIR_DOC_METHOD(Tensor_Arithmetic, mod); 64 | -------------------------------------------------------------------------------- /ext/tensor/arithmetic.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_arithmetic_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Arithmetic); 5 | 6 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_arithmetic_multiply, 0, 0, 1) 7 | ZEND_ARG_INFO(0, b) 8 | ZEND_END_ARG_INFO() 9 | 10 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_arithmetic_divide, 0, 0, 1) 11 | ZEND_ARG_INFO(0, b) 12 | ZEND_END_ARG_INFO() 13 | 14 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_arithmetic_add, 0, 0, 1) 15 | ZEND_ARG_INFO(0, b) 16 | ZEND_END_ARG_INFO() 17 | 18 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_arithmetic_subtract, 0, 0, 1) 19 | ZEND_ARG_INFO(0, b) 20 | ZEND_END_ARG_INFO() 21 | 22 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_arithmetic_pow, 0, 0, 1) 23 | ZEND_ARG_INFO(0, b) 24 | ZEND_END_ARG_INFO() 25 | 26 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_arithmetic_mod, 0, 0, 1) 27 | ZEND_ARG_INFO(0, b) 28 | ZEND_END_ARG_INFO() 29 | 30 | ZEPHIR_INIT_FUNCS(tensor_arithmetic_method_entry) { 31 | PHP_ABSTRACT_ME(Tensor_Arithmetic, multiply, arginfo_tensor_arithmetic_multiply) 32 | PHP_ABSTRACT_ME(Tensor_Arithmetic, divide, arginfo_tensor_arithmetic_divide) 33 | PHP_ABSTRACT_ME(Tensor_Arithmetic, add, arginfo_tensor_arithmetic_add) 34 | PHP_ABSTRACT_ME(Tensor_Arithmetic, subtract, arginfo_tensor_arithmetic_subtract) 35 | PHP_ABSTRACT_ME(Tensor_Arithmetic, pow, arginfo_tensor_arithmetic_pow) 36 | PHP_ABSTRACT_ME(Tensor_Arithmetic, mod, arginfo_tensor_arithmetic_mod) 37 | PHP_FE_END 38 | }; 39 | -------------------------------------------------------------------------------- /ext/tensor/arraylike.zep.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef HAVE_CONFIG_H 3 | #include "../ext_config.h" 4 | #endif 5 | 6 | #include 7 | #include "../php_ext.h" 8 | #include "../ext.h" 9 | 10 | #include 11 | 12 | #include "kernel/main.h" 13 | 14 | 15 | ZEPHIR_INIT_CLASS(Tensor_ArrayLike) 16 | { 17 | ZEPHIR_REGISTER_INTERFACE(Tensor, ArrayLike, tensor, arraylike, tensor_arraylike_method_entry); 18 | 19 | zend_class_implements(tensor_arraylike_ce, 1, zend_ce_arrayaccess); 20 | zend_class_implements(tensor_arraylike_ce, 1, zephir_get_internal_ce(SL("iteratoraggregate"))); 21 | zend_class_implements(tensor_arraylike_ce, 1, zend_ce_countable); 22 | return SUCCESS; 23 | } 24 | 25 | /** 26 | * Return a tuple with the dimensionality of the array-like. 27 | * 28 | * @return int[] 29 | */ 30 | ZEPHIR_DOC_METHOD(Tensor_ArrayLike, shape); 31 | /** 32 | * Return the shape of the tensor as a string. 33 | * 34 | * @return string 35 | */ 36 | ZEPHIR_DOC_METHOD(Tensor_ArrayLike, shapeString); 37 | /** 38 | * Return the number of elements in the array-like object. 39 | * 40 | * @return int 41 | */ 42 | ZEPHIR_DOC_METHOD(Tensor_ArrayLike, size); 43 | /** 44 | * Map a function over all of the elements in the tensor. 45 | * 46 | * @param callable callback 47 | * @return mixed 48 | */ 49 | ZEPHIR_DOC_METHOD(Tensor_ArrayLike, map); 50 | /** 51 | * Reduce the tensor down to a scalar. 52 | * 53 | * @param callable callback 54 | * @param float initial 55 | * @return float 56 | */ 57 | ZEPHIR_DOC_METHOD(Tensor_ArrayLike, reduce); 58 | /** 59 | * Return the elements of the tensor as an array. 60 | * 61 | * @return array 62 | */ 63 | ZEPHIR_DOC_METHOD(Tensor_ArrayLike, asArray); 64 | -------------------------------------------------------------------------------- /ext/tensor/arraylike.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_arraylike_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_ArrayLike); 5 | 6 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_arraylike_shape, 0, 0, IS_ARRAY, 0) 7 | ZEND_END_ARG_INFO() 8 | 9 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_arraylike_shapestring, 0, 0, IS_STRING, 0) 10 | ZEND_END_ARG_INFO() 11 | 12 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_arraylike_size, 0, 0, IS_LONG, 0) 13 | ZEND_END_ARG_INFO() 14 | 15 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_arraylike_map, 0, 0, 1) 16 | ZEND_ARG_INFO(0, callback) 17 | ZEND_END_ARG_INFO() 18 | 19 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_arraylike_reduce, 0, 1, IS_DOUBLE, 0) 20 | ZEND_ARG_INFO(0, callback) 21 | ZEND_ARG_TYPE_INFO(0, initial, IS_DOUBLE, 0) 22 | ZEND_END_ARG_INFO() 23 | 24 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_arraylike_asarray, 0, 0, IS_ARRAY, 0) 25 | ZEND_END_ARG_INFO() 26 | 27 | ZEPHIR_INIT_FUNCS(tensor_arraylike_method_entry) { 28 | PHP_ABSTRACT_ME(Tensor_ArrayLike, shape, arginfo_tensor_arraylike_shape) 29 | PHP_ABSTRACT_ME(Tensor_ArrayLike, shapeString, arginfo_tensor_arraylike_shapestring) 30 | PHP_ABSTRACT_ME(Tensor_ArrayLike, size, arginfo_tensor_arraylike_size) 31 | PHP_ABSTRACT_ME(Tensor_ArrayLike, map, arginfo_tensor_arraylike_map) 32 | PHP_ABSTRACT_ME(Tensor_ArrayLike, reduce, arginfo_tensor_arraylike_reduce) 33 | PHP_ABSTRACT_ME(Tensor_ArrayLike, asArray, arginfo_tensor_arraylike_asarray) 34 | PHP_FE_END 35 | }; 36 | -------------------------------------------------------------------------------- /ext/tensor/comparable.zep.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef HAVE_CONFIG_H 3 | #include "../ext_config.h" 4 | #endif 5 | 6 | #include 7 | #include "../php_ext.h" 8 | #include "../ext.h" 9 | 10 | #include 11 | 12 | #include "kernel/main.h" 13 | 14 | 15 | ZEPHIR_INIT_CLASS(Tensor_Comparable) 16 | { 17 | ZEPHIR_REGISTER_INTERFACE(Tensor, Comparable, tensor, comparable, tensor_comparable_method_entry); 18 | 19 | return SUCCESS; 20 | } 21 | 22 | /** 23 | * A universal function to compute the equality comparison of a tensor and another tensor element-wise. 24 | * 25 | * @param mixed b 26 | * @return mixed 27 | */ 28 | ZEPHIR_DOC_METHOD(Tensor_Comparable, equal); 29 | /** 30 | * A universal function to compute the not equal comparison of this tensor and another tensor element-wise. 31 | * 32 | * @param mixed b 33 | * @return mixed 34 | */ 35 | ZEPHIR_DOC_METHOD(Tensor_Comparable, notEqual); 36 | /** 37 | * A universal function to compute the greater than comparison of a tensor and another tensor element-wise. 38 | * 39 | * @param mixed b 40 | * @return mixed 41 | */ 42 | ZEPHIR_DOC_METHOD(Tensor_Comparable, greater); 43 | /** 44 | * A universal function to compute the greater than or equal to comparison of a tensor and another tensor element-wise. 45 | * 46 | * @param mixed b 47 | * @return mixed 48 | */ 49 | ZEPHIR_DOC_METHOD(Tensor_Comparable, greaterEqual); 50 | /** 51 | * A universal function to compute the less than comparison of a tensor and another tensor element-wise. 52 | * 53 | * @param mixed b 54 | * @return mixed 55 | */ 56 | ZEPHIR_DOC_METHOD(Tensor_Comparable, less); 57 | /** 58 | * A universal function to compute the less than or equal to comparison of a tensor and another tensor element-wise. 59 | * 60 | * @param mixed b 61 | * @return mixed 62 | */ 63 | ZEPHIR_DOC_METHOD(Tensor_Comparable, lessEqual); 64 | -------------------------------------------------------------------------------- /ext/tensor/comparable.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_comparable_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Comparable); 5 | 6 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_comparable_equal, 0, 0, 1) 7 | ZEND_ARG_INFO(0, b) 8 | ZEND_END_ARG_INFO() 9 | 10 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_comparable_notequal, 0, 0, 1) 11 | ZEND_ARG_INFO(0, b) 12 | ZEND_END_ARG_INFO() 13 | 14 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_comparable_greater, 0, 0, 1) 15 | ZEND_ARG_INFO(0, b) 16 | ZEND_END_ARG_INFO() 17 | 18 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_comparable_greaterequal, 0, 0, 1) 19 | ZEND_ARG_INFO(0, b) 20 | ZEND_END_ARG_INFO() 21 | 22 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_comparable_less, 0, 0, 1) 23 | ZEND_ARG_INFO(0, b) 24 | ZEND_END_ARG_INFO() 25 | 26 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_comparable_lessequal, 0, 0, 1) 27 | ZEND_ARG_INFO(0, b) 28 | ZEND_END_ARG_INFO() 29 | 30 | ZEPHIR_INIT_FUNCS(tensor_comparable_method_entry) { 31 | PHP_ABSTRACT_ME(Tensor_Comparable, equal, arginfo_tensor_comparable_equal) 32 | PHP_ABSTRACT_ME(Tensor_Comparable, notEqual, arginfo_tensor_comparable_notequal) 33 | PHP_ABSTRACT_ME(Tensor_Comparable, greater, arginfo_tensor_comparable_greater) 34 | PHP_ABSTRACT_ME(Tensor_Comparable, greaterEqual, arginfo_tensor_comparable_greaterequal) 35 | PHP_ABSTRACT_ME(Tensor_Comparable, less, arginfo_tensor_comparable_less) 36 | PHP_ABSTRACT_ME(Tensor_Comparable, lessEqual, arginfo_tensor_comparable_lessequal) 37 | PHP_FE_END 38 | }; 39 | -------------------------------------------------------------------------------- /ext/tensor/decompositions/cholesky.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_decompositions_cholesky_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Decompositions_Cholesky); 5 | 6 | PHP_METHOD(Tensor_Decompositions_Cholesky, decompose); 7 | PHP_METHOD(Tensor_Decompositions_Cholesky, __construct); 8 | PHP_METHOD(Tensor_Decompositions_Cholesky, l); 9 | PHP_METHOD(Tensor_Decompositions_Cholesky, lT); 10 | 11 | ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_decompositions_cholesky_decompose, 0, 1, Tensor\\Decompositions\\Cholesky, 0) 12 | ZEND_ARG_OBJ_INFO(0, a, Tensor\\Matrix, 0) 13 | ZEND_END_ARG_INFO() 14 | 15 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_decompositions_cholesky___construct, 0, 0, 1) 16 | ZEND_ARG_OBJ_INFO(0, l, Tensor\\Matrix, 0) 17 | ZEND_END_ARG_INFO() 18 | 19 | ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_decompositions_cholesky_l, 0, 0, Tensor\\Matrix, 0) 20 | ZEND_END_ARG_INFO() 21 | 22 | ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_decompositions_cholesky_lt, 0, 0, Tensor\\Matrix, 0) 23 | ZEND_END_ARG_INFO() 24 | 25 | ZEPHIR_INIT_FUNCS(tensor_decompositions_cholesky_method_entry) { 26 | PHP_ME(Tensor_Decompositions_Cholesky, decompose, arginfo_tensor_decompositions_cholesky_decompose, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) 27 | PHP_ME(Tensor_Decompositions_Cholesky, __construct, arginfo_tensor_decompositions_cholesky___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) 28 | PHP_ME(Tensor_Decompositions_Cholesky, l, arginfo_tensor_decompositions_cholesky_l, ZEND_ACC_PUBLIC) 29 | PHP_ME(Tensor_Decompositions_Cholesky, lT, arginfo_tensor_decompositions_cholesky_lt, ZEND_ACC_PUBLIC) 30 | PHP_FE_END 31 | }; 32 | -------------------------------------------------------------------------------- /ext/tensor/decompositions/eigen.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_decompositions_eigen_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Decompositions_Eigen); 5 | 6 | PHP_METHOD(Tensor_Decompositions_Eigen, decompose); 7 | PHP_METHOD(Tensor_Decompositions_Eigen, __construct); 8 | PHP_METHOD(Tensor_Decompositions_Eigen, eigenvalues); 9 | PHP_METHOD(Tensor_Decompositions_Eigen, eigenvectors); 10 | 11 | ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_decompositions_eigen_decompose, 0, 1, Tensor\\Decompositions\\Eigen, 0) 12 | ZEND_ARG_OBJ_INFO(0, a, Tensor\\Matrix, 0) 13 | ZEND_ARG_TYPE_INFO(0, symmetric, _IS_BOOL, 0) 14 | ZEND_END_ARG_INFO() 15 | 16 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_decompositions_eigen___construct, 0, 0, 2) 17 | ZEND_ARG_ARRAY_INFO(0, eigenvalues, 0) 18 | ZEND_ARG_OBJ_INFO(0, eigenvectors, Tensor\\Matrix, 0) 19 | ZEND_END_ARG_INFO() 20 | 21 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_decompositions_eigen_eigenvalues, 0, 0, IS_ARRAY, 0) 22 | ZEND_END_ARG_INFO() 23 | 24 | ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_decompositions_eigen_eigenvectors, 0, 0, Tensor\\Matrix, 0) 25 | ZEND_END_ARG_INFO() 26 | 27 | ZEPHIR_INIT_FUNCS(tensor_decompositions_eigen_method_entry) { 28 | PHP_ME(Tensor_Decompositions_Eigen, decompose, arginfo_tensor_decompositions_eigen_decompose, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) 29 | PHP_ME(Tensor_Decompositions_Eigen, __construct, arginfo_tensor_decompositions_eigen___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) 30 | PHP_ME(Tensor_Decompositions_Eigen, eigenvalues, arginfo_tensor_decompositions_eigen_eigenvalues, ZEND_ACC_PUBLIC) 31 | PHP_ME(Tensor_Decompositions_Eigen, eigenvectors, arginfo_tensor_decompositions_eigen_eigenvectors, ZEND_ACC_PUBLIC) 32 | PHP_FE_END 33 | }; 34 | -------------------------------------------------------------------------------- /ext/tensor/decompositions/lu.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_decompositions_lu_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Decompositions_Lu); 5 | 6 | PHP_METHOD(Tensor_Decompositions_Lu, decompose); 7 | PHP_METHOD(Tensor_Decompositions_Lu, __construct); 8 | PHP_METHOD(Tensor_Decompositions_Lu, l); 9 | PHP_METHOD(Tensor_Decompositions_Lu, u); 10 | PHP_METHOD(Tensor_Decompositions_Lu, p); 11 | 12 | ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_decompositions_lu_decompose, 0, 1, Tensor\\Decompositions\\Lu, 0) 13 | ZEND_ARG_OBJ_INFO(0, a, Tensor\\Matrix, 0) 14 | ZEND_END_ARG_INFO() 15 | 16 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_decompositions_lu___construct, 0, 0, 3) 17 | ZEND_ARG_OBJ_INFO(0, l, Tensor\\Matrix, 0) 18 | ZEND_ARG_OBJ_INFO(0, u, Tensor\\Matrix, 0) 19 | ZEND_ARG_OBJ_INFO(0, p, Tensor\\Matrix, 0) 20 | ZEND_END_ARG_INFO() 21 | 22 | ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_decompositions_lu_l, 0, 0, Tensor\\Matrix, 0) 23 | ZEND_END_ARG_INFO() 24 | 25 | ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_decompositions_lu_u, 0, 0, Tensor\\Matrix, 0) 26 | ZEND_END_ARG_INFO() 27 | 28 | ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_decompositions_lu_p, 0, 0, Tensor\\Matrix, 0) 29 | ZEND_END_ARG_INFO() 30 | 31 | ZEPHIR_INIT_FUNCS(tensor_decompositions_lu_method_entry) { 32 | PHP_ME(Tensor_Decompositions_Lu, decompose, arginfo_tensor_decompositions_lu_decompose, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) 33 | PHP_ME(Tensor_Decompositions_Lu, __construct, arginfo_tensor_decompositions_lu___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) 34 | PHP_ME(Tensor_Decompositions_Lu, l, arginfo_tensor_decompositions_lu_l, ZEND_ACC_PUBLIC) 35 | PHP_ME(Tensor_Decompositions_Lu, u, arginfo_tensor_decompositions_lu_u, ZEND_ACC_PUBLIC) 36 | PHP_ME(Tensor_Decompositions_Lu, p, arginfo_tensor_decompositions_lu_p, ZEND_ACC_PUBLIC) 37 | PHP_FE_END 38 | }; 39 | -------------------------------------------------------------------------------- /ext/tensor/exceptions/dimensionalitymismatch.zep.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef HAVE_CONFIG_H 3 | #include "../../ext_config.h" 4 | #endif 5 | 6 | #include 7 | #include "../../php_ext.h" 8 | #include "../../ext.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "kernel/main.h" 15 | 16 | 17 | ZEPHIR_INIT_CLASS(Tensor_Exceptions_DimensionalityMismatch) 18 | { 19 | ZEPHIR_REGISTER_CLASS_EX(Tensor\\Exceptions, DimensionalityMismatch, tensor, exceptions_dimensionalitymismatch, tensor_exceptions_invalidargumentexception_ce, NULL, 0); 20 | 21 | return SUCCESS; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /ext/tensor/exceptions/dimensionalitymismatch.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_exceptions_dimensionalitymismatch_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Exceptions_DimensionalityMismatch); 5 | 6 | -------------------------------------------------------------------------------- /ext/tensor/exceptions/invalidargumentexception.zep.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef HAVE_CONFIG_H 3 | #include "../../ext_config.h" 4 | #endif 5 | 6 | #include 7 | #include "../../php_ext.h" 8 | #include "../../ext.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "kernel/main.h" 15 | #include "ext/spl/spl_exceptions.h" 16 | 17 | 18 | ZEPHIR_INIT_CLASS(Tensor_Exceptions_InvalidArgumentException) 19 | { 20 | ZEPHIR_REGISTER_CLASS_EX(Tensor\\Exceptions, InvalidArgumentException, tensor, exceptions_invalidargumentexception, spl_ce_InvalidArgumentException, NULL, 0); 21 | 22 | zend_class_implements(tensor_exceptions_invalidargumentexception_ce, 1, tensor_exceptions_tensorexception_ce); 23 | return SUCCESS; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /ext/tensor/exceptions/invalidargumentexception.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_exceptions_invalidargumentexception_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Exceptions_InvalidArgumentException); 5 | 6 | -------------------------------------------------------------------------------- /ext/tensor/exceptions/runtimeexception.zep.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef HAVE_CONFIG_H 3 | #include "../../ext_config.h" 4 | #endif 5 | 6 | #include 7 | #include "../../php_ext.h" 8 | #include "../../ext.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "kernel/main.h" 15 | #include "ext/spl/spl_exceptions.h" 16 | 17 | 18 | ZEPHIR_INIT_CLASS(Tensor_Exceptions_RuntimeException) 19 | { 20 | ZEPHIR_REGISTER_CLASS_EX(Tensor\\Exceptions, RuntimeException, tensor, exceptions_runtimeexception, spl_ce_RuntimeException, NULL, 0); 21 | 22 | zend_class_implements(tensor_exceptions_runtimeexception_ce, 1, tensor_exceptions_tensorexception_ce); 23 | return SUCCESS; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /ext/tensor/exceptions/runtimeexception.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_exceptions_runtimeexception_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Exceptions_RuntimeException); 5 | 6 | -------------------------------------------------------------------------------- /ext/tensor/exceptions/tensorexception.zep.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef HAVE_CONFIG_H 3 | #include "../../ext_config.h" 4 | #endif 5 | 6 | #include 7 | #include "../../php_ext.h" 8 | #include "../../ext.h" 9 | 10 | #include 11 | 12 | #include "kernel/main.h" 13 | 14 | 15 | ZEPHIR_INIT_CLASS(Tensor_Exceptions_TensorException) 16 | { 17 | ZEPHIR_REGISTER_INTERFACE(Tensor\\Exceptions, TensorException, tensor, exceptions_tensorexception, NULL); 18 | 19 | zend_class_implements(tensor_exceptions_tensorexception_ce, 1, zend_ce_throwable); 20 | return SUCCESS; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /ext/tensor/exceptions/tensorexception.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_exceptions_tensorexception_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Exceptions_TensorException); 5 | 6 | -------------------------------------------------------------------------------- /ext/tensor/reductions/ref.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_reductions_ref_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Reductions_Ref); 5 | 6 | PHP_METHOD(Tensor_Reductions_Ref, reduce); 7 | PHP_METHOD(Tensor_Reductions_Ref, __construct); 8 | PHP_METHOD(Tensor_Reductions_Ref, a); 9 | PHP_METHOD(Tensor_Reductions_Ref, swaps); 10 | 11 | ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_reductions_ref_reduce, 0, 1, Tensor\\Reductions\\Ref, 0) 12 | ZEND_ARG_OBJ_INFO(0, a, Tensor\\Matrix, 0) 13 | ZEND_END_ARG_INFO() 14 | 15 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_reductions_ref___construct, 0, 0, 2) 16 | ZEND_ARG_OBJ_INFO(0, a, Tensor\\Matrix, 0) 17 | ZEND_ARG_TYPE_INFO(0, swaps, IS_LONG, 0) 18 | ZEND_END_ARG_INFO() 19 | 20 | ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_reductions_ref_a, 0, 0, Tensor\\Matrix, 0) 21 | ZEND_END_ARG_INFO() 22 | 23 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_reductions_ref_swaps, 0, 0, IS_LONG, 0) 24 | ZEND_END_ARG_INFO() 25 | 26 | ZEPHIR_INIT_FUNCS(tensor_reductions_ref_method_entry) { 27 | PHP_ME(Tensor_Reductions_Ref, reduce, arginfo_tensor_reductions_ref_reduce, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) 28 | PHP_ME(Tensor_Reductions_Ref, __construct, arginfo_tensor_reductions_ref___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) 29 | PHP_ME(Tensor_Reductions_Ref, a, arginfo_tensor_reductions_ref_a, ZEND_ACC_PUBLIC) 30 | PHP_ME(Tensor_Reductions_Ref, swaps, arginfo_tensor_reductions_ref_swaps, ZEND_ACC_PUBLIC) 31 | PHP_FE_END 32 | }; 33 | -------------------------------------------------------------------------------- /ext/tensor/reductions/rref.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_reductions_rref_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Reductions_Rref); 5 | 6 | PHP_METHOD(Tensor_Reductions_Rref, reduce); 7 | PHP_METHOD(Tensor_Reductions_Rref, __construct); 8 | PHP_METHOD(Tensor_Reductions_Rref, a); 9 | 10 | ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_reductions_rref_reduce, 0, 1, Tensor\\Reductions\\Rref, 0) 11 | ZEND_ARG_OBJ_INFO(0, a, Tensor\\Matrix, 0) 12 | ZEND_END_ARG_INFO() 13 | 14 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_reductions_rref___construct, 0, 0, 1) 15 | ZEND_ARG_OBJ_INFO(0, a, Tensor\\Matrix, 0) 16 | ZEND_END_ARG_INFO() 17 | 18 | ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_reductions_rref_a, 0, 0, Tensor\\Matrix, 0) 19 | ZEND_END_ARG_INFO() 20 | 21 | ZEPHIR_INIT_FUNCS(tensor_reductions_rref_method_entry) { 22 | PHP_ME(Tensor_Reductions_Rref, reduce, arginfo_tensor_reductions_rref_reduce, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) 23 | PHP_ME(Tensor_Reductions_Rref, __construct, arginfo_tensor_reductions_rref___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) 24 | PHP_ME(Tensor_Reductions_Rref, a, arginfo_tensor_reductions_rref_a, ZEND_ACC_PUBLIC) 25 | PHP_FE_END 26 | }; 27 | -------------------------------------------------------------------------------- /ext/tensor/settings.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_settings_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Settings); 5 | 6 | PHP_METHOD(Tensor_Settings, setNumThreads); 7 | PHP_METHOD(Tensor_Settings, numThreads); 8 | 9 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_settings_setnumthreads, 0, 1, IS_VOID, 0) 10 | 11 | ZEND_ARG_TYPE_INFO(0, threads, IS_LONG, 0) 12 | ZEND_END_ARG_INFO() 13 | 14 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_settings_numthreads, 0, 0, IS_LONG, 0) 15 | ZEND_END_ARG_INFO() 16 | 17 | ZEPHIR_INIT_FUNCS(tensor_settings_method_entry) { 18 | PHP_ME(Tensor_Settings, setNumThreads, arginfo_tensor_settings_setnumthreads, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) 19 | PHP_ME(Tensor_Settings, numThreads, arginfo_tensor_settings_numthreads, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) 20 | PHP_FE_END 21 | }; 22 | -------------------------------------------------------------------------------- /ext/tensor/special.zep.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef HAVE_CONFIG_H 3 | #include "../ext_config.h" 4 | #endif 5 | 6 | #include 7 | #include "../php_ext.h" 8 | #include "../ext.h" 9 | 10 | #include 11 | 12 | #include "kernel/main.h" 13 | 14 | 15 | ZEPHIR_INIT_CLASS(Tensor_Special) 16 | { 17 | ZEPHIR_REGISTER_INTERFACE(Tensor, Special, tensor, special, tensor_special_method_entry); 18 | 19 | return SUCCESS; 20 | } 21 | 22 | /** 23 | * Sum the tensor. 24 | * 25 | * @return mixed 26 | */ 27 | ZEPHIR_DOC_METHOD(Tensor_Special, sum); 28 | /** 29 | * Calculate the product of the tensor. 30 | * 31 | * @return mixed 32 | */ 33 | ZEPHIR_DOC_METHOD(Tensor_Special, product); 34 | /** 35 | * Return the minimum of the tensor. 36 | * 37 | * @return mixed 38 | */ 39 | ZEPHIR_DOC_METHOD(Tensor_Special, min); 40 | /** 41 | * Return the maximum of the tensor. 42 | * 43 | * @return mixed 44 | */ 45 | ZEPHIR_DOC_METHOD(Tensor_Special, max); 46 | /** 47 | * Clip the tensor to be between the given minimum and maximum. 48 | * 49 | * @param float min 50 | * @param float max 51 | * @return mixed 52 | */ 53 | ZEPHIR_DOC_METHOD(Tensor_Special, clip); 54 | /** 55 | * Clip the tensor to be lower bounded by a given minimum. 56 | * 57 | * @param float min 58 | * @return mixed 59 | */ 60 | ZEPHIR_DOC_METHOD(Tensor_Special, clipLower); 61 | /** 62 | * Clip the tensor to be upper bounded by a given maximum. 63 | * 64 | * @param float max 65 | * @return mixed 66 | */ 67 | ZEPHIR_DOC_METHOD(Tensor_Special, clipUpper); 68 | -------------------------------------------------------------------------------- /ext/tensor/special.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_special_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Special); 5 | 6 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_sum, 0, 0, 0) 7 | ZEND_END_ARG_INFO() 8 | 9 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_product, 0, 0, 0) 10 | ZEND_END_ARG_INFO() 11 | 12 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_min, 0, 0, 0) 13 | ZEND_END_ARG_INFO() 14 | 15 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_max, 0, 0, 0) 16 | ZEND_END_ARG_INFO() 17 | 18 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_clip, 0, 0, 2) 19 | ZEND_ARG_TYPE_INFO(0, min, IS_DOUBLE, 0) 20 | ZEND_ARG_TYPE_INFO(0, max, IS_DOUBLE, 0) 21 | ZEND_END_ARG_INFO() 22 | 23 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_cliplower, 0, 0, 1) 24 | ZEND_ARG_TYPE_INFO(0, min, IS_DOUBLE, 0) 25 | ZEND_END_ARG_INFO() 26 | 27 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_clipupper, 0, 0, 1) 28 | ZEND_ARG_TYPE_INFO(0, max, IS_DOUBLE, 0) 29 | ZEND_END_ARG_INFO() 30 | 31 | ZEPHIR_INIT_FUNCS(tensor_special_method_entry) { 32 | PHP_ABSTRACT_ME(Tensor_Special, sum, arginfo_tensor_special_sum) 33 | PHP_ABSTRACT_ME(Tensor_Special, product, arginfo_tensor_special_product) 34 | PHP_ABSTRACT_ME(Tensor_Special, min, arginfo_tensor_special_min) 35 | PHP_ABSTRACT_ME(Tensor_Special, max, arginfo_tensor_special_max) 36 | PHP_ABSTRACT_ME(Tensor_Special, clip, arginfo_tensor_special_clip) 37 | PHP_ABSTRACT_ME(Tensor_Special, clipLower, arginfo_tensor_special_cliplower) 38 | PHP_ABSTRACT_ME(Tensor_Special, clipUpper, arginfo_tensor_special_clipupper) 39 | PHP_FE_END 40 | }; 41 | -------------------------------------------------------------------------------- /ext/tensor/statistical.zep.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef HAVE_CONFIG_H 3 | #include "../ext_config.h" 4 | #endif 5 | 6 | #include 7 | #include "../php_ext.h" 8 | #include "../ext.h" 9 | 10 | #include 11 | 12 | #include "kernel/main.h" 13 | 14 | 15 | ZEPHIR_INIT_CLASS(Tensor_Statistical) 16 | { 17 | ZEPHIR_REGISTER_INTERFACE(Tensor, Statistical, tensor, statistical, tensor_statistical_method_entry); 18 | 19 | return SUCCESS; 20 | } 21 | 22 | /** 23 | * Return the mean of the tensor. 24 | * 25 | * @return mixed 26 | */ 27 | ZEPHIR_DOC_METHOD(Tensor_Statistical, mean); 28 | /** 29 | * Compute the variance of the tensor. 30 | * 31 | * @param mixed mean 32 | * @return mixed 33 | */ 34 | ZEPHIR_DOC_METHOD(Tensor_Statistical, variance); 35 | /** 36 | * Return the median of the tensor. 37 | * 38 | * @return mixed 39 | */ 40 | ZEPHIR_DOC_METHOD(Tensor_Statistical, median); 41 | /** 42 | * Return the q'th quantile of the tensor. 43 | * 44 | * @param float q 45 | * @return mixed 46 | */ 47 | ZEPHIR_DOC_METHOD(Tensor_Statistical, quantile); 48 | -------------------------------------------------------------------------------- /ext/tensor/statistical.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_statistical_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Statistical); 5 | 6 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_statistical_mean, 0, 0, 0) 7 | ZEND_END_ARG_INFO() 8 | 9 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_statistical_variance, 0, 0, 0) 10 | ZEND_ARG_INFO(0, mean) 11 | ZEND_END_ARG_INFO() 12 | 13 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_statistical_median, 0, 0, 0) 14 | ZEND_END_ARG_INFO() 15 | 16 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_statistical_quantile, 0, 0, 1) 17 | ZEND_ARG_TYPE_INFO(0, q, IS_DOUBLE, 0) 18 | ZEND_END_ARG_INFO() 19 | 20 | ZEPHIR_INIT_FUNCS(tensor_statistical_method_entry) { 21 | PHP_ABSTRACT_ME(Tensor_Statistical, mean, arginfo_tensor_statistical_mean) 22 | PHP_ABSTRACT_ME(Tensor_Statistical, variance, arginfo_tensor_statistical_variance) 23 | PHP_ABSTRACT_ME(Tensor_Statistical, median, arginfo_tensor_statistical_median) 24 | PHP_ABSTRACT_ME(Tensor_Statistical, quantile, arginfo_tensor_statistical_quantile) 25 | PHP_FE_END 26 | }; 27 | -------------------------------------------------------------------------------- /ext/tensor/tensor.zep.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef HAVE_CONFIG_H 3 | #include "../ext_config.h" 4 | #endif 5 | 6 | #include 7 | #include "../php_ext.h" 8 | #include "../ext.h" 9 | 10 | #include 11 | 12 | #include "kernel/main.h" 13 | 14 | 15 | ZEPHIR_INIT_CLASS(Tensor_Tensor) 16 | { 17 | ZEPHIR_REGISTER_INTERFACE(Tensor, Tensor, tensor, tensor, NULL); 18 | 19 | zephir_declare_class_constant_double(tensor_tensor_ce, SL("EPSILON"), 0.00000001); 20 | 21 | zend_class_implements(tensor_tensor_ce, 1, tensor_arraylike_ce); 22 | zend_class_implements(tensor_tensor_ce, 1, tensor_arithmetic_ce); 23 | zend_class_implements(tensor_tensor_ce, 1, tensor_comparable_ce); 24 | zend_class_implements(tensor_tensor_ce, 1, tensor_algebraic_ce); 25 | zend_class_implements(tensor_tensor_ce, 1, tensor_trigonometric_ce); 26 | zend_class_implements(tensor_tensor_ce, 1, tensor_statistical_ce); 27 | zend_class_implements(tensor_tensor_ce, 1, tensor_special_ce); 28 | return SUCCESS; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /ext/tensor/tensor.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_tensor_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Tensor); 5 | 6 | -------------------------------------------------------------------------------- /ext/tensor/trigonometric.zep.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef HAVE_CONFIG_H 3 | #include "../ext_config.h" 4 | #endif 5 | 6 | #include 7 | #include "../php_ext.h" 8 | #include "../ext.h" 9 | 10 | #include 11 | 12 | #include "kernel/main.h" 13 | 14 | 15 | ZEPHIR_INIT_CLASS(Tensor_Trigonometric) 16 | { 17 | ZEPHIR_REGISTER_INTERFACE(Tensor, Trigonometric, tensor, trigonometric, tensor_trigonometric_method_entry); 18 | 19 | zephir_declare_class_constant_double(tensor_trigonometric_ce, SL("M_PI"), 3.14159265358979323846); 20 | 21 | zephir_declare_class_constant_double(tensor_trigonometric_ce, SL("TWO_PI"), 6.28318530718); 22 | 23 | return SUCCESS; 24 | } 25 | 26 | /** 27 | * Return the sine of the tensor. 28 | * 29 | * @return mixed 30 | */ 31 | ZEPHIR_DOC_METHOD(Tensor_Trigonometric, sin); 32 | /** 33 | * Compute the arc sine of the tensor. 34 | * 35 | * @return mixed 36 | */ 37 | ZEPHIR_DOC_METHOD(Tensor_Trigonometric, asin); 38 | /** 39 | * Return the cosine of the tensor. 40 | * 41 | * @return mixed 42 | */ 43 | ZEPHIR_DOC_METHOD(Tensor_Trigonometric, cos); 44 | /** 45 | * Compute the arc cosine of the tensor. 46 | * 47 | * @return mixed 48 | */ 49 | ZEPHIR_DOC_METHOD(Tensor_Trigonometric, acos); 50 | /** 51 | * Return the tangent of the tensor. 52 | * 53 | * @return mixed 54 | */ 55 | ZEPHIR_DOC_METHOD(Tensor_Trigonometric, tan); 56 | /** 57 | * Compute the arc tangent of the tensor. 58 | * 59 | * @return mixed 60 | */ 61 | ZEPHIR_DOC_METHOD(Tensor_Trigonometric, atan); 62 | /** 63 | * Convert angles from radians to degrees. 64 | * 65 | * @return mixed 66 | */ 67 | ZEPHIR_DOC_METHOD(Tensor_Trigonometric, rad2deg); 68 | /** 69 | * Convert angles from degrees to radians. 70 | * 71 | * @return mixed 72 | */ 73 | ZEPHIR_DOC_METHOD(Tensor_Trigonometric, deg2rad); 74 | -------------------------------------------------------------------------------- /ext/tensor/trigonometric.zep.h: -------------------------------------------------------------------------------- 1 | 2 | extern zend_class_entry *tensor_trigonometric_ce; 3 | 4 | ZEPHIR_INIT_CLASS(Tensor_Trigonometric); 5 | 6 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_trigonometric_sin, 0, 0, 0) 7 | ZEND_END_ARG_INFO() 8 | 9 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_trigonometric_asin, 0, 0, 0) 10 | ZEND_END_ARG_INFO() 11 | 12 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_trigonometric_cos, 0, 0, 0) 13 | ZEND_END_ARG_INFO() 14 | 15 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_trigonometric_acos, 0, 0, 0) 16 | ZEND_END_ARG_INFO() 17 | 18 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_trigonometric_tan, 0, 0, 0) 19 | ZEND_END_ARG_INFO() 20 | 21 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_trigonometric_atan, 0, 0, 0) 22 | ZEND_END_ARG_INFO() 23 | 24 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_trigonometric_rad2deg, 0, 0, 0) 25 | ZEND_END_ARG_INFO() 26 | 27 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_trigonometric_deg2rad, 0, 0, 0) 28 | ZEND_END_ARG_INFO() 29 | 30 | ZEPHIR_INIT_FUNCS(tensor_trigonometric_method_entry) { 31 | PHP_ABSTRACT_ME(Tensor_Trigonometric, sin, arginfo_tensor_trigonometric_sin) 32 | PHP_ABSTRACT_ME(Tensor_Trigonometric, asin, arginfo_tensor_trigonometric_asin) 33 | PHP_ABSTRACT_ME(Tensor_Trigonometric, cos, arginfo_tensor_trigonometric_cos) 34 | PHP_ABSTRACT_ME(Tensor_Trigonometric, acos, arginfo_tensor_trigonometric_acos) 35 | PHP_ABSTRACT_ME(Tensor_Trigonometric, tan, arginfo_tensor_trigonometric_tan) 36 | PHP_ABSTRACT_ME(Tensor_Trigonometric, atan, arginfo_tensor_trigonometric_atan) 37 | PHP_ABSTRACT_ME(Tensor_Trigonometric, rad2deg, arginfo_tensor_trigonometric_rad2deg) 38 | PHP_ABSTRACT_ME(Tensor_Trigonometric, deg2rad, arginfo_tensor_trigonometric_deg2rad) 39 | PHP_FE_END 40 | }; 41 | -------------------------------------------------------------------------------- /optimizers/TensorAddOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/arithmetic', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_add($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorAddScalarOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/arithmetic', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_add_scalar($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorCholeskyOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/linear_algebra', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_cholesky($symbol, {$resolvedParams[0]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorDivideOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/arithmetic', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_divide($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorDivideScalarOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/arithmetic', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_divide_scalar($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorDotOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/linear_algebra', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_dot($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorEigOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/linear_algebra', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_eig($symbol, {$resolvedParams[0]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorEigSymmetricOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/linear_algebra', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_eig_symmetric($symbol, {$resolvedParams[0]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorEqualOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/comparison', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_equal($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorEqualScalarOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/comparison', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_equal_scalar($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorGetNumThreadsOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 24 | 25 | $symbolVariable = $call->getSymbolVariable(); 26 | 27 | if ($symbolVariable->getType() !== 'variable') { 28 | throw new CompilerException( 29 | 'Return value must only be assigned to a dynamic variable.', 30 | $expression 31 | ); 32 | } 33 | 34 | if ($call->mustInitSymbolVariable()) { 35 | $symbolVariable->initVariant($context); 36 | } 37 | 38 | $context->headersManager->add( 39 | 'include/settings', 40 | HeadersManager::POSITION_LAST 41 | ); 42 | 43 | $resolvedParams = $call->getResolvedParams( 44 | [], 45 | $context, 46 | $expression 47 | ); 48 | 49 | $symbol = $context->backend->getVariableCode($symbolVariable); 50 | 51 | $context->codePrinter->output( 52 | "tensor_get_num_threads($symbol);" 53 | ); 54 | 55 | return new CompiledExpression( 56 | 'variable', 57 | $symbolVariable->getRealName(), 58 | $expression 59 | ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /optimizers/TensorGreaterOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/comparison', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_greater($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorInverseOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/linear_algebra', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_inverse($symbol, {$resolvedParams[0]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorLessEqualOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/comparison', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_less_equal($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorLessOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/comparison', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_less($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorLessScalarOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/comparison', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_less_scalar($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorLuOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/linear_algebra', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_lu($symbol, {$resolvedParams[0]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorMatmulOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/linear_algebra', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_matmul($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorModOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/arithmetic', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_mod($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorModScalarOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/arithmetic', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_mod_scalar($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorMultiplyOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/arithmetic', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_multiply($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorNotEqualOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/comparison', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_not_equal($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorPowOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/arithmetic', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_pow($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorPowScalarOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/arithmetic', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_pow_scalar($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorPseudoinverseOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/linear_algebra', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_pseudoinverse($symbol, {$resolvedParams[0]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorRefOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/linear_algebra', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_ref($symbol, {$resolvedParams[0]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorSetNumThreadsOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/settings', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_set_num_threads($symbol, {$resolvedParams[0]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorSubtractOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/arithmetic', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_subtract($symbol, {$resolvedParams[0]}, {$resolvedParams[1]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /optimizers/TensorSvdOptimizer.php: -------------------------------------------------------------------------------- 1 | processExpectedReturn($context); 35 | 36 | $symbolVariable = $call->getSymbolVariable(); 37 | 38 | if ($symbolVariable->getType() !== 'variable') { 39 | throw new CompilerException( 40 | 'Return value must only be assigned to a dynamic variable.', 41 | $expression 42 | ); 43 | } 44 | 45 | if ($call->mustInitSymbolVariable()) { 46 | $symbolVariable->initVariant($context); 47 | } 48 | 49 | $context->headersManager->add( 50 | 'include/linear_algebra', 51 | HeadersManager::POSITION_LAST 52 | ); 53 | 54 | $resolvedParams = $call->getResolvedParams( 55 | $expression['parameters'], 56 | $context, 57 | $expression 58 | ); 59 | 60 | $symbol = $context->backend->getVariableCode($symbolVariable); 61 | 62 | $context->codePrinter->output( 63 | "tensor_svd($symbol, {$resolvedParams[0]});" 64 | ); 65 | 66 | return new CompiledExpression( 67 | 'variable', 68 | $symbolVariable->getRealName(), 69 | $expression 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /phpbench.json.dist: -------------------------------------------------------------------------------- 1 | { 2 | "bootstrap": "vendor/autoload.php", 3 | "path": "benchmarks", 4 | "time_unit": "seconds", 5 | "progress": "blinken", 6 | "php_config": { 7 | "memory_limit": "-1" 8 | } 9 | } -------------------------------------------------------------------------------- /phpstan.neon: -------------------------------------------------------------------------------- 1 | parameters: 2 | level: 8 3 | paths: 4 | - 'src' 5 | - 'optimizers' 6 | - 'tests' 7 | - 'benchmarks' 8 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | src 6 | 7 | 8 | 9 | 10 | tests 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/Algebraic.php: -------------------------------------------------------------------------------- 1 | 11 | * @extends IteratorAggregate 12 | */ 13 | interface ArrayLike extends ArrayAccess, IteratorAggregate, Countable 14 | { 15 | /** 16 | * Return a tuple with the dimensionality of the array-like. 17 | * 18 | * @return int[] 19 | */ 20 | public function shape() : array; 21 | 22 | /** 23 | * Return the shape of the tensor as a string. 24 | * 25 | * @return string 26 | */ 27 | public function shapeString() : string; 28 | 29 | /** 30 | * Return the number of elements in the tensor. 31 | * 32 | * @return int 33 | */ 34 | public function size() : int; 35 | 36 | /** 37 | * Map a function over all of the elements in the tensor. 38 | * 39 | * @param callable $callback 40 | * @return mixed 41 | */ 42 | public function map(callable $callback); 43 | 44 | /** 45 | * Reduce the tensor down to a scalar. 46 | * 47 | * @param callable $callback 48 | * @param float $initial 49 | * @return float 50 | */ 51 | public function reduce(callable $callback, float $initial = 0.0) : float; 52 | 53 | /** 54 | * Return the elements of the tensor as an array. 55 | * 56 | * @return mixed[] 57 | */ 58 | public function asArray() : array; 59 | } 60 | -------------------------------------------------------------------------------- /src/Comparable.php: -------------------------------------------------------------------------------- 1 | eigenvalues = $eigenvalues; 54 | $this->eigenvectors = $eigenvectors; 55 | } 56 | 57 | /** 58 | * Return the eigenvalues of the eigendecomposition. 59 | * 60 | * @return (int|float)[] 61 | */ 62 | public function eigenvalues() : array 63 | { 64 | return $this->eigenvalues; 65 | } 66 | 67 | /** 68 | * Return the eigenvectors of the eigendecomposition. 69 | * 70 | * @return \Tensor\Matrix 71 | */ 72 | public function eigenvectors() : Matrix 73 | { 74 | return $this->eigenvectors; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Exceptions/DimensionalityMismatch.php: -------------------------------------------------------------------------------- 1 | array; 15 | 16 | /** 17 | * Return the shape of the tensor as a string. 18 | * 19 | * @return string 20 | */ 21 | public function shapeString() -> string; 22 | 23 | /** 24 | * Return the number of elements in the array-like object. 25 | * 26 | * @return int 27 | */ 28 | public function size() -> int; 29 | 30 | /** 31 | * Map a function over all of the elements in the tensor. 32 | * 33 | * @param callable callback 34 | * @return mixed 35 | */ 36 | public function map(const callback); 37 | 38 | /** 39 | * Reduce the tensor down to a scalar. 40 | * 41 | * @param callable callback 42 | * @param float initial 43 | * @return float 44 | */ 45 | public function reduce(const callback, float initial = 0.0) -> float; 46 | 47 | /** 48 | * Return the elements of the tensor as an array. 49 | * 50 | * @return array 51 | */ 52 | public function asArray() -> array; 53 | } 54 | -------------------------------------------------------------------------------- /tensor/comparable.zep: -------------------------------------------------------------------------------- 1 | namespace Tensor; 2 | 3 | interface Comparable 4 | { 5 | /** 6 | * A universal function to compute the equality comparison of a tensor and another tensor element-wise. 7 | * 8 | * @param mixed b 9 | * @return mixed 10 | */ 11 | public function equal(const b); 12 | 13 | /** 14 | * A universal function to compute the not equal comparison of this tensor and another tensor element-wise. 15 | * 16 | * @param mixed b 17 | * @return mixed 18 | */ 19 | public function notEqual(const b); 20 | 21 | /** 22 | * A universal function to compute the greater than comparison of a tensor and another tensor element-wise. 23 | * 24 | * @param mixed b 25 | * @return mixed 26 | */ 27 | public function greater(const b); 28 | 29 | /** 30 | * A universal function to compute the greater than or equal to comparison of a tensor and another tensor element-wise. 31 | * 32 | * @param mixed b 33 | * @return mixed 34 | */ 35 | public function greaterEqual(const b); 36 | 37 | /** 38 | * A universal function to compute the less than comparison of a tensor and another tensor element-wise. 39 | * 40 | * @param mixed b 41 | * @return mixed 42 | */ 43 | public function less(const b); 44 | 45 | /** 46 | * A universal function to compute the less than or equal to comparison of a tensor and another tensor element-wise. 47 | * 48 | * @param mixed b 49 | * @return mixed 50 | */ 51 | public function lessEqual(const b); 52 | } 53 | -------------------------------------------------------------------------------- /tensor/decompositions/cholesky.zep: -------------------------------------------------------------------------------- 1 | namespace Tensor\Decompositions; 2 | 3 | use Tensor\Matrix; 4 | use Tensor\Exceptions\InvalidArgumentException; 5 | use Tensor\Exceptions\RuntimeException; 6 | 7 | /** 8 | * Cholesky 9 | * 10 | * An efficient decomposition of a square positive definite matrix into a lower triangular matrix and its conjugate transpose. 11 | * 12 | * @category Scientific Computing 13 | * @package Rubix/Tensor 14 | * @author Andrew DalPino 15 | */ 16 | class Cholesky 17 | { 18 | /** 19 | * The lower triangular matrix. 20 | * 21 | * @var \Tensor\Matrix 22 | */ 23 | protected l; 24 | 25 | /** 26 | * Factory method to decompose a matrix. 27 | * 28 | * @param \Tensor\Matrix a 29 | * @throws \Tensor\Exceptions\InvalidArgumentException 30 | * @throws \Tensor\Exceptions\RuntimeException 31 | * @return self 32 | */ 33 | public static function decompose(const a) -> 34 | { 35 | if !a->isSquare() { 36 | throw new InvalidArgumentException("Matrix must be" 37 | . " square, " . $a->shapeString() . " given."); 38 | } 39 | 40 | var l = tensor_cholesky(a->asArray()); 41 | 42 | if is_null(l) { 43 | throw new RuntimeException("Failed to decompose matrix."); 44 | } 45 | 46 | return new self(Matrix::quick(l)); 47 | } 48 | 49 | /** 50 | * @param \Tensor\Matrix l 51 | */ 52 | public function __construct(const l) 53 | { 54 | let this->l = l; 55 | } 56 | 57 | /** 58 | * Return the lower triangular matrix. 59 | * 60 | * @return \Tensor\Matrix 61 | */ 62 | public function l() -> 63 | { 64 | return this->l; 65 | } 66 | 67 | /** 68 | * Return the conjugate transpose of the lower triangular matrix. 69 | * 70 | * @return \Tensor\Matrix 71 | */ 72 | public function lT() -> 73 | { 74 | return this->l->transpose(); 75 | } 76 | } -------------------------------------------------------------------------------- /tensor/exceptions/DimensionalityMismatch.zep: -------------------------------------------------------------------------------- 1 | namespace Tensor\Exceptions; 2 | 3 | class DimensionalityMismatch extends InvalidArgumentException 4 | { 5 | // 6 | } 7 | -------------------------------------------------------------------------------- /tensor/exceptions/InvalidArgumentException.zep: -------------------------------------------------------------------------------- 1 | namespace Tensor\Exceptions; 2 | 3 | use InvalidArgumentException as SplInvalidArgumentException; 4 | 5 | class InvalidArgumentException extends SplInvalidArgumentException implements TensorException 6 | { 7 | // 8 | } 9 | -------------------------------------------------------------------------------- /tensor/exceptions/RuntimeException.zep: -------------------------------------------------------------------------------- 1 | namespace Tensor\Exceptions; 2 | 3 | use RuntimeException as SplRuntimeException; 4 | 5 | class RuntimeException extends SplRuntimeException implements TensorException 6 | { 7 | // 8 | } 9 | -------------------------------------------------------------------------------- /tensor/exceptions/TensorException.zep: -------------------------------------------------------------------------------- 1 | namespace Tensor\Exceptions; 2 | 3 | use Throwable; 4 | 5 | interface TensorException extends Throwable 6 | { 7 | // 8 | } 9 | -------------------------------------------------------------------------------- /tensor/settings.zep: -------------------------------------------------------------------------------- 1 | namespace Tensor; 2 | 3 | use Tensor\Exceptions\InvalidArgumentException; 4 | 5 | /** 6 | * Settings 7 | * 8 | * @internal 9 | * 10 | * @category Scientific Computing 11 | * @package Rubix/Tensor 12 | * @author Andrew DalPino 13 | */ 14 | class Settings 15 | { 16 | /** 17 | * Set the number of CPU threads to use when multiprocessing. 18 | * 19 | * @param int threads 20 | * @return void 21 | */ 22 | public static function setNumThreads(const int threads) -> void 23 | { 24 | if unlikely threads < 1 { 25 | throw new InvalidArgumentException("The number of threads" 26 | . " must be greater than 0, " . strval(threads) . " given."); 27 | } 28 | 29 | var status = tensor_set_num_threads(threads); 30 | } 31 | 32 | /** 33 | * Return the number of CPU threads used for multiprocessing. 34 | * 35 | * @return int 36 | */ 37 | public static function numThreads() -> int 38 | { 39 | return tensor_get_num_threads(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tensor/special.zep: -------------------------------------------------------------------------------- 1 | namespace Tensor; 2 | 3 | interface Special 4 | { 5 | /** 6 | * Sum the tensor. 7 | * 8 | * @return mixed 9 | */ 10 | public function sum(); 11 | 12 | /** 13 | * Calculate the product of the tensor. 14 | * 15 | * @return mixed 16 | */ 17 | public function product(); 18 | 19 | /** 20 | * Return the minimum of the tensor. 21 | * 22 | * @return mixed 23 | */ 24 | public function min(); 25 | 26 | /** 27 | * Return the maximum of the tensor. 28 | * 29 | * @return mixed 30 | */ 31 | public function max(); 32 | 33 | /** 34 | * Clip the tensor to be between the given minimum and maximum. 35 | * 36 | * @param float min 37 | * @param float max 38 | * @return mixed 39 | */ 40 | public function clip(const float min, const float max); 41 | 42 | /** 43 | * Clip the tensor to be lower bounded by a given minimum. 44 | * 45 | * @param float min 46 | * @return mixed 47 | */ 48 | public function clipLower(const float min); 49 | 50 | /** 51 | * Clip the tensor to be upper bounded by a given maximum. 52 | * 53 | * @param float max 54 | * @return mixed 55 | */ 56 | public function clipUpper(const float max); 57 | } 58 | -------------------------------------------------------------------------------- /tensor/statistical.zep: -------------------------------------------------------------------------------- 1 | namespace Tensor; 2 | 3 | interface Statistical 4 | { 5 | /** 6 | * Return the mean of the tensor. 7 | * 8 | * @return mixed 9 | */ 10 | public function mean(); 11 | 12 | /** 13 | * Compute the variance of the tensor. 14 | * 15 | * @param mixed mean 16 | * @return mixed 17 | */ 18 | public function variance(mean = null); 19 | 20 | /** 21 | * Return the median of the tensor. 22 | * 23 | * @return mixed 24 | */ 25 | public function median(); 26 | 27 | /** 28 | * Return the q'th quantile of the tensor. 29 | * 30 | * @param float q 31 | * @return mixed 32 | */ 33 | public function quantile(const float q); 34 | } 35 | -------------------------------------------------------------------------------- /tensor/tensor.zep: -------------------------------------------------------------------------------- 1 | namespace Tensor; 2 | 3 | interface Tensor extends ArrayLike, Arithmetic, Comparable, Algebraic, Trigonometric, Statistical, Special 4 | { 5 | const EPSILON = 0.00000001; 6 | } 7 | -------------------------------------------------------------------------------- /tensor/trigonometric.zep: -------------------------------------------------------------------------------- 1 | namespace Tensor; 2 | 3 | interface Trigonometric 4 | { 5 | const M_PI = 3.14159265358979323846; 6 | 7 | const TWO_PI = 6.28318530718; 8 | 9 | /** 10 | * Return the sine of the tensor. 11 | * 12 | * @return mixed 13 | */ 14 | public function sin(); 15 | 16 | /** 17 | * Compute the arc sine of the tensor. 18 | * 19 | * @return mixed 20 | */ 21 | public function asin(); 22 | 23 | /** 24 | * Return the cosine of the tensor. 25 | * 26 | * @return mixed 27 | */ 28 | public function cos(); 29 | 30 | /** 31 | * Compute the arc cosine of the tensor. 32 | * 33 | * @return mixed 34 | */ 35 | public function acos(); 36 | 37 | /** 38 | * Return the tangent of the tensor. 39 | * 40 | * @return mixed 41 | */ 42 | public function tan(); 43 | 44 | /** 45 | * Compute the arc tangent of the tensor. 46 | * 47 | * @return mixed 48 | */ 49 | public function atan(); 50 | 51 | /** 52 | * Convert angles from radians to degrees. 53 | * 54 | * @return mixed 55 | */ 56 | public function rad2deg(); 57 | 58 | /** 59 | * Convert angles from degrees to radians. 60 | * 61 | * @return mixed 62 | */ 63 | public function deg2rad(); 64 | } 65 | --------------------------------------------------------------------------------