Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"homepage": "https://www.numpower.org",
"require": {
"php": ">=8.2",
"ext-numpower": "0.6.0"
"ext-numpower": "0.6.0",
"ext-gd": "*"
},
"minimum-stability": "stable",
"prefer-stable": true
Expand Down
189 changes: 164 additions & 25 deletions stubs/numpower.stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static function reciprocal(NDArray|array|float|int $a): NDArray|float|int
* @param NDArray|array|float|int $b Input array
* @return NDArray|float|int $a ** $b
*/
public static function pow(NDArray|array|float|int $a, NDArray|array|float|int $b): NDArray|float|int {};
public static function pow(NDArray|array|float|int $a, NDArray|array|float|int $b): NDArray|float|int {}

/**
* Subtract two arrays element-wise
Expand Down Expand Up @@ -201,17 +201,19 @@ public static function logb(NDArray|array|float|int $array): NDArray|float|int {
* Finds the maximum value in the array.
*
* @param NDArray|array|float|int $a Input array
* @param int|null $axis If $a is an array, this specifies the axis along which to perform the operation. If NULL, the operation is applied across all elements.
* @return float|int
*/
public static function max(NDArray|array|float|int $a): float|int {}
public static function max(NDArray|array|float|int $a, ?int $axis = null): float|int {}

/**
* Finds the minimum value in the array.
*
* @param NDArray|array|float|int $a Input array
* @param int|null $axis If $a is an array, this specifies the axis along which to perform the operation. If NULL, the operation is applied across all elements.
* @return float|int
*/
public static function min(NDArray|array|float|int $a): float|int {}
public static function min(NDArray|array|float|int $a, ?int $axis = null): float|int {}

/**
* Calculates the element-wise inverse hyperbolic cosine (arccosineh) of an array,
Expand Down Expand Up @@ -376,29 +378,29 @@ public static function trunc(NDArray|array|float|int $array): NDArray|float|int

/**
* Calculates the product of all elements in the array over a given axis
* along which a product is performed. The default, axis=NULL,
* along which a product is performed. The default, axis=null,
* will calculate the product of all the elements in the input array.
*
* @param NDArray|array|float|int $a Input array
* @param int|null $axis The axis to perform the product. If `$axis` is NULL, will calculate the product of all the elements of `$a`.
* @return NDArray|float|int The product of `$a`. If `$axis` is not NULL, the specified axis is removed.
* @param int|null $axis The axis to perform the product. If `$axis` is null, will calculate the product of all the elements of `$a`.
* @return NDArray|float|int The product of `$a`. If `$axis` is not null, the specified axis is removed.
*/
public static function prod(NDArray|array|float|int $a, ?int $axis = NULL): NDArray|float|int {}
public static function prod(NDArray|array|float|int $a, ?int $axis = null): NDArray|float|int {}

/**
* Calculates the sum of all elements in the array over a given axis
* along which a sum is performed. The default, axis=NULL,
* along which a sum is performed. The default, axis=null,
* will calculate the product of all the elements in the input array.
*
* @param NDArray|array|float|int $a Input array
* @param int|null $axis Specifies the axis along which the sum is performed. By default, ($axis=NULL),
* @param int|null $axis Specifies the axis along which the sum is performed. By default, ($axis=null),
* the function sums all elements of the input array.
* @return NDArray|float|int The function returns the summed array along the
* specified axis, resulting in an array with the same shape as the input array,
* but with the specified axis removed. If the input array is 0-dimensional
* or if axis=NULL, a scalar value is returned.
* or if axis=null, a scalar value is returned.
*/
public static function sum(NDArray|array|float|int $a, ?int $axis = NULL): NDArray|float|int {}
public static function sum(NDArray|array|float|int $a, ?int $axis = null): NDArray|float|int {}

/**
* Calculates the element-wise inverse cosine (arccosine) of an array,
Expand Down Expand Up @@ -541,7 +543,7 @@ public static function convolve2d(NDArray|array $a, NDArray|array $b, string $mo
* @param NDArray|array|float|int|null $weights
* @return float|int
*/
public static function average(NDArray|array|float|int $array, NDArray|array|float|int|null $weights = NULL): float|int {}
public static function average(NDArray|array|float|int $array, NDArray|array|float|int|null $weights = null): float|int {}

/**
* The arithmetic mean of the elements in the array. It computes the sum
Expand All @@ -550,18 +552,20 @@ public static function average(NDArray|array|float|int $array, NDArray|array|flo
* Same as calling `nd::sum($a) / $a->size()`
*
* @param NDArray|array|float|int $a
* @param int|null $axis If $a is an array, this specifies the axis along which to perform the operation. If NULL, the operation is applied across all elements.
* @return float|int
*/
public static function mean(NDArray|array|float|int $a): float|int {}
public static function mean(NDArray|array|float|int $a, ?int $axis = null): float|int {}

