@d4c/numjs
Version:
Like NumPy, in TypeScript and JavaScript
272 lines (271 loc) • 12.9 kB
TypeScript
export { default as config } from "./config";
export { default as dtypes } from "./dtypes";
export { default as ndarray } from "ndarray";
import { NdArray, ArbDimNumArray, ArrayLikeConstructor, DType } from "./ndarray";
export { NdArray };
import * as errors from "./errors";
export { errors };
export declare function broadcast(shape1: number[], shape2: number[]): number[];
/**
* Add arguments, element-wise.
*/
export declare function add(a: NdArray | ArbDimNumArray | number, b: NdArray | ArbDimNumArray | number): NdArray;
/**
* Multiply arguments, element-wise.
*/
export declare function multiply(a: ArbDimNumArray | NdArray, b: ArbDimNumArray | NdArray | number): NdArray;
/**
* Divide `a` by `b`, element-wise.
*/
export declare function divide(a: ArbDimNumArray | NdArray, b: ArbDimNumArray | NdArray | number): NdArray;
/**
* Subtract second argument from the first, element-wise.
*/
export declare function subtract(a: ArbDimNumArray | NdArray | number, b: ArbDimNumArray | NdArray | number): NdArray;
/**
* Return true if two arrays have the same shape and elements, false otherwise.
*/
export declare function equal(array1: ArbDimNumArray | NdArray, array2: ArbDimNumArray | NdArray): boolean;
/**
* Return a copy of the array collapsed into one dimension using row-major order (C-style)
*/
export declare function flatten(array: ArbDimNumArray | NdArray): NdArray;
/**
* Gives a new shape to an array without changing its data.
* @param array
* @param shape - The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length
*/
export declare function reshape(array: ArbDimNumArray | NdArray, shape: number[] | number): NdArray;
/**
* Calculate the exponential of all elements in the input array, element-wise.
*/
export declare function exp(x: ArbDimNumArray | NdArray | number): NdArray;
/**
* Calculate the natural logarithm of all elements in the input array, element-wise.
*/
export declare function log(x: ArbDimNumArray | NdArray | number): NdArray;
/**
* Calculate the positive square-root of all elements in the input array, element-wise.
*/
export declare function sqrt(x: ArbDimNumArray | NdArray | number): NdArray;
/**
* Raise first array elements to powers from second array, element-wise.
*/
export declare function power(x1: ArbDimNumArray | NdArray | number, x2: ArbDimNumArray | NdArray | number): NdArray;
/**
* Return the sum of input array elements.
*/
export declare function sum(x: ArbDimNumArray | NdArray | number): number;
/**
* Return the arithmetic mean of input array elements.
*/
export declare function mean(x: ArbDimNumArray | NdArray | number): number;
/**
* Returns the standard deviation, a measure of the spread of a distribution, of the input array elements.
*/
export declare function std(x: ArbDimNumArray | NdArray | number, options?: {
ddof: number;
}): number;
/**
* Return the minimum value of the array
*/
export declare function min(x: ArbDimNumArray | NdArray | number): number;
/**
* Return the maximum value of the array
*/
export declare function max(x: ArbDimNumArray | NdArray | number): number;
/**
* Return element-wise remainder of division.
* Computes the remainder complementary to the `floor` function. It is equivalent to the Javascript modulus operator``x1 % x2`` and has the same sign as the divisor x2.
*/
export declare function mod(x1: NdArray | ArbDimNumArray | number, x2: NdArray | ArbDimNumArray | number): NdArray;
/**
* Permute the dimensions of the input array according to the given axes.
*/
export declare function transpose(x: NdArray | ArbDimNumArray | number, axes?: number[]): NdArray;
/**
* Return the inverse of the input array, element-wise.
*/
export declare function negative(x: ArbDimNumArray | NdArray | number): NdArray;
/**
* Return evenly spaced values within a given interval.
*
* @param start - Default 0 (int). Start of interval. The interval includes this value.
* @param stop - End of interval (int). The interval does not include this value.
* @param step - Default 1 (int). Spacing between values. The default step size is 1. If step is specified, start must also be given.
* @param dtype Defaut is "array". The type of the output array. Either string (e.g. 'uint8') or a Constructor function (e.g. Uint8Array).
*/
export declare function arange(start: number, stop: number, step: number, dtype: DType | ArrayLikeConstructor): NdArray;
export declare function arange(start: number, stop: number, step: number): NdArray;
export declare function arange(start: number, stop: number, dtype: DType | ArrayLikeConstructor): NdArray;
export declare function arange(start: number, stop: number): NdArray;
export declare function arange(stop: number, dtype: DType | ArrayLikeConstructor): NdArray;
export declare function arange(stop: number): NdArray;
/**
* Return a new array of given shape and type, filled with zeros.
*
* @param shape - Shape of the new array, e.g., [2, 3] or 2.
* @param dtype Defaut is "array". The type of the output array. E.g., 'uint8' or Uint8Array.
*
*/
export declare function zeros(shape: number | number[], dtype?: DType | ArrayLikeConstructor): NdArray;
/**
* Return a new array of given shape and type, filled with ones.
*
* @param shape - Shape of the new array, e.g., [2, 3] or 2.
* @param dtype - Defaut is "array". The type of the output array. E.g., 'uint8' or Uint8Array.
*
* @return Array of ones with the given shape and dtype
*/
export declare function ones(shape: number[] | number, dtype?: DType | ArrayLikeConstructor): NdArray;
/**
* Return a new array of given shape and type, filled with `undefined` values.
*
* @param shape - Shape of the new array, e.g., [2, 3] or 2.
* @param dtype - Defaut is "array". The type of the output array. E.g., 'uint8' or Uint8Array.
*
* @return Array of `undefined` values with the given shape and dtype
*/
export declare function empty(shape: number[] | number, dtype?: DType | ArrayLikeConstructor): NdArray;
/**
* Create an array of the given shape and propagate it with random samples from a uniform distribution over [0, 1].
* @param shape - The dimensions of the returned array, should all be positive integers
*/
export declare function random(...shape: number[]): NdArray;
export declare function random(shape?: number | number[]): NdArray;
/**
* Return the softmax, or normalized exponential, of the input array, element-wise.
*/
export declare function softmax(x: ArbDimNumArray | NdArray | number): NdArray;
/**
* Return the sigmoid of the input array, element-wise.
* @param x
* @param t - stifness parameter
*/
export declare function sigmoid(x: ArbDimNumArray | NdArray | number, t?: number): NdArray;
/**
* Clip (limit) the values in an array between min and max, element-wise.
*/
export declare function clip(x: ArbDimNumArray | NdArray | number, min?: number, max?: number): NdArray;
export declare function leakyRelu(x: NdArray | ArbDimNumArray | number, alpha?: number): NdArray;
/**
* Return hyperbolic tangent of the input array, element-wise.
*/
export declare function tanh(x: ArbDimNumArray | NdArray | number): NdArray;
/**
* Return absolute value of the input array, element-wise.
*/
export declare function abs(x: ArbDimNumArray | NdArray | number): NdArray;
/**
* Return trigonometric cosine of the input array, element-wise.
*/
export declare function cos(x: ArbDimNumArray | NdArray | number): NdArray;
/**
* Return trigonometric inverse cosine of the input array, element-wise.
*/
export declare function arccos(x: ArbDimNumArray | NdArray | number): NdArray;
/**
* Return trigonometric sine of the input array, element-wise.
*/
export declare function sin(x: ArbDimNumArray | NdArray | number): NdArray;
/**
* Return trigonometric inverse sine of the input array, element-wise.
*/
export declare function arcsin(x: ArbDimNumArray | NdArray | number): NdArray;
/**
* Return trigonometric tangent of the input array, element-wise.
*/
export declare function tan(x: ArbDimNumArray | NdArray | number): NdArray;
/**
* Return trigonometric inverse tangent of the input array, element-wise.
*/
export declare function arctan(x: ArbDimNumArray | NdArray | number): NdArray;
/**
* Dot product of two arrays.
*
* WARNING: supported products are:
* - matrix dot matrix
* - vector dot vector
* - matrix dot vector
* - vector dot matrix
*/
export declare function dot(a: ArbDimNumArray | NdArray, b: ArbDimNumArray | NdArray): NdArray;
/**
* Join given arrays along the last axis.
*/
export declare function concatenate(...arrays: Array<number | ArbDimNumArray | NdArray>): NdArray;
export declare function concatenate(arrays: Array<number | ArbDimNumArray | NdArray>): NdArray;
/**
* Round an array to the to the nearest integer.
*/
export declare function round(x: ArbDimNumArray | NdArray): NdArray;
/**
* Convolve 2 N-dimensionnal arrays
*
* @note: Arrays must have the same dimensions and a must be greater than b.
* @note: The convolution product is only given for points where the signals overlap completely. Values outside the signal boundary have no effect. This behaviour is known as the 'valid' mode.
*/
export declare function convolve(a: ArbDimNumArray | NdArray, b: ArbDimNumArray | NdArray): NdArray;
/**
* Convolve 2 N-dimensionnal arrays using Fast Fourier Transform (FFT)
*
* @note: Arrays must have the same dimensions and a must be greater than b.
* @note: The convolution product is only given for points where the signals overlap completely. Values outside the signal boundary have no effect. This behaviour is known as the 'valid' mode.
*/
export declare function fftconvolve(a: ArbDimNumArray | NdArray, b: ArbDimNumArray | NdArray): NdArray;
export declare function fft(x: ArbDimNumArray | NdArray): NdArray;
export declare function ifft(x: ArbDimNumArray | NdArray): NdArray;
/**
* Extract a diagonal or construct a diagonal array.
* @returns a view a of the original array when possible, a new array otherwise
*/
export declare function diag(x: ArbDimNumArray | NdArray): NdArray;
/**
* The identity array is a square array with ones on the main diagonal.
* @param n number of rows (and columns) in n x n output.
* @param dtype Defaut is "array". The type of the output array. E.g., 'uint8' or Uint8Array.
* @return n x n array with its main diagonal set to one, and all other elements 0
*/
export declare function identity(n: number, dtype?: DType | ArrayLikeConstructor): NdArray;
/**
* Join a sequence of arrays along a new axis.
* The axis parameter specifies the index of the new axis in the dimensions of the result.
* For example, if axis=0 it will be the first dimension and if axis=-1 it will be the last dimension.
* @param arrays Sequence of array_like
* @param axis The axis in the result array along which the input arrays are stacked.
* @return The stacked array has one more dimension than the input arrays.
*/
export declare function stack(arrays: Array<NdArray | ArbDimNumArray | number>, axis?: number): NdArray;
/**
* Reverse the order of elements in an array along the given axis.
* The shape of the array is preserved, but the elements are reordered.
* New in version 0.15.0.
* @param m Input array.
* @param axis Axis in array, which entries are reversed.
* @return A view of `m` with the entries of axis reversed. Since a view is returned, this operation is done in constant time.
*/
export declare function flip(m: ArbDimNumArray | NdArray, axis: number): NdArray;
/**
* Rotate an array by 90 degrees in the plane specified by axes.
* Rotation direction is from the first towards the second axis.
* New in version 0.15.0.
* @param m array_like
* @param k Number of times the array is rotated by 90 degrees.
* @param axes Default [0, 1]. The array is rotated in the plane defined by the axes. Axes must be different.
* @return A rotated view of m.
*/
export declare function rot90(m: ArbDimNumArray | NdArray, k?: number, axes?: number[] | NdArray): NdArray;
/**
* @param dtype Defaut is "array". The type of the output array. E.g., 'uint8' or Uint8Array.
*/
export declare const array: typeof NdArray.new;
export declare const remainder: typeof mod;
export declare function int8(array: ArbDimNumArray | number): NdArray;
export declare function uint8(array: ArbDimNumArray | number): NdArray;
export declare function int16(array: ArbDimNumArray | number): NdArray;
export declare function uint16(array: ArbDimNumArray | number): NdArray;
export declare function int32(array: ArbDimNumArray | number): NdArray;
export declare function uint32(array: ArbDimNumArray | number): NdArray;
export declare function float32(array: ArbDimNumArray | number): NdArray;
export declare function float64(array: ArbDimNumArray | number): NdArray;
export declare function uint8Clamped(array: ArbDimNumArray | number): NdArray;