ts-scikit
Version:
A scientific toolkit written in Typescript
466 lines (465 loc) • 17.4 kB
TypeScript
/**
* Utilities for arrays plus math methods
* @packageDocumentation
*/
/**
* Returns the number of dimensions for the provided array.
* @param array the array.
* @param dim the starting dimension.
* @returns the number of dimensions.
*/
export declare function arrayDimensions(array: any, dim?: number): number;
/**
* Takes the cosine of a number by using the sine and an additional angle.
* @param sin the sine of an angle.
* @param angle the angle.
* @returns the resulting cosine.
*/
export declare function cosFromSin(sin: number, angle: number): number;
/**
* Converts degrees to radians.
* @param degrees the angle in degrees
* @returns the angle in radians.
*/
export declare function toRadians(degrees: number): number;
/**
* Converts radians to degrees.
* @param radians the angle in radians.
* @returns the angle in degrees.
*/
export declare function toDegrees(radians: number): number;
/**
* Determines whether the specified array is increasing.
* The array is increasing if its elements a[i] increase with array index i,
* with no equal values.
* @param a the array.
* @returns true, if increasing (or a.length < 2); false, otherwise.
*/
export declare function isIncreasing(a: number[]): boolean;
/**
* Determines whether the specified array is decreasing.
* The array is decreasing if its elements a[i] decrease with array index i,
* with no equal values.
* @param a the array.
* @returns true, if decreasing (or a.length < 2); false, otherwise.
*/
export declare function isDecreasing(a: number[]): boolean;
/**
* Determines whether the specified array is monotonic.
* The array is monotonic if its elements[i] either increase or
* decrease (but not both) with array index i, with no equal values.
* @param a the array.
* @returns true, if monotonic (or a.length < 2); false, otherwise.
*/
export declare function isMonotonic(a: number[]): boolean;
/**
* Determines if two values are almost equal given a provided tolerance.
* @param v1 a value.
* @param v2 a value.
* @param tiny the tolerance.
* @returns true, if almost equal; false, otherwise.
*/
export declare function almostEqual(v1: number, v2: number, tiny: number): boolean;
/**
* Returns array copy of elements from the specified array.
* @param rx source array.
* @returns array copy.
*/
export declare function copy(rx: number[]): number[];
/**
* Returns array copy of elements from the specified array.
* @param rx source array.
* @returns array copy.
*/
export declare function copy(rx: number[][]): number[][];
/**
* Returns array copy of elements from the specified array.
* @param rx source array.
* @returns array copy.
*/
export declare function copy(rx: number[][][]): number[][][];
/**
* Returns array copy of elements from the specified array.
* @param rx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @returns array copy.
*/
export declare function copy(rx: number[], n1: number): number[];
/**
* Returns array copy of elements from the specified array.
* @param rx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param n2 number of elements to copy in the 2nd dimension.
* @returns array copy.
*/
export declare function copy(rx: number[][], n1: number, n2: number): number[][];
/**
* Returns array copy of elements from the specified array.
* @param rx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param n2 number of elements to copy in the 2nd dimension.
* @param n3 number of elements to copy in the 3rd dimension.
* @returns array copy.
*/
export declare function copy(rx: number[][][], n1: number, n2: number, n3: number): number[][][];
/**
* Returns array copy of elements from the specified array.
* @param rx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param j1 offset in 1st dimension of rx.
* @returns array copy.
*/
export declare function copy(rx: number[], n1: number, j1: number): number[];
/**
* Returns array copy of elements from the specified array.
* @param rx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param n2 number of elements to copy in the 2nd dimension.
* @param j1 offset in 1st dimension of rx.
* @param j2 offset in 2nd dimension of rx.
* @returns array copy.
*/
export declare function copy(rx: number[][], n1: number, n2: number, j1: number, j2: number): number[][];
/**
* Returns array copy of elements from the specified array.
* @param rx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param n2 number of elements to copy in the 2nd dimension.
* @param n3 number of elements to copy in the 3rd dimension.
* @param j1 offset in 1st dimension of rx.
* @param j2 offset in 2nd dimension of rx.
* @param j3 offset in 3rd dimension of rx.
* @returns array copy.
*/
export declare function copy(rx: number[][][], n1: number, n2: number, n3: number, j1: number, j2: number, j3: number): number[][][];
/**
* Returns array copy of elements from the specified array.
* @param rx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param j1 offset in 1st dimension of rx.
* @param k1 stride in 1st dimension of rx.
* @returns array copy.
*/
export declare function copy(rx: number[], n1: number, j1: number, k1: number): number[];
/**
* Returns array copy of elements from the specified array.
* @param rx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param n2 number of elements to copy in the 2nd dimension.
* @param j1 offset in 1st dimension of rx.
* @param j2 offset in 2nd dimension of rx.
* @param k1 stride in 1st dimension of rx.
* @param k2 stride in 2nd dimension of rx.
* @returns array copy.
*/
export declare function copy(rx: number[][], n1: number, n2: number, j1: number, j2: number, k1: number, k2: number): number[][];
/**
* Returns array copy of elements from the specified array.
* @param rx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param n2 number of elements to copy in the 2nd dimension.
* @param n3 number of elements to copy in the 3rd dimension.
* @param j1 offset in 1st dimension of rx.
* @param j2 offset in 2nd dimension of rx.
* @param j3 offset in 3rd dimension of rx.
* @param k1 stride in 1st dimension of rx.
* @param k2 stride in 2nd dimension of rx.
* @param k3 stride in 3rd dimension of rx.
* @returns array copy.
*/
export declare function copy(rx: number[][][], n1: number, n2: number, n3: number, j1: number, j2: number, j3: number, k1: number, k2: number, k3: number): number[][][];
/**
* Returns array copy of elements from the specified array.
* @param cx source array.
* @returns array copy.
*/
export declare function ccopy(cx: number[]): number[];
/**
* Returns array copy of elements from the specified array.
* @param cx source array.
* @returns array copy.
*/
export declare function ccopy(cx: number[][]): number[][];
/**
* Returns array copy of elements from the specified array.
* @param cx source array.
* @returns array copy.
*/
export declare function ccopy(cx: number[][][]): number[][][];
/**
* Returns array copy of elements from the specified array.
* @param cx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @returns array copy.
*/
export declare function ccopy(cx: number[], n1: number): number[];
/**
* Returns array copy of elements from the specified array.
* @param cx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param n2 number of elements to copy in the 2nd dimension.
* @returns array copy.
*/
export declare function ccopy(cx: number[][], n1: number, n2: number): number[][];
/**
* Returns array copy of elements from the specified array.
* @param cx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param n2 number of elements to copy in the 2nd dimension.
* @param n3 number of elements to copy in the 3rd dimension.
* @returns array copy.
*/
export declare function ccopy(cx: number[][][], n1: number, n2: number, n3: number): number[][][];
/**
* Returns array copy of elements from the specified array.
* @param cx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param j1 offset in 1st dimension of cx.
* @returns array copy.
*/
export declare function ccopy(cx: number[], n1: number, j1: number): number[];
/**
* Returns array copy of elements from the specified array.
* @param cx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param n2 number of elements to copy in the 2nd dimension.
* @param j1 offset in 1st dimension of cx.
* @param j2 offset in 2nd dimension of cx.
* @returns array copy.
*/
export declare function ccopy(cx: number[][], n1: number, n2: number, j1: number, j2: number): number[][];
/**
* Returns array copy of elements from the specified array.
* @param cx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param n2 number of elements to copy in the 2nd dimension.
* @param n3 number of elements to copy in the 3rd dimension.
* @param j1 offset in 1st dimension of cx.
* @param j2 offset in 2nd dimension of cx.
* @param j3 offset in 3rd dimension of cx.
* @returns array copy.
*/
export declare function ccopy(cx: number[][][], n1: number, n2: number, n3: number, j1: number, j2: number, j3: number): number[][][];
/**
* Returns array copy of elements from the specified array.
* @param cx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param j1 offset in 1st dimension of cx.
* @param k1 stride in 1st dimension of cx.
* @returns array copy.
*/
export declare function ccopy(cx: number[], n1: number, j1: number, k1: number): number[];
/**
* Returns array copy of elements from the specified array.
* @param cx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param n2 number of elements to copy in the 2nd dimension.
* @param j1 offset in 1st dimension of cx.
* @param j2 offset in 2nd dimension of cx.
* @param k1 stride in 1st dimension of cx.
* @param k2 stride in 2nd dimension of cx.
* @returns array copy.
*/
export declare function ccopy(cx: number[][], n1: number, n2: number, j1: number, j2: number, k1: number, k2: number): number[][];
/**
* Returns array copy of elements from the specified array.
* @param cx source array.
* @param n1 number of elements to copy in the 1st dimension.
* @param n2 number of elements to copy in the 2nd dimension.
* @param n3 number of elements to copy in the 3rd dimension.
* @param j1 offset in 1st dimension of cx.
* @param j2 offset in 2nd dimension of cx.
* @param j3 offset in 3rd dimension of cx.
* @param k1 stride in 1st dimension of cx.
* @param k2 stride in 2nd dimension of cx.
* @param k3 stride in 3rd dimension of cx.
* @returns array copy.
*/
export declare function ccopy(cx: number[][][], n1: number, n2: number, n3: number, j1: number, j2: number, j3: number, k1: number, k2: number, k3: number): number[][][];
/**
* Returns an array of zeros.
* @param n1 1st array dimension.
* @returns an array[2 * n1] of zero complex numbers.
*/
export declare function czero(n1: number): number[];
/**
* Returns an array of zeros.
* @param n1 1st array dimension.
* @param n2 2nd array dimension.
* @returns an array[n2][2 * n1] of zero complex numbers.
*/
export declare function czero(n1: number, n2: number): number[][];
/**
* Returns an array of zeros.
* @param n1 1st array dimension.
* @param n2 2nd array dimension.
* @param n3 3rd array dimension.
* @returns an array[n3][n2][2 * n1] of zero complex numbers.
*/
export declare function czero(n1: number, n2: number, n3: number): number[][][];
/**
* Zeros the specified array.
* @param cx the array.
*/
export declare function czero(cx: number[]): void;
/**
* Zeros the specified array.
* @param cx the array.
*/
export declare function czero(cx: number[][]): void;
/**
* Zeros the specified array.
* @param cx the array.
*/
export declare function czero(cx: number[][][]): void;
/**
* Returns an array of zeros.
* @param n1 1st array dimension.
*/
export declare function zero(n1: number): number[];
/**
* Returns an array of zeros.
* @param n1 1st array dimension.
* @param n2 2nd array dimension.
*/
export declare function zero(n1: number, n2: number): number[][];
/**
* Returns an array of zeros.
* @param n1 1st array dimension.
* @param n2 2nd array dimension.
* @param n3 3rd array dimension.
*/
export declare function zero(n1: number, n2: number, n3: number): number[][][];
/**
* Zeros the specified array.
* @param rx the array.
*/
export declare function zero(rx: number[]): void;
/**
* Zeros the specified array.
* @param rx the array.
*/
export declare function zero(rx: number[][]): void;
/**
* Zeros the specified array.
* @param rx the array.
*/
export declare function zero(rx: number[][][]): void;
/**
* Returns an array initialized to a specified value.
* @param ra the value.
* @param n1 1st array dimension.
* @returns the array.
*/
export declare function fill(ra: number, n1: number): number[];
/**
* Returns an array initialized to a specified value.
* @param ra the value.
* @param n1 1st array dimension.
* @param n2 2nd array dimension.
* @returns the array.
*/
export declare function fill(ra: number, n1: number, n2: number): number[][];
/**
* Returns an array initialized to a specified value.
* @param ra the value.
* @param n1 1st array dimension.
* @param n2 2nd array dimension.
* @param n3 3rd array dimension.
* @returns the array.
*/
export declare function fill(ra: number, n1: number, n2: number, n3: number): number[][][];
/**
* Fills an array to a specified value.
* @param rx the array.
* @param ra the value.
*/
export declare function fill(rx: number[], ra: number): void;
/**
* Fills an array to a specified value.
* @param rx the array.
* @param ra the value.
*/
export declare function fill(rx: number[][], ra: number): void;
/**
* Fills an array to a specified value.
* @param rx the array.
* @pram ra the value.
*/
export declare function fill(rx: number[][][], ra: number): void;
/**
* Returns an array initialized to a specified linear ramp.
* @param ra value of the first element.
* @param rb1 gradient in the 1st dimension.
* @param n1 1st array dimension.
*/
export declare function ramp(ra: number, rb1: number, n1: number): number[];
/**
* Returns an array initialized to a specified linear ramp.
* @param ra value of the first element.
* @param rb1 gradient in the 1st dimension.
* @param rb2 gradient in the 2nd dimension.
* @param n1 1st array dimension.
* @param n2 2nd array dimension.
*/
export declare function ramp(ra: number, rb1: number, rb2: number, n1: number, n2: number): number[][];
/**
* Returns an array initialized to a specified linear ramp.
* @param ra value of the first element.
* @param rb1 gradient in the 1st dimension.
* @param rb2 gradient in the 2nd dimension.
* @param rb3 gradient in the 3rd dimension.
* @param n1 1st array dimension.
* @param n2 2nd array dimension.
* @param n3 3rd array dimension.
*/
export declare function ramp(ra: number, rb1: number, rb2: number, rb3: number, n1: number, n2: number, n3: number): number[][][];
/**
* Replaces an array values with a specified linear ramp.
* @param rx the array.
* @param ra value of the first element.
* @param rb1 gradient in the 1st dimension.
*/
export declare function ramp(rx: number[], ra: number, rb1: number): void;
/**
* Replaces an array values with a specified linear ramp.
* @param rx the array.
* @param ra value of the first element.
* @param rb1 gradient in the 1st dimension.
* @param rb2 gradient in the 2nd dimension.
*/
export declare function ramp(rx: number[][], ra: number, rb1: number, rb2: number): void;
/**
* Replaces an array values with a specified linear ramp.
* @param rx the array.
* @param ra value of the first element.
* @param rb1 gradient in the 1st dimension.
* @param rb2 gradient in the 2nd dimension.
* @param rb3 gradient in the 3rd dimension.
*/
export declare function ramp(rx: number[][][], ra: number, rb1: number, rb2: number, rb3: number): void;
/**
* Performs a quick partial sort.
* @param k
* @param arr
*/
export declare function quickPartialSort(k: number, arr: number[]): void;
/**
* Performs a binary search in a monotonic array of values.
* <p>
* Values are assumed to increase or decrease monotonically, with no equal
* values.
* <p>
* Warning: this method does not ensure that the specified array is
* monotonic; that check would be more costly than this search.
* @param a the array of values, assumed to be monotonic.
* @param x the value for which to search.
* @param i the index at which to begin the search. If negative, this
* method interprets this index as if returned from a
* previous call.
* @returns the index at which the specified value is found, or, if not
* found, -(i + 1), where i equals the index at which the
* specified value would be located if it was inserted into
* the monotonic array.
*/
export declare function binarySearch(a: number[], x: number, i?: number): number;