/**
* The median of the elements in the array. It sorts the array, and if the number of elements is odd,
* it returns the middle value; if the number of elements is even, it returns the average of the two middle values
*
* @param NDArray|array|float|int $a
* @param int|null $axis If $a is an array, this specifies the axis along which to perform the operation. If NULL, the operation is applied across all elements.
* @return float|int
*/
public static function median(NDArray|array|float|int $a): float|int {}
public static function median(NDArray|array|float|int $a, ?int $axis = null): float|int {}

/**
* Computes the specified quantile of the elements in the array. A quantile represents a
Expand All @@ -580,18 +584,20 @@ public static function quantile(NDArray|array|float|int $a, float|int $q): float
* or dispersion in the data.
*
* @param NDArray|array|float|int $a
* @param int|null $axis If $a is an array, this specifies the axis along which to perform the operation. If NULL, the operation is applied across all elements.
* @return float|int
*/
public static function std(NDArray|array|float|int $a): float|int {}
public static function std(NDArray|array|float|int $a, ?int $axis = null): float|int {}

/**
* Calculates the variance of the elements in the array. It measures the average of the
* squared differences between each element and the mean.
*
* @param NDArray|array|float|int $array
* @param int|null $axis If $a is an array, this specifies the axis along which to perform the operation. If NULL, the operation is applied across all elements.
* @return float|int
*/
public static function variance(NDArray|array|float|int $array): float|int {}
public static function variance(NDArray|array|float|int $array, ?int $axis = null): float|int {}

/**
* Convert inputs to arrays with at least one dimension.
Expand All @@ -615,24 +621,25 @@ public static function atleast_2d(NDArray|array|float|int $array): NDArray {}
* Convert inputs to arrays with at least three dimensions.
*
* @param NDArray|array|float|int $array
* @param int|null $axis If $a is an array, this specifies the axis along which to perform the operation. If NULL, the operation is applied across all elements.
* @return NDArray
*/
public static function atleast_3d(NDArray|array|float|int $array): NDArray {}
public static function atleast_3d(NDArray|array|float|int $array, ?int $axis = null): NDArray {}

/**
* Create a copy of array `$a`.
*
* #### $device options
* Default = NULL, copy on the same device as `$a`
* Default = null, copy on the same device as `$a`
*
* - **0** - CPU copy (same as `$a->cpu()`);
* - **1** - GPU copy (same as `$a->gpu()`);
*
* @param NDArray|array|float|int $a
* @param int|null $device NULL = Same device, 0 - copy to CPU, 1 - copy to GPU
* @param int|null $device null = Same device, 0 - copy to CPU, 1 - copy to GPU
* @return NDArray copy of $a
*/
public static function copy(NDArray|array|float|int $a, int $device = NULL): NDArray {}
public static function copy(NDArray|array|float|int $a, int $device = null): NDArray {}

/**
* Adds a new axis to the array at the specified position, thereby expanding its shape.
Expand All @@ -641,7 +648,7 @@ public static function copy(NDArray|array|float|int $a, int $device = NULL): NDA
* @param int|int[]|null $axis This parameter specifies the position where the new axis (or axes) will be inserted within the expanded array.
* @return NDArray
*/
public static function expand_dims(NDArray|array|float|int $target, int|array $axis = NULL): NDArray {}
public static function expand_dims(NDArray|array|float|int $target, int|array $axis = null): NDArray {}

/**
* Return a **copy** of the array `$a` into one dimension.
Expand Down Expand Up @@ -823,9 +830,10 @@ public static function dumpDevices(): void {}

/**
* @param NDArray|array|float|int $a
* @param int|null $axis If $a is an array, this specifies the axis along which to perform the operation. If NULL, the operation is applied across all elements.
* @return bool
*/
public static function all(NDArray|array|float|int $a): bool {}
public static function all(NDArray|array|float|int $a, ?int $axis = null): bool {}

