From 82f77d12793d5c2ea40d58b4c8550514849f5ad0 Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Tue, 6 Oct 2026 00:25:26 -0500 Subject: [PATCH 01/14] Initial commit --- benchmarks/Unary/SoftplusMatrixBench.php | 62 +++++++++ docs/Matrix.md | 1 + docs/Vector.md | 1 + docs/interfaces/tensor.md | 2 +- docs/interfaces/unary.md | 8 ++ ext/include/unary.c | 1 + ext/include/unary.h | 1 + ext/tensor/matrix.zep.c | 160 ++++++++++++++--------- ext/tensor/matrix.zep.h | 5 + ext/tensor/unary.zep.c | 6 + ext/tensor/unary.zep.h | 4 + ext/tensor/vector.zep.c | 114 ++++++++++------ ext/tensor/vector.zep.h | 5 + optimizers/TensorSoftplusOptimizer.php | 76 +++++++++++ tensor/matrix.zep | 12 +- tensor/unary.zep | 7 + tensor/vector.zep | 10 ++ tests/ColumnVectorTest.php | 11 ++ tests/MatrixTest.php | 63 +++++++++ tests/VectorTest.php | 54 ++++++++ 20 files changed, 500 insertions(+), 103 deletions(-) create mode 100644 benchmarks/Unary/SoftplusMatrixBench.php create mode 100644 optimizers/TensorSoftplusOptimizer.php diff --git a/benchmarks/Unary/SoftplusMatrixBench.php b/benchmarks/Unary/SoftplusMatrixBench.php new file mode 100644 index 0000000..77c1f44 --- /dev/null +++ b/benchmarks/Unary/SoftplusMatrixBench.php @@ -0,0 +1,62 @@ +a = Matrix::uniform(...$params['size']); + } + + /** + * @return list}> + */ + public function sizes() : Generator + { + yield 'small' => ['size' => [1024, 1024]]; + yield 'medium' => ['size' => [4096, 4096]]; + yield 'large' => ['size' => [8192, 8192]]; + } + + /** + * @Subject + * @Iterations(5) + * @ParamProviders({"sizes"}) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function benchFused() : void + { + $this->a->softplus(); + } + + /** + * @Subject + * @Iterations(5) + * @ParamProviders({"sizes"}) + * @OutputTimeUnit("milliseconds", precision=3) + */ + public function benchComposed() : void + { + $e = $this->a->exp(); + + $e->add(1.0)->log(); + } +} diff --git a/docs/Matrix.md b/docs/Matrix.md index 20e7dee..a707992 100644 --- a/docs/Matrix.md +++ b/docs/Matrix.md @@ -425,6 +425,7 @@ See [Unary](interfaces/unary.md). Each method returns a new `Matrix`. - `log(float $base = M_E) : self` — logarithm of the matrix in the specified base - `log1p() : self` — log of 1 plus each element - `sigmoid() : self` — element-wise logistic function, `1 / (1 + exp(-x))` +- `softplus() : self` — element-wise softplus, `log(1 + exp(x))` - `round(int $precision = 0) : self` — round the elements to a given decimal place (throws `InvalidArgumentException` if `$precision < 0`) - `floor() : self` — round down to the nearest integer - `ceil() : self` — round up to the nearest integer diff --git a/docs/Vector.md b/docs/Vector.md index 1b73b2c..d1efcff 100644 --- a/docs/Vector.md +++ b/docs/Vector.md @@ -308,6 +308,7 @@ See [Unary](interfaces/unary.md). Each method returns a new `Vector`. - `log(float $base = M_E) : self` — log to the given base of each element - `log1p() : self` — log of 1 plus each element - `sigmoid() : self` — element-wise logistic function, `1 / (1 + exp(-x))` +- `softplus() : self` — element-wise softplus, `log(1 + exp(x))` - `round(int $precision = 0) : self` — round the elements to a given decimal place (throws `InvalidArgumentException` if `$precision < 0`) - `floor() : self` — round down to the nearest integer - `ceil() : self` — round up to the nearest integer diff --git a/docs/interfaces/tensor.md b/docs/interfaces/tensor.md index 1210683..2f118f3 100644 --- a/docs/interfaces/tensor.md +++ b/docs/interfaces/tensor.md @@ -20,7 +20,7 @@ interface Tensor extends ArrayLike, Arithmetic, Comparable, | [ArrayLike](arraylike.md) | `shape`, `shapeString`, `size`, `map`, `reduce`, `asArray` | | [Arithmetic](arithmetic.md) | `multiply`, `divide`, `add`, `subtract`, `pow`, `mod` | | [Comparable](comparable.md) | `equal`, `notEqual`, `greater`, `greaterEqual`, `less`, `lessEqual` | -| [Unary](unary.md) | `abs`, `square`, `sqrt`, `exp`, `expm1`, `log`, `log1p`, `sigmoid`, `round`, `floor`, `ceil`, `sign`, `negate`, `clip`, `clipLower`, `clipUpper` | +| [Unary](unary.md) | `abs`, `square`, `sqrt`, `exp`, `expm1`, `log`, `log1p`, `sigmoid`, `softplus`, `round`, `floor`, `ceil`, `sign`, `negate`, `clip`, `clipLower`, `clipUpper` | | [Trigonometric](trigonometric.md) | `sin`, `asin`, `cos`, `acos`, `tan`, `atan`, `tanh`, `rad2deg`, `deg2rad` | | [Reductions](reductions.md) | `sum`, `product`, `min`, `max`, `argmin`, `argmax`, `mean`, `variance`, `median`, `quantile` | | [Special](special.md) | `softmax` | diff --git a/docs/interfaces/unary.md b/docs/interfaces/unary.md index 8f9f817..9edae16 100644 --- a/docs/interfaces/unary.md +++ b/docs/interfaces/unary.md @@ -56,6 +56,14 @@ Return the element-wise logistic function, `1 / (1 + exp(-x))`. A large negative input saturates to exactly `0.0` and a large positive one to exactly `1.0`, so the result never overflows to an infinity. +### `softplus() : mixed` + +Return the element-wise softplus, `log(1 + exp(x))`. + +The computation is numerically stable: for a large positive input it reduces to +`x + log1p(0) == x` and for a large negative input to `log1p(0) == 0.0`, so the +result never overflows to an infinity. + ### `round(int $precision = 0) : self` Round the elements in the tensor to a given decimal place. diff --git a/ext/include/unary.c b/ext/include/unary.c index ce6f820..4a07a71 100644 --- a/ext/include/unary.c +++ b/ext/include/unary.c @@ -134,6 +134,7 @@ TENSOR_UNARY(expm1, expm1(va[i])) TENSOR_UNARY(log, log(va[i])) TENSOR_UNARY(log1p, log1p(va[i])) TENSOR_UNARY(sigmoid, 1.0 / (1.0 + exp(-va[i]))) +TENSOR_UNARY(softplus, va[i] > 0.0 ? va[i] + log1p(exp(-va[i])) : log1p(exp(va[i]))) TENSOR_UNARY(sin, sin(va[i])) TENSOR_UNARY(asin, asin(va[i])) TENSOR_UNARY(cos, cos(va[i])) diff --git a/ext/include/unary.h b/ext/include/unary.h index 778760e..31235bb 100644 --- a/ext/include/unary.h +++ b/ext/include/unary.h @@ -11,6 +11,7 @@ void tensor_log(zval * return_value, zval * a); void tensor_log_base(zval * return_value, zval * a, zval * b); void tensor_log1p(zval * return_value, zval * a); void tensor_sigmoid(zval * return_value, zval * a); +void tensor_softplus(zval * return_value, zval * a); void tensor_tanh(zval * return_value, zval * a); void tensor_sin(zval * return_value, zval * a); void tensor_asin(zval * return_value, zval * a); diff --git a/ext/tensor/matrix.zep.c b/ext/tensor/matrix.zep.c index 568071d..5d78715 100644 --- a/ext/tensor/matrix.zep.c +++ b/ext/tensor/matrix.zep.c @@ -3925,6 +3925,48 @@ PHP_METHOD(Tensor_Matrix, sigmoid) RETURN_MM(); } +/** + * Return the element-wise softplus i.e. log(1 + exp(x)). + * + * @return self + */ +PHP_METHOD(Tensor_Matrix, softplus) +{ + zval _0, _1, _2, _3; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + tensor_softplus(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 17, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 18, &_0, &_2, &_3); + zephir_check_call_status(); + RETURN_MM(); +} + /** * Return the sine of the matrix. * @@ -4666,7 +4708,7 @@ PHP_METHOD(Tensor_Matrix, quantile) ZEPHIR_CONCAT_SS(&_3$$3, "Q must be a finite value", " between 0 and 1."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1613); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1623); ZEPHIR_MM_RESTORE(); return; } @@ -4684,7 +4726,7 @@ PHP_METHOD(Tensor_Matrix, quantile) ZEPHIR_CONCAT_SSVS(&_8$$4, "Q must be between", " 0 and 1, ", &_7$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_8$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 1618); + zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 1628); ZEPHIR_MM_RESTORE(); return; } @@ -4802,7 +4844,7 @@ PHP_METHOD(Tensor_Matrix, variance) ZEPHIR_CONCAT_SSVS(&_2$$4, "Mean must be a", " column vector ", &_1$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$4, "__construct", NULL, 2, &_2$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$4, "tensor/matrix.zep", 1647); + zephir_throw_exception_debug(&_0$$4, "tensor/matrix.zep", 1657); ZEPHIR_MM_RESTORE(); return; } @@ -4822,7 +4864,7 @@ PHP_METHOD(Tensor_Matrix, variance) ZEPHIR_CONCAT_SSVSVS(&_10$$5, "Mean vector must", " have ", &_7$$5, " rows, ", &_9$$5, " given."); ZEPHIR_CALL_METHOD(NULL, &_5$$5, "__construct", NULL, 2, &_10$$5); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$5, "tensor/matrix.zep", 1653); + zephir_throw_exception_debug(&_5$$5, "tensor/matrix.zep", 1663); ZEPHIR_MM_RESTORE(); return; } @@ -4941,7 +4983,7 @@ PHP_METHOD(Tensor_Matrix, round) ZEPHIR_CONCAT_SSVS(&_3$$3, "Decimal precision cannot", " be less than 0, ", &_2$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1684); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1694); ZEPHIR_MM_RESTORE(); return; } @@ -5178,7 +5220,7 @@ PHP_METHOD(Tensor_Matrix, clip) ZEPHIR_CONCAT_SS(&_1$$3, "Minimum cannot be", " greater than maximum."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_1$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1743); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1753); ZEPHIR_MM_RESTORE(); return; } @@ -5378,7 +5420,7 @@ PHP_METHOD(Tensor_Matrix, augmentAbove) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " columns but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1789); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1799); ZEPHIR_MM_RESTORE(); return; } @@ -5495,7 +5537,7 @@ PHP_METHOD(Tensor_Matrix, augmentBelow) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " columns but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1811); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1821); ZEPHIR_MM_RESTORE(); return; } @@ -5622,7 +5664,7 @@ PHP_METHOD(Tensor_Matrix, augmentLeft) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " rows but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1833); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1843); ZEPHIR_MM_RESTORE(); return; } @@ -5675,7 +5717,7 @@ PHP_METHOD(Tensor_Matrix, augmentLeft) zephir_array_fast_append(&_27$$4, &bufferA); ZEPHIR_CALL_METHOD(&_26$$4, &bufferB, "concat", &_28, 0, &_27$$4); zephir_check_call_status(); - zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1849); + zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1859); } } ZEPHIR_CALL_CE_STATIC(&buffer, tensor_tensorbuffer_ce, "fromBuffers", NULL, 0, &c); @@ -5785,7 +5827,7 @@ PHP_METHOD(Tensor_Matrix, augmentRight) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " rows but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1869); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1879); ZEPHIR_MM_RESTORE(); return; } @@ -5838,7 +5880,7 @@ PHP_METHOD(Tensor_Matrix, augmentRight) zephir_array_fast_append(&_27$$4, &bufferB); ZEPHIR_CALL_METHOD(&_26$$4, &bufferA, "concat", NULL, 0, &_27$$4); zephir_check_call_status(); - zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1885); + zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1895); } } ZEPHIR_CALL_CE_STATIC(&buffer, tensor_tensorbuffer_ce, "fromBuffers", NULL, 0, &c); @@ -5924,7 +5966,7 @@ PHP_METHOD(Tensor_Matrix, repeat) ZEPHIR_CONCAT_SS(&_4$$4, "Chunk length must be", " greater than 0, 0 given."); ZEPHIR_CALL_METHOD(NULL, &_3$$4, "__construct", NULL, 2, &_4$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_3$$4, "tensor/matrix.zep", 1909); + zephir_throw_exception_debug(&_3$$4, "tensor/matrix.zep", 1919); ZEPHIR_MM_RESTORE(); return; } @@ -6019,7 +6061,7 @@ PHP_METHOD(Tensor_Matrix, multiplyMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1932); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1942); ZEPHIR_MM_RESTORE(); return; } @@ -6096,7 +6138,7 @@ PHP_METHOD(Tensor_Matrix, divideMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1951); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1961); ZEPHIR_MM_RESTORE(); return; } @@ -6173,7 +6215,7 @@ PHP_METHOD(Tensor_Matrix, addMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1970); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1980); ZEPHIR_MM_RESTORE(); return; } @@ -6250,7 +6292,7 @@ PHP_METHOD(Tensor_Matrix, subtractMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1989); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1999); ZEPHIR_MM_RESTORE(); return; } @@ -6328,7 +6370,7 @@ PHP_METHOD(Tensor_Matrix, powMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2009); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2019); ZEPHIR_MM_RESTORE(); return; } @@ -6406,7 +6448,7 @@ PHP_METHOD(Tensor_Matrix, modMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2029); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2039); ZEPHIR_MM_RESTORE(); return; } @@ -6484,7 +6526,7 @@ PHP_METHOD(Tensor_Matrix, equalMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2049); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2059); ZEPHIR_MM_RESTORE(); return; } @@ -6561,7 +6603,7 @@ PHP_METHOD(Tensor_Matrix, notEqualMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2068); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2078); ZEPHIR_MM_RESTORE(); return; } @@ -6639,7 +6681,7 @@ PHP_METHOD(Tensor_Matrix, greaterMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2088); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2098); ZEPHIR_MM_RESTORE(); return; } @@ -6717,7 +6759,7 @@ PHP_METHOD(Tensor_Matrix, greaterEqualMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2108); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2118); ZEPHIR_MM_RESTORE(); return; } @@ -6794,7 +6836,7 @@ PHP_METHOD(Tensor_Matrix, lessMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2127); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2137); ZEPHIR_MM_RESTORE(); return; } @@ -6871,7 +6913,7 @@ PHP_METHOD(Tensor_Matrix, lessEqualMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2146); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2156); ZEPHIR_MM_RESTORE(); return; } @@ -6953,7 +6995,7 @@ PHP_METHOD(Tensor_Matrix, multiplyVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2166); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2176); ZEPHIR_MM_RESTORE(); return; } @@ -7036,7 +7078,7 @@ PHP_METHOD(Tensor_Matrix, divideVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2186); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2196); ZEPHIR_MM_RESTORE(); return; } @@ -7119,7 +7161,7 @@ PHP_METHOD(Tensor_Matrix, addVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2206); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2216); ZEPHIR_MM_RESTORE(); return; } @@ -7202,7 +7244,7 @@ PHP_METHOD(Tensor_Matrix, subtractVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2226); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2236); ZEPHIR_MM_RESTORE(); return; } @@ -7285,7 +7327,7 @@ PHP_METHOD(Tensor_Matrix, powVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2246); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2256); ZEPHIR_MM_RESTORE(); return; } @@ -7368,7 +7410,7 @@ PHP_METHOD(Tensor_Matrix, modVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2266); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2276); ZEPHIR_MM_RESTORE(); return; } @@ -7452,7 +7494,7 @@ PHP_METHOD(Tensor_Matrix, equalVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2287); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2297); ZEPHIR_MM_RESTORE(); return; } @@ -7535,7 +7577,7 @@ PHP_METHOD(Tensor_Matrix, notEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2307); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2317); ZEPHIR_MM_RESTORE(); return; } @@ -7618,7 +7660,7 @@ PHP_METHOD(Tensor_Matrix, greaterVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2327); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2337); ZEPHIR_MM_RESTORE(); return; } @@ -7701,7 +7743,7 @@ PHP_METHOD(Tensor_Matrix, greaterEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2347); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2357); ZEPHIR_MM_RESTORE(); return; } @@ -7784,7 +7826,7 @@ PHP_METHOD(Tensor_Matrix, lessVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2367); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2377); ZEPHIR_MM_RESTORE(); return; } @@ -7868,7 +7910,7 @@ PHP_METHOD(Tensor_Matrix, lessEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2388); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2398); ZEPHIR_MM_RESTORE(); return; } @@ -7951,7 +7993,7 @@ PHP_METHOD(Tensor_Matrix, multiplyColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2408); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2418); ZEPHIR_MM_RESTORE(); return; } @@ -8034,7 +8076,7 @@ PHP_METHOD(Tensor_Matrix, divideColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2428); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2438); ZEPHIR_MM_RESTORE(); return; } @@ -8117,7 +8159,7 @@ PHP_METHOD(Tensor_Matrix, addColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2448); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2458); ZEPHIR_MM_RESTORE(); return; } @@ -8200,7 +8242,7 @@ PHP_METHOD(Tensor_Matrix, subtractColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2468); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2478); ZEPHIR_MM_RESTORE(); return; } @@ -8283,7 +8325,7 @@ PHP_METHOD(Tensor_Matrix, powColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2488); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2498); ZEPHIR_MM_RESTORE(); return; } @@ -8366,7 +8408,7 @@ PHP_METHOD(Tensor_Matrix, modColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2508); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2518); ZEPHIR_MM_RESTORE(); return; } @@ -8449,7 +8491,7 @@ PHP_METHOD(Tensor_Matrix, equalColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2528); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2538); ZEPHIR_MM_RESTORE(); return; } @@ -8532,7 +8574,7 @@ PHP_METHOD(Tensor_Matrix, notEqualColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2548); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2558); ZEPHIR_MM_RESTORE(); return; } @@ -8615,7 +8657,7 @@ PHP_METHOD(Tensor_Matrix, greaterColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2568); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2578); ZEPHIR_MM_RESTORE(); return; } @@ -8698,7 +8740,7 @@ PHP_METHOD(Tensor_Matrix, greaterEqualColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2588); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2598); ZEPHIR_MM_RESTORE(); return; } @@ -8781,7 +8823,7 @@ PHP_METHOD(Tensor_Matrix, lessColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2608); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2618); ZEPHIR_MM_RESTORE(); return; } @@ -8864,7 +8906,7 @@ PHP_METHOD(Tensor_Matrix, lessEqualColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2628); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2638); ZEPHIR_MM_RESTORE(); return; } @@ -9516,7 +9558,7 @@ PHP_METHOD(Tensor_Matrix, offsetSet) Z_PARAM_ZVAL(values) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(2, 0, &index, &values); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2809); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2819); return; } @@ -9567,7 +9609,7 @@ PHP_METHOD(Tensor_Matrix, offsetUnset) Z_PARAM_ZVAL(index) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(1, 0, &index); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2833); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2843); return; } @@ -9627,7 +9669,7 @@ PHP_METHOD(Tensor_Matrix, offsetGet) ZEPHIR_CONCAT_SSVS(&_2$$3, "Row offset must be", " an integer, ", &_1$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 2847); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 2857); ZEPHIR_MM_RESTORE(); return; } @@ -9644,7 +9686,7 @@ PHP_METHOD(Tensor_Matrix, offsetGet) ZEPHIR_CONCAT_SSVS(&_7$$4, "Row offset out of", " bounds, ", &_6$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_7$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 2852); + zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 2862); ZEPHIR_MM_RESTORE(); return; } @@ -9771,30 +9813,30 @@ PHP_METHOD(Tensor_Matrix, __unserialize) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &data_param); zephir_get_arrval(&data, data_param); - zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2895); + zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2905); ZVAL_BOOL(&_1, 0); ZEPHIR_CALL_SELF(&a, "fromArray", NULL, 0, &_0, &_1); zephir_check_call_status(); - zephir_array_fetch_string(&_2, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2897); + zephir_array_fetch_string(&_2, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2907); ZEPHIR_CALL_METHOD(&_3, &a, "m", NULL, 0); zephir_check_call_status(); _4 = !ZEPHIR_IS_EQUAL(&_2, &_3); if (!(_4)) { - zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2897); + zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2907); ZEPHIR_CALL_METHOD(&_6, &a, "n", NULL, 0); zephir_check_call_status(); _4 = !ZEPHIR_IS_EQUAL(&_5, &_6); } if (UNEXPECTED(_4)) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid matrix data.", "tensor/matrix.zep", 2898); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid matrix data.", "tensor/matrix.zep", 2908); return; } ZEPHIR_CALL_METHOD(&_7, &a, "buffer", NULL, 0); zephir_check_call_status(); zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 15, &_7); - zephir_array_fetch_string(&_8, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2902); + zephir_array_fetch_string(&_8, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2912); zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 16, &_8); - zephir_array_fetch_string(&_9, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2903); + zephir_array_fetch_string(&_9, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2913); zephir_update_property_zval_cached(this_ptr, _zephir_prop_2, 17, &_9); ZEPHIR_MM_RESTORE(); } diff --git a/ext/tensor/matrix.zep.h b/ext/tensor/matrix.zep.h index 1e2d74d..7b8e7f2 100644 --- a/ext/tensor/matrix.zep.h +++ b/ext/tensor/matrix.zep.h @@ -76,6 +76,7 @@ PHP_METHOD(Tensor_Matrix, expm1); PHP_METHOD(Tensor_Matrix, log); PHP_METHOD(Tensor_Matrix, log1p); PHP_METHOD(Tensor_Matrix, sigmoid); +PHP_METHOD(Tensor_Matrix, softplus); PHP_METHOD(Tensor_Matrix, sin); PHP_METHOD(Tensor_Matrix, asin); PHP_METHOD(Tensor_Matrix, cos); @@ -435,6 +436,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_sigmoid, 0, 0, Tensor\\Matrix, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_softplus, 0, 0, Tensor\\Matrix, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_sin, 0, 0, Tensor\\Matrix, 0) ZEND_END_ARG_INFO() @@ -848,6 +852,7 @@ ZEPHIR_INIT_FUNCS(tensor_matrix_method_entry) { PHP_ME(Tensor_Matrix, log, arginfo_tensor_matrix_log, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, log1p, arginfo_tensor_matrix_log1p, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, sigmoid, arginfo_tensor_matrix_sigmoid, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Matrix, softplus, arginfo_tensor_matrix_softplus, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, sin, arginfo_tensor_matrix_sin, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, asin, arginfo_tensor_matrix_asin, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, cos, arginfo_tensor_matrix_cos, ZEND_ACC_PUBLIC) diff --git a/ext/tensor/unary.zep.c b/ext/tensor/unary.zep.c index 81acfb1..082b2d9 100644 --- a/ext/tensor/unary.zep.c +++ b/ext/tensor/unary.zep.c @@ -70,6 +70,12 @@ ZEPHIR_DOC_METHOD(Tensor_Unary, log1p); * @return mixed */ ZEPHIR_DOC_METHOD(Tensor_Unary, sigmoid); +/** + * Return the element-wise softplus i.e. log(1 + exp(x)). + * + * @return mixed + */ +ZEPHIR_DOC_METHOD(Tensor_Unary, softplus); /** * Round the elements in the tensor to a given decimal place. * diff --git a/ext/tensor/unary.zep.h b/ext/tensor/unary.zep.h index 4e75644..f0c7bbb 100644 --- a/ext/tensor/unary.zep.h +++ b/ext/tensor/unary.zep.h @@ -28,6 +28,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_unary_sigmoid, 0, 0, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_unary_softplus, 0, 0, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_unary_round, 0, 0, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, precision, IS_LONG, 0, "0") ZEND_END_ARG_INFO() @@ -66,6 +69,7 @@ ZEPHIR_INIT_FUNCS(tensor_unary_method_entry) { PHP_ABSTRACT_ME(Tensor_Unary, log, arginfo_tensor_unary_log) PHP_ABSTRACT_ME(Tensor_Unary, log1p, arginfo_tensor_unary_log1p) PHP_ABSTRACT_ME(Tensor_Unary, sigmoid, arginfo_tensor_unary_sigmoid) + PHP_ABSTRACT_ME(Tensor_Unary, softplus, arginfo_tensor_unary_softplus) PHP_ABSTRACT_ME(Tensor_Unary, round, arginfo_tensor_unary_round) PHP_ABSTRACT_ME(Tensor_Unary, floor, arginfo_tensor_unary_floor) PHP_ABSTRACT_ME(Tensor_Unary, ceil, arginfo_tensor_unary_ceil) diff --git a/ext/tensor/vector.zep.c b/ext/tensor/vector.zep.c index 8773d18..1fc4f80 100644 --- a/ext/tensor/vector.zep.c +++ b/ext/tensor/vector.zep.c @@ -2601,6 +2601,36 @@ PHP_METHOD(Tensor_Vector, sigmoid) RETURN_MM(); } +/** + * Return the element-wise softplus i.e. log(1 + exp(x)). + * + * @return self + */ +PHP_METHOD(Tensor_Vector, softplus) +{ + zval _0, _1; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + object_init_ex(return_value, zend_get_called_scope(execute_data)); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_softplus(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 3, &_0); + zephir_check_call_status(); + RETURN_MM(); +} + /** * Return the sine of this vector. * @@ -2992,7 +3022,7 @@ PHP_METHOD(Tensor_Vector, min) ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the minimum of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1137); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1147); ZEPHIR_MM_RESTORE(); return; } @@ -3048,7 +3078,7 @@ PHP_METHOD(Tensor_Vector, max) ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the maximum of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1154); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1164); ZEPHIR_MM_RESTORE(); return; } @@ -3104,7 +3134,7 @@ PHP_METHOD(Tensor_Vector, argmin) ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the argmin of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1171); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1181); ZEPHIR_MM_RESTORE(); return; } @@ -3160,7 +3190,7 @@ PHP_METHOD(Tensor_Vector, argmax) ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the argmax of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1188); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1198); ZEPHIR_MM_RESTORE(); return; } @@ -3243,7 +3273,7 @@ PHP_METHOD(Tensor_Vector, median) ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the median of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1215); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1225); ZEPHIR_MM_RESTORE(); return; } @@ -3315,7 +3345,7 @@ PHP_METHOD(Tensor_Vector, quantile) ZEPHIR_CONCAT_SS(&_3$$3, "Q must be a finite value", " between 0 and 1."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1234); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1244); ZEPHIR_MM_RESTORE(); return; } @@ -3333,7 +3363,7 @@ PHP_METHOD(Tensor_Vector, quantile) ZEPHIR_CONCAT_SSVS(&_8$$4, "Q must be", " between 0 and 1, ", &_7$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_8$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/vector.zep", 1239); + zephir_throw_exception_debug(&_5$$4, "tensor/vector.zep", 1249); ZEPHIR_MM_RESTORE(); return; } @@ -3345,7 +3375,7 @@ PHP_METHOD(Tensor_Vector, quantile) ZEPHIR_CONCAT_SS(&_10$$5, "Cannot compute", " the quantile of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_9$$5, "__construct", NULL, 2, &_10$$5); zephir_check_call_status(); - zephir_throw_exception_debug(&_9$$5, "tensor/vector.zep", 1244); + zephir_throw_exception_debug(&_9$$5, "tensor/vector.zep", 1254); ZEPHIR_MM_RESTORE(); return; } @@ -3454,7 +3484,7 @@ PHP_METHOD(Tensor_Vector, variance) ZEPHIR_CONCAT_SSVS(&_3$$4, "Mean scalar must be", " a floating point number ", &_2$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_1$$4, "__construct", NULL, 2, &_3$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$4, "tensor/vector.zep", 1277); + zephir_throw_exception_debug(&_1$$4, "tensor/vector.zep", 1287); ZEPHIR_MM_RESTORE(); return; } @@ -3520,7 +3550,7 @@ PHP_METHOD(Tensor_Vector, round) ZEPHIR_CONCAT_SSVS(&_3$$3, "Decimal precision cannot", " be less than 0, ", &_2$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1301); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1311); ZEPHIR_MM_RESTORE(); return; } @@ -3697,7 +3727,7 @@ PHP_METHOD(Tensor_Vector, clip) ZEPHIR_CONCAT_SS(&_1$$3, "Minimum cannot be", " greater than maximum."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_1$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1360); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1370); ZEPHIR_MM_RESTORE(); return; } @@ -3849,7 +3879,7 @@ PHP_METHOD(Tensor_Vector, multiplyMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1400); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1410); ZEPHIR_MM_RESTORE(); return; } @@ -3929,7 +3959,7 @@ PHP_METHOD(Tensor_Vector, divideMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1420); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1430); ZEPHIR_MM_RESTORE(); return; } @@ -4009,7 +4039,7 @@ PHP_METHOD(Tensor_Vector, addMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1440); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1450); ZEPHIR_MM_RESTORE(); return; } @@ -4089,7 +4119,7 @@ PHP_METHOD(Tensor_Vector, subtractMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1460); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1470); ZEPHIR_MM_RESTORE(); return; } @@ -4169,7 +4199,7 @@ PHP_METHOD(Tensor_Vector, powMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1480); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1490); ZEPHIR_MM_RESTORE(); return; } @@ -4249,7 +4279,7 @@ PHP_METHOD(Tensor_Vector, modMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1500); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1510); ZEPHIR_MM_RESTORE(); return; } @@ -4329,7 +4359,7 @@ PHP_METHOD(Tensor_Vector, equalMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1520); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1530); ZEPHIR_MM_RESTORE(); return; } @@ -4409,7 +4439,7 @@ PHP_METHOD(Tensor_Vector, notEqualMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1540); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1550); ZEPHIR_MM_RESTORE(); return; } @@ -4489,7 +4519,7 @@ PHP_METHOD(Tensor_Vector, greaterMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1560); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1570); ZEPHIR_MM_RESTORE(); return; } @@ -4569,7 +4599,7 @@ PHP_METHOD(Tensor_Vector, greaterEqualMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1580); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1590); ZEPHIR_MM_RESTORE(); return; } @@ -4649,7 +4679,7 @@ PHP_METHOD(Tensor_Vector, lessMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1600); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1610); ZEPHIR_MM_RESTORE(); return; } @@ -4729,7 +4759,7 @@ PHP_METHOD(Tensor_Vector, lessEqualMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1620); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1630); ZEPHIR_MM_RESTORE(); return; } @@ -4806,7 +4836,7 @@ PHP_METHOD(Tensor_Vector, multiplyVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1640); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1650); ZEPHIR_MM_RESTORE(); return; } @@ -4879,7 +4909,7 @@ PHP_METHOD(Tensor_Vector, divideVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1658); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1668); ZEPHIR_MM_RESTORE(); return; } @@ -4952,7 +4982,7 @@ PHP_METHOD(Tensor_Vector, addVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1676); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1686); ZEPHIR_MM_RESTORE(); return; } @@ -5025,7 +5055,7 @@ PHP_METHOD(Tensor_Vector, subtractVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1694); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1704); ZEPHIR_MM_RESTORE(); return; } @@ -5098,7 +5128,7 @@ PHP_METHOD(Tensor_Vector, powVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1712); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1722); ZEPHIR_MM_RESTORE(); return; } @@ -5171,7 +5201,7 @@ PHP_METHOD(Tensor_Vector, modVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1730); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1740); ZEPHIR_MM_RESTORE(); return; } @@ -5245,7 +5275,7 @@ PHP_METHOD(Tensor_Vector, equalVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1749); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1759); ZEPHIR_MM_RESTORE(); return; } @@ -5318,7 +5348,7 @@ PHP_METHOD(Tensor_Vector, notEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1767); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1777); ZEPHIR_MM_RESTORE(); return; } @@ -5391,7 +5421,7 @@ PHP_METHOD(Tensor_Vector, greaterVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1785); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1795); ZEPHIR_MM_RESTORE(); return; } @@ -5464,7 +5494,7 @@ PHP_METHOD(Tensor_Vector, greaterEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1803); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1813); ZEPHIR_MM_RESTORE(); return; } @@ -5537,7 +5567,7 @@ PHP_METHOD(Tensor_Vector, lessVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1821); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1831); ZEPHIR_MM_RESTORE(); return; } @@ -5610,7 +5640,7 @@ PHP_METHOD(Tensor_Vector, lessEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1839); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1849); ZEPHIR_MM_RESTORE(); return; } @@ -6110,7 +6140,7 @@ PHP_METHOD(Tensor_Vector, offsetSet) Z_PARAM_ZVAL(values) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(2, 0, &index, &values); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 1996); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2006); return; } @@ -6161,7 +6191,7 @@ PHP_METHOD(Tensor_Vector, offsetUnset) Z_PARAM_ZVAL(index) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(1, 0, &index); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2020); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2030); return; } @@ -6219,7 +6249,7 @@ PHP_METHOD(Tensor_Vector, offsetGet) ZEPHIR_CONCAT_SSVS(&_5$$3, "Element not found at", " offset ", &_4$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_3$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_3$$3, "tensor/vector.zep", 2034); + zephir_throw_exception_debug(&_3$$3, "tensor/vector.zep", 2044); ZEPHIR_MM_RESTORE(); return; } @@ -6330,21 +6360,21 @@ PHP_METHOD(Tensor_Vector, __unserialize) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &data_param); zephir_get_arrval(&data, data_param); - zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2075); + zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2085); ZVAL_BOOL(&_1, 0); ZEPHIR_CALL_SELF(&a, "fromArray", NULL, 0, &_0, &_1); zephir_check_call_status(); - zephir_array_fetch_string(&_2, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2077); + zephir_array_fetch_string(&_2, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2087); ZEPHIR_CALL_METHOD(&_3, &a, "size", NULL, 0); zephir_check_call_status(); if (UNEXPECTED(!ZEPHIR_IS_EQUAL(&_2, &_3))) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid vector data.", "tensor/vector.zep", 2078); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid vector data.", "tensor/vector.zep", 2088); return; } ZEPHIR_CALL_METHOD(&_4, &a, "buffer", NULL, 0); zephir_check_call_status(); zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 1, &_4); - zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2082); + zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2092); zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 2, &_5); ZEPHIR_MM_RESTORE(); } diff --git a/ext/tensor/vector.zep.h b/ext/tensor/vector.zep.h index 191f788..6093301 100644 --- a/ext/tensor/vector.zep.h +++ b/ext/tensor/vector.zep.h @@ -59,6 +59,7 @@ PHP_METHOD(Tensor_Vector, expm1); PHP_METHOD(Tensor_Vector, log); PHP_METHOD(Tensor_Vector, log1p); PHP_METHOD(Tensor_Vector, sigmoid); +PHP_METHOD(Tensor_Vector, softplus); PHP_METHOD(Tensor_Vector, sin); PHP_METHOD(Tensor_Vector, asin); PHP_METHOD(Tensor_Vector, cos); @@ -345,6 +346,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_sigmoid, 0, 0, Tensor\\Vector, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_softplus, 0, 0, Tensor\\Vector, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_sin, 0, 0, Tensor\\Vector, 0) ZEND_END_ARG_INFO() @@ -669,6 +673,7 @@ PHP_ME(Tensor_Vector, transpose, arginfo_tensor_vector_transpose, ZEND_ACC_PUBLI PHP_ME(Tensor_Vector, log, arginfo_tensor_vector_log, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, log1p, arginfo_tensor_vector_log1p, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, sigmoid, arginfo_tensor_vector_sigmoid, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Vector, softplus, arginfo_tensor_vector_softplus, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, sin, arginfo_tensor_vector_sin, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, asin, arginfo_tensor_vector_asin, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, cos, arginfo_tensor_vector_cos, ZEND_ACC_PUBLIC) diff --git a/optimizers/TensorSoftplusOptimizer.php b/optimizers/TensorSoftplusOptimizer.php new file mode 100644 index 0000000..ae1adcb --- /dev/null +++ b/optimizers/TensorSoftplusOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_softplus($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/tensor/matrix.zep b/tensor/matrix.zep index 0a35be4..67cbf73 100644 --- a/tensor/matrix.zep +++ b/tensor/matrix.zep @@ -1428,7 +1428,17 @@ class Matrix implements Tensor { return new self(tensor_sigmoid(this->a), this->m, this->n); } - + + /** + * Return the element-wise softplus i.e. log(1 + exp(x)). + * + * @return self + */ + public function softplus() -> + { + return new self(tensor_softplus(this->a), this->m, this->n); + } + /** * Return the sine of the matrix. * diff --git a/tensor/unary.zep b/tensor/unary.zep index 681127c..980e072 100644 --- a/tensor/unary.zep +++ b/tensor/unary.zep @@ -61,6 +61,13 @@ interface Unary */ public function sigmoid(); + /** + * Return the element-wise softplus i.e. log(1 + exp(x)). + * + * @return mixed + */ + public function softplus(); + /** * Round the elements in the tensor to a given decimal place. * diff --git a/tensor/vector.zep b/tensor/vector.zep index fd8920e..2c47634 100644 --- a/tensor/vector.zep +++ b/tensor/vector.zep @@ -1011,6 +1011,16 @@ class Vector implements Tensor return new static(tensor_sigmoid(this->a)); } + /** + * Return the element-wise softplus i.e. log(1 + exp(x)). + * + * @return self + */ + public function softplus() -> + { + return new static(tensor_softplus(this->a)); + } + /** * Return the sine of this vector. * diff --git a/tests/ColumnVectorTest.php b/tests/ColumnVectorTest.php index 6e3be6f..2e13c32 100644 --- a/tests/ColumnVectorTest.php +++ b/tests/ColumnVectorTest.php @@ -438,6 +438,17 @@ public function sigmoidReturnsColumnVector() : void $this->assertEqualsWithDelta([0.7310585786300049, 0.2689414213699951, 0.5], $b->asArray(), 1e-8); } + /** + * @test + */ + public function softplusReturnsColumnVector() : void + { + $b = ColumnVector::fromArray([1.0, -1.0, 0.0])->softplus(); + + $this->assertInstanceOf(ColumnVector::class, $b); + $this->assertEqualsWithDelta([1.3132616875182, 0.31326168751822, 0.69314718055995], $b->asArray(), 1e-8); + } + /** * @test */ diff --git a/tests/MatrixTest.php b/tests/MatrixTest.php index 06fa02b..dab2d0a 100644 --- a/tests/MatrixTest.php +++ b/tests/MatrixTest.php @@ -3653,6 +3653,69 @@ public function sigmoidMatchesComposition() : void ); } + /** + * @test + */ + public function softplus() : void + { + $a = Matrix::fromArray([ + [13.0, 1.0, -13.0, 0.5], + [11.0, -1.0, -11.0, -0.5], + [9.0, 0.0, -9.0, 2.5], + ]); + + $b = $a->softplus(); + + $expected = Matrix::fromArray([ + [13.000002260327, 1.3132616875182, 2.2603268524372e-6, 0.97407698418011], + [11.000016701561, 0.31326168751822, 1.6701561318304e-5, 0.47407698418011], + [9.0001234021897, 0.69314718055995, 0.00012340218972334, 2.5788897342925], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); + } + + /** + * A large positive input must not overflow the exponential that softplus + * evaluates and must saturate to x, and a large negative one to 0. + * + * @test + */ + public function softplusSaturates() : void + { + $a = Matrix::fromArray([ + [-800.0, 800.0, -1000.0], + [-745.0, 745.0, 0.0], + ]); + + $b = $a->softplus()->asArray(); + + $this->assertLessThan(1e-300, $b[0][0]); + $this->assertSame(800.0, $b[0][1]); + $this->assertLessThan(1e-300, $b[0][2]); + $this->assertLessThan(1e-300, $b[1][0]); + $this->assertSame(745.0, $b[1][1]); + $this->assertEqualsWithDelta(log(2.0), $b[1][2], self::MAX_DELTA); + } + + /** + * The fused kernel must agree with the composition it replaces, elementwise. + * + * @test + */ + public function softplusMatchesComposition() : void + { + $a = Matrix::rand(17, 23)->multiply(8.0)->subtract(4.0); + + $e = $a->exp(); + + $this->assertEqualsWithDelta( + $e->add(1.0)->log()->asArray(), + $a->softplus()->asArray(), + self::MAX_DELTA + ); + } + /** * @test */ diff --git a/tests/VectorTest.php b/tests/VectorTest.php index c22942c..606d31a 100644 --- a/tests/VectorTest.php +++ b/tests/VectorTest.php @@ -146,6 +146,7 @@ public function unaryInterfaceSurface() : void 'round', 'sigmoid', 'sign', + 'softplus', 'sqrt', 'square', ], $methods); @@ -2114,6 +2115,59 @@ public function sigmoidMatchesComposition() : void ); } + /** + * @test + */ + public function softplus() : void + { + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + + $b = $a->softplus(); + + $expected = Vector::fromArray([ + 4.0181499279178, 6.5015023101598, 2.953562776218, + 20.000000002061, 2.6716446919677, 11.900006790382, + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); + } + + /** + * A large positive input must not overflow the exponential that softplus + * evaluates and must saturate to x, and a large negative one to 0. + * + * @test + */ + public function softplusSaturates() : void + { + $a = Vector::fromArray([-800.0, 800.0, 0.0, -1000.0]); + + $b = $a->softplus()->asArray(); + + $this->assertSame(0.0, $b[0]); + $this->assertSame(800.0, $b[1]); + $this->assertEqualsWithDelta(log(2.0), $b[2], self::MAX_DELTA); + $this->assertSame(0.0, $b[3]); + } + + /** + * The fused kernel must agree with the composition it replaces, elementwise. + * + * @test + */ + public function softplusMatchesComposition() : void + { + $a = Vector::rand(257)->multiply(8.0)->subtract(4.0); + + $e = $a->exp(); + + $this->assertEqualsWithDelta( + $e->add(1.0)->log()->asArray(), + $a->softplus()->asArray(), + self::MAX_DELTA + ); + } + /** * @test */ From becbe92f5db31747aa12f0709edde75dd7c3ea59 Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Tue, 6 Oct 2026 20:46:48 -0500 Subject: [PATCH 02/14] Add erf, cerf, cosh, and sinh --- docs/Matrix.md | 6 +- docs/Vector.md | 6 +- docs/index.md | 2 +- docs/interfaces/special.md | 20 +- docs/interfaces/tensor.md | 7 +- docs/interfaces/trigonometric.md | 12 ++ ext/include/unary.c | 4 + ext/include/unary.h | 4 + ext/tensor/matrix.zep.c | 287 +++++++++++++++++++++++------ ext/tensor/matrix.zep.h | 20 ++ ext/tensor/special.zep.c | 13 ++ ext/tensor/special.zep.h | 8 + ext/tensor/trigonometric.zep.c | 12 ++ ext/tensor/trigonometric.zep.h | 8 + ext/tensor/vector.zep.c | 205 ++++++++++++++++----- ext/tensor/vector.zep.h | 20 ++ optimizers/TensorCerfOptimizer.php | 76 ++++++++ optimizers/TensorCoshOptimizer.php | 76 ++++++++ optimizers/TensorErfOptimizer.php | 76 ++++++++ optimizers/TensorSinhOptimizer.php | 76 ++++++++ tensor/matrix.zep | 41 +++++ tensor/special.zep | 15 ++ tensor/trigonometric.zep | 14 ++ tensor/vector.zep | 41 +++++ tests/ColumnVectorTest.php | 44 +++++ tests/MatrixTest.php | 154 ++++++++++++++++ tests/VectorTest.php | 133 +++++++++++++ 27 files changed, 1270 insertions(+), 110 deletions(-) create mode 100644 optimizers/TensorCerfOptimizer.php create mode 100644 optimizers/TensorCoshOptimizer.php create mode 100644 optimizers/TensorErfOptimizer.php create mode 100644 optimizers/TensorSinhOptimizer.php diff --git a/docs/Matrix.md b/docs/Matrix.md index a707992..3cacb8f 100644 --- a/docs/Matrix.md +++ b/docs/Matrix.md @@ -446,6 +446,8 @@ See [Trigonometric](interfaces/trigonometric.md). Each method returns a new `Mat - `tan()` — tangent of the matrix - `atan()` — arc tangent of the matrix - `tanh() : self` — element-wise hyperbolic tangent +- `sinh() : self` — element-wise hyperbolic sine +- `cosh() : self` — element-wise hyperbolic cosine - `rad2deg()` — convert angles from radians to degrees - `deg2rad()` — convert angles from degrees to radians @@ -467,9 +469,11 @@ See [Reductions](interfaces/reductions.md). For a `Matrix`, row-wise reductions ## Special -See [Special](interfaces/special.md). These preserve the shape of the matrix without being element-wise. +See [Special](interfaces/special.md). `softmax()` preserves the shape of the matrix; `erf()` and `cerf()` are element-wise. - `softmax() : self` — exponentials normalized so each **row** sums to `1.0`; transpose on either side to normalize each column +- `erf() : self` — element-wise Gaussian error function +- `cerf() : self` — element-wise scaled complementary error function, `exp(-x^2) * erfc(-x)` ## Array Access diff --git a/docs/Vector.md b/docs/Vector.md index d1efcff..5cdb56e 100644 --- a/docs/Vector.md +++ b/docs/Vector.md @@ -329,6 +329,8 @@ See [Trigonometric](interfaces/trigonometric.md). Each method returns a new `Vec - `tan()` — tangent of the vector - `atan()` — arc tangent of the vector - `tanh() : self` — element-wise hyperbolic tangent +- `sinh() : self` — element-wise hyperbolic sine +- `cosh() : self` — element-wise hyperbolic cosine - `rad2deg()` — convert angles from radians to degrees - `deg2rad()` — convert angles from degrees to radians @@ -349,9 +351,11 @@ See [Reductions](interfaces/reductions.md). For a `Vector` these return scalar ` ## Special -See [Special](interfaces/special.md). These preserve the shape of the vector without being element-wise. +See [Special](interfaces/special.md). `softmax()` preserves the shape of the vector; `erf()` and `cerf()` are element-wise. - `softmax() : self` — the exponentials of the vector normalized so they sum to `1.0` +- `erf() : self` — element-wise Gaussian error function +- `cerf() : self` — element-wise scaled complementary error function, `exp(-x^2) * erfc(-x)` ## Array Access diff --git a/docs/index.md b/docs/index.md index 8ee259d..6dbf77b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -55,7 +55,7 @@ Tensor \ | [Unary](interfaces/unary.md) | Element-wise unary functions, including clipping. | | [Trigonometric](interfaces/trigonometric.md) | Element-wise trigonometric functions. | | [Reductions](interfaces/reductions.md) | Aggregate reduction operations, including the statistical summaries. | -| [Special](interfaces/special.md) | Operations that preserve shape without being element-wise, such as `softmax`. | +| [Special](interfaces/special.md) | Operations that fit no other group, such as `softmax` and the error-function family `erf` / `cerf`. | ## Decompositions diff --git a/docs/interfaces/special.md b/docs/interfaces/special.md index b8d55a5..a918a56 100644 --- a/docs/interfaces/special.md +++ b/docs/interfaces/special.md @@ -6,9 +6,9 @@ Operations that do not belong to any of the other interface groups. ## Overview -`Special` holds the operations that neither pointwise element-wise functions (`Arithmetic`, `Comparable`, `Unary`, `Trigonometric`), nor aggregate reductions (`Reductions`), nor array-like access (`ArrayLike`) can describe. +`Special` holds the operations that neither the basic algebraic and trigonometric families (`Arithmetic`, `Comparable`, `Unary`, `Trigonometric`), aggregate reductions (`Reductions`), nor array-like access (`ArrayLike`) can describe. -`softmax()` is the sole member: it preserves the shape of the tensor, but each element of the output depends on a whole reduction axis rather than on one input element, so it is neither element-wise nor a reduction. +`softmax()` is the only shape-preserving member whose output depends on a whole reduction axis rather than on one input element, so it is neither element-wise nor a reduction. `erf()` and `cerf()` are element-wise error-function transforms grouped here so the error-function family stays together, distinct from the basic algebraic operations. ```php interface Special @@ -36,3 +36,19 @@ The maximum of each row is subtracted before exponentiating, so no intermediate can overflow regardless of the magnitude of the input, and a single-element row normalizes to `1.0`. Note the degenerate case this implies: a matrix with a single *column* has one-element rows, so it normalizes to all ones. + +### `erf() : mixed` + +Return the element-wise Gaussian error function. + +A large input saturates to exactly `1.0` or `-1.0` rather than returning an +infinity. + +### `cerf() : mixed` + +Return the element-wise scaled complementary error function, +`exp(-x^2) * erfc(-x)`. + +The `exp(-x^2)` factor cancels the exponential decay of `erfc(-x)`, so the +result stays finite for a large input where the plain scaled complement would +underflow to `0.0`. `cerf(0) == 1.0`. diff --git a/docs/interfaces/tensor.md b/docs/interfaces/tensor.md index 2f118f3..70f605f 100644 --- a/docs/interfaces/tensor.md +++ b/docs/interfaces/tensor.md @@ -21,15 +21,14 @@ interface Tensor extends ArrayLike, Arithmetic, Comparable, | [Arithmetic](arithmetic.md) | `multiply`, `divide`, `add`, `subtract`, `pow`, `mod` | | [Comparable](comparable.md) | `equal`, `notEqual`, `greater`, `greaterEqual`, `less`, `lessEqual` | | [Unary](unary.md) | `abs`, `square`, `sqrt`, `exp`, `expm1`, `log`, `log1p`, `sigmoid`, `softplus`, `round`, `floor`, `ceil`, `sign`, `negate`, `clip`, `clipLower`, `clipUpper` | -| [Trigonometric](trigonometric.md) | `sin`, `asin`, `cos`, `acos`, `tan`, `atan`, `tanh`, `rad2deg`, `deg2rad` | +| [Trigonometric](trigonometric.md) | `sin`, `asin`, `cos`, `acos`, `tan`, `atan`, `tanh`, `sinh`, `cosh`, `rad2deg`, `deg2rad` | | [Reductions](reductions.md) | `sum`, `product`, `min`, `max`, `argmin`, `argmax`, `mean`, `variance`, `median`, `quantile` | -| [Special](special.md) | `softmax` | +| [Special](special.md) | `softmax`, `erf`, `cerf` | Every group is homogeneous in what it does to the tensor's shape: `Arithmetic`, `Comparable`, `Unary`, and `Trigonometric` are element-wise and preserve it, `Reductions` collapse it, and `ArrayLike` is about access rather than arithmetic. -`Special` is the escape hatch for operations that preserve the shape without being -element-wise. +`Special` is the escape hatch for operations that fit no other group, such as shape-preserving cross-axis operations like `softmax()` and the element-wise error-function family `erf()` / `cerf()`. Additionally, because `ArrayLike` extends `ArrayAccess`, `IteratorAggregate`, and `Countable`, every tensor is array-accessible, iterable, and countable. diff --git a/docs/interfaces/trigonometric.md b/docs/interfaces/trigonometric.md index 334953d..213e1dc 100644 --- a/docs/interfaces/trigonometric.md +++ b/docs/interfaces/trigonometric.md @@ -52,3 +52,15 @@ Return the element-wise hyperbolic tangent. A large input saturates to exactly `1.0` or `-1.0` rather than returning an infinity. + +### `sinh() : mixed` + +Return the element-wise hyperbolic sine. + +### `cosh() : mixed` + +Return the element-wise hyperbolic cosine. + +The result is always positive, and `cosh(0) == 1.0`. For a large input it grows +as `exp(|x|) / 2`, so it can overflow to an infinity for sufficiently large +arguments. diff --git a/ext/include/unary.c b/ext/include/unary.c index 4a07a71..faf6039 100644 --- a/ext/include/unary.c +++ b/ext/include/unary.c @@ -142,6 +142,10 @@ TENSOR_UNARY(acos, acos(va[i])) TENSOR_UNARY(tan, tan(va[i])) TENSOR_UNARY(atan, atan(va[i])) TENSOR_UNARY(tanh, tanh(va[i])) +TENSOR_UNARY(sinh, sinh(va[i])) +TENSOR_UNARY(cosh, cosh(va[i])) +TENSOR_UNARY(erf, erf(va[i])) +TENSOR_UNARY(cerf, exp(-va[i] * va[i]) * erfc(-va[i])) #undef TENSOR_UNARY diff --git a/ext/include/unary.h b/ext/include/unary.h index 31235bb..542fb43 100644 --- a/ext/include/unary.h +++ b/ext/include/unary.h @@ -13,6 +13,10 @@ void tensor_log1p(zval * return_value, zval * a); void tensor_sigmoid(zval * return_value, zval * a); void tensor_softplus(zval * return_value, zval * a); void tensor_tanh(zval * return_value, zval * a); +void tensor_sinh(zval * return_value, zval * a); +void tensor_cosh(zval * return_value, zval * a); +void tensor_erf(zval * return_value, zval * a); +void tensor_cerf(zval * return_value, zval * a); void tensor_sin(zval * return_value, zval * a); void tensor_asin(zval * return_value, zval * a); void tensor_cos(zval * return_value, zval * a); diff --git a/ext/tensor/matrix.zep.c b/ext/tensor/matrix.zep.c index 5d78715..959576b 100644 --- a/ext/tensor/matrix.zep.c +++ b/ext/tensor/matrix.zep.c @@ -4261,6 +4261,90 @@ PHP_METHOD(Tensor_Matrix, tanh) RETURN_MM(); } +/** + * Return the element-wise hyperbolic sine of the matrix. + * + * @return self + */ +PHP_METHOD(Tensor_Matrix, sinh) +{ + zval _0, _1, _2, _3; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + tensor_sinh(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 17, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 18, &_0, &_2, &_3); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return the element-wise hyperbolic cosine of the matrix. + * + * @return self + */ +PHP_METHOD(Tensor_Matrix, cosh) +{ + zval _0, _1, _2, _3; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + tensor_cosh(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 17, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 18, &_0, &_2, &_3); + zephir_check_call_status(); + RETURN_MM(); +} + /** * Convert angles from radians to degrees. * @@ -4708,7 +4792,7 @@ PHP_METHOD(Tensor_Matrix, quantile) ZEPHIR_CONCAT_SS(&_3$$3, "Q must be a finite value", " between 0 and 1."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1623); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1643); ZEPHIR_MM_RESTORE(); return; } @@ -4726,7 +4810,7 @@ PHP_METHOD(Tensor_Matrix, quantile) ZEPHIR_CONCAT_SSVS(&_8$$4, "Q must be between", " 0 and 1, ", &_7$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_8$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 1628); + zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 1648); ZEPHIR_MM_RESTORE(); return; } @@ -4784,6 +4868,91 @@ PHP_METHOD(Tensor_Matrix, softmax) RETURN_MM(); } +/** + * Return the element-wise Gaussian error function. + * + * @return self + */ +PHP_METHOD(Tensor_Matrix, erf) +{ + zval _0, _1, _2, _3; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + tensor_erf(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 17, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 18, &_0, &_2, &_3); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return the element-wise scaled complementary error function, + * i.e. exp(-x^2) * erfc(-x). + * + * @return self + */ +PHP_METHOD(Tensor_Matrix, cerf) +{ + zval _0, _1, _2, _3; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + tensor_cerf(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 17, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 18, &_0, &_2, &_3); + zephir_check_call_status(); + RETURN_MM(); +} + /** * Compute the row variance of the matrix. * @@ -4844,7 +5013,7 @@ PHP_METHOD(Tensor_Matrix, variance) ZEPHIR_CONCAT_SSVS(&_2$$4, "Mean must be a", " column vector ", &_1$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$4, "__construct", NULL, 2, &_2$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$4, "tensor/matrix.zep", 1657); + zephir_throw_exception_debug(&_0$$4, "tensor/matrix.zep", 1698); ZEPHIR_MM_RESTORE(); return; } @@ -4864,7 +5033,7 @@ PHP_METHOD(Tensor_Matrix, variance) ZEPHIR_CONCAT_SSVSVS(&_10$$5, "Mean vector must", " have ", &_7$$5, " rows, ", &_9$$5, " given."); ZEPHIR_CALL_METHOD(NULL, &_5$$5, "__construct", NULL, 2, &_10$$5); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$5, "tensor/matrix.zep", 1663); + zephir_throw_exception_debug(&_5$$5, "tensor/matrix.zep", 1704); ZEPHIR_MM_RESTORE(); return; } @@ -4983,7 +5152,7 @@ PHP_METHOD(Tensor_Matrix, round) ZEPHIR_CONCAT_SSVS(&_3$$3, "Decimal precision cannot", " be less than 0, ", &_2$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1694); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1735); ZEPHIR_MM_RESTORE(); return; } @@ -5220,7 +5389,7 @@ PHP_METHOD(Tensor_Matrix, clip) ZEPHIR_CONCAT_SS(&_1$$3, "Minimum cannot be", " greater than maximum."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_1$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1753); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1794); ZEPHIR_MM_RESTORE(); return; } @@ -5420,7 +5589,7 @@ PHP_METHOD(Tensor_Matrix, augmentAbove) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " columns but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1799); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1840); ZEPHIR_MM_RESTORE(); return; } @@ -5537,7 +5706,7 @@ PHP_METHOD(Tensor_Matrix, augmentBelow) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " columns but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1821); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1862); ZEPHIR_MM_RESTORE(); return; } @@ -5664,7 +5833,7 @@ PHP_METHOD(Tensor_Matrix, augmentLeft) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " rows but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1843); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1884); ZEPHIR_MM_RESTORE(); return; } @@ -5717,7 +5886,7 @@ PHP_METHOD(Tensor_Matrix, augmentLeft) zephir_array_fast_append(&_27$$4, &bufferA); ZEPHIR_CALL_METHOD(&_26$$4, &bufferB, "concat", &_28, 0, &_27$$4); zephir_check_call_status(); - zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1859); + zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1900); } } ZEPHIR_CALL_CE_STATIC(&buffer, tensor_tensorbuffer_ce, "fromBuffers", NULL, 0, &c); @@ -5827,7 +5996,7 @@ PHP_METHOD(Tensor_Matrix, augmentRight) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " rows but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1879); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1920); ZEPHIR_MM_RESTORE(); return; } @@ -5880,7 +6049,7 @@ PHP_METHOD(Tensor_Matrix, augmentRight) zephir_array_fast_append(&_27$$4, &bufferB); ZEPHIR_CALL_METHOD(&_26$$4, &bufferA, "concat", NULL, 0, &_27$$4); zephir_check_call_status(); - zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1895); + zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1936); } } ZEPHIR_CALL_CE_STATIC(&buffer, tensor_tensorbuffer_ce, "fromBuffers", NULL, 0, &c); @@ -5966,7 +6135,7 @@ PHP_METHOD(Tensor_Matrix, repeat) ZEPHIR_CONCAT_SS(&_4$$4, "Chunk length must be", " greater than 0, 0 given."); ZEPHIR_CALL_METHOD(NULL, &_3$$4, "__construct", NULL, 2, &_4$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_3$$4, "tensor/matrix.zep", 1919); + zephir_throw_exception_debug(&_3$$4, "tensor/matrix.zep", 1960); ZEPHIR_MM_RESTORE(); return; } @@ -6061,7 +6230,7 @@ PHP_METHOD(Tensor_Matrix, multiplyMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1942); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1983); ZEPHIR_MM_RESTORE(); return; } @@ -6138,7 +6307,7 @@ PHP_METHOD(Tensor_Matrix, divideMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1961); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2002); ZEPHIR_MM_RESTORE(); return; } @@ -6215,7 +6384,7 @@ PHP_METHOD(Tensor_Matrix, addMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1980); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2021); ZEPHIR_MM_RESTORE(); return; } @@ -6292,7 +6461,7 @@ PHP_METHOD(Tensor_Matrix, subtractMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1999); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2040); ZEPHIR_MM_RESTORE(); return; } @@ -6370,7 +6539,7 @@ PHP_METHOD(Tensor_Matrix, powMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2019); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2060); ZEPHIR_MM_RESTORE(); return; } @@ -6448,7 +6617,7 @@ PHP_METHOD(Tensor_Matrix, modMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2039); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2080); ZEPHIR_MM_RESTORE(); return; } @@ -6526,7 +6695,7 @@ PHP_METHOD(Tensor_Matrix, equalMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2059); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2100); ZEPHIR_MM_RESTORE(); return; } @@ -6603,7 +6772,7 @@ PHP_METHOD(Tensor_Matrix, notEqualMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2078); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2119); ZEPHIR_MM_RESTORE(); return; } @@ -6681,7 +6850,7 @@ PHP_METHOD(Tensor_Matrix, greaterMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2098); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2139); ZEPHIR_MM_RESTORE(); return; } @@ -6759,7 +6928,7 @@ PHP_METHOD(Tensor_Matrix, greaterEqualMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2118); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2159); ZEPHIR_MM_RESTORE(); return; } @@ -6836,7 +7005,7 @@ PHP_METHOD(Tensor_Matrix, lessMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2137); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2178); ZEPHIR_MM_RESTORE(); return; } @@ -6913,7 +7082,7 @@ PHP_METHOD(Tensor_Matrix, lessEqualMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2156); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2197); ZEPHIR_MM_RESTORE(); return; } @@ -6995,7 +7164,7 @@ PHP_METHOD(Tensor_Matrix, multiplyVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2176); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2217); ZEPHIR_MM_RESTORE(); return; } @@ -7078,7 +7247,7 @@ PHP_METHOD(Tensor_Matrix, divideVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2196); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2237); ZEPHIR_MM_RESTORE(); return; } @@ -7161,7 +7330,7 @@ PHP_METHOD(Tensor_Matrix, addVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2216); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2257); ZEPHIR_MM_RESTORE(); return; } @@ -7244,7 +7413,7 @@ PHP_METHOD(Tensor_Matrix, subtractVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2236); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2277); ZEPHIR_MM_RESTORE(); return; } @@ -7327,7 +7496,7 @@ PHP_METHOD(Tensor_Matrix, powVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2256); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2297); ZEPHIR_MM_RESTORE(); return; } @@ -7410,7 +7579,7 @@ PHP_METHOD(Tensor_Matrix, modVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2276); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2317); ZEPHIR_MM_RESTORE(); return; } @@ -7494,7 +7663,7 @@ PHP_METHOD(Tensor_Matrix, equalVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2297); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2338); ZEPHIR_MM_RESTORE(); return; } @@ -7577,7 +7746,7 @@ PHP_METHOD(Tensor_Matrix, notEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2317); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2358); ZEPHIR_MM_RESTORE(); return; } @@ -7660,7 +7829,7 @@ PHP_METHOD(Tensor_Matrix, greaterVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2337); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2378); ZEPHIR_MM_RESTORE(); return; } @@ -7743,7 +7912,7 @@ PHP_METHOD(Tensor_Matrix, greaterEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2357); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2398); ZEPHIR_MM_RESTORE(); return; } @@ -7826,7 +7995,7 @@ PHP_METHOD(Tensor_Matrix, lessVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2377); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2418); ZEPHIR_MM_RESTORE(); return; } @@ -7910,7 +8079,7 @@ PHP_METHOD(Tensor_Matrix, lessEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2398); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2439); ZEPHIR_MM_RESTORE(); return; } @@ -7993,7 +8162,7 @@ PHP_METHOD(Tensor_Matrix, multiplyColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2418); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2459); ZEPHIR_MM_RESTORE(); return; } @@ -8076,7 +8245,7 @@ PHP_METHOD(Tensor_Matrix, divideColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2438); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2479); ZEPHIR_MM_RESTORE(); return; } @@ -8159,7 +8328,7 @@ PHP_METHOD(Tensor_Matrix, addColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2458); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2499); ZEPHIR_MM_RESTORE(); return; } @@ -8242,7 +8411,7 @@ PHP_METHOD(Tensor_Matrix, subtractColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2478); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2519); ZEPHIR_MM_RESTORE(); return; } @@ -8325,7 +8494,7 @@ PHP_METHOD(Tensor_Matrix, powColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2498); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2539); ZEPHIR_MM_RESTORE(); return; } @@ -8408,7 +8577,7 @@ PHP_METHOD(Tensor_Matrix, modColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2518); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2559); ZEPHIR_MM_RESTORE(); return; } @@ -8491,7 +8660,7 @@ PHP_METHOD(Tensor_Matrix, equalColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2538); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2579); ZEPHIR_MM_RESTORE(); return; } @@ -8574,7 +8743,7 @@ PHP_METHOD(Tensor_Matrix, notEqualColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2558); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2599); ZEPHIR_MM_RESTORE(); return; } @@ -8657,7 +8826,7 @@ PHP_METHOD(Tensor_Matrix, greaterColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2578); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2619); ZEPHIR_MM_RESTORE(); return; } @@ -8740,7 +8909,7 @@ PHP_METHOD(Tensor_Matrix, greaterEqualColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2598); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2639); ZEPHIR_MM_RESTORE(); return; } @@ -8823,7 +8992,7 @@ PHP_METHOD(Tensor_Matrix, lessColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2618); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2659); ZEPHIR_MM_RESTORE(); return; } @@ -8906,7 +9075,7 @@ PHP_METHOD(Tensor_Matrix, lessEqualColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2638); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2679); ZEPHIR_MM_RESTORE(); return; } @@ -9558,7 +9727,7 @@ PHP_METHOD(Tensor_Matrix, offsetSet) Z_PARAM_ZVAL(values) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(2, 0, &index, &values); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2819); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2860); return; } @@ -9609,7 +9778,7 @@ PHP_METHOD(Tensor_Matrix, offsetUnset) Z_PARAM_ZVAL(index) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(1, 0, &index); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2843); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2884); return; } @@ -9669,7 +9838,7 @@ PHP_METHOD(Tensor_Matrix, offsetGet) ZEPHIR_CONCAT_SSVS(&_2$$3, "Row offset must be", " an integer, ", &_1$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 2857); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 2898); ZEPHIR_MM_RESTORE(); return; } @@ -9686,7 +9855,7 @@ PHP_METHOD(Tensor_Matrix, offsetGet) ZEPHIR_CONCAT_SSVS(&_7$$4, "Row offset out of", " bounds, ", &_6$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_7$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 2862); + zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 2903); ZEPHIR_MM_RESTORE(); return; } @@ -9813,30 +9982,30 @@ PHP_METHOD(Tensor_Matrix, __unserialize) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &data_param); zephir_get_arrval(&data, data_param); - zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2905); + zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2946); ZVAL_BOOL(&_1, 0); ZEPHIR_CALL_SELF(&a, "fromArray", NULL, 0, &_0, &_1); zephir_check_call_status(); - zephir_array_fetch_string(&_2, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2907); + zephir_array_fetch_string(&_2, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2948); ZEPHIR_CALL_METHOD(&_3, &a, "m", NULL, 0); zephir_check_call_status(); _4 = !ZEPHIR_IS_EQUAL(&_2, &_3); if (!(_4)) { - zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2907); + zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2948); ZEPHIR_CALL_METHOD(&_6, &a, "n", NULL, 0); zephir_check_call_status(); _4 = !ZEPHIR_IS_EQUAL(&_5, &_6); } if (UNEXPECTED(_4)) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid matrix data.", "tensor/matrix.zep", 2908); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid matrix data.", "tensor/matrix.zep", 2949); return; } ZEPHIR_CALL_METHOD(&_7, &a, "buffer", NULL, 0); zephir_check_call_status(); zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 15, &_7); - zephir_array_fetch_string(&_8, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2912); + zephir_array_fetch_string(&_8, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2953); zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 16, &_8); - zephir_array_fetch_string(&_9, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2913); + zephir_array_fetch_string(&_9, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2954); zephir_update_property_zval_cached(this_ptr, _zephir_prop_2, 17, &_9); ZEPHIR_MM_RESTORE(); } diff --git a/ext/tensor/matrix.zep.h b/ext/tensor/matrix.zep.h index 7b8e7f2..291dec3 100644 --- a/ext/tensor/matrix.zep.h +++ b/ext/tensor/matrix.zep.h @@ -84,6 +84,8 @@ PHP_METHOD(Tensor_Matrix, acos); PHP_METHOD(Tensor_Matrix, tan); PHP_METHOD(Tensor_Matrix, atan); PHP_METHOD(Tensor_Matrix, tanh); +PHP_METHOD(Tensor_Matrix, sinh); +PHP_METHOD(Tensor_Matrix, cosh); PHP_METHOD(Tensor_Matrix, rad2deg); PHP_METHOD(Tensor_Matrix, deg2rad); PHP_METHOD(Tensor_Matrix, sum); @@ -96,6 +98,8 @@ PHP_METHOD(Tensor_Matrix, mean); PHP_METHOD(Tensor_Matrix, median); PHP_METHOD(Tensor_Matrix, quantile); PHP_METHOD(Tensor_Matrix, softmax); +PHP_METHOD(Tensor_Matrix, erf); +PHP_METHOD(Tensor_Matrix, cerf); PHP_METHOD(Tensor_Matrix, variance); PHP_METHOD(Tensor_Matrix, covariance); PHP_METHOD(Tensor_Matrix, round); @@ -460,6 +464,12 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_tanh, 0, 0, Tensor\\Matrix, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_sinh, 0, 0, Tensor\\Matrix, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_cosh, 0, 0, Tensor\\Matrix, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_rad2deg, 0, 0, Tensor\\Matrix, 0) ZEND_END_ARG_INFO() @@ -497,6 +507,12 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_softmax, 0, 0, Tensor\\Matrix, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_erf, 0, 0, Tensor\\Matrix, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_cerf, 0, 0, Tensor\\Matrix, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_variance, 0, 0, Tensor\\ColumnVector, 0) ZEND_ARG_INFO(0, mean) ZEND_END_ARG_INFO() @@ -860,6 +876,8 @@ ZEPHIR_INIT_FUNCS(tensor_matrix_method_entry) { PHP_ME(Tensor_Matrix, tan, arginfo_tensor_matrix_tan, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, atan, arginfo_tensor_matrix_atan, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, tanh, arginfo_tensor_matrix_tanh, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Matrix, sinh, arginfo_tensor_matrix_sinh, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Matrix, cosh, arginfo_tensor_matrix_cosh, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, rad2deg, arginfo_tensor_matrix_rad2deg, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, deg2rad, arginfo_tensor_matrix_deg2rad, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, sum, arginfo_tensor_matrix_sum, ZEND_ACC_PUBLIC) @@ -872,6 +890,8 @@ ZEPHIR_INIT_FUNCS(tensor_matrix_method_entry) { PHP_ME(Tensor_Matrix, median, arginfo_tensor_matrix_median, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, quantile, arginfo_tensor_matrix_quantile, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, softmax, arginfo_tensor_matrix_softmax, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Matrix, erf, arginfo_tensor_matrix_erf, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Matrix, cerf, arginfo_tensor_matrix_cerf, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, variance, arginfo_tensor_matrix_variance, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, covariance, arginfo_tensor_matrix_covariance, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, round, arginfo_tensor_matrix_round, ZEND_ACC_PUBLIC) diff --git a/ext/tensor/special.zep.c b/ext/tensor/special.zep.c index 51f5621..22a4503 100644 --- a/ext/tensor/special.zep.c +++ b/ext/tensor/special.zep.c @@ -25,3 +25,16 @@ ZEPHIR_INIT_CLASS(Tensor_Special) * @return mixed */ ZEPHIR_DOC_METHOD(Tensor_Special, softmax); +/** + * Return the element-wise Gaussian error function. + * + * @return mixed + */ +ZEPHIR_DOC_METHOD(Tensor_Special, erf); +/** + * Return the element-wise scaled complementary error function, + * i.e. exp(-x^2) * erfc(-x). + * + * @return mixed + */ +ZEPHIR_DOC_METHOD(Tensor_Special, cerf); diff --git a/ext/tensor/special.zep.h b/ext/tensor/special.zep.h index 4637411..83e91fb 100644 --- a/ext/tensor/special.zep.h +++ b/ext/tensor/special.zep.h @@ -6,7 +6,15 @@ ZEPHIR_INIT_CLASS(Tensor_Special); ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_softmax, 0, 0, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_erf, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_cerf, 0, 0, 0) +ZEND_END_ARG_INFO() + ZEPHIR_INIT_FUNCS(tensor_special_method_entry) { PHP_ABSTRACT_ME(Tensor_Special, softmax, arginfo_tensor_special_softmax) + PHP_ABSTRACT_ME(Tensor_Special, erf, arginfo_tensor_special_erf) + PHP_ABSTRACT_ME(Tensor_Special, cerf, arginfo_tensor_special_cerf) PHP_FE_END }; diff --git a/ext/tensor/trigonometric.zep.c b/ext/tensor/trigonometric.zep.c index 06343b3..723997e 100644 --- a/ext/tensor/trigonometric.zep.c +++ b/ext/tensor/trigonometric.zep.c @@ -65,6 +65,18 @@ ZEPHIR_DOC_METHOD(Tensor_Trigonometric, atan); * @return mixed */ ZEPHIR_DOC_METHOD(Tensor_Trigonometric, tanh); +/** + * Return the element-wise hyperbolic sine. + * + * @return mixed + */ +ZEPHIR_DOC_METHOD(Tensor_Trigonometric, sinh); +/** + * Return the element-wise hyperbolic cosine. + * + * @return mixed + */ +ZEPHIR_DOC_METHOD(Tensor_Trigonometric, cosh); /** * Convert angles from radians to degrees. * diff --git a/ext/tensor/trigonometric.zep.h b/ext/tensor/trigonometric.zep.h index 56ce624..668d5c2 100644 --- a/ext/tensor/trigonometric.zep.h +++ b/ext/tensor/trigonometric.zep.h @@ -24,6 +24,12 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_trigonometric_tanh, 0, 0, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_trigonometric_sinh, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_trigonometric_cosh, 0, 0, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_trigonometric_rad2deg, 0, 0, 0) ZEND_END_ARG_INFO() @@ -38,6 +44,8 @@ ZEPHIR_INIT_FUNCS(tensor_trigonometric_method_entry) { PHP_ABSTRACT_ME(Tensor_Trigonometric, tan, arginfo_tensor_trigonometric_tan) PHP_ABSTRACT_ME(Tensor_Trigonometric, atan, arginfo_tensor_trigonometric_atan) PHP_ABSTRACT_ME(Tensor_Trigonometric, tanh, arginfo_tensor_trigonometric_tanh) + PHP_ABSTRACT_ME(Tensor_Trigonometric, sinh, arginfo_tensor_trigonometric_sinh) + PHP_ABSTRACT_ME(Tensor_Trigonometric, cosh, arginfo_tensor_trigonometric_cosh) PHP_ABSTRACT_ME(Tensor_Trigonometric, rad2deg, arginfo_tensor_trigonometric_rad2deg) PHP_ABSTRACT_ME(Tensor_Trigonometric, deg2rad, arginfo_tensor_trigonometric_deg2rad) PHP_FE_END diff --git a/ext/tensor/vector.zep.c b/ext/tensor/vector.zep.c index 1fc4f80..02764b4 100644 --- a/ext/tensor/vector.zep.c +++ b/ext/tensor/vector.zep.c @@ -2841,6 +2841,66 @@ PHP_METHOD(Tensor_Vector, tanh) RETURN_MM(); } +/** + * Return the element-wise hyperbolic sine of the vector. + * + * @return self + */ +PHP_METHOD(Tensor_Vector, sinh) +{ + zval _0, _1; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + object_init_ex(return_value, zend_get_called_scope(execute_data)); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_sinh(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 3, &_0); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return the element-wise hyperbolic cosine of the vector. + * + * @return self + */ +PHP_METHOD(Tensor_Vector, cosh) +{ + zval _0, _1; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + object_init_ex(return_value, zend_get_called_scope(execute_data)); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_cosh(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 3, &_0); + zephir_check_call_status(); + RETURN_MM(); +} + /** * Convert angles from radians to degrees. * @@ -3022,7 +3082,7 @@ PHP_METHOD(Tensor_Vector, min) ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the minimum of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1147); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1167); ZEPHIR_MM_RESTORE(); return; } @@ -3078,7 +3138,7 @@ PHP_METHOD(Tensor_Vector, max) ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the maximum of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1164); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1184); ZEPHIR_MM_RESTORE(); return; } @@ -3134,7 +3194,7 @@ PHP_METHOD(Tensor_Vector, argmin) ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the argmin of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1181); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1201); ZEPHIR_MM_RESTORE(); return; } @@ -3190,7 +3250,7 @@ PHP_METHOD(Tensor_Vector, argmax) ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the argmax of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1198); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1218); ZEPHIR_MM_RESTORE(); return; } @@ -3273,7 +3333,7 @@ PHP_METHOD(Tensor_Vector, median) ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the median of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1225); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1245); ZEPHIR_MM_RESTORE(); return; } @@ -3345,7 +3405,7 @@ PHP_METHOD(Tensor_Vector, quantile) ZEPHIR_CONCAT_SS(&_3$$3, "Q must be a finite value", " between 0 and 1."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1244); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1264); ZEPHIR_MM_RESTORE(); return; } @@ -3363,7 +3423,7 @@ PHP_METHOD(Tensor_Vector, quantile) ZEPHIR_CONCAT_SSVS(&_8$$4, "Q must be", " between 0 and 1, ", &_7$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_8$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/vector.zep", 1249); + zephir_throw_exception_debug(&_5$$4, "tensor/vector.zep", 1269); ZEPHIR_MM_RESTORE(); return; } @@ -3375,7 +3435,7 @@ PHP_METHOD(Tensor_Vector, quantile) ZEPHIR_CONCAT_SS(&_10$$5, "Cannot compute", " the quantile of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_9$$5, "__construct", NULL, 2, &_10$$5); zephir_check_call_status(); - zephir_throw_exception_debug(&_9$$5, "tensor/vector.zep", 1254); + zephir_throw_exception_debug(&_9$$5, "tensor/vector.zep", 1274); ZEPHIR_MM_RESTORE(); return; } @@ -3429,6 +3489,67 @@ PHP_METHOD(Tensor_Vector, softmax) RETURN_MM(); } +/** + * Return the element-wise Gaussian error function. + * + * @return self + */ +PHP_METHOD(Tensor_Vector, erf) +{ + zval _0, _1; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + object_init_ex(return_value, zend_get_called_scope(execute_data)); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_erf(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 3, &_0); + zephir_check_call_status(); + RETURN_MM(); +} + +/** + * Return the element-wise scaled complementary error function, + * i.e. exp(-x^2) * erfc(-x). + * + * @return self + */ +PHP_METHOD(Tensor_Vector, cerf) +{ + zval _0, _1; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + object_init_ex(return_value, zend_get_called_scope(execute_data)); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_cerf(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 3, &_0); + zephir_check_call_status(); + RETURN_MM(); +} + /** * Return the variance of the vector. * @@ -3484,7 +3605,7 @@ PHP_METHOD(Tensor_Vector, variance) ZEPHIR_CONCAT_SSVS(&_3$$4, "Mean scalar must be", " a floating point number ", &_2$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_1$$4, "__construct", NULL, 2, &_3$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$4, "tensor/vector.zep", 1287); + zephir_throw_exception_debug(&_1$$4, "tensor/vector.zep", 1328); ZEPHIR_MM_RESTORE(); return; } @@ -3550,7 +3671,7 @@ PHP_METHOD(Tensor_Vector, round) ZEPHIR_CONCAT_SSVS(&_3$$3, "Decimal precision cannot", " be less than 0, ", &_2$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1311); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1352); ZEPHIR_MM_RESTORE(); return; } @@ -3727,7 +3848,7 @@ PHP_METHOD(Tensor_Vector, clip) ZEPHIR_CONCAT_SS(&_1$$3, "Minimum cannot be", " greater than maximum."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_1$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1370); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1411); ZEPHIR_MM_RESTORE(); return; } @@ -3879,7 +4000,7 @@ PHP_METHOD(Tensor_Vector, multiplyMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1410); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1451); ZEPHIR_MM_RESTORE(); return; } @@ -3959,7 +4080,7 @@ PHP_METHOD(Tensor_Vector, divideMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1430); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1471); ZEPHIR_MM_RESTORE(); return; } @@ -4039,7 +4160,7 @@ PHP_METHOD(Tensor_Vector, addMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1450); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1491); ZEPHIR_MM_RESTORE(); return; } @@ -4119,7 +4240,7 @@ PHP_METHOD(Tensor_Vector, subtractMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1470); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1511); ZEPHIR_MM_RESTORE(); return; } @@ -4199,7 +4320,7 @@ PHP_METHOD(Tensor_Vector, powMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1490); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1531); ZEPHIR_MM_RESTORE(); return; } @@ -4279,7 +4400,7 @@ PHP_METHOD(Tensor_Vector, modMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1510); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1551); ZEPHIR_MM_RESTORE(); return; } @@ -4359,7 +4480,7 @@ PHP_METHOD(Tensor_Vector, equalMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1530); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1571); ZEPHIR_MM_RESTORE(); return; } @@ -4439,7 +4560,7 @@ PHP_METHOD(Tensor_Vector, notEqualMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1550); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1591); ZEPHIR_MM_RESTORE(); return; } @@ -4519,7 +4640,7 @@ PHP_METHOD(Tensor_Vector, greaterMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1570); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1611); ZEPHIR_MM_RESTORE(); return; } @@ -4599,7 +4720,7 @@ PHP_METHOD(Tensor_Vector, greaterEqualMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1590); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1631); ZEPHIR_MM_RESTORE(); return; } @@ -4679,7 +4800,7 @@ PHP_METHOD(Tensor_Vector, lessMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1610); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1651); ZEPHIR_MM_RESTORE(); return; } @@ -4759,7 +4880,7 @@ PHP_METHOD(Tensor_Vector, lessEqualMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1630); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1671); ZEPHIR_MM_RESTORE(); return; } @@ -4836,7 +4957,7 @@ PHP_METHOD(Tensor_Vector, multiplyVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1650); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1691); ZEPHIR_MM_RESTORE(); return; } @@ -4909,7 +5030,7 @@ PHP_METHOD(Tensor_Vector, divideVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1668); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1709); ZEPHIR_MM_RESTORE(); return; } @@ -4982,7 +5103,7 @@ PHP_METHOD(Tensor_Vector, addVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1686); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1727); ZEPHIR_MM_RESTORE(); return; } @@ -5055,7 +5176,7 @@ PHP_METHOD(Tensor_Vector, subtractVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1704); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1745); ZEPHIR_MM_RESTORE(); return; } @@ -5128,7 +5249,7 @@ PHP_METHOD(Tensor_Vector, powVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1722); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1763); ZEPHIR_MM_RESTORE(); return; } @@ -5201,7 +5322,7 @@ PHP_METHOD(Tensor_Vector, modVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1740); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1781); ZEPHIR_MM_RESTORE(); return; } @@ -5275,7 +5396,7 @@ PHP_METHOD(Tensor_Vector, equalVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1759); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1800); ZEPHIR_MM_RESTORE(); return; } @@ -5348,7 +5469,7 @@ PHP_METHOD(Tensor_Vector, notEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1777); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1818); ZEPHIR_MM_RESTORE(); return; } @@ -5421,7 +5542,7 @@ PHP_METHOD(Tensor_Vector, greaterVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1795); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1836); ZEPHIR_MM_RESTORE(); return; } @@ -5494,7 +5615,7 @@ PHP_METHOD(Tensor_Vector, greaterEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1813); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1854); ZEPHIR_MM_RESTORE(); return; } @@ -5567,7 +5688,7 @@ PHP_METHOD(Tensor_Vector, lessVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1831); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1872); ZEPHIR_MM_RESTORE(); return; } @@ -5640,7 +5761,7 @@ PHP_METHOD(Tensor_Vector, lessEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1849); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1890); ZEPHIR_MM_RESTORE(); return; } @@ -6140,7 +6261,7 @@ PHP_METHOD(Tensor_Vector, offsetSet) Z_PARAM_ZVAL(values) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(2, 0, &index, &values); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2006); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2047); return; } @@ -6191,7 +6312,7 @@ PHP_METHOD(Tensor_Vector, offsetUnset) Z_PARAM_ZVAL(index) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(1, 0, &index); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2030); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2071); return; } @@ -6249,7 +6370,7 @@ PHP_METHOD(Tensor_Vector, offsetGet) ZEPHIR_CONCAT_SSVS(&_5$$3, "Element not found at", " offset ", &_4$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_3$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_3$$3, "tensor/vector.zep", 2044); + zephir_throw_exception_debug(&_3$$3, "tensor/vector.zep", 2085); ZEPHIR_MM_RESTORE(); return; } @@ -6360,21 +6481,21 @@ PHP_METHOD(Tensor_Vector, __unserialize) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &data_param); zephir_get_arrval(&data, data_param); - zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2085); + zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2126); ZVAL_BOOL(&_1, 0); ZEPHIR_CALL_SELF(&a, "fromArray", NULL, 0, &_0, &_1); zephir_check_call_status(); - zephir_array_fetch_string(&_2, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2087); + zephir_array_fetch_string(&_2, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2128); ZEPHIR_CALL_METHOD(&_3, &a, "size", NULL, 0); zephir_check_call_status(); if (UNEXPECTED(!ZEPHIR_IS_EQUAL(&_2, &_3))) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid vector data.", "tensor/vector.zep", 2088); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid vector data.", "tensor/vector.zep", 2129); return; } ZEPHIR_CALL_METHOD(&_4, &a, "buffer", NULL, 0); zephir_check_call_status(); zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 1, &_4); - zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2092); + zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2133); zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 2, &_5); ZEPHIR_MM_RESTORE(); } diff --git a/ext/tensor/vector.zep.h b/ext/tensor/vector.zep.h index 6093301..29f7e83 100644 --- a/ext/tensor/vector.zep.h +++ b/ext/tensor/vector.zep.h @@ -67,6 +67,8 @@ PHP_METHOD(Tensor_Vector, acos); PHP_METHOD(Tensor_Vector, tan); PHP_METHOD(Tensor_Vector, atan); PHP_METHOD(Tensor_Vector, tanh); +PHP_METHOD(Tensor_Vector, sinh); +PHP_METHOD(Tensor_Vector, cosh); PHP_METHOD(Tensor_Vector, rad2deg); PHP_METHOD(Tensor_Vector, deg2rad); PHP_METHOD(Tensor_Vector, sum); @@ -79,6 +81,8 @@ PHP_METHOD(Tensor_Vector, mean); PHP_METHOD(Tensor_Vector, median); PHP_METHOD(Tensor_Vector, quantile); PHP_METHOD(Tensor_Vector, softmax); +PHP_METHOD(Tensor_Vector, erf); +PHP_METHOD(Tensor_Vector, cerf); PHP_METHOD(Tensor_Vector, variance); PHP_METHOD(Tensor_Vector, round); PHP_METHOD(Tensor_Vector, floor); @@ -370,6 +374,12 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_tanh, 0, 0, Tensor\\Vector, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_sinh, 0, 0, Tensor\\Vector, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_cosh, 0, 0, Tensor\\Vector, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_rad2deg, 0, 0, Tensor\\Vector, 0) ZEND_END_ARG_INFO() @@ -407,6 +417,12 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_softmax, 0, 0, Tensor\\Vector, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_erf, 0, 0, Tensor\\Vector, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_cerf, 0, 0, Tensor\\Vector, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_vector_variance, 0, 0, IS_DOUBLE, 0) ZEND_ARG_INFO(0, mean) ZEND_END_ARG_INFO() @@ -681,6 +697,8 @@ PHP_ME(Tensor_Vector, transpose, arginfo_tensor_vector_transpose, ZEND_ACC_PUBLI PHP_ME(Tensor_Vector, tan, arginfo_tensor_vector_tan, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, atan, arginfo_tensor_vector_atan, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, tanh, arginfo_tensor_vector_tanh, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Vector, sinh, arginfo_tensor_vector_sinh, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Vector, cosh, arginfo_tensor_vector_cosh, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, rad2deg, arginfo_tensor_vector_rad2deg, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, deg2rad, arginfo_tensor_vector_deg2rad, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, sum, arginfo_tensor_vector_sum, ZEND_ACC_PUBLIC) @@ -693,6 +711,8 @@ PHP_ME(Tensor_Vector, transpose, arginfo_tensor_vector_transpose, ZEND_ACC_PUBLI PHP_ME(Tensor_Vector, median, arginfo_tensor_vector_median, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, quantile, arginfo_tensor_vector_quantile, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, softmax, arginfo_tensor_vector_softmax, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Vector, erf, arginfo_tensor_vector_erf, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Vector, cerf, arginfo_tensor_vector_cerf, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, variance, arginfo_tensor_vector_variance, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, round, arginfo_tensor_vector_round, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, floor, arginfo_tensor_vector_floor, ZEND_ACC_PUBLIC) diff --git a/optimizers/TensorCerfOptimizer.php b/optimizers/TensorCerfOptimizer.php new file mode 100644 index 0000000..d65c47a --- /dev/null +++ b/optimizers/TensorCerfOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_cerf($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorCoshOptimizer.php b/optimizers/TensorCoshOptimizer.php new file mode 100644 index 0000000..2cf6d2d --- /dev/null +++ b/optimizers/TensorCoshOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_cosh($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorErfOptimizer.php b/optimizers/TensorErfOptimizer.php new file mode 100644 index 0000000..653faae --- /dev/null +++ b/optimizers/TensorErfOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_erf($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/optimizers/TensorSinhOptimizer.php b/optimizers/TensorSinhOptimizer.php new file mode 100644 index 0000000..f05c831 --- /dev/null +++ b/optimizers/TensorSinhOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_sinh($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/tensor/matrix.zep b/tensor/matrix.zep index 67cbf73..09f41d8 100644 --- a/tensor/matrix.zep +++ b/tensor/matrix.zep @@ -1508,6 +1508,26 @@ class Matrix implements Tensor { return new self(tensor_tanh(this->a), this->m, this->n); } + + /** + * Return the element-wise hyperbolic sine of the matrix. + * + * @return self + */ + public function sinh() -> + { + return new self(tensor_sinh(this->a), this->m, this->n); + } + + /** + * Return the element-wise hyperbolic cosine of the matrix. + * + * @return self + */ + public function cosh() -> + { + return new self(tensor_cosh(this->a), this->m, this->n); + } /** * Convert angles from radians to degrees. @@ -1641,6 +1661,27 @@ class Matrix implements Tensor return new self(tensor_softmax(this->a, this->n), this->m, this->n); } + /** + * Return the element-wise Gaussian error function. + * + * @return self + */ + public function erf() -> + { + return new self(tensor_erf(this->a), this->m, this->n); + } + + /** + * Return the element-wise scaled complementary error function, + * i.e. exp(-x^2) * erfc(-x). + * + * @return self + */ + public function cerf() -> + { + return new self(tensor_cerf(this->a), this->m, this->n); + } + /** * Compute the row variance of the matrix. * diff --git a/tensor/special.zep b/tensor/special.zep index ef4bc59..d0a350e 100644 --- a/tensor/special.zep +++ b/tensor/special.zep @@ -8,4 +8,19 @@ interface Special * @return mixed */ public function softmax(); + + /** + * Return the element-wise Gaussian error function. + * + * @return mixed + */ + public function erf(); + + /** + * Return the element-wise scaled complementary error function, + * i.e. exp(-x^2) * erfc(-x). + * + * @return mixed + */ + public function cerf(); } diff --git a/tensor/trigonometric.zep b/tensor/trigonometric.zep index 11819ce..bba609f 100644 --- a/tensor/trigonometric.zep +++ b/tensor/trigonometric.zep @@ -55,6 +55,20 @@ interface Trigonometric */ public function tanh(); + /** + * Return the element-wise hyperbolic sine. + * + * @return mixed + */ + public function sinh(); + + /** + * Return the element-wise hyperbolic cosine. + * + * @return mixed + */ + public function cosh(); + /** * Convert angles from radians to degrees. * diff --git a/tensor/vector.zep b/tensor/vector.zep index 2c47634..cb95dfb 100644 --- a/tensor/vector.zep +++ b/tensor/vector.zep @@ -1091,6 +1091,26 @@ class Vector implements Tensor return new static(tensor_tanh(this->a)); } + /** + * Return the element-wise hyperbolic sine of the vector. + * + * @return self + */ + public function sinh() -> + { + return new static(tensor_sinh(this->a)); + } + + /** + * Return the element-wise hyperbolic cosine of the vector. + * + * @return self + */ + public function cosh() -> + { + return new static(tensor_cosh(this->a)); + } + /** * Convert angles from radians to degrees. * @@ -1272,6 +1292,27 @@ class Vector implements Tensor return new static(tensor_softmax(this->a, this->n)); } + /** + * Return the element-wise Gaussian error function. + * + * @return self + */ + public function erf() -> + { + return new static(tensor_erf(this->a)); + } + + /** + * Return the element-wise scaled complementary error function, + * i.e. exp(-x^2) * erfc(-x). + * + * @return self + */ + public function cerf() -> + { + return new static(tensor_cerf(this->a)); + } + /** * Return the variance of the vector. * diff --git a/tests/ColumnVectorTest.php b/tests/ColumnVectorTest.php index 2e13c32..ffb815c 100644 --- a/tests/ColumnVectorTest.php +++ b/tests/ColumnVectorTest.php @@ -460,6 +460,50 @@ public function tanhReturnsColumnVector() : void $this->assertEqualsWithDelta([0.76159415595576485, -0.76159415595576485, 0.0], $b->asArray(), 1e-8); } + /** + * @test + */ + public function sinhReturnsColumnVector() : void + { + $b = ColumnVector::fromArray([1.0, -1.0, 0.0])->sinh(); + + $this->assertInstanceOf(ColumnVector::class, $b); + $this->assertEqualsWithDelta([1.1752011936438014, -1.1752011936438014, 0.0], $b->asArray(), 1e-8); + } + + /** + * @test + */ + public function coshReturnsColumnVector() : void + { + $b = ColumnVector::fromArray([1.0, -1.0, 0.0])->cosh(); + + $this->assertInstanceOf(ColumnVector::class, $b); + $this->assertEqualsWithDelta([1.5430806348152437, 1.5430806348152437, 1.0], $b->asArray(), 1e-8); + } + + /** + * @test + */ + public function erfReturnsColumnVector() : void + { + $b = ColumnVector::fromArray([1.0, -1.0, 0.0])->erf(); + + $this->assertInstanceOf(ColumnVector::class, $b); + $this->assertEqualsWithDelta([0.8427007929497148, -0.8427007929497148, 0.0], $b->asArray(), 1e-8); + } + + /** + * @test + */ + public function cerfReturnsColumnVector() : void + { + $b = ColumnVector::fromArray([1.0, -1.0, 0.0])->cerf(); + + $this->assertInstanceOf(ColumnVector::class, $b); + $this->assertEqualsWithDelta([0.6778917379565147, 0.05786714438636991, 1.0], $b->asArray(), 1e-8); + } + /** * @test */ diff --git a/tests/MatrixTest.php b/tests/MatrixTest.php index dab2d0a..279df28 100644 --- a/tests/MatrixTest.php +++ b/tests/MatrixTest.php @@ -3779,6 +3779,88 @@ public function tanhMatchesComposition() : void ); } + /** + * @test + */ + public function sinh() : void + { + $a = Matrix::fromArray([ + [0.0, 1.0, -1.0], + [0.5, -0.5, 2.0], + ]); + + $this->assertSame(0.0, $a->sinh()->asArray()[0][0]); + + $this->assertEqualsWithDelta( + array_map( + static fn (array $row) : array => array_map('sinh', $row), + $a->asArray() + ), + $a->sinh()->asArray(), + self::MAX_DELTA + ); + } + + /** + * The kernel must agree with the exp difference composition it replaces. + * + * @test + */ + public function sinhMatchesComposition() : void + { + $a = Matrix::rand(17, 23)->multiply(0.5)->subtract(0.25); + + $e = $a->exp(); + $em = $a->multiply(-1.0)->exp(); + + $this->assertEqualsWithDelta( + $e->subtract($em)->multiply(0.5)->asArray(), + $a->sinh()->asArray(), + self::MAX_DELTA + ); + } + + /** + * @test + */ + public function cosh() : void + { + $a = Matrix::fromArray([ + [0.0, 1.0, -1.0], + [0.5, -0.5, 2.0], + ]); + + $this->assertSame(1.0, $a->cosh()->asArray()[0][0]); + + $this->assertEqualsWithDelta( + array_map( + static fn (array $row) : array => array_map('cosh', $row), + $a->asArray() + ), + $a->cosh()->asArray(), + self::MAX_DELTA + ); + } + + /** + * The kernel must agree with the exp sum composition it replaces. + * + * @test + */ + public function coshMatchesComposition() : void + { + $a = Matrix::rand(17, 23)->multiply(0.5)->subtract(0.25); + + $e = $a->exp(); + $em = $a->multiply(-1.0)->exp(); + + $this->assertEqualsWithDelta( + $e->add($em)->multiply(0.5)->asArray(), + $a->cosh()->asArray(), + self::MAX_DELTA + ); + } + /** * @test */ @@ -4292,6 +4374,78 @@ public function softmaxDoesNotMutate() : void $this->assertSame($before, $a->asArray()); } + /** + * @test + */ + public function erf() : void + { + $a = Matrix::fromArray([ + [0.0, 1.0, -1.0], + [0.5, -0.5, 2.0], + ]); + + $b = $a->erf(); + + $expected = Matrix::fromArray([ + [0.0, 0.8427007929497148, -0.8427007929497148], + [0.5204998778130465, -0.5204998778130465, 0.9953222650189527], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); + } + + /** + * A large input saturates to exactly +/-1.0 rather than an infinity. + * + * @test + */ + public function erfSaturates() : void + { + $a = Matrix::fromArray([ + [100.0, -100.0], + ]); + + $this->assertSame([1.0, -1.0], $a->erf()->asArray()[0]); + } + + /** + * @test + */ + public function cerf() : void + { + $a = Matrix::fromArray([ + [0.0, 1.0, -1.0], + [0.5, -0.5, 2.0], + ]); + + $b = $a->cerf(); + + $expected = Matrix::fromArray([ + [1.0, 0.6778917379565147, 0.05786714438636991], + [1.184166495500776, 0.3734350706420337, 0.0365456020727383], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); + } + + /** + * The scaled form stays finite for large inputs where the unscaled + * erfc would underflow. + * + * @test + */ + public function cerfStaysFinite() : void + { + $a = Matrix::fromArray([ + [50.0, -50.0], + ]); + + $b = $a->cerf()->asArray()[0]; + + $this->assertTrue(is_finite($b[0])); + $this->assertTrue(is_finite($b[1])); + } + /** * A single row is one group, so it normalizes to one across its width. * diff --git a/tests/VectorTest.php b/tests/VectorTest.php index 606d31a..7ad3e11 100644 --- a/tests/VectorTest.php +++ b/tests/VectorTest.php @@ -2217,6 +2217,76 @@ public function tanhMatchesComposition() : void ); } + /** + * @test + */ + public function sinh() : void + { + $a = Vector::fromArray([0.0, 1.0, -1.0, 0.5, -0.5, 2.0]); + + $this->assertSame(0.0, $a->sinh()->asArray()[0]); + + $this->assertEqualsWithDelta( + array_map('sinh', $a->asArray()), + $a->sinh()->asArray(), + self::MAX_DELTA + ); + } + + /** + * The kernel must agree with the exp difference composition it replaces. + * + * @test + */ + public function sinhMatchesComposition() : void + { + $a = Vector::rand(257)->multiply(0.5)->subtract(0.25); + + $e = $a->exp(); + $em = $a->multiply(-1.0)->exp(); + + $this->assertEqualsWithDelta( + $e->subtract($em)->multiply(0.5)->asArray(), + $a->sinh()->asArray(), + self::MAX_DELTA + ); + } + + /** + * @test + */ + public function cosh() : void + { + $a = Vector::fromArray([0.0, 1.0, -1.0, 0.5, -0.5, 2.0]); + + $this->assertSame(1.0, $a->cosh()->asArray()[0]); + + $this->assertEqualsWithDelta( + array_map('cosh', $a->asArray()), + $a->cosh()->asArray(), + self::MAX_DELTA + ); + } + + /** + * The kernel must agree with the exp sum composition it replaces. + * + * @test + */ + public function coshMatchesComposition() : void + { + $a = Vector::rand(257)->multiply(0.5)->subtract(0.25); + + $e = $a->exp(); + $em = $a->multiply(-1.0)->exp(); + + $this->assertEqualsWithDelta( + $e->add($em)->multiply(0.5)->asArray(), + $a->cosh()->asArray(), + self::MAX_DELTA + ); + } + /** * A vector softmax normalizes the whole vector, as a single row, so the * result sums to one. @@ -2317,6 +2387,69 @@ public function softmaxDoesNotMutate() : void $this->assertSame($before, $a->asArray()); } + /** + * @test + */ + public function erf() : void + { + $a = Vector::fromArray([0.0, 1.0, -1.0, 0.5, -0.5, 2.0, 10.0]); + + $b = $a->erf(); + + $expected = Vector::fromArray([ + 0.0, 0.8427007929497148, -0.8427007929497148, + 0.5204998778130465, -0.5204998778130465, + 0.9953222650189527, 1.0, + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); + } + + /** + * A large input saturates to exactly +/-1.0 rather than an infinity. + * + * @test + */ + public function erfSaturates() : void + { + $a = Vector::fromArray([100.0, -100.0]); + + $this->assertSame([1.0, -1.0], $a->erf()->asArray()); + } + + /** + * @test + */ + public function cerf() : void + { + $a = Vector::fromArray([0.0, 1.0, -1.0, 0.5, -0.5, 2.0]); + + $b = $a->cerf(); + + $expected = Vector::fromArray([ + 1.0, 0.6778917379565147, 0.05786714438636991, + 1.184166495500776, 0.3734350706420337, 0.0365456020727383, + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); + } + + /** + * The scaled form stays finite for large inputs where the unscaled + * erfc would underflow. + * + * @test + */ + public function cerfStaysFinite() : void + { + $a = Vector::fromArray([50.0, -50.0]); + + $b = $a->cerf()->asArray(); + + $this->assertTrue(is_finite($b[0])); + $this->assertTrue(is_finite($b[1])); + } + /** * Lengths on both sides of the kernel's block boundary: a single element, a * block narrower than the floor, and one wider than the cap. From 541b4075a8c5ebde76083c40ca6829bfb0c385c6 Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Tue, 6 Oct 2026 23:40:24 -0500 Subject: [PATCH 03/14] A little nicer --- CHANGELOG.md | 4 + docs/Matrix.md | 3 +- docs/Vector.md | 3 +- docs/index.md | 2 +- docs/interfaces/special.md | 11 +- docs/interfaces/tensor.md | 4 +- ext/include/unary.c | 1 - ext/include/unary.h | 1 - ext/tensor/matrix.zep.c | 157 +++++++++++------------------ ext/tensor/matrix.zep.h | 5 - ext/tensor/special.zep.c | 19 ++-- ext/tensor/special.zep.h | 12 ++- ext/tensor/unary.zep.c | 12 --- ext/tensor/unary.zep.h | 8 -- ext/tensor/vector.zep.c | 99 +++++++----------- ext/tensor/vector.zep.h | 5 - optimizers/TensorCerfOptimizer.php | 76 -------------- tensor/matrix.zep | 11 -- tensor/special.zep | 22 ++-- tensor/unary.zep | 14 --- tensor/vector.zep | 11 -- tests/ColumnVectorTest.php | 11 -- tests/MatrixTest.php | 38 ------- tests/VectorTest.php | 35 ------- 24 files changed, 135 insertions(+), 429 deletions(-) delete mode 100644 optimizers/TensorCerfOptimizer.php diff --git a/CHANGELOG.md b/CHANGELOG.md index e5eb7fe..c6cf1f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +- 4.1.0 + - Added `softplus()` and `erf()` special functions + - Added `sinh()` and `cosh()` trigonometric functions + - 4.0.0 - Data are now backed by a contiguous C buffer instead of PHP array - Added `fromArray()` factory method to build from PHP array diff --git a/docs/Matrix.md b/docs/Matrix.md index 3cacb8f..ae09059 100644 --- a/docs/Matrix.md +++ b/docs/Matrix.md @@ -469,11 +469,10 @@ See [Reductions](interfaces/reductions.md). For a `Matrix`, row-wise reductions ## Special -See [Special](interfaces/special.md). `softmax()` preserves the shape of the matrix; `erf()` and `cerf()` are element-wise. +See [Special](interfaces/special.md). `softmax()` preserves the shape of the matrix; `erf()` is element-wise. - `softmax() : self` — exponentials normalized so each **row** sums to `1.0`; transpose on either side to normalize each column - `erf() : self` — element-wise Gaussian error function -- `cerf() : self` — element-wise scaled complementary error function, `exp(-x^2) * erfc(-x)` ## Array Access diff --git a/docs/Vector.md b/docs/Vector.md index 5cdb56e..5d20aed 100644 --- a/docs/Vector.md +++ b/docs/Vector.md @@ -351,11 +351,10 @@ See [Reductions](interfaces/reductions.md). For a `Vector` these return scalar ` ## Special -See [Special](interfaces/special.md). `softmax()` preserves the shape of the vector; `erf()` and `cerf()` are element-wise. +See [Special](interfaces/special.md). `softmax()` preserves the shape of the vector; `erf()` is element-wise. - `softmax() : self` — the exponentials of the vector normalized so they sum to `1.0` - `erf() : self` — element-wise Gaussian error function -- `cerf() : self` — element-wise scaled complementary error function, `exp(-x^2) * erfc(-x)` ## Array Access diff --git a/docs/index.md b/docs/index.md index 6dbf77b..de23d8a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -55,7 +55,7 @@ Tensor \ | [Unary](interfaces/unary.md) | Element-wise unary functions, including clipping. | | [Trigonometric](interfaces/trigonometric.md) | Element-wise trigonometric functions. | | [Reductions](interfaces/reductions.md) | Aggregate reduction operations, including the statistical summaries. | -| [Special](interfaces/special.md) | Operations that fit no other group, such as `softmax` and the error-function family `erf` / `cerf`. | +| [Special](interfaces/special.md) | Operations that fit no other group, such as `softmax` and the error-function`erf`. | ## Decompositions diff --git a/docs/interfaces/special.md b/docs/interfaces/special.md index a918a56..bf05868 100644 --- a/docs/interfaces/special.md +++ b/docs/interfaces/special.md @@ -8,7 +8,7 @@ Operations that do not belong to any of the other interface groups. `Special` holds the operations that neither the basic algebraic and trigonometric families (`Arithmetic`, `Comparable`, `Unary`, `Trigonometric`), aggregate reductions (`Reductions`), nor array-like access (`ArrayLike`) can describe. -`softmax()` is the only shape-preserving member whose output depends on a whole reduction axis rather than on one input element, so it is neither element-wise nor a reduction. `erf()` and `cerf()` are element-wise error-function transforms grouped here so the error-function family stays together, distinct from the basic algebraic operations. +`softmax()` is the only shape-preserving member whose output depends on a whole reduction axis rather than on one input element, so it is neither element-wise nor a reduction. `erf()` is element-wise error-function transforms grouped here so the error-function family stays together, distinct from the basic algebraic operations. ```php interface Special @@ -43,12 +43,3 @@ Return the element-wise Gaussian error function. A large input saturates to exactly `1.0` or `-1.0` rather than returning an infinity. - -### `cerf() : mixed` - -Return the element-wise scaled complementary error function, -`exp(-x^2) * erfc(-x)`. - -The `exp(-x^2)` factor cancels the exponential decay of `erfc(-x)`, so the -result stays finite for a large input where the plain scaled complement would -underflow to `0.0`. `cerf(0) == 1.0`. diff --git a/docs/interfaces/tensor.md b/docs/interfaces/tensor.md index 70f605f..8c9c03d 100644 --- a/docs/interfaces/tensor.md +++ b/docs/interfaces/tensor.md @@ -23,12 +23,12 @@ interface Tensor extends ArrayLike, Arithmetic, Comparable, | [Unary](unary.md) | `abs`, `square`, `sqrt`, `exp`, `expm1`, `log`, `log1p`, `sigmoid`, `softplus`, `round`, `floor`, `ceil`, `sign`, `negate`, `clip`, `clipLower`, `clipUpper` | | [Trigonometric](trigonometric.md) | `sin`, `asin`, `cos`, `acos`, `tan`, `atan`, `tanh`, `sinh`, `cosh`, `rad2deg`, `deg2rad` | | [Reductions](reductions.md) | `sum`, `product`, `min`, `max`, `argmin`, `argmax`, `mean`, `variance`, `median`, `quantile` | -| [Special](special.md) | `softmax`, `erf`, `cerf` | +| [Special](special.md) | `softmax`, `erf` | Every group is homogeneous in what it does to the tensor's shape: `Arithmetic`, `Comparable`, `Unary`, and `Trigonometric` are element-wise and preserve it, `Reductions` collapse it, and `ArrayLike` is about access rather than arithmetic. -`Special` is the escape hatch for operations that fit no other group, such as shape-preserving cross-axis operations like `softmax()` and the element-wise error-function family `erf()` / `cerf()`. +`Special` is the escape hatch for operations that fit no other group, such as shape-preserving cross-axis operations like `softmax()` and the element-wise error-function family `erf()`. Additionally, because `ArrayLike` extends `ArrayAccess`, `IteratorAggregate`, and `Countable`, every tensor is array-accessible, iterable, and countable. diff --git a/ext/include/unary.c b/ext/include/unary.c index faf6039..61d8777 100644 --- a/ext/include/unary.c +++ b/ext/include/unary.c @@ -145,7 +145,6 @@ TENSOR_UNARY(tanh, tanh(va[i])) TENSOR_UNARY(sinh, sinh(va[i])) TENSOR_UNARY(cosh, cosh(va[i])) TENSOR_UNARY(erf, erf(va[i])) -TENSOR_UNARY(cerf, exp(-va[i] * va[i]) * erfc(-va[i])) #undef TENSOR_UNARY diff --git a/ext/include/unary.h b/ext/include/unary.h index 542fb43..0246ab6 100644 --- a/ext/include/unary.h +++ b/ext/include/unary.h @@ -16,7 +16,6 @@ void tensor_tanh(zval * return_value, zval * a); void tensor_sinh(zval * return_value, zval * a); void tensor_cosh(zval * return_value, zval * a); void tensor_erf(zval * return_value, zval * a); -void tensor_cerf(zval * return_value, zval * a); void tensor_sin(zval * return_value, zval * a); void tensor_asin(zval * return_value, zval * a); void tensor_cos(zval * return_value, zval * a); diff --git a/ext/tensor/matrix.zep.c b/ext/tensor/matrix.zep.c index 959576b..fa87544 100644 --- a/ext/tensor/matrix.zep.c +++ b/ext/tensor/matrix.zep.c @@ -4910,49 +4910,6 @@ PHP_METHOD(Tensor_Matrix, erf) RETURN_MM(); } -/** - * Return the element-wise scaled complementary error function, - * i.e. exp(-x^2) * erfc(-x). - * - * @return self - */ -PHP_METHOD(Tensor_Matrix, cerf) -{ - zval _0, _1, _2, _3; - zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS; - zval *this_ptr = getThis(); - - ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_1); - ZVAL_UNDEF(&_2); - ZVAL_UNDEF(&_3); - static zend_string *_zephir_prop_0 = NULL; - static zend_string *_zephir_prop_1 = NULL; - static zend_string *_zephir_prop_2 = NULL; - if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); - } - if (UNEXPECTED(!_zephir_prop_1)) { - _zephir_prop_1 = zend_string_init("m", 1, 1); - } - if (UNEXPECTED(!_zephir_prop_2)) { - _zephir_prop_2 = zend_string_init("n", 1, 1); - } - ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); - zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - - object_init_ex(return_value, tensor_matrix_ce); - ZEPHIR_INIT_VAR(&_0); - zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); - tensor_cerf(&_0, &_1); - zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); - zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 17, PH_NOISY_CC | PH_READONLY); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 18, &_0, &_2, &_3); - zephir_check_call_status(); - RETURN_MM(); -} - /** * Compute the row variance of the matrix. * @@ -5013,7 +4970,7 @@ PHP_METHOD(Tensor_Matrix, variance) ZEPHIR_CONCAT_SSVS(&_2$$4, "Mean must be a", " column vector ", &_1$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$4, "__construct", NULL, 2, &_2$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$4, "tensor/matrix.zep", 1698); + zephir_throw_exception_debug(&_0$$4, "tensor/matrix.zep", 1687); ZEPHIR_MM_RESTORE(); return; } @@ -5033,7 +4990,7 @@ PHP_METHOD(Tensor_Matrix, variance) ZEPHIR_CONCAT_SSVSVS(&_10$$5, "Mean vector must", " have ", &_7$$5, " rows, ", &_9$$5, " given."); ZEPHIR_CALL_METHOD(NULL, &_5$$5, "__construct", NULL, 2, &_10$$5); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$5, "tensor/matrix.zep", 1704); + zephir_throw_exception_debug(&_5$$5, "tensor/matrix.zep", 1693); ZEPHIR_MM_RESTORE(); return; } @@ -5152,7 +5109,7 @@ PHP_METHOD(Tensor_Matrix, round) ZEPHIR_CONCAT_SSVS(&_3$$3, "Decimal precision cannot", " be less than 0, ", &_2$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1735); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1724); ZEPHIR_MM_RESTORE(); return; } @@ -5389,7 +5346,7 @@ PHP_METHOD(Tensor_Matrix, clip) ZEPHIR_CONCAT_SS(&_1$$3, "Minimum cannot be", " greater than maximum."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_1$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1794); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1783); ZEPHIR_MM_RESTORE(); return; } @@ -5589,7 +5546,7 @@ PHP_METHOD(Tensor_Matrix, augmentAbove) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " columns but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1840); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1829); ZEPHIR_MM_RESTORE(); return; } @@ -5706,7 +5663,7 @@ PHP_METHOD(Tensor_Matrix, augmentBelow) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " columns but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1862); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1851); ZEPHIR_MM_RESTORE(); return; } @@ -5833,7 +5790,7 @@ PHP_METHOD(Tensor_Matrix, augmentLeft) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " rows but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1884); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1873); ZEPHIR_MM_RESTORE(); return; } @@ -5886,7 +5843,7 @@ PHP_METHOD(Tensor_Matrix, augmentLeft) zephir_array_fast_append(&_27$$4, &bufferA); ZEPHIR_CALL_METHOD(&_26$$4, &bufferB, "concat", &_28, 0, &_27$$4); zephir_check_call_status(); - zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1900); + zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1889); } } ZEPHIR_CALL_CE_STATIC(&buffer, tensor_tensorbuffer_ce, "fromBuffers", NULL, 0, &c); @@ -5996,7 +5953,7 @@ PHP_METHOD(Tensor_Matrix, augmentRight) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " rows but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1920); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1909); ZEPHIR_MM_RESTORE(); return; } @@ -6049,7 +6006,7 @@ PHP_METHOD(Tensor_Matrix, augmentRight) zephir_array_fast_append(&_27$$4, &bufferB); ZEPHIR_CALL_METHOD(&_26$$4, &bufferA, "concat", NULL, 0, &_27$$4); zephir_check_call_status(); - zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1936); + zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1925); } } ZEPHIR_CALL_CE_STATIC(&buffer, tensor_tensorbuffer_ce, "fromBuffers", NULL, 0, &c); @@ -6135,7 +6092,7 @@ PHP_METHOD(Tensor_Matrix, repeat) ZEPHIR_CONCAT_SS(&_4$$4, "Chunk length must be", " greater than 0, 0 given."); ZEPHIR_CALL_METHOD(NULL, &_3$$4, "__construct", NULL, 2, &_4$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_3$$4, "tensor/matrix.zep", 1960); + zephir_throw_exception_debug(&_3$$4, "tensor/matrix.zep", 1949); ZEPHIR_MM_RESTORE(); return; } @@ -6230,7 +6187,7 @@ PHP_METHOD(Tensor_Matrix, multiplyMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1983); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1972); ZEPHIR_MM_RESTORE(); return; } @@ -6307,7 +6264,7 @@ PHP_METHOD(Tensor_Matrix, divideMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2002); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1991); ZEPHIR_MM_RESTORE(); return; } @@ -6384,7 +6341,7 @@ PHP_METHOD(Tensor_Matrix, addMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2021); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2010); ZEPHIR_MM_RESTORE(); return; } @@ -6461,7 +6418,7 @@ PHP_METHOD(Tensor_Matrix, subtractMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2040); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2029); ZEPHIR_MM_RESTORE(); return; } @@ -6539,7 +6496,7 @@ PHP_METHOD(Tensor_Matrix, powMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2060); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2049); ZEPHIR_MM_RESTORE(); return; } @@ -6617,7 +6574,7 @@ PHP_METHOD(Tensor_Matrix, modMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2080); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2069); ZEPHIR_MM_RESTORE(); return; } @@ -6695,7 +6652,7 @@ PHP_METHOD(Tensor_Matrix, equalMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2100); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2089); ZEPHIR_MM_RESTORE(); return; } @@ -6772,7 +6729,7 @@ PHP_METHOD(Tensor_Matrix, notEqualMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2119); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2108); ZEPHIR_MM_RESTORE(); return; } @@ -6850,7 +6807,7 @@ PHP_METHOD(Tensor_Matrix, greaterMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2139); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2128); ZEPHIR_MM_RESTORE(); return; } @@ -6928,7 +6885,7 @@ PHP_METHOD(Tensor_Matrix, greaterEqualMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2159); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2148); ZEPHIR_MM_RESTORE(); return; } @@ -7005,7 +6962,7 @@ PHP_METHOD(Tensor_Matrix, lessMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2178); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2167); ZEPHIR_MM_RESTORE(); return; } @@ -7082,7 +7039,7 @@ PHP_METHOD(Tensor_Matrix, lessEqualMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2197); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2186); ZEPHIR_MM_RESTORE(); return; } @@ -7164,7 +7121,7 @@ PHP_METHOD(Tensor_Matrix, multiplyVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2217); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2206); ZEPHIR_MM_RESTORE(); return; } @@ -7247,7 +7204,7 @@ PHP_METHOD(Tensor_Matrix, divideVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2237); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2226); ZEPHIR_MM_RESTORE(); return; } @@ -7330,7 +7287,7 @@ PHP_METHOD(Tensor_Matrix, addVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2257); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2246); ZEPHIR_MM_RESTORE(); return; } @@ -7413,7 +7370,7 @@ PHP_METHOD(Tensor_Matrix, subtractVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2277); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2266); ZEPHIR_MM_RESTORE(); return; } @@ -7496,7 +7453,7 @@ PHP_METHOD(Tensor_Matrix, powVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2297); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2286); ZEPHIR_MM_RESTORE(); return; } @@ -7579,7 +7536,7 @@ PHP_METHOD(Tensor_Matrix, modVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2317); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2306); ZEPHIR_MM_RESTORE(); return; } @@ -7663,7 +7620,7 @@ PHP_METHOD(Tensor_Matrix, equalVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2338); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2327); ZEPHIR_MM_RESTORE(); return; } @@ -7746,7 +7703,7 @@ PHP_METHOD(Tensor_Matrix, notEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2358); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2347); ZEPHIR_MM_RESTORE(); return; } @@ -7829,7 +7786,7 @@ PHP_METHOD(Tensor_Matrix, greaterVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2378); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2367); ZEPHIR_MM_RESTORE(); return; } @@ -7912,7 +7869,7 @@ PHP_METHOD(Tensor_Matrix, greaterEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2398); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2387); ZEPHIR_MM_RESTORE(); return; } @@ -7995,7 +7952,7 @@ PHP_METHOD(Tensor_Matrix, lessVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2418); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2407); ZEPHIR_MM_RESTORE(); return; } @@ -8079,7 +8036,7 @@ PHP_METHOD(Tensor_Matrix, lessEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2439); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2428); ZEPHIR_MM_RESTORE(); return; } @@ -8162,7 +8119,7 @@ PHP_METHOD(Tensor_Matrix, multiplyColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2459); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2448); ZEPHIR_MM_RESTORE(); return; } @@ -8245,7 +8202,7 @@ PHP_METHOD(Tensor_Matrix, divideColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2479); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2468); ZEPHIR_MM_RESTORE(); return; } @@ -8328,7 +8285,7 @@ PHP_METHOD(Tensor_Matrix, addColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2499); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2488); ZEPHIR_MM_RESTORE(); return; } @@ -8411,7 +8368,7 @@ PHP_METHOD(Tensor_Matrix, subtractColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2519); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2508); ZEPHIR_MM_RESTORE(); return; } @@ -8494,7 +8451,7 @@ PHP_METHOD(Tensor_Matrix, powColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2539); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2528); ZEPHIR_MM_RESTORE(); return; } @@ -8577,7 +8534,7 @@ PHP_METHOD(Tensor_Matrix, modColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2559); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2548); ZEPHIR_MM_RESTORE(); return; } @@ -8660,7 +8617,7 @@ PHP_METHOD(Tensor_Matrix, equalColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2579); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2568); ZEPHIR_MM_RESTORE(); return; } @@ -8743,7 +8700,7 @@ PHP_METHOD(Tensor_Matrix, notEqualColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2599); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2588); ZEPHIR_MM_RESTORE(); return; } @@ -8826,7 +8783,7 @@ PHP_METHOD(Tensor_Matrix, greaterColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2619); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2608); ZEPHIR_MM_RESTORE(); return; } @@ -8909,7 +8866,7 @@ PHP_METHOD(Tensor_Matrix, greaterEqualColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2639); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2628); ZEPHIR_MM_RESTORE(); return; } @@ -8992,7 +8949,7 @@ PHP_METHOD(Tensor_Matrix, lessColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2659); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2648); ZEPHIR_MM_RESTORE(); return; } @@ -9075,7 +9032,7 @@ PHP_METHOD(Tensor_Matrix, lessEqualColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2679); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2668); ZEPHIR_MM_RESTORE(); return; } @@ -9727,7 +9684,7 @@ PHP_METHOD(Tensor_Matrix, offsetSet) Z_PARAM_ZVAL(values) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(2, 0, &index, &values); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2860); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2849); return; } @@ -9778,7 +9735,7 @@ PHP_METHOD(Tensor_Matrix, offsetUnset) Z_PARAM_ZVAL(index) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(1, 0, &index); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2884); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2873); return; } @@ -9838,7 +9795,7 @@ PHP_METHOD(Tensor_Matrix, offsetGet) ZEPHIR_CONCAT_SSVS(&_2$$3, "Row offset must be", " an integer, ", &_1$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 2898); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 2887); ZEPHIR_MM_RESTORE(); return; } @@ -9855,7 +9812,7 @@ PHP_METHOD(Tensor_Matrix, offsetGet) ZEPHIR_CONCAT_SSVS(&_7$$4, "Row offset out of", " bounds, ", &_6$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_7$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 2903); + zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 2892); ZEPHIR_MM_RESTORE(); return; } @@ -9982,30 +9939,30 @@ PHP_METHOD(Tensor_Matrix, __unserialize) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &data_param); zephir_get_arrval(&data, data_param); - zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2946); + zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2935); ZVAL_BOOL(&_1, 0); ZEPHIR_CALL_SELF(&a, "fromArray", NULL, 0, &_0, &_1); zephir_check_call_status(); - zephir_array_fetch_string(&_2, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2948); + zephir_array_fetch_string(&_2, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2937); ZEPHIR_CALL_METHOD(&_3, &a, "m", NULL, 0); zephir_check_call_status(); _4 = !ZEPHIR_IS_EQUAL(&_2, &_3); if (!(_4)) { - zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2948); + zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2937); ZEPHIR_CALL_METHOD(&_6, &a, "n", NULL, 0); zephir_check_call_status(); _4 = !ZEPHIR_IS_EQUAL(&_5, &_6); } if (UNEXPECTED(_4)) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid matrix data.", "tensor/matrix.zep", 2949); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid matrix data.", "tensor/matrix.zep", 2938); return; } ZEPHIR_CALL_METHOD(&_7, &a, "buffer", NULL, 0); zephir_check_call_status(); zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 15, &_7); - zephir_array_fetch_string(&_8, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2953); + zephir_array_fetch_string(&_8, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2942); zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 16, &_8); - zephir_array_fetch_string(&_9, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2954); + zephir_array_fetch_string(&_9, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2943); zephir_update_property_zval_cached(this_ptr, _zephir_prop_2, 17, &_9); ZEPHIR_MM_RESTORE(); } diff --git a/ext/tensor/matrix.zep.h b/ext/tensor/matrix.zep.h index 291dec3..a786280 100644 --- a/ext/tensor/matrix.zep.h +++ b/ext/tensor/matrix.zep.h @@ -99,7 +99,6 @@ PHP_METHOD(Tensor_Matrix, median); PHP_METHOD(Tensor_Matrix, quantile); PHP_METHOD(Tensor_Matrix, softmax); PHP_METHOD(Tensor_Matrix, erf); -PHP_METHOD(Tensor_Matrix, cerf); PHP_METHOD(Tensor_Matrix, variance); PHP_METHOD(Tensor_Matrix, covariance); PHP_METHOD(Tensor_Matrix, round); @@ -510,9 +509,6 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_erf, 0, 0, Tensor\\Matrix, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_cerf, 0, 0, Tensor\\Matrix, 0) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_variance, 0, 0, Tensor\\ColumnVector, 0) ZEND_ARG_INFO(0, mean) ZEND_END_ARG_INFO() @@ -891,7 +887,6 @@ ZEPHIR_INIT_FUNCS(tensor_matrix_method_entry) { PHP_ME(Tensor_Matrix, quantile, arginfo_tensor_matrix_quantile, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, softmax, arginfo_tensor_matrix_softmax, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, erf, arginfo_tensor_matrix_erf, ZEND_ACC_PUBLIC) - PHP_ME(Tensor_Matrix, cerf, arginfo_tensor_matrix_cerf, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, variance, arginfo_tensor_matrix_variance, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, covariance, arginfo_tensor_matrix_covariance, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, round, arginfo_tensor_matrix_round, ZEND_ACC_PUBLIC) diff --git a/ext/tensor/special.zep.c b/ext/tensor/special.zep.c index 22a4503..53ad273 100644 --- a/ext/tensor/special.zep.c +++ b/ext/tensor/special.zep.c @@ -20,21 +20,26 @@ ZEPHIR_INIT_CLASS(Tensor_Special) } /** - * Return the softmax of the tensor i.e. each row normalized to sum to 1. + * Return the element-wise logistic function i.e. 1 / (1 + exp(-x)). * * @return mixed */ -ZEPHIR_DOC_METHOD(Tensor_Special, softmax); +ZEPHIR_DOC_METHOD(Tensor_Special, sigmoid); /** - * Return the element-wise Gaussian error function. + * Return the element-wise softplus i.e. log(1 + exp(x)). * * @return mixed */ -ZEPHIR_DOC_METHOD(Tensor_Special, erf); +ZEPHIR_DOC_METHOD(Tensor_Special, softplus); +/** + * Return the softmax of the tensor i.e. each row normalized to sum to 1. + * + * @return mixed + */ +ZEPHIR_DOC_METHOD(Tensor_Special, softmax); /** - * Return the element-wise scaled complementary error function, - * i.e. exp(-x^2) * erfc(-x). + * Return the element-wise Gaussian error function. * * @return mixed */ -ZEPHIR_DOC_METHOD(Tensor_Special, cerf); +ZEPHIR_DOC_METHOD(Tensor_Special, erf); diff --git a/ext/tensor/special.zep.h b/ext/tensor/special.zep.h index 83e91fb..ddfd979 100644 --- a/ext/tensor/special.zep.h +++ b/ext/tensor/special.zep.h @@ -3,18 +3,22 @@ extern zend_class_entry *tensor_special_ce; ZEPHIR_INIT_CLASS(Tensor_Special); -ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_softmax, 0, 0, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_sigmoid, 0, 0, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_erf, 0, 0, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_softplus, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_softmax, 0, 0, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_cerf, 0, 0, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_special_erf, 0, 0, 0) ZEND_END_ARG_INFO() ZEPHIR_INIT_FUNCS(tensor_special_method_entry) { + PHP_ABSTRACT_ME(Tensor_Special, sigmoid, arginfo_tensor_special_sigmoid) + PHP_ABSTRACT_ME(Tensor_Special, softplus, arginfo_tensor_special_softplus) PHP_ABSTRACT_ME(Tensor_Special, softmax, arginfo_tensor_special_softmax) PHP_ABSTRACT_ME(Tensor_Special, erf, arginfo_tensor_special_erf) - PHP_ABSTRACT_ME(Tensor_Special, cerf, arginfo_tensor_special_cerf) PHP_FE_END }; diff --git a/ext/tensor/unary.zep.c b/ext/tensor/unary.zep.c index 082b2d9..e684d3b 100644 --- a/ext/tensor/unary.zep.c +++ b/ext/tensor/unary.zep.c @@ -64,18 +64,6 @@ ZEPHIR_DOC_METHOD(Tensor_Unary, log); * @return mixed */ ZEPHIR_DOC_METHOD(Tensor_Unary, log1p); -/** - * Return the element-wise logistic function i.e. 1 / (1 + exp(-x)). - * - * @return mixed - */ -ZEPHIR_DOC_METHOD(Tensor_Unary, sigmoid); -/** - * Return the element-wise softplus i.e. log(1 + exp(x)). - * - * @return mixed - */ -ZEPHIR_DOC_METHOD(Tensor_Unary, softplus); /** * Round the elements in the tensor to a given decimal place. * diff --git a/ext/tensor/unary.zep.h b/ext/tensor/unary.zep.h index f0c7bbb..2517f5e 100644 --- a/ext/tensor/unary.zep.h +++ b/ext/tensor/unary.zep.h @@ -25,12 +25,6 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_unary_log1p, 0, 0, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_unary_sigmoid, 0, 0, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_unary_softplus, 0, 0, 0) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_unary_round, 0, 0, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, precision, IS_LONG, 0, "0") ZEND_END_ARG_INFO() @@ -68,8 +62,6 @@ ZEPHIR_INIT_FUNCS(tensor_unary_method_entry) { PHP_ABSTRACT_ME(Tensor_Unary, expm1, arginfo_tensor_unary_expm1) PHP_ABSTRACT_ME(Tensor_Unary, log, arginfo_tensor_unary_log) PHP_ABSTRACT_ME(Tensor_Unary, log1p, arginfo_tensor_unary_log1p) - PHP_ABSTRACT_ME(Tensor_Unary, sigmoid, arginfo_tensor_unary_sigmoid) - PHP_ABSTRACT_ME(Tensor_Unary, softplus, arginfo_tensor_unary_softplus) PHP_ABSTRACT_ME(Tensor_Unary, round, arginfo_tensor_unary_round) PHP_ABSTRACT_ME(Tensor_Unary, floor, arginfo_tensor_unary_floor) PHP_ABSTRACT_ME(Tensor_Unary, ceil, arginfo_tensor_unary_ceil) diff --git a/ext/tensor/vector.zep.c b/ext/tensor/vector.zep.c index 02764b4..479290d 100644 --- a/ext/tensor/vector.zep.c +++ b/ext/tensor/vector.zep.c @@ -3519,37 +3519,6 @@ PHP_METHOD(Tensor_Vector, erf) RETURN_MM(); } -/** - * Return the element-wise scaled complementary error function, - * i.e. exp(-x^2) * erfc(-x). - * - * @return self - */ -PHP_METHOD(Tensor_Vector, cerf) -{ - zval _0, _1; - zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; - zend_long ZEPHIR_LAST_CALL_STATUS; - zval *this_ptr = getThis(); - - ZVAL_UNDEF(&_0); - ZVAL_UNDEF(&_1); - static zend_string *_zephir_prop_0 = NULL; - if (UNEXPECTED(!_zephir_prop_0)) { - _zephir_prop_0 = zend_string_init("a", 1, 1); - } - ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); - zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); - - object_init_ex(return_value, zend_get_called_scope(execute_data)); - ZEPHIR_INIT_VAR(&_0); - zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); - tensor_cerf(&_0, &_1); - ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 3, &_0); - zephir_check_call_status(); - RETURN_MM(); -} - /** * Return the variance of the vector. * @@ -3605,7 +3574,7 @@ PHP_METHOD(Tensor_Vector, variance) ZEPHIR_CONCAT_SSVS(&_3$$4, "Mean scalar must be", " a floating point number ", &_2$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_1$$4, "__construct", NULL, 2, &_3$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$4, "tensor/vector.zep", 1328); + zephir_throw_exception_debug(&_1$$4, "tensor/vector.zep", 1317); ZEPHIR_MM_RESTORE(); return; } @@ -3671,7 +3640,7 @@ PHP_METHOD(Tensor_Vector, round) ZEPHIR_CONCAT_SSVS(&_3$$3, "Decimal precision cannot", " be less than 0, ", &_2$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1352); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1341); ZEPHIR_MM_RESTORE(); return; } @@ -3848,7 +3817,7 @@ PHP_METHOD(Tensor_Vector, clip) ZEPHIR_CONCAT_SS(&_1$$3, "Minimum cannot be", " greater than maximum."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_1$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1411); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1400); ZEPHIR_MM_RESTORE(); return; } @@ -4000,7 +3969,7 @@ PHP_METHOD(Tensor_Vector, multiplyMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1451); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1440); ZEPHIR_MM_RESTORE(); return; } @@ -4080,7 +4049,7 @@ PHP_METHOD(Tensor_Vector, divideMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1471); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1460); ZEPHIR_MM_RESTORE(); return; } @@ -4160,7 +4129,7 @@ PHP_METHOD(Tensor_Vector, addMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1491); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1480); ZEPHIR_MM_RESTORE(); return; } @@ -4240,7 +4209,7 @@ PHP_METHOD(Tensor_Vector, subtractMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1511); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1500); ZEPHIR_MM_RESTORE(); return; } @@ -4320,7 +4289,7 @@ PHP_METHOD(Tensor_Vector, powMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1531); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1520); ZEPHIR_MM_RESTORE(); return; } @@ -4400,7 +4369,7 @@ PHP_METHOD(Tensor_Vector, modMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1551); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1540); ZEPHIR_MM_RESTORE(); return; } @@ -4480,7 +4449,7 @@ PHP_METHOD(Tensor_Vector, equalMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1571); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1560); ZEPHIR_MM_RESTORE(); return; } @@ -4560,7 +4529,7 @@ PHP_METHOD(Tensor_Vector, notEqualMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1591); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1580); ZEPHIR_MM_RESTORE(); return; } @@ -4640,7 +4609,7 @@ PHP_METHOD(Tensor_Vector, greaterMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1611); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1600); ZEPHIR_MM_RESTORE(); return; } @@ -4720,7 +4689,7 @@ PHP_METHOD(Tensor_Vector, greaterEqualMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1631); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1620); ZEPHIR_MM_RESTORE(); return; } @@ -4800,7 +4769,7 @@ PHP_METHOD(Tensor_Vector, lessMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1651); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1640); ZEPHIR_MM_RESTORE(); return; } @@ -4880,7 +4849,7 @@ PHP_METHOD(Tensor_Vector, lessEqualMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1671); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1660); ZEPHIR_MM_RESTORE(); return; } @@ -4957,7 +4926,7 @@ PHP_METHOD(Tensor_Vector, multiplyVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1691); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1680); ZEPHIR_MM_RESTORE(); return; } @@ -5030,7 +4999,7 @@ PHP_METHOD(Tensor_Vector, divideVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1709); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1698); ZEPHIR_MM_RESTORE(); return; } @@ -5103,7 +5072,7 @@ PHP_METHOD(Tensor_Vector, addVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1727); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1716); ZEPHIR_MM_RESTORE(); return; } @@ -5176,7 +5145,7 @@ PHP_METHOD(Tensor_Vector, subtractVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1745); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1734); ZEPHIR_MM_RESTORE(); return; } @@ -5249,7 +5218,7 @@ PHP_METHOD(Tensor_Vector, powVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1763); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1752); ZEPHIR_MM_RESTORE(); return; } @@ -5322,7 +5291,7 @@ PHP_METHOD(Tensor_Vector, modVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1781); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1770); ZEPHIR_MM_RESTORE(); return; } @@ -5396,7 +5365,7 @@ PHP_METHOD(Tensor_Vector, equalVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1800); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1789); ZEPHIR_MM_RESTORE(); return; } @@ -5469,7 +5438,7 @@ PHP_METHOD(Tensor_Vector, notEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1818); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1807); ZEPHIR_MM_RESTORE(); return; } @@ -5542,7 +5511,7 @@ PHP_METHOD(Tensor_Vector, greaterVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1836); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1825); ZEPHIR_MM_RESTORE(); return; } @@ -5615,7 +5584,7 @@ PHP_METHOD(Tensor_Vector, greaterEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1854); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1843); ZEPHIR_MM_RESTORE(); return; } @@ -5688,7 +5657,7 @@ PHP_METHOD(Tensor_Vector, lessVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1872); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1861); ZEPHIR_MM_RESTORE(); return; } @@ -5761,7 +5730,7 @@ PHP_METHOD(Tensor_Vector, lessEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1890); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1879); ZEPHIR_MM_RESTORE(); return; } @@ -6261,7 +6230,7 @@ PHP_METHOD(Tensor_Vector, offsetSet) Z_PARAM_ZVAL(values) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(2, 0, &index, &values); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2047); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2036); return; } @@ -6312,7 +6281,7 @@ PHP_METHOD(Tensor_Vector, offsetUnset) Z_PARAM_ZVAL(index) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(1, 0, &index); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2071); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2060); return; } @@ -6370,7 +6339,7 @@ PHP_METHOD(Tensor_Vector, offsetGet) ZEPHIR_CONCAT_SSVS(&_5$$3, "Element not found at", " offset ", &_4$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_3$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_3$$3, "tensor/vector.zep", 2085); + zephir_throw_exception_debug(&_3$$3, "tensor/vector.zep", 2074); ZEPHIR_MM_RESTORE(); return; } @@ -6481,21 +6450,21 @@ PHP_METHOD(Tensor_Vector, __unserialize) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &data_param); zephir_get_arrval(&data, data_param); - zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2126); + zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2115); ZVAL_BOOL(&_1, 0); ZEPHIR_CALL_SELF(&a, "fromArray", NULL, 0, &_0, &_1); zephir_check_call_status(); - zephir_array_fetch_string(&_2, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2128); + zephir_array_fetch_string(&_2, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2117); ZEPHIR_CALL_METHOD(&_3, &a, "size", NULL, 0); zephir_check_call_status(); if (UNEXPECTED(!ZEPHIR_IS_EQUAL(&_2, &_3))) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid vector data.", "tensor/vector.zep", 2129); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid vector data.", "tensor/vector.zep", 2118); return; } ZEPHIR_CALL_METHOD(&_4, &a, "buffer", NULL, 0); zephir_check_call_status(); zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 1, &_4); - zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2133); + zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2122); zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 2, &_5); ZEPHIR_MM_RESTORE(); } diff --git a/ext/tensor/vector.zep.h b/ext/tensor/vector.zep.h index 29f7e83..e3f902b 100644 --- a/ext/tensor/vector.zep.h +++ b/ext/tensor/vector.zep.h @@ -82,7 +82,6 @@ PHP_METHOD(Tensor_Vector, median); PHP_METHOD(Tensor_Vector, quantile); PHP_METHOD(Tensor_Vector, softmax); PHP_METHOD(Tensor_Vector, erf); -PHP_METHOD(Tensor_Vector, cerf); PHP_METHOD(Tensor_Vector, variance); PHP_METHOD(Tensor_Vector, round); PHP_METHOD(Tensor_Vector, floor); @@ -420,9 +419,6 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_erf, 0, 0, Tensor\\Vector, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_cerf, 0, 0, Tensor\\Vector, 0) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tensor_vector_variance, 0, 0, IS_DOUBLE, 0) ZEND_ARG_INFO(0, mean) ZEND_END_ARG_INFO() @@ -712,7 +708,6 @@ PHP_ME(Tensor_Vector, transpose, arginfo_tensor_vector_transpose, ZEND_ACC_PUBLI PHP_ME(Tensor_Vector, quantile, arginfo_tensor_vector_quantile, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, softmax, arginfo_tensor_vector_softmax, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, erf, arginfo_tensor_vector_erf, ZEND_ACC_PUBLIC) - PHP_ME(Tensor_Vector, cerf, arginfo_tensor_vector_cerf, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, variance, arginfo_tensor_vector_variance, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, round, arginfo_tensor_vector_round, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, floor, arginfo_tensor_vector_floor, ZEND_ACC_PUBLIC) diff --git a/optimizers/TensorCerfOptimizer.php b/optimizers/TensorCerfOptimizer.php deleted file mode 100644 index d65c47a..0000000 --- a/optimizers/TensorCerfOptimizer.php +++ /dev/null @@ -1,76 +0,0 @@ -processExpectedReturn($context); - - $symbolVariable = $call->getSymbolVariable(); - - if (empty($symbolVariable)) { - throw new CompilerException('Missing symbol variable.'); - } - - if ($symbolVariable->getType() !== 'variable') { - throw new CompilerException( - 'Return value must only be assigned to a dynamic variable.', - $expression - ); - } - - if ($call->mustInitSymbolVariable()) { - $symbolVariable->initVariant($context); - } - - $context->headersManager->add( - 'include/unary', - HeadersManager::POSITION_LAST - ); - - $resolvedParams = $call->getResolvedParams( - $expression['parameters'], - $context, - $expression - ); - - $symbol = $context->backend->getVariableCode($symbolVariable); - - $context->codePrinter->output( - "tensor_cerf($symbol, {$resolvedParams[0]});" - ); - - return new CompiledExpression( - 'variable', - $symbolVariable->getRealName(), - $expression - ); - } -} diff --git a/tensor/matrix.zep b/tensor/matrix.zep index 09f41d8..a0b515f 100644 --- a/tensor/matrix.zep +++ b/tensor/matrix.zep @@ -1671,17 +1671,6 @@ class Matrix implements Tensor return new self(tensor_erf(this->a), this->m, this->n); } - /** - * Return the element-wise scaled complementary error function, - * i.e. exp(-x^2) * erfc(-x). - * - * @return self - */ - public function cerf() -> - { - return new self(tensor_cerf(this->a), this->m, this->n); - } - /** * Compute the row variance of the matrix. * diff --git a/tensor/special.zep b/tensor/special.zep index d0a350e..2e7b166 100644 --- a/tensor/special.zep +++ b/tensor/special.zep @@ -2,6 +2,20 @@ namespace Tensor; interface Special { + /** + * Return the element-wise logistic function i.e. 1 / (1 + exp(-x)). + * + * @return mixed + */ + public function sigmoid(); + + /** + * Return the element-wise softplus i.e. log(1 + exp(x)). + * + * @return mixed + */ + public function softplus(); + /** * Return the softmax of the tensor i.e. each row normalized to sum to 1. * @@ -15,12 +29,4 @@ interface Special * @return mixed */ public function erf(); - - /** - * Return the element-wise scaled complementary error function, - * i.e. exp(-x^2) * erfc(-x). - * - * @return mixed - */ - public function cerf(); } diff --git a/tensor/unary.zep b/tensor/unary.zep index 980e072..a0070b9 100644 --- a/tensor/unary.zep +++ b/tensor/unary.zep @@ -54,20 +54,6 @@ interface Unary */ public function log1p(); - /** - * Return the element-wise logistic function i.e. 1 / (1 + exp(-x)). - * - * @return mixed - */ - public function sigmoid(); - - /** - * Return the element-wise softplus i.e. log(1 + exp(x)). - * - * @return mixed - */ - public function softplus(); - /** * Round the elements in the tensor to a given decimal place. * diff --git a/tensor/vector.zep b/tensor/vector.zep index cb95dfb..3dfca90 100644 --- a/tensor/vector.zep +++ b/tensor/vector.zep @@ -1302,17 +1302,6 @@ class Vector implements Tensor return new static(tensor_erf(this->a)); } - /** - * Return the element-wise scaled complementary error function, - * i.e. exp(-x^2) * erfc(-x). - * - * @return self - */ - public function cerf() -> - { - return new static(tensor_cerf(this->a)); - } - /** * Return the variance of the vector. * diff --git a/tests/ColumnVectorTest.php b/tests/ColumnVectorTest.php index ffb815c..3cb533a 100644 --- a/tests/ColumnVectorTest.php +++ b/tests/ColumnVectorTest.php @@ -493,17 +493,6 @@ public function erfReturnsColumnVector() : void $this->assertEqualsWithDelta([0.8427007929497148, -0.8427007929497148, 0.0], $b->asArray(), 1e-8); } - /** - * @test - */ - public function cerfReturnsColumnVector() : void - { - $b = ColumnVector::fromArray([1.0, -1.0, 0.0])->cerf(); - - $this->assertInstanceOf(ColumnVector::class, $b); - $this->assertEqualsWithDelta([0.6778917379565147, 0.05786714438636991, 1.0], $b->asArray(), 1e-8); - } - /** * @test */ diff --git a/tests/MatrixTest.php b/tests/MatrixTest.php index 279df28..8ecb92f 100644 --- a/tests/MatrixTest.php +++ b/tests/MatrixTest.php @@ -4408,44 +4408,6 @@ public function erfSaturates() : void $this->assertSame([1.0, -1.0], $a->erf()->asArray()[0]); } - /** - * @test - */ - public function cerf() : void - { - $a = Matrix::fromArray([ - [0.0, 1.0, -1.0], - [0.5, -0.5, 2.0], - ]); - - $b = $a->cerf(); - - $expected = Matrix::fromArray([ - [1.0, 0.6778917379565147, 0.05786714438636991], - [1.184166495500776, 0.3734350706420337, 0.0365456020727383], - ]); - - $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); - } - - /** - * The scaled form stays finite for large inputs where the unscaled - * erfc would underflow. - * - * @test - */ - public function cerfStaysFinite() : void - { - $a = Matrix::fromArray([ - [50.0, -50.0], - ]); - - $b = $a->cerf()->asArray()[0]; - - $this->assertTrue(is_finite($b[0])); - $this->assertTrue(is_finite($b[1])); - } - /** * A single row is one group, so it normalizes to one across its width. * diff --git a/tests/VectorTest.php b/tests/VectorTest.php index 7ad3e11..c08b3c0 100644 --- a/tests/VectorTest.php +++ b/tests/VectorTest.php @@ -144,9 +144,7 @@ public function unaryInterfaceSurface() : void 'log1p', 'negate', 'round', - 'sigmoid', 'sign', - 'softplus', 'sqrt', 'square', ], $methods); @@ -2417,39 +2415,6 @@ public function erfSaturates() : void $this->assertSame([1.0, -1.0], $a->erf()->asArray()); } - /** - * @test - */ - public function cerf() : void - { - $a = Vector::fromArray([0.0, 1.0, -1.0, 0.5, -0.5, 2.0]); - - $b = $a->cerf(); - - $expected = Vector::fromArray([ - 1.0, 0.6778917379565147, 0.05786714438636991, - 1.184166495500776, 0.3734350706420337, 0.0365456020727383, - ]); - - $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); - } - - /** - * The scaled form stays finite for large inputs where the unscaled - * erfc would underflow. - * - * @test - */ - public function cerfStaysFinite() : void - { - $a = Vector::fromArray([50.0, -50.0]); - - $b = $a->cerf()->asArray(); - - $this->assertTrue(is_finite($b[0])); - $this->assertTrue(is_finite($b[1])); - } - /** * Lengths on both sides of the kernel's block boundary: a single element, a * block narrower than the floor, and one wider than the cap. From b19e2a307f5f2a13daeac0c0bc7edffbd2f702c1 Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Wed, 7 Oct 2026 00:19:50 -0500 Subject: [PATCH 04/14] Add rsqrt --- CHANGELOG.md | 1 + docs/Matrix.md | 1 + docs/Vector.md | 1 + docs/interfaces/tensor.md | 2 +- docs/interfaces/unary.md | 4 + ext/include/unary.c | 4 + ext/include/unary.h | 1 + ext/tensor/matrix.zep.c | 162 +++++++++++++++++----------- ext/tensor/matrix.zep.h | 5 + ext/tensor/unary.zep.c | 6 ++ ext/tensor/unary.zep.h | 4 + ext/tensor/vector.zep.c | 116 ++++++++++++-------- ext/tensor/vector.zep.h | 5 + optimizers/TensorRsqrtOptimizer.php | 76 +++++++++++++ tensor/matrix.zep | 10 ++ tensor/unary.zep | 7 ++ tensor/vector.zep | 10 ++ tests/ColumnVectorTest.php | 11 ++ tests/MatrixTest.php | 20 ++++ tests/SettingsTest.php | 10 ++ tests/VectorTest.php | 18 ++++ 21 files changed, 370 insertions(+), 104 deletions(-) create mode 100644 optimizers/TensorRsqrtOptimizer.php diff --git a/CHANGELOG.md b/CHANGELOG.md index c6cf1f1..4ac30c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - 4.1.0 - Added `softplus()` and `erf()` special functions - Added `sinh()` and `cosh()` trigonometric functions + - Added reciprocal square root `rsqrt()` function - 4.0.0 - Data are now backed by a contiguous C buffer instead of PHP array diff --git a/docs/Matrix.md b/docs/Matrix.md index ae09059..cef9bee 100644 --- a/docs/Matrix.md +++ b/docs/Matrix.md @@ -419,6 +419,7 @@ See [Unary](interfaces/unary.md). Each method returns a new `Matrix`. - `abs() : self` — absolute value of each element - `square() : self` — square of the matrix element-wise - `sqrt() : self` — square root of the matrix +- `rsqrt() : self` — reciprocal square root of the matrix - `reciprocal() : self` — element-wise reciprocal of the matrix - `exp() : self` — exponential of the matrix - `expm1() : self` — exponential of each element minus 1 diff --git a/docs/Vector.md b/docs/Vector.md index 5d20aed..b18ead8 100644 --- a/docs/Vector.md +++ b/docs/Vector.md @@ -302,6 +302,7 @@ See [Unary](interfaces/unary.md). Each method returns a new `Vector`. - `abs() : self` — absolute value of the vector - `square() : self` — square the vector - `sqrt() : self` — square root of the vector +- `rsqrt() : self` — reciprocal square root of the vector - `reciprocal() : self` — element-wise reciprocal of the vector - `exp() : self` — exponentiate each element - `expm1() : self` — exponential of each element minus 1 diff --git a/docs/interfaces/tensor.md b/docs/interfaces/tensor.md index 8c9c03d..d9c221e 100644 --- a/docs/interfaces/tensor.md +++ b/docs/interfaces/tensor.md @@ -20,7 +20,7 @@ interface Tensor extends ArrayLike, Arithmetic, Comparable, | [ArrayLike](arraylike.md) | `shape`, `shapeString`, `size`, `map`, `reduce`, `asArray` | | [Arithmetic](arithmetic.md) | `multiply`, `divide`, `add`, `subtract`, `pow`, `mod` | | [Comparable](comparable.md) | `equal`, `notEqual`, `greater`, `greaterEqual`, `less`, `lessEqual` | -| [Unary](unary.md) | `abs`, `square`, `sqrt`, `exp`, `expm1`, `log`, `log1p`, `sigmoid`, `softplus`, `round`, `floor`, `ceil`, `sign`, `negate`, `clip`, `clipLower`, `clipUpper` | +| [Unary](unary.md) | `abs`, `square`, `sqrt`, `rsqrt`, `exp`, `expm1`, `log`, `log1p`, `sigmoid`, `softplus`, `round`, `floor`, `ceil`, `sign`, `negate`, `clip`, `clipLower`, `clipUpper` | | [Trigonometric](trigonometric.md) | `sin`, `asin`, `cos`, `acos`, `tan`, `atan`, `tanh`, `sinh`, `cosh`, `rad2deg`, `deg2rad` | | [Reductions](reductions.md) | `sum`, `product`, `min`, `max`, `argmin`, `argmax`, `mean`, `variance`, `median`, `quantile` | | [Special](special.md) | `softmax`, `erf` | diff --git a/docs/interfaces/unary.md b/docs/interfaces/unary.md index 9edae16..4b16994 100644 --- a/docs/interfaces/unary.md +++ b/docs/interfaces/unary.md @@ -26,6 +26,10 @@ Square the tensor. Return the square root of the tensor. +### `rsqrt() : mixed` + +Return the reciprocal square root of the tensor. + ### `reciprocal() : mixed` Return the element-wise reciprocal of the tensor. diff --git a/ext/include/unary.c b/ext/include/unary.c index 61d8777..4607bf7 100644 --- a/ext/include/unary.c +++ b/ext/include/unary.c @@ -86,6 +86,7 @@ TENSOR_UNARY_DISPATCH(abs, fabs(va[i])) TENSOR_UNARY_DISPATCH(sqrt, sqrt(va[i])) +TENSOR_UNARY_DISPATCH(rsqrt, 1.0 / sqrt(va[i])) TENSOR_UNARY_DISPATCH(floor, floor(va[i])) TENSOR_UNARY_DISPATCH(ceil, ceil(va[i])) TENSOR_UNARY_DISPATCH(negate, -va[i]) @@ -466,6 +467,7 @@ void tensor_unary_dispatch_sse_init(void) { tensor_abs_route = tensor_abs_sse; tensor_sqrt_route = tensor_sqrt_sse; + tensor_rsqrt_route = tensor_rsqrt_sse; tensor_floor_route = tensor_floor_sse; tensor_ceil_route = tensor_ceil_sse; tensor_negate_route = tensor_negate_sse; @@ -484,6 +486,7 @@ void tensor_unary_dispatch_avx_init(void) { tensor_abs_route = tensor_abs_avx; tensor_sqrt_route = tensor_sqrt_avx; + tensor_rsqrt_route = tensor_rsqrt_avx; tensor_floor_route = tensor_floor_avx; tensor_ceil_route = tensor_ceil_avx; tensor_negate_route = tensor_negate_avx; @@ -502,6 +505,7 @@ void tensor_unary_dispatch_avx512_init(void) { tensor_abs_route = tensor_abs_avx512; tensor_sqrt_route = tensor_sqrt_avx512; + tensor_rsqrt_route = tensor_rsqrt_avx512; tensor_floor_route = tensor_floor_avx512; tensor_ceil_route = tensor_ceil_avx512; tensor_negate_route = tensor_negate_avx512; diff --git a/ext/include/unary.h b/ext/include/unary.h index 0246ab6..de3c810 100644 --- a/ext/include/unary.h +++ b/ext/include/unary.h @@ -5,6 +5,7 @@ void tensor_abs(zval * return_value, zval * a); void tensor_sqrt(zval * return_value, zval * a); +void tensor_rsqrt(zval * return_value, zval * a); void tensor_exp(zval * return_value, zval * a); void tensor_expm1(zval * return_value, zval * a); void tensor_log(zval * return_value, zval * a); diff --git a/ext/tensor/matrix.zep.c b/ext/tensor/matrix.zep.c index fa87544..60a2e87 100644 --- a/ext/tensor/matrix.zep.c +++ b/ext/tensor/matrix.zep.c @@ -3669,6 +3669,48 @@ PHP_METHOD(Tensor_Matrix, sqrt) RETURN_MM(); } +/** + * Return the reciprocal square root of the matrix. + * + * @return self + */ +PHP_METHOD(Tensor_Matrix, rsqrt) +{ + zval _0, _1, _2, _3; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + ZVAL_UNDEF(&_2); + ZVAL_UNDEF(&_3); + static zend_string *_zephir_prop_0 = NULL; + static zend_string *_zephir_prop_1 = NULL; + static zend_string *_zephir_prop_2 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_1)) { + _zephir_prop_1 = zend_string_init("m", 1, 1); + } + if (UNEXPECTED(!_zephir_prop_2)) { + _zephir_prop_2 = zend_string_init("n", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + object_init_ex(return_value, tensor_matrix_ce); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 15, PH_NOISY_CC | PH_READONLY); + tensor_rsqrt(&_0, &_1); + zephir_read_property_cached(&_2, this_ptr, _zephir_prop_1, 16, PH_NOISY_CC | PH_READONLY); + zephir_read_property_cached(&_3, this_ptr, _zephir_prop_2, 17, PH_NOISY_CC | PH_READONLY); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 18, &_0, &_2, &_3); + zephir_check_call_status(); + RETURN_MM(); +} + /** * Return the exponential of the matrix. * @@ -3814,7 +3856,7 @@ PHP_METHOD(Tensor_Matrix, log) ZEPHIR_CONCAT_SSVS(&_3$$3, "Log base must be greater", " than 0, ", &_2$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1400); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1410); ZEPHIR_MM_RESTORE(); return; } @@ -4792,7 +4834,7 @@ PHP_METHOD(Tensor_Matrix, quantile) ZEPHIR_CONCAT_SS(&_3$$3, "Q must be a finite value", " between 0 and 1."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1643); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1653); ZEPHIR_MM_RESTORE(); return; } @@ -4810,7 +4852,7 @@ PHP_METHOD(Tensor_Matrix, quantile) ZEPHIR_CONCAT_SSVS(&_8$$4, "Q must be between", " 0 and 1, ", &_7$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_8$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 1648); + zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 1658); ZEPHIR_MM_RESTORE(); return; } @@ -4970,7 +5012,7 @@ PHP_METHOD(Tensor_Matrix, variance) ZEPHIR_CONCAT_SSVS(&_2$$4, "Mean must be a", " column vector ", &_1$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$4, "__construct", NULL, 2, &_2$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$4, "tensor/matrix.zep", 1687); + zephir_throw_exception_debug(&_0$$4, "tensor/matrix.zep", 1697); ZEPHIR_MM_RESTORE(); return; } @@ -4990,7 +5032,7 @@ PHP_METHOD(Tensor_Matrix, variance) ZEPHIR_CONCAT_SSVSVS(&_10$$5, "Mean vector must", " have ", &_7$$5, " rows, ", &_9$$5, " given."); ZEPHIR_CALL_METHOD(NULL, &_5$$5, "__construct", NULL, 2, &_10$$5); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$5, "tensor/matrix.zep", 1693); + zephir_throw_exception_debug(&_5$$5, "tensor/matrix.zep", 1703); ZEPHIR_MM_RESTORE(); return; } @@ -5109,7 +5151,7 @@ PHP_METHOD(Tensor_Matrix, round) ZEPHIR_CONCAT_SSVS(&_3$$3, "Decimal precision cannot", " be less than 0, ", &_2$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1724); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1734); ZEPHIR_MM_RESTORE(); return; } @@ -5346,7 +5388,7 @@ PHP_METHOD(Tensor_Matrix, clip) ZEPHIR_CONCAT_SS(&_1$$3, "Minimum cannot be", " greater than maximum."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_1$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1783); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 1793); ZEPHIR_MM_RESTORE(); return; } @@ -5546,7 +5588,7 @@ PHP_METHOD(Tensor_Matrix, augmentAbove) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " columns but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1829); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1839); ZEPHIR_MM_RESTORE(); return; } @@ -5663,7 +5705,7 @@ PHP_METHOD(Tensor_Matrix, augmentBelow) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " columns but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1851); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1861); ZEPHIR_MM_RESTORE(); return; } @@ -5790,7 +5832,7 @@ PHP_METHOD(Tensor_Matrix, augmentLeft) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " rows but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1873); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1883); ZEPHIR_MM_RESTORE(); return; } @@ -5843,7 +5885,7 @@ PHP_METHOD(Tensor_Matrix, augmentLeft) zephir_array_fast_append(&_27$$4, &bufferA); ZEPHIR_CALL_METHOD(&_26$$4, &bufferB, "concat", &_28, 0, &_27$$4); zephir_check_call_status(); - zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1889); + zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1899); } } ZEPHIR_CALL_CE_STATIC(&buffer, tensor_tensorbuffer_ce, "fromBuffers", NULL, 0, &c); @@ -5953,7 +5995,7 @@ PHP_METHOD(Tensor_Matrix, augmentRight) ZEPHIR_CONCAT_SVSVS(&_11$$3, "Matrix A requires", &_8$$3, " rows but Matrix B has ", &_10$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_6$$3, "__construct", NULL, 2, &_11$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1909); + zephir_throw_exception_debug(&_6$$3, "tensor/matrix.zep", 1919); ZEPHIR_MM_RESTORE(); return; } @@ -6006,7 +6048,7 @@ PHP_METHOD(Tensor_Matrix, augmentRight) zephir_array_fast_append(&_27$$4, &bufferB); ZEPHIR_CALL_METHOD(&_26$$4, &bufferA, "concat", NULL, 0, &_27$$4); zephir_check_call_status(); - zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1925); + zephir_array_append(&c, &_26$$4, PH_SEPARATE, "tensor/matrix.zep", 1935); } } ZEPHIR_CALL_CE_STATIC(&buffer, tensor_tensorbuffer_ce, "fromBuffers", NULL, 0, &c); @@ -6092,7 +6134,7 @@ PHP_METHOD(Tensor_Matrix, repeat) ZEPHIR_CONCAT_SS(&_4$$4, "Chunk length must be", " greater than 0, 0 given."); ZEPHIR_CALL_METHOD(NULL, &_3$$4, "__construct", NULL, 2, &_4$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_3$$4, "tensor/matrix.zep", 1949); + zephir_throw_exception_debug(&_3$$4, "tensor/matrix.zep", 1959); ZEPHIR_MM_RESTORE(); return; } @@ -6187,7 +6229,7 @@ PHP_METHOD(Tensor_Matrix, multiplyMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1972); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1982); ZEPHIR_MM_RESTORE(); return; } @@ -6264,7 +6306,7 @@ PHP_METHOD(Tensor_Matrix, divideMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 1991); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2001); ZEPHIR_MM_RESTORE(); return; } @@ -6341,7 +6383,7 @@ PHP_METHOD(Tensor_Matrix, addMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2010); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2020); ZEPHIR_MM_RESTORE(); return; } @@ -6418,7 +6460,7 @@ PHP_METHOD(Tensor_Matrix, subtractMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2029); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2039); ZEPHIR_MM_RESTORE(); return; } @@ -6496,7 +6538,7 @@ PHP_METHOD(Tensor_Matrix, powMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2049); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2059); ZEPHIR_MM_RESTORE(); return; } @@ -6574,7 +6616,7 @@ PHP_METHOD(Tensor_Matrix, modMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2069); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2079); ZEPHIR_MM_RESTORE(); return; } @@ -6652,7 +6694,7 @@ PHP_METHOD(Tensor_Matrix, equalMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2089); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2099); ZEPHIR_MM_RESTORE(); return; } @@ -6729,7 +6771,7 @@ PHP_METHOD(Tensor_Matrix, notEqualMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2108); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2118); ZEPHIR_MM_RESTORE(); return; } @@ -6807,7 +6849,7 @@ PHP_METHOD(Tensor_Matrix, greaterMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2128); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2138); ZEPHIR_MM_RESTORE(); return; } @@ -6885,7 +6927,7 @@ PHP_METHOD(Tensor_Matrix, greaterEqualMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2148); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2158); ZEPHIR_MM_RESTORE(); return; } @@ -6962,7 +7004,7 @@ PHP_METHOD(Tensor_Matrix, lessMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2167); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2177); ZEPHIR_MM_RESTORE(); return; } @@ -7039,7 +7081,7 @@ PHP_METHOD(Tensor_Matrix, lessEqualMatrix) ZEPHIR_CONCAT_VSVS(&_5$$3, &_3$$3, " matrix expected but ", &_4$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2186); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2196); ZEPHIR_MM_RESTORE(); return; } @@ -7121,7 +7163,7 @@ PHP_METHOD(Tensor_Matrix, multiplyVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2206); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2216); ZEPHIR_MM_RESTORE(); return; } @@ -7204,7 +7246,7 @@ PHP_METHOD(Tensor_Matrix, divideVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2226); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2236); ZEPHIR_MM_RESTORE(); return; } @@ -7287,7 +7329,7 @@ PHP_METHOD(Tensor_Matrix, addVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2246); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2256); ZEPHIR_MM_RESTORE(); return; } @@ -7370,7 +7412,7 @@ PHP_METHOD(Tensor_Matrix, subtractVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2266); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2276); ZEPHIR_MM_RESTORE(); return; } @@ -7453,7 +7495,7 @@ PHP_METHOD(Tensor_Matrix, powVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2286); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2296); ZEPHIR_MM_RESTORE(); return; } @@ -7536,7 +7578,7 @@ PHP_METHOD(Tensor_Matrix, modVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2306); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2316); ZEPHIR_MM_RESTORE(); return; } @@ -7620,7 +7662,7 @@ PHP_METHOD(Tensor_Matrix, equalVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2327); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2337); ZEPHIR_MM_RESTORE(); return; } @@ -7703,7 +7745,7 @@ PHP_METHOD(Tensor_Matrix, notEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2347); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2357); ZEPHIR_MM_RESTORE(); return; } @@ -7786,7 +7828,7 @@ PHP_METHOD(Tensor_Matrix, greaterVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2367); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2377); ZEPHIR_MM_RESTORE(); return; } @@ -7869,7 +7911,7 @@ PHP_METHOD(Tensor_Matrix, greaterEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2387); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2397); ZEPHIR_MM_RESTORE(); return; } @@ -7952,7 +7994,7 @@ PHP_METHOD(Tensor_Matrix, lessVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2407); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2417); ZEPHIR_MM_RESTORE(); return; } @@ -8036,7 +8078,7 @@ PHP_METHOD(Tensor_Matrix, lessEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " columns but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2428); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2438); ZEPHIR_MM_RESTORE(); return; } @@ -8119,7 +8161,7 @@ PHP_METHOD(Tensor_Matrix, multiplyColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2448); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2458); ZEPHIR_MM_RESTORE(); return; } @@ -8202,7 +8244,7 @@ PHP_METHOD(Tensor_Matrix, divideColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2468); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2478); ZEPHIR_MM_RESTORE(); return; } @@ -8285,7 +8327,7 @@ PHP_METHOD(Tensor_Matrix, addColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2488); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2498); ZEPHIR_MM_RESTORE(); return; } @@ -8368,7 +8410,7 @@ PHP_METHOD(Tensor_Matrix, subtractColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2508); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2518); ZEPHIR_MM_RESTORE(); return; } @@ -8451,7 +8493,7 @@ PHP_METHOD(Tensor_Matrix, powColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2528); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2538); ZEPHIR_MM_RESTORE(); return; } @@ -8534,7 +8576,7 @@ PHP_METHOD(Tensor_Matrix, modColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2548); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2558); ZEPHIR_MM_RESTORE(); return; } @@ -8617,7 +8659,7 @@ PHP_METHOD(Tensor_Matrix, equalColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2568); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2578); ZEPHIR_MM_RESTORE(); return; } @@ -8700,7 +8742,7 @@ PHP_METHOD(Tensor_Matrix, notEqualColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2588); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2598); ZEPHIR_MM_RESTORE(); return; } @@ -8783,7 +8825,7 @@ PHP_METHOD(Tensor_Matrix, greaterColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2608); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2618); ZEPHIR_MM_RESTORE(); return; } @@ -8866,7 +8908,7 @@ PHP_METHOD(Tensor_Matrix, greaterEqualColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2628); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2638); ZEPHIR_MM_RESTORE(); return; } @@ -8949,7 +8991,7 @@ PHP_METHOD(Tensor_Matrix, lessColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2648); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2658); ZEPHIR_MM_RESTORE(); return; } @@ -9032,7 +9074,7 @@ PHP_METHOD(Tensor_Matrix, lessEqualColumnVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Matrix A expects ", &_4$$3, " rows but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2668); + zephir_throw_exception_debug(&_2$$3, "tensor/matrix.zep", 2678); ZEPHIR_MM_RESTORE(); return; } @@ -9684,7 +9726,7 @@ PHP_METHOD(Tensor_Matrix, offsetSet) Z_PARAM_ZVAL(values) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(2, 0, &index, &values); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2849); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2859); return; } @@ -9735,7 +9777,7 @@ PHP_METHOD(Tensor_Matrix, offsetUnset) Z_PARAM_ZVAL(index) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(1, 0, &index); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2873); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Matrix cannot be mutated directly.", "tensor/matrix.zep", 2883); return; } @@ -9795,7 +9837,7 @@ PHP_METHOD(Tensor_Matrix, offsetGet) ZEPHIR_CONCAT_SSVS(&_2$$3, "Row offset must be", " an integer, ", &_1$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 2887); + zephir_throw_exception_debug(&_0$$3, "tensor/matrix.zep", 2897); ZEPHIR_MM_RESTORE(); return; } @@ -9812,7 +9854,7 @@ PHP_METHOD(Tensor_Matrix, offsetGet) ZEPHIR_CONCAT_SSVS(&_7$$4, "Row offset out of", " bounds, ", &_6$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_7$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 2892); + zephir_throw_exception_debug(&_5$$4, "tensor/matrix.zep", 2902); ZEPHIR_MM_RESTORE(); return; } @@ -9939,30 +9981,30 @@ PHP_METHOD(Tensor_Matrix, __unserialize) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &data_param); zephir_get_arrval(&data, data_param); - zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2935); + zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2945); ZVAL_BOOL(&_1, 0); ZEPHIR_CALL_SELF(&a, "fromArray", NULL, 0, &_0, &_1); zephir_check_call_status(); - zephir_array_fetch_string(&_2, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2937); + zephir_array_fetch_string(&_2, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2947); ZEPHIR_CALL_METHOD(&_3, &a, "m", NULL, 0); zephir_check_call_status(); _4 = !ZEPHIR_IS_EQUAL(&_2, &_3); if (!(_4)) { - zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2937); + zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2947); ZEPHIR_CALL_METHOD(&_6, &a, "n", NULL, 0); zephir_check_call_status(); _4 = !ZEPHIR_IS_EQUAL(&_5, &_6); } if (UNEXPECTED(_4)) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid matrix data.", "tensor/matrix.zep", 2938); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid matrix data.", "tensor/matrix.zep", 2948); return; } ZEPHIR_CALL_METHOD(&_7, &a, "buffer", NULL, 0); zephir_check_call_status(); zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 15, &_7); - zephir_array_fetch_string(&_8, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2942); + zephir_array_fetch_string(&_8, &data, SL("m"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2952); zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 16, &_8); - zephir_array_fetch_string(&_9, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2943); + zephir_array_fetch_string(&_9, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/matrix.zep", 2953); zephir_update_property_zval_cached(this_ptr, _zephir_prop_2, 17, &_9); ZEPHIR_MM_RESTORE(); } diff --git a/ext/tensor/matrix.zep.h b/ext/tensor/matrix.zep.h index a786280..008b3a4 100644 --- a/ext/tensor/matrix.zep.h +++ b/ext/tensor/matrix.zep.h @@ -71,6 +71,7 @@ PHP_METHOD(Tensor_Matrix, reciprocal); PHP_METHOD(Tensor_Matrix, abs); PHP_METHOD(Tensor_Matrix, square); PHP_METHOD(Tensor_Matrix, sqrt); +PHP_METHOD(Tensor_Matrix, rsqrt); PHP_METHOD(Tensor_Matrix, exp); PHP_METHOD(Tensor_Matrix, expm1); PHP_METHOD(Tensor_Matrix, log); @@ -423,6 +424,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_sqrt, 0, 0, Tensor\\Matrix, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_rsqrt, 0, 0, Tensor\\Matrix, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_matrix_exp, 0, 0, Tensor\\Matrix, 0) ZEND_END_ARG_INFO() @@ -859,6 +863,7 @@ ZEPHIR_INIT_FUNCS(tensor_matrix_method_entry) { PHP_ME(Tensor_Matrix, abs, arginfo_tensor_matrix_abs, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, square, arginfo_tensor_matrix_square, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, sqrt, arginfo_tensor_matrix_sqrt, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Matrix, rsqrt, arginfo_tensor_matrix_rsqrt, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, exp, arginfo_tensor_matrix_exp, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, expm1, arginfo_tensor_matrix_expm1, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Matrix, log, arginfo_tensor_matrix_log, ZEND_ACC_PUBLIC) diff --git a/ext/tensor/unary.zep.c b/ext/tensor/unary.zep.c index e684d3b..55001c7 100644 --- a/ext/tensor/unary.zep.c +++ b/ext/tensor/unary.zep.c @@ -39,6 +39,12 @@ ZEPHIR_DOC_METHOD(Tensor_Unary, square); * @return mixed */ ZEPHIR_DOC_METHOD(Tensor_Unary, sqrt); +/** + * Return the reciprocal square root of the tensor. + * + * @return mixed + */ +ZEPHIR_DOC_METHOD(Tensor_Unary, rsqrt); /** * Return the exponential of the tensor. * diff --git a/ext/tensor/unary.zep.h b/ext/tensor/unary.zep.h index 2517f5e..52bedc7 100644 --- a/ext/tensor/unary.zep.h +++ b/ext/tensor/unary.zep.h @@ -12,6 +12,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_unary_sqrt, 0, 0, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_unary_rsqrt, 0, 0, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_tensor_unary_exp, 0, 0, 0) ZEND_END_ARG_INFO() @@ -58,6 +61,7 @@ ZEPHIR_INIT_FUNCS(tensor_unary_method_entry) { PHP_ABSTRACT_ME(Tensor_Unary, abs, arginfo_tensor_unary_abs) PHP_ABSTRACT_ME(Tensor_Unary, square, arginfo_tensor_unary_square) PHP_ABSTRACT_ME(Tensor_Unary, sqrt, arginfo_tensor_unary_sqrt) + PHP_ABSTRACT_ME(Tensor_Unary, rsqrt, arginfo_tensor_unary_rsqrt) PHP_ABSTRACT_ME(Tensor_Unary, exp, arginfo_tensor_unary_exp) PHP_ABSTRACT_ME(Tensor_Unary, expm1, arginfo_tensor_unary_expm1) PHP_ABSTRACT_ME(Tensor_Unary, log, arginfo_tensor_unary_log) diff --git a/ext/tensor/vector.zep.c b/ext/tensor/vector.zep.c index 479290d..3fafe2d 100644 --- a/ext/tensor/vector.zep.c +++ b/ext/tensor/vector.zep.c @@ -2409,6 +2409,36 @@ PHP_METHOD(Tensor_Vector, sqrt) RETURN_MM(); } +/** + * Return the reciprocal square root of the vector. + * + * @return self + */ +PHP_METHOD(Tensor_Vector, rsqrt) +{ + zval _0, _1; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zend_long ZEPHIR_LAST_CALL_STATUS; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&_0); + ZVAL_UNDEF(&_1); + static zend_string *_zephir_prop_0 = NULL; + if (UNEXPECTED(!_zephir_prop_0)) { + _zephir_prop_0 = zend_string_init("a", 1, 1); + } + ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0); + zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); + + object_init_ex(return_value, zend_get_called_scope(execute_data)); + ZEPHIR_INIT_VAR(&_0); + zephir_read_property_cached(&_1, this_ptr, _zephir_prop_0, 1, PH_NOISY_CC | PH_READONLY); + tensor_rsqrt(&_0, &_1); + ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 3, &_0); + zephir_check_call_status(); + RETURN_MM(); +} + /** * Exponentiate each element in the vector. * @@ -2518,7 +2548,7 @@ PHP_METHOD(Tensor_Vector, log) ZEPHIR_CONCAT_SSVS(&_3$$3, "Log base must be greater", " than 0, ", &_2$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 984); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 994); ZEPHIR_MM_RESTORE(); return; } @@ -3082,7 +3112,7 @@ PHP_METHOD(Tensor_Vector, min) ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the minimum of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1167); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1177); ZEPHIR_MM_RESTORE(); return; } @@ -3138,7 +3168,7 @@ PHP_METHOD(Tensor_Vector, max) ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the maximum of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1184); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1194); ZEPHIR_MM_RESTORE(); return; } @@ -3194,7 +3224,7 @@ PHP_METHOD(Tensor_Vector, argmin) ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the argmin of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1201); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1211); ZEPHIR_MM_RESTORE(); return; } @@ -3250,7 +3280,7 @@ PHP_METHOD(Tensor_Vector, argmax) ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the argmax of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1218); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1228); ZEPHIR_MM_RESTORE(); return; } @@ -3333,7 +3363,7 @@ PHP_METHOD(Tensor_Vector, median) ZEPHIR_CONCAT_SS(&_2$$3, "Cannot compute", " the median of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 2, &_2$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1245); + zephir_throw_exception_debug(&_1$$3, "tensor/vector.zep", 1255); ZEPHIR_MM_RESTORE(); return; } @@ -3405,7 +3435,7 @@ PHP_METHOD(Tensor_Vector, quantile) ZEPHIR_CONCAT_SS(&_3$$3, "Q must be a finite value", " between 0 and 1."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1264); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1274); ZEPHIR_MM_RESTORE(); return; } @@ -3423,7 +3453,7 @@ PHP_METHOD(Tensor_Vector, quantile) ZEPHIR_CONCAT_SSVS(&_8$$4, "Q must be", " between 0 and 1, ", &_7$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_5$$4, "__construct", NULL, 2, &_8$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_5$$4, "tensor/vector.zep", 1269); + zephir_throw_exception_debug(&_5$$4, "tensor/vector.zep", 1279); ZEPHIR_MM_RESTORE(); return; } @@ -3435,7 +3465,7 @@ PHP_METHOD(Tensor_Vector, quantile) ZEPHIR_CONCAT_SS(&_10$$5, "Cannot compute", " the quantile of an empty vector."); ZEPHIR_CALL_METHOD(NULL, &_9$$5, "__construct", NULL, 2, &_10$$5); zephir_check_call_status(); - zephir_throw_exception_debug(&_9$$5, "tensor/vector.zep", 1274); + zephir_throw_exception_debug(&_9$$5, "tensor/vector.zep", 1284); ZEPHIR_MM_RESTORE(); return; } @@ -3574,7 +3604,7 @@ PHP_METHOD(Tensor_Vector, variance) ZEPHIR_CONCAT_SSVS(&_3$$4, "Mean scalar must be", " a floating point number ", &_2$$4, " given."); ZEPHIR_CALL_METHOD(NULL, &_1$$4, "__construct", NULL, 2, &_3$$4); zephir_check_call_status(); - zephir_throw_exception_debug(&_1$$4, "tensor/vector.zep", 1317); + zephir_throw_exception_debug(&_1$$4, "tensor/vector.zep", 1327); ZEPHIR_MM_RESTORE(); return; } @@ -3640,7 +3670,7 @@ PHP_METHOD(Tensor_Vector, round) ZEPHIR_CONCAT_SSVS(&_3$$3, "Decimal precision cannot", " be less than 0, ", &_2$$3, " given."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_3$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1341); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1351); ZEPHIR_MM_RESTORE(); return; } @@ -3817,7 +3847,7 @@ PHP_METHOD(Tensor_Vector, clip) ZEPHIR_CONCAT_SS(&_1$$3, "Minimum cannot be", " greater than maximum."); ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", NULL, 2, &_1$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1400); + zephir_throw_exception_debug(&_0$$3, "tensor/vector.zep", 1410); ZEPHIR_MM_RESTORE(); return; } @@ -3969,7 +3999,7 @@ PHP_METHOD(Tensor_Vector, multiplyMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1440); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1450); ZEPHIR_MM_RESTORE(); return; } @@ -4049,7 +4079,7 @@ PHP_METHOD(Tensor_Vector, divideMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1460); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1470); ZEPHIR_MM_RESTORE(); return; } @@ -4129,7 +4159,7 @@ PHP_METHOD(Tensor_Vector, addMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1480); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1490); ZEPHIR_MM_RESTORE(); return; } @@ -4209,7 +4239,7 @@ PHP_METHOD(Tensor_Vector, subtractMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1500); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1510); ZEPHIR_MM_RESTORE(); return; } @@ -4289,7 +4319,7 @@ PHP_METHOD(Tensor_Vector, powMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1520); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1530); ZEPHIR_MM_RESTORE(); return; } @@ -4369,7 +4399,7 @@ PHP_METHOD(Tensor_Vector, modMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1540); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1550); ZEPHIR_MM_RESTORE(); return; } @@ -4449,7 +4479,7 @@ PHP_METHOD(Tensor_Vector, equalMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1560); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1570); ZEPHIR_MM_RESTORE(); return; } @@ -4529,7 +4559,7 @@ PHP_METHOD(Tensor_Vector, notEqualMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1580); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1590); ZEPHIR_MM_RESTORE(); return; } @@ -4609,7 +4639,7 @@ PHP_METHOD(Tensor_Vector, greaterMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1600); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1610); ZEPHIR_MM_RESTORE(); return; } @@ -4689,7 +4719,7 @@ PHP_METHOD(Tensor_Vector, greaterEqualMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1620); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1630); ZEPHIR_MM_RESTORE(); return; } @@ -4769,7 +4799,7 @@ PHP_METHOD(Tensor_Vector, lessMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1640); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1650); ZEPHIR_MM_RESTORE(); return; } @@ -4849,7 +4879,7 @@ PHP_METHOD(Tensor_Vector, lessEqualMatrix) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A expects ", &_4$$3, " columns but Matrix B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1660); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1670); ZEPHIR_MM_RESTORE(); return; } @@ -4926,7 +4956,7 @@ PHP_METHOD(Tensor_Vector, multiplyVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1680); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1690); ZEPHIR_MM_RESTORE(); return; } @@ -4999,7 +5029,7 @@ PHP_METHOD(Tensor_Vector, divideVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1698); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1708); ZEPHIR_MM_RESTORE(); return; } @@ -5072,7 +5102,7 @@ PHP_METHOD(Tensor_Vector, addVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1716); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1726); ZEPHIR_MM_RESTORE(); return; } @@ -5145,7 +5175,7 @@ PHP_METHOD(Tensor_Vector, subtractVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1734); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1744); ZEPHIR_MM_RESTORE(); return; } @@ -5218,7 +5248,7 @@ PHP_METHOD(Tensor_Vector, powVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1752); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1762); ZEPHIR_MM_RESTORE(); return; } @@ -5291,7 +5321,7 @@ PHP_METHOD(Tensor_Vector, modVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1770); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1780); ZEPHIR_MM_RESTORE(); return; } @@ -5365,7 +5395,7 @@ PHP_METHOD(Tensor_Vector, equalVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1789); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1799); ZEPHIR_MM_RESTORE(); return; } @@ -5438,7 +5468,7 @@ PHP_METHOD(Tensor_Vector, notEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1807); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1817); ZEPHIR_MM_RESTORE(); return; } @@ -5511,7 +5541,7 @@ PHP_METHOD(Tensor_Vector, greaterVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1825); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1835); ZEPHIR_MM_RESTORE(); return; } @@ -5584,7 +5614,7 @@ PHP_METHOD(Tensor_Vector, greaterEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1843); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1853); ZEPHIR_MM_RESTORE(); return; } @@ -5657,7 +5687,7 @@ PHP_METHOD(Tensor_Vector, lessVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1861); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1871); ZEPHIR_MM_RESTORE(); return; } @@ -5730,7 +5760,7 @@ PHP_METHOD(Tensor_Vector, lessEqualVector) ZEPHIR_CONCAT_SVSVS(&_7$$3, "Vector A requires ", &_4$$3, " elements but Vector B has ", &_6$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", NULL, 2, &_7$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1879); + zephir_throw_exception_debug(&_2$$3, "tensor/vector.zep", 1889); ZEPHIR_MM_RESTORE(); return; } @@ -6230,7 +6260,7 @@ PHP_METHOD(Tensor_Vector, offsetSet) Z_PARAM_ZVAL(values) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(2, 0, &index, &values); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2036); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2046); return; } @@ -6281,7 +6311,7 @@ PHP_METHOD(Tensor_Vector, offsetUnset) Z_PARAM_ZVAL(index) ZEND_PARSE_PARAMETERS_END(); zephir_fetch_params_without_memory_grow(1, 0, &index); - ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2060); + ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(tensor_exceptions_runtimeexception_ce, "Vector cannot be mutated directly.", "tensor/vector.zep", 2070); return; } @@ -6339,7 +6369,7 @@ PHP_METHOD(Tensor_Vector, offsetGet) ZEPHIR_CONCAT_SSVS(&_5$$3, "Element not found at", " offset ", &_4$$3, "."); ZEPHIR_CALL_METHOD(NULL, &_3$$3, "__construct", NULL, 2, &_5$$3); zephir_check_call_status(); - zephir_throw_exception_debug(&_3$$3, "tensor/vector.zep", 2074); + zephir_throw_exception_debug(&_3$$3, "tensor/vector.zep", 2084); ZEPHIR_MM_RESTORE(); return; } @@ -6450,21 +6480,21 @@ PHP_METHOD(Tensor_Vector, __unserialize) zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__); zephir_fetch_params(1, 1, 0, &data_param); zephir_get_arrval(&data, data_param); - zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2115); + zephir_array_fetch_string(&_0, &data, SL("a"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2125); ZVAL_BOOL(&_1, 0); ZEPHIR_CALL_SELF(&a, "fromArray", NULL, 0, &_0, &_1); zephir_check_call_status(); - zephir_array_fetch_string(&_2, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2117); + zephir_array_fetch_string(&_2, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2127); ZEPHIR_CALL_METHOD(&_3, &a, "size", NULL, 0); zephir_check_call_status(); if (UNEXPECTED(!ZEPHIR_IS_EQUAL(&_2, &_3))) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid vector data.", "tensor/vector.zep", 2118); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(tensor_exceptions_runtimeexception_ce, "Invalid vector data.", "tensor/vector.zep", 2128); return; } ZEPHIR_CALL_METHOD(&_4, &a, "buffer", NULL, 0); zephir_check_call_status(); zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 1, &_4); - zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2122); + zephir_array_fetch_string(&_5, &data, SL("n"), PH_NOISY | PH_READONLY, "tensor/vector.zep", 2132); zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 2, &_5); ZEPHIR_MM_RESTORE(); } diff --git a/ext/tensor/vector.zep.h b/ext/tensor/vector.zep.h index e3f902b..321cb30 100644 --- a/ext/tensor/vector.zep.h +++ b/ext/tensor/vector.zep.h @@ -54,6 +54,7 @@ PHP_METHOD(Tensor_Vector, reciprocal); PHP_METHOD(Tensor_Vector, abs); PHP_METHOD(Tensor_Vector, square); PHP_METHOD(Tensor_Vector, sqrt); +PHP_METHOD(Tensor_Vector, rsqrt); PHP_METHOD(Tensor_Vector, exp); PHP_METHOD(Tensor_Vector, expm1); PHP_METHOD(Tensor_Vector, log); @@ -333,6 +334,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_sqrt, 0, 0, Tensor\\Vector, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_rsqrt, 0, 0, Tensor\\Vector, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tensor_vector_exp, 0, 0, Tensor\\Vector, 0) ZEND_END_ARG_INFO() @@ -680,6 +684,7 @@ PHP_ME(Tensor_Vector, transpose, arginfo_tensor_vector_transpose, ZEND_ACC_PUBLI PHP_ME(Tensor_Vector, abs, arginfo_tensor_vector_abs, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, square, arginfo_tensor_vector_square, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, sqrt, arginfo_tensor_vector_sqrt, ZEND_ACC_PUBLIC) + PHP_ME(Tensor_Vector, rsqrt, arginfo_tensor_vector_rsqrt, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, exp, arginfo_tensor_vector_exp, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, expm1, arginfo_tensor_vector_expm1, ZEND_ACC_PUBLIC) PHP_ME(Tensor_Vector, log, arginfo_tensor_vector_log, ZEND_ACC_PUBLIC) diff --git a/optimizers/TensorRsqrtOptimizer.php b/optimizers/TensorRsqrtOptimizer.php new file mode 100644 index 0000000..bc57cf1 --- /dev/null +++ b/optimizers/TensorRsqrtOptimizer.php @@ -0,0 +1,76 @@ +processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(); + + if (empty($symbolVariable)) { + throw new CompilerException('Missing symbol variable.'); + } + + if ($symbolVariable->getType() !== 'variable') { + throw new CompilerException( + 'Return value must only be assigned to a dynamic variable.', + $expression + ); + } + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); + } + + $context->headersManager->add( + 'include/unary', + HeadersManager::POSITION_LAST + ); + + $resolvedParams = $call->getResolvedParams( + $expression['parameters'], + $context, + $expression + ); + + $symbol = $context->backend->getVariableCode($symbolVariable); + + $context->codePrinter->output( + "tensor_rsqrt($symbol, {$resolvedParams[0]});" + ); + + return new CompiledExpression( + 'variable', + $symbolVariable->getRealName(), + $expression + ); + } +} diff --git a/tensor/matrix.zep b/tensor/matrix.zep index a0b515f..e002c73 100644 --- a/tensor/matrix.zep +++ b/tensor/matrix.zep @@ -1367,6 +1367,16 @@ class Matrix implements Tensor return new self(tensor_sqrt(this->a), this->m, this->n); } + /** + * Return the reciprocal square root of the matrix. + * + * @return self + */ + public function rsqrt() -> + { + return new self(tensor_rsqrt(this->a), this->m, this->n); + } + /** * Return the exponential of the matrix. * diff --git a/tensor/unary.zep b/tensor/unary.zep index a0070b9..538f115 100644 --- a/tensor/unary.zep +++ b/tensor/unary.zep @@ -25,6 +25,13 @@ interface Unary */ public function sqrt(); + /** + * Return the reciprocal square root of the tensor. + * + * @return mixed + */ + public function rsqrt(); + /** * Return the exponential of the tensor. * diff --git a/tensor/vector.zep b/tensor/vector.zep index 3dfca90..730e4d6 100644 --- a/tensor/vector.zep +++ b/tensor/vector.zep @@ -951,6 +951,16 @@ class Vector implements Tensor return new static(tensor_sqrt(this->a)); } + /** + * Return the reciprocal square root of the vector. + * + * @return self + */ + public function rsqrt() -> + { + return new static(tensor_rsqrt(this->a)); + } + /** * Exponentiate each element in the vector. * diff --git a/tests/ColumnVectorTest.php b/tests/ColumnVectorTest.php index 3cb533a..a00c0b1 100644 --- a/tests/ColumnVectorTest.php +++ b/tests/ColumnVectorTest.php @@ -493,6 +493,17 @@ public function erfReturnsColumnVector() : void $this->assertEqualsWithDelta([0.8427007929497148, -0.8427007929497148, 0.0], $b->asArray(), 1e-8); } + /** + * @test + */ + public function rsqrtReturnsColumnVector() : void + { + $b = ColumnVector::fromArray([4.0, 9.0, 0.25])->rsqrt(); + + $this->assertInstanceOf(ColumnVector::class, $b); + $this->assertEqualsWithDelta([0.5, 0.3333333333333333, 2.0], $b->asArray(), 1e-8); + } + /** * @test */ diff --git a/tests/MatrixTest.php b/tests/MatrixTest.php index 8ecb92f..0f8ef04 100644 --- a/tests/MatrixTest.php +++ b/tests/MatrixTest.php @@ -3476,6 +3476,26 @@ public function sqrt() : void $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } + /** + * @test + */ + public function rsqrt() : void + { + $a = Matrix::fromArray([ + [4.0, 9.0], + [16.0, 25.0], + ]); + + $b = $a->rsqrt(); + + $expected = Matrix::fromArray([ + [0.5, 0.3333333333333333], + [0.25, 0.2], + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); + } + /** * @test */ diff --git a/tests/SettingsTest.php b/tests/SettingsTest.php index dce14ad..51c87cd 100644 --- a/tests/SettingsTest.php +++ b/tests/SettingsTest.php @@ -116,6 +116,16 @@ public function dispatchedKernelsAreCorrect() : void $va->negate()->asArray(), "negate failed for length {$n}" ); + + $positive = array_values(array_filter($a, fn ($x) => $x > 0.0)); + if (!empty($positive)) { + $vpos = Vector::fromArray($positive); + $this->assertSame( + array_map(fn ($x) => 1.0 / sqrt($x), $positive), + $vpos->rsqrt()->asArray(), + "rsqrt failed for length {$n}" + ); + } } } diff --git a/tests/VectorTest.php b/tests/VectorTest.php index c08b3c0..2f33ea6 100644 --- a/tests/VectorTest.php +++ b/tests/VectorTest.php @@ -144,6 +144,7 @@ public function unaryInterfaceSurface() : void 'log1p', 'negate', 'round', + 'rsqrt', 'sign', 'sqrt', 'square', @@ -2031,6 +2032,23 @@ public function sqrt() : void $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); } + /** + * @test + */ + public function rsqrt() : void + { + $a = Vector::fromArray([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); + + $b = $a->rsqrt(); + + $expected = Vector::fromArray([ + 0.5, 0.3922322702763681, 0.5872202195147035, 0.22360679774997896, + 0.6201736729460422, 0.28988551782622424, + ]); + + $this->assertEqualsWithDelta($expected->asArray(), $b->asArray(), self::MAX_DELTA); + } + /** * @test */ From c6ffe65d965d2eca9777c7f88c194ecd53fe48f4 Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Wed, 7 Oct 2026 00:20:21 -0500 Subject: [PATCH 05/14] Fix coding style --- tests/SettingsTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/SettingsTest.php b/tests/SettingsTest.php index 51c87cd..a67b18d 100644 --- a/tests/SettingsTest.php +++ b/tests/SettingsTest.php @@ -118,6 +118,7 @@ public function dispatchedKernelsAreCorrect() : void ); $positive = array_values(array_filter($a, fn ($x) => $x > 0.0)); + if (!empty($positive)) { $vpos = Vector::fromArray($positive); $this->assertSame( From 99e44d5213c707cf783f1566d315694cb238ee89 Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Wed, 7 Oct 2026 13:17:23 -0500 Subject: [PATCH 06/14] Correct formatting in Special section description Fix formatting of the description for the Special section. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index de23d8a..ab7d76c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -55,7 +55,7 @@ Tensor \ | [Unary](interfaces/unary.md) | Element-wise unary functions, including clipping. | | [Trigonometric](interfaces/trigonometric.md) | Element-wise trigonometric functions. | | [Reductions](interfaces/reductions.md) | Aggregate reduction operations, including the statistical summaries. | -| [Special](interfaces/special.md) | Operations that fit no other group, such as `softmax` and the error-function`erf`. | +| [Special](interfaces/special.md) | Operations that fit no other group, such as `softmax` and the error-function `erf`. | ## Decompositions From 14331b709b00fc07c8e41f82ad63e4d93e615962 Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Wed, 7 Oct 2026 13:18:06 -0500 Subject: [PATCH 07/14] Fix typo in error message for Tensor erf Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- optimizers/TensorErfOptimizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimizers/TensorErfOptimizer.php b/optimizers/TensorErfOptimizer.php index 653faae..e72b4a7 100644 --- a/optimizers/TensorErfOptimizer.php +++ b/optimizers/TensorErfOptimizer.php @@ -26,7 +26,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont if (count($expression['parameters']) !== 1) { throw new CompilerException( - 'Tensor erf accepts exactly 1 argument, ' . count($expression['parameters']) . 'given.', + 'Tensor erf accepts exactly 1 argument, ' . count($expression['parameters']) . ' given.', $expression ); } From a2776f6084283f59d2681d7649b00534ce60ec74 Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Wed, 7 Oct 2026 13:18:28 -0500 Subject: [PATCH 08/14] Fix typo in error message for Tensor rsqrt Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- optimizers/TensorRsqrtOptimizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimizers/TensorRsqrtOptimizer.php b/optimizers/TensorRsqrtOptimizer.php index bc57cf1..85ecebf 100644 --- a/optimizers/TensorRsqrtOptimizer.php +++ b/optimizers/TensorRsqrtOptimizer.php @@ -26,7 +26,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont if (count($expression['parameters']) !== 1) { throw new CompilerException( - 'Tensor rsqrt accepts exactly 1 argument, ' . count($expression['parameters']) . 'given.', + 'Tensor rsqrt accepts exactly 1 argument, ' . count($expression['parameters']) . ' given.', $expression ); } From 6d243370c37b29f64992699c074312e870b2d930 Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Wed, 7 Oct 2026 13:18:42 -0500 Subject: [PATCH 09/14] Fix typo in error message for TensorSoftplusOptimizer Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- optimizers/TensorSoftplusOptimizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimizers/TensorSoftplusOptimizer.php b/optimizers/TensorSoftplusOptimizer.php index ae1adcb..8a81cad 100644 --- a/optimizers/TensorSoftplusOptimizer.php +++ b/optimizers/TensorSoftplusOptimizer.php @@ -26,7 +26,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont if (count($expression['parameters']) !== 1) { throw new CompilerException( - 'Tensor softplus accepts exactly 1 argument, ' . count($expression['parameters']) . 'given.', + 'Tensor softplus accepts exactly 1 argument, ' . count($expression['parameters']) . ' given.', $expression ); } From f2191ef923b04aaaff1c14bde59cfd5c43070902 Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Wed, 7 Oct 2026 13:18:57 -0500 Subject: [PATCH 10/14] Fix error message formatting in TensorSinhOptimizer Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- optimizers/TensorSinhOptimizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimizers/TensorSinhOptimizer.php b/optimizers/TensorSinhOptimizer.php index f05c831..beb2f17 100644 --- a/optimizers/TensorSinhOptimizer.php +++ b/optimizers/TensorSinhOptimizer.php @@ -26,7 +26,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont if (count($expression['parameters']) !== 1) { throw new CompilerException( - 'Tensor sinh accepts exactly 1 argument, ' . count($expression['parameters']) . 'given.', + 'Tensor sinh accepts exactly 1 argument, ' . count($expression['parameters']) . ' given.', $expression ); } From 5e63322e65e81d650a2e5b952bbe2a62ceb90bde Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Wed, 7 Oct 2026 13:19:10 -0500 Subject: [PATCH 11/14] Fix error message formatting in TensorCoshOptimizer Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- optimizers/TensorCoshOptimizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimizers/TensorCoshOptimizer.php b/optimizers/TensorCoshOptimizer.php index 2cf6d2d..0313956 100644 --- a/optimizers/TensorCoshOptimizer.php +++ b/optimizers/TensorCoshOptimizer.php @@ -26,7 +26,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont if (count($expression['parameters']) !== 1) { throw new CompilerException( - 'Tensor cosh accepts exactly 1 argument, ' . count($expression['parameters']) . 'given.', + 'Tensor cosh accepts exactly 1 argument, ' . count($expression['parameters']) . ' given.', $expression ); } From 8f13728c4843058d680b3a63a854ec5c2bd28f00 Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Wed, 7 Oct 2026 13:19:35 -0500 Subject: [PATCH 12/14] Update description of Special interface operations Clarify the description of the `Special` interface and correct formatting for `erf()`. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- docs/interfaces/special.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/interfaces/special.md b/docs/interfaces/special.md index bf05868..f765470 100644 --- a/docs/interfaces/special.md +++ b/docs/interfaces/special.md @@ -8,7 +8,7 @@ Operations that do not belong to any of the other interface groups. `Special` holds the operations that neither the basic algebraic and trigonometric families (`Arithmetic`, `Comparable`, `Unary`, `Trigonometric`), aggregate reductions (`Reductions`), nor array-like access (`ArrayLike`) can describe. -`softmax()` is the only shape-preserving member whose output depends on a whole reduction axis rather than on one input element, so it is neither element-wise nor a reduction. `erf()` is element-wise error-function transforms grouped here so the error-function family stays together, distinct from the basic algebraic operations. +`softmax()` is the only shape-preserving member whose output depends on a whole reduction axis rather than on one input element, so it is neither element-wise nor a reduction. `erf()` is an element-wise error-function transform grouped here so the error-function family stays together, distinct from the basic algebraic operations. ```php interface Special From 9054f1368b1caf7a6df5d13a2fdb1424d3755a03 Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Wed, 7 Oct 2026 13:22:14 -0500 Subject: [PATCH 13/14] Fix the docs --- docs/Matrix.md | 4 ++-- docs/interfaces/special.md | 15 +++++++++++++++ docs/interfaces/unary.md | 15 --------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/Matrix.md b/docs/Matrix.md index cef9bee..5b426f3 100644 --- a/docs/Matrix.md +++ b/docs/Matrix.md @@ -425,8 +425,6 @@ See [Unary](interfaces/unary.md). Each method returns a new `Matrix`. - `expm1() : self` — exponential of each element minus 1 - `log(float $base = M_E) : self` — logarithm of the matrix in the specified base - `log1p() : self` — log of 1 plus each element -- `sigmoid() : self` — element-wise logistic function, `1 / (1 + exp(-x))` -- `softplus() : self` — element-wise softplus, `log(1 + exp(x))` - `round(int $precision = 0) : self` — round the elements to a given decimal place (throws `InvalidArgumentException` if `$precision < 0`) - `floor() : self` — round down to the nearest integer - `ceil() : self` — round up to the nearest integer @@ -472,6 +470,8 @@ See [Reductions](interfaces/reductions.md). For a `Matrix`, row-wise reductions See [Special](interfaces/special.md). `softmax()` preserves the shape of the matrix; `erf()` is element-wise. +- `sigmoid() : self` — element-wise logistic function, `1 / (1 + exp(-x))` +- `softplus() : self` — element-wise softplus, `log(1 + exp(x))` - `softmax() : self` — exponentials normalized so each **row** sums to `1.0`; transpose on either side to normalize each column - `erf() : self` — element-wise Gaussian error function diff --git a/docs/interfaces/special.md b/docs/interfaces/special.md index bf05868..ff88b40 100644 --- a/docs/interfaces/special.md +++ b/docs/interfaces/special.md @@ -16,6 +16,21 @@ interface Special ## Methods +### `sigmoid() : mixed` + +Return the element-wise logistic function, `1 / (1 + exp(-x))`. + +A large negative input saturates to exactly `0.0` and a large positive one to +exactly `1.0`, so the result never overflows to an infinity. + +### `softplus() : mixed` + +Return the element-wise softplus, `log(1 + exp(x))`. + +The computation is numerically stable: for a large positive input it reduces to +`x + log1p(0) == x` and for a large negative input to `log1p(0) == 0.0`, so the +result never overflows to an infinity. + ### `softmax() : mixed` Return the softmax of the tensor, i.e. the exponentials of its elements diff --git a/docs/interfaces/unary.md b/docs/interfaces/unary.md index 4b16994..59439d1 100644 --- a/docs/interfaces/unary.md +++ b/docs/interfaces/unary.md @@ -53,21 +53,6 @@ Return the logarithm of the tensor in a specified base. Return the log of 1 plus the tensor, i.e. a transform. -### `sigmoid() : mixed` - -Return the element-wise logistic function, `1 / (1 + exp(-x))`. - -A large negative input saturates to exactly `0.0` and a large positive one to -exactly `1.0`, so the result never overflows to an infinity. - -### `softplus() : mixed` - -Return the element-wise softplus, `log(1 + exp(x))`. - -The computation is numerically stable: for a large positive input it reduces to -`x + log1p(0) == x` and for a large negative input to `log1p(0) == 0.0`, so the -result never overflows to an infinity. - ### `round(int $precision = 0) : self` Round the elements in the tensor to a given decimal place. From 4c8a5d264d0e08e843e604404d13b0bcce8091df Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Wed, 7 Oct 2026 13:23:06 -0500 Subject: [PATCH 14/14] Fix docs --- docs/interfaces/tensor.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/interfaces/tensor.md b/docs/interfaces/tensor.md index d9c221e..583a772 100644 --- a/docs/interfaces/tensor.md +++ b/docs/interfaces/tensor.md @@ -20,10 +20,10 @@ interface Tensor extends ArrayLike, Arithmetic, Comparable, | [ArrayLike](arraylike.md) | `shape`, `shapeString`, `size`, `map`, `reduce`, `asArray` | | [Arithmetic](arithmetic.md) | `multiply`, `divide`, `add`, `subtract`, `pow`, `mod` | | [Comparable](comparable.md) | `equal`, `notEqual`, `greater`, `greaterEqual`, `less`, `lessEqual` | -| [Unary](unary.md) | `abs`, `square`, `sqrt`, `rsqrt`, `exp`, `expm1`, `log`, `log1p`, `sigmoid`, `softplus`, `round`, `floor`, `ceil`, `sign`, `negate`, `clip`, `clipLower`, `clipUpper` | +| [Unary](unary.md) | `abs`, `square`, `sqrt`, `rsqrt`, `exp`, `expm1`, `log`, `log1p`, `round`, `floor`, `ceil`, `sign`, `negate`, `clip`, `clipLower`, `clipUpper` | | [Trigonometric](trigonometric.md) | `sin`, `asin`, `cos`, `acos`, `tan`, `atan`, `tanh`, `sinh`, `cosh`, `rad2deg`, `deg2rad` | | [Reductions](reductions.md) | `sum`, `product`, `min`, `max`, `argmin`, `argmax`, `mean`, `variance`, `median`, `quantile` | -| [Special](special.md) | `softmax`, `erf` | +| [Special](special.md) | `sigmoid`, `softplus`, `softmax`, `erf` | Every group is homogeneous in what it does to the tensor's shape: `Arithmetic`, `Comparable`, `Unary`, and `Trigonometric` are element-wise and preserve it,