// Type definitions for numjs 0.14 // Project: https://github.com/nicolaspanel/numjs#readme // Definitions by: taoqf // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 export as namespace nj; import * as BaseNdArray from 'ndarray'; export type NdType = BaseNdArray.DataType | BaseNdArray.Data; export interface NdArray extends BaseNdArray { ndim: number; T: NdArray; slice(...args: number[]): NdArray; /** * Return a copy of the array collapsed into one dimension using row-major order (C-style) */ flatten

(): NdArray

; /** * Permute the dimensions of the array. */ transpose(args?: number[]): NdArray; transpose(...args: number[]): NdArray; /** * Dot product of two arrays. */ dot(x: NjArray): NdArray; /** * Assign `x` to the array, element-wise. */ assign(x: NjParam, copy?: boolean): NdArray; /** * Add `x` to the array, element-wise. */ add(x: NjParam, copy?: boolean): NdArray; /** * Subtract `x` to the array, element-wise. */ subtract(x: NjParam, copy?: boolean): NdArray; /** * Multiply array by `x`, element-wise. */ multiply(x: NjParam, copy?: boolean): NdArray; /** * Divide array by `x`, element-wise. */ divide(x: NjParam, copy?: boolean): NdArray; /** * Raise array elements to powers from given array, element-wise. * * @param [copy=true] - set to false to modify the array rather than create a new one */ pow(x: NjParam, copy?: boolean): NdArray; /** * Calculate the exponential of all elements in the array, element-wise. * * @param [copy=true] - set to false to modify the array rather than create a new one */ exp(copy?: boolean): NdArray; /** * Calculate the positive square-root of all elements in the array, element-wise. * * @param [copy=true] - set to false to modify the array rather than create a new one */ sqrt(copy?: boolean): NdArray; /** * Return the maximum value of the array */ max(): T; /** * Return the minimum value of the array */ min(): T; /** * Sum of array elements. */ sum(): T; /** * Returns the standard deviation, a measure of the spread of a distribution, of the array elements. */ std(): number; /** * Return the arithmetic mean of array elements. */ mean(): T; /** * Converts {NdArray} to a native JavaScript {Array} */ tolist(): LT[]; valueOf(): LT[]; /** * Stringify the array to make it readable in the console, by a human. */ inspect(): string; /** * Stringify object to JSON */ toJSON(): any; /** * Create a full copy of the array */ clone(): NdArray; /** * Return true if two arrays have the same shape and elements, false otherwise. */ equal(array: NjArray): boolean; /** * Round array to the to the nearest integer. */ round(copy?: boolean): NdArray; /** * Return the inverse of the array, element-wise. */ negative(): NdArray; diag(): NdArray; iteraxis(axis: number, cb: (x: NdArray, i: number) => any): void; /** * Returns the discrete, linear convolution of the array using the given filter. * * @note: Arrays must have the same dimensions and `filter` must be smaller than the array. * @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. * @note: Use optimized code for 3x3, 3x3x1, 5x5, 5x5x1 filters, FFT otherwise. */ convolve(filter: NjArray): NdArray; fftconvolve(filter: NjArray): NdArray; } export type NdArrayData = BaseNdArray.Data; export type NjArray = NdArrayData | NdArray; export type NjParam = NjArray | number; /** * Return absolute value of the input array, element-wise. * */ export function abs(x: NjParam): NdArray; /** * Add arguments, element-wise. * */ export function add(a: NjParam, b: NjParam): NdArray; /** * Return evenly spaced values within a given interval. * * @param [start = 0] Start of interval. The interval includes this value. * @param stop End of interval. The interval does not include this value. * @param [step = 1] Spacing between values. The default step size is 1. If step is specified, start must also be given. * @param [dtype = Array] The type of the output array. * @returns Array of evenly spaced values. */ export function arange(start: number, stop?: number, dtype?: NdType): NdArray; export function arange(stop: number, dtype: NdType): NdArray; export function arange(start: number, stop: number, step: number, dtype?: NdType): NdArray; /** * Return trigonometric inverse cosine of the input array, element-wise. * */ export function arccos(x: NjParam): NdArray; /** * Return trigonometric inverse sine of the input array, element-wise. * */ export function arcsin(x: NjParam): NdArray; /** * Return trigonometric inverse tangent of the input array, element-wise. * */ export function arctan(x: NjParam): NdArray; /** * Clip (limit) the values in an array between min and max, element-wise. * */ export function clip(x: NjParam, min?: number, max?: number): NdArray; /** * Join given arrays along the last axis. * */ export function concatenate(...arrays: Array>): NdArray; /** * Convolve 2 N-dimensionnal arrays * */ export function convolve(a: NjArray, b: NjArray): NdArray; /** * Return trigonometric cosine of the input array, element-wise. * */ export function cos(x: NjParam): NdArray; /** * Divide `a` by `b`, element-wise. * */ export function divide(a: NjArray, b: NjParam): NdArray; /** * Dot product of two arrays. WARNING: supported products are: - matrix dot matrix - vector dot vector - matrix dot vector - vector dot matrix * */ export function dot(a: NjArray, b: NjArray): 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] The type of the output array. * @returns Array of `undefined` values with the given shape and dtype */ export function empty(shape: NdArrayData | number, dtype?: NdType): NdArray; /** * Return true if two arrays have the same shape and elements, false otherwise. * */ export function equal(a: NjArray, b: NjArray): boolean; /** * Calculate the exponential of all elements in the input array, element-wise. * */ export function exp(x: NjParam): NdArray; /** * Convolve 2 N-dimensionnal arrays using Fast Fourier Transform (FFT) * */ export function fftconvolve(a: NjArray, b: NjArray): NdArray; /** * Return a copy of the array collapsed into one dimension using row-major order (C-style) * */ export function flatten(array: NjArray): NdArray; export function getRawData(array: NdArrayData): Uint8Array; export function setRawData(array: NdArrayData, data: NdArrayData): Uint8Array; /** * Return the maximum value of the array * */ export function max(x: NjParam): T; /** * Return the arithmetic mean of input array elements. * */ export function mean(x: NjParam): T; /** * Return the minimum value of the array * */ export function min(x: NjParam): T; /** * Multiply arguments, element-wise. * */ export function multiply(a: NjArray, b: NjParam): NdArray; /** * Return the inverse of the input array, element-wise. * */ export function negative(x: NjParam): 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] The type of the output array. * @returns Array of ones with the given shape and dtype */ export function ones(shape: NdArrayData | number, dtype?: BaseNdArray.DataType): NdArray; /** * Raise first array elements to powers from second array, element-wise. * */ export function power(x1: NjParam, x2: NjParam): NdArray; /** * Create an array of the given shape and propagate it with random samples from a uniform distribution over [0, 1]. * * @param [shape] he dimensions of the returned array, should all be positive integers */ export function random(shape?: NdArrayData | number): NdArray; /** * Gives a new shape to an array without changing its data. * * @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 function reshape(array: NjArray, shape: NdArray): NdArray; /** * Round an array to the to the nearest integer. * */ export function round(x: NjArray): NdArray; /** * Return the sigmoid of the input array, element-wise. * * @param [t = 1] stifness parameter */ export function sigmoid(x: NjParam, t?: number): NdArray; /** * Return trigonometric sine of the input array, element-wise. * */ export function sin(x: NjParam): NdArray; /** * Return the softmax, or normalized exponential, of the input array, element-wise. * */ export function softmax(x: NjParam): NdArray; /** * Calculate the positive square-root of all elements in the input array, element-wise. * */ export function sqrt(x: NjParam): NdArray; /** * Returns the standard deviation, a measure of the spread of a distribution, of the input array elements. * */ export function std(x: NjParam): T; /** * Subtract second argument from the first, element-wise. * */ export function subtract(a: NjParam, b: NjParam): T; /** * Return the sum of input array elements. * */ export function sum(x: NjParam): T; /** * Return trigonometric tangent of the input array, element-wise. * */ export function tan(x: NjParam): NdArray; /** * Return hyperbolic tangent of the input array, element-wise. * */ export function tanh(x: NjParam): NdArray; /** * Permute the dimensions of the input array according to the given axes. * * @example * * arr = nj.arange(6).reshape(1,2,3) * // array([[[ 0, 1, 2], * // [ 3, 4, 5]]]) * arr.T * // array([[[ 0], * // [ 3]], * // [[ 1], * // [ 4]], * // [[ 2], * // [ 5]]]) * arr.transpose(1,0,2) * // array([[[ 0, 1, 2]], * // [[ 3, 4, 5]]]) */ export function transpose(x: NjParam, axes?: 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 = Array] The type of the output array. * @returns Array of zeros with the given shape and dtype */ export function zeros(shape: NdArrayData | number, dtype?: BaseNdArray.DataType): NdArray; export namespace errors { function ValueError(message?: string): Error; function ConfigError(message?: string): Error; function NotImplementedError(message?: string): Error; } export function broadcast(shape1: T[], shape2: U[]): Array; export function fft(x: NjArray): NdArray; export function ifft(x: NjArray): NdArray; /** * Extract a diagonal or construct a diagonal array. * * @returns a view a of the original array when possible, a new array otherwise */ export function diag(x: NjArray): NdArray; /** * The identity array is a square array with ones on the main diagonal. * @param Number of rows (and columns) in n x n output. * @param [dtype=Array] The type of the output array. * @return n x n array with its main diagonal set to one, and all other elements 0 */ export function identity(n: T, dtype?: BaseNdArray.DataType): 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 sequence of array_like * @param [axis=0] 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 function stack(arrays: Array>, axis?: number): NdArray; export namespace images { namespace data { /** 28x28 grayscale image with an handwritten digit extracted from MNIST database */ const digit: NdArray; /** 28x28 grayscale image with an handwritten digit extracted from MNIST database */ const five: NdArray; /** 300x600 COLOR image representing Node.js's logo */ const node: NdArray; /** * The standard, yet sometimes controversial * Lena test image was scanned from the November 1972 edition of * Playboy magazine. From an image processing perspective, this image * is useful because it contains smooth, textured, shaded as well as * detail areas. */ const lena: NdArray; /** * The standard, yet sometimes * controversial Lena test image was scanned from the November 1972 * edition of Playboy magazine. From an image processing perspective, * this image is useful because it contains smooth, textured, shaded as * well as detail areas. */ const lenna: NdArray; /** * This low-contrast image of the surface of * the moon is useful for illustrating histogram equalization and * contrast stretching. */ const moon: NdArray; } function read(input: string): NdArray; function save(img: NdArray, dest: string): void; function resize(img: NdArray, height: number, width: number): NdArray; function sat(img: NdArray): NdArray; function ssat(img: NdArray): NdArray; function sobel(img: NdArray): NdArray; function scharr(img: NdArray): NdArray; function areaSum(h0: number, w0: number, H: number, W: number, SAT: NdArray): number; function areaValue(img: NdArray): number; function rgb2gray(img: NdArray): NdArray; function flip(img: NdArray): NdArray; } export function array(arr: NjArray, dtype?: BaseNdArray.DataType): NdArray; export function int8(arr: NjArray): NjArray; export function uint8(arr: NjArray): NjArray; export function int16(arr: NjArray): NjArray; export function uint16(arr: NjArray): NjArray; export function int32(arr: NjArray): NjArray; export function uint32(arr: NjArray): NjArray; export function float32(arr: NjArray): NjArray; export function float64(arr: NjArray): NjArray;