/**
* Checks if all elements in two arrays are approximately equal within a specified tolerance element-wise.
Expand Down Expand Up @@ -1124,7 +1132,7 @@ public function fill(float|int $fill_value): NDArray {}
* Returns the indices of the minimum values along an axis.
*
* @param NDArray|array $a Target array
* @param int|null $axis If NULL, the index is into the flattened array, otherwise along the specified axis.
* @param int|null $axis If null, the index is into the flattened array, otherwise along the specified axis.
* @param bool $keepdims
* @return NDArray Array of indices into the array. It has the same shape as $a with the dimension along $axis removed.
*/
Expand All @@ -1134,7 +1142,7 @@ public static function argmin(NDArray|array $a, ?int $axis, bool $keepdims = fal
* Returns the indices of the maximum values along an axis.
*
* @param NDArray|array $a Target array
* @param int|null $axis If NULL, the index is into the flattened array, otherwise along the specified axis.
* @param int|null $axis If null, the index is into the flattened array, otherwise along the specified axis.
* @param bool $keepdims
* @return NDArray Array of indices into the array. It has the same shape as $a with the dimension along axis removed.
*/
Expand Down Expand Up @@ -1162,5 +1170,136 @@ public static function argmax(NDArray|array $a, ?int $axis, bool $keepdims = fal
* @param array ...$indices
* @return NDArray|float
*/
public function slice(...$indices): NDArray|float {};
public function slice(...$indices): NDArray|float {}

/**
* Calculates the element-wise reciprocal square root (1/√x) of an array,
* returning a new NDArray with the result for each element.
*
* @param NDArray|array $array Input array
* @return NDArray
*/
public static function rsqrt(NDArray|array $array): NDArray {}

/**
* Returns the element-wise maximum of array elements.
*
* @param NDArray|array|float|int $a The first input array.
* @param NDArray|array|float|int $b The second input array.
* @return NDArray
*/
public static function maximum(NDArray|array|float|int $a, NDArray|array|float|int $b): NDArray {}

/**
* Returns the element-wise minimum of array elements.
*
* @param NDArray|array|float|int $a The first input array.
* @param NDArray|array|float|int $b The second input array.
* @return NDArray
*/
public static function minimum(NDArray|array|float|int $a, NDArray|array|float|int $b): NDArray {}


/**
* Element-wise arctangent of x/y choosing the quadrant correctly.
*
* @param NDArray|array|float|int $x The x-coordinates.
* @param NDArray|array|float|int $y The y-coordinates.
* @return NDArray
*/
public static function arctan2(NDArray|array|float|int $x, NDArray|array|float|int $y): NDArray {}

/**
* Converts the NDArray to a GD image resource.
*
* @param NDArray|null $alpha Optional alpha channel NDArray.
* @return \GdImage|null
*/
public function toImage(?NDArray $alpha = null): ?\GdImage {}

/**
* Reverses the order of elements in an array along the given axis.
*
* @param NDArray|array $a Input array.
* @param NDArray|array|int|null $axis Axis or axes along which to flip.
* If axis is None, flips all the elements in the input array.
* @return NDArray
*/
public static function flip(NDArray|array $a, NDArray|array|int|null $axis = null): NDArray {}

/**
* Extracts a diagonal or constructs a diagonal array.
*
* @param NDArray|array $target Input array. If the target is a 2-D array,
* return a 1-D array of its diagonals.
* If the target is a 1-D array, return a 2-D
* array with the 1-D array as a diagonal.
* @return NDArray
*/
public static function diagonal(NDArray|array $target): NDArray {}

/**
* Creates an NDArray from a GD image resource.
*
* @param \GdImage $image The GD image resource.
* @param bool $channelLast Whether the output array should have channels
* as the last dimension (default: true). If false,
* channels will be the first dimension.
* @return NDArray
*/
public static function fromImage(\GdImage $image, bool $channelLast = true): NDArray {}

/**
* Draws samples from a binomial distribution.
*
* @param NDArray|array $shape Shape of the output array.
* @param float $n Number of trials.
* @param float $p Probability of success of each trial.
* @return NDArray
*/
public static function random_binomial(NDArray|array $shape, float $n, float $p): NDArray {}

/**
* Cross-correlation of two 2-dimensional arrays.
*
* @param NDArray|array $a First input array.
* @param NDArray|array $b Second input array.
* @param string $mode A string indicating the size of the output:
* 'valid' (default), 'same', or 'full'.
* @param string $boundary A string indicating the boundary handling:
* 'fill' (default), 'wrap', or 'symm'.
* @param float $fill_value Value to fill pad boundaries with (default: 0).
* @return NDArray
*/
public static function correlate2d(NDArray|array $a, NDArray|array $b, string $mode, string $boundary, float $fill_value = 0.0): NDArray {}

/**
* Performs a 2D forward convolution operation for deep neural networks.
*
* @param NDArray|array $input Input tensor (e.g., [batch, channels, height, width]).
* @param NDArray|array $filters Filter kernel tensor (e.g., [num_filters, channels, kernel_height, kernel_width]).
* @return NDArray Output tensor of the convolution operation.
*/
public static function dnn_conv2d_forward(NDArray|array $input, NDArray|array $filters): NDArray {}

/**
* Performs a 2D backward convolution operation for deep neural networks.
*
* @param NDArray|array $x Input tensor.
* @param NDArray|array $y Output gradient tensor.
* @param NDArray|array $filters Filter kernel tensor.
* @return array{NDArray, NDArray} An array containing the gradient with
* respect to the input and the gradient
* with respect to the filters.
*/
public static function dnn_conv2d_backward(NDArray|array $x, NDArray|array $y, NDArray|array $filters): array {}

/**
* Performs a 1D convolution operation for deep neural networks.
*
* @param NDArray|array $input Input tensor (e.g., [batch, channels, width]).
* @param NDArray|array $filters Filter kernel tensor (e.g., [num_filters, channels, kernel_width]).
* @return NDArray Output tensor of the convolution operation.
*/
public static function dnn_conv1d_forward(NDArray|array $input, NDArray|array $filters): NDArray {}
}