UNPKG

mathjslab

Version:

MathJSLab - An interpreter with language syntax like MATLAB®/Octave, ISBN 978-65-00-82338-7.

322 lines (321 loc) 9.38 kB
import { ComplexDecimal } from './ComplexDecimal'; import { type ElementType, MultiArray } from './MultiArray'; import * as AST from './AST'; declare abstract class CoreFunctions { static functions: Record<string, Function>; /** * Throw invalid call error if (optional) test is true. * @param name */ static throwInvalidCallError(name: string, test?: boolean): void; /** * * @param name * @param M */ static throwErrorIfCellArray(name: string, M: MultiArray | ComplexDecimal): void; /** * Return true if M is an empty matrix * @param X * @returns */ static isempty(X: ElementType): ComplexDecimal; /** * Return true if X is a scalar. * @param X * @returns */ static isscalar(X: ElementType): ComplexDecimal; /** * Return true if X is a 2-D array. * @param X * @returns */ static ismatrix(X: ElementType): ComplexDecimal; /** * Return true if X is a vector. * @param X * @returns */ static isvector(X: ElementType): ComplexDecimal; /** * Return true if X is a cell array object. * @param M * @returns */ static iscell(X: ElementType): ComplexDecimal; /** * Return true if X is a row vector. * @param X * @returns */ static isrow(X: ElementType): ComplexDecimal; /** * Return true if X is a column vector. * @param X * @returns */ static iscolumn(X: ElementType): ComplexDecimal; /** * Return true if X is a column vector. * @param X * @returns */ static isstruct(X: ElementType): ComplexDecimal; /** * Return the number of dimensions of M. * @param M * @returns */ static ndims(M: ElementType): ComplexDecimal; /** * eturn the number of rows of M. * @param M * @returns */ static rows(M: ElementType): ComplexDecimal; /** * Return the number of columns of M. * @param M * @returns */ static columns(M: ElementType): ComplexDecimal; /** * Return the length of the object M. The length is the number of elements * along the largest dimension. * @param M * @returns */ static Length(M: ElementType): ComplexDecimal; static numel(M: ElementType, ...IDX: ElementType[]): ComplexDecimal; /** * Convert linear indices to subscripts. * @param DIMS * @param IND * @returns */ static ind2sub(DIMS: ElementType, IND: ElementType): AST.NodeReturnList; /** * Convert subscripts to linear indices. * @param DIMS * @param S * @returns */ static sub2ind(DIMS: ElementType, ...S: ElementType[]): ElementType; /** * Returns array dimensions. * @param M MultiArray * @param DIM Dimensions * @returns Dimensions of `M` parameter. */ static size(M: ElementType, ...DIM: ElementType[]): ElementType; /** * Return the result of the colon expression. * @param args * @returns */ static colon(...args: ElementType[]): ElementType; /** * Return a row vector with linearly spaced elements. * @param args * @returns */ static linspace(...args: ElementType[]): ElementType; /** * Return a row vector with elements logarithmically spaced. * @param args * @returns */ static logspace(...args: ElementType[]): ElementType; /** * Generate 2-D and 3-D grids. * @param args * @returns */ static meshgrid(...args: ElementType[]): AST.NodeReturnList; /** * Given n vectors X1, ..., Xn, returns n arrays of n dimensions. * @returns */ static ndgrid(...args: ElementType[]): AST.NodeReturnList; /** * Repeat N-D array. * @param A * @param dim * @returns */ static repmat(A: ElementType, ...dim: ElementType[]): ElementType; /** * Return a matrix with the specified dimensions whose elements are taken from the matrix M. * @param M * @param dimension * @returns */ static reshape(M: ElementType, ...dimension: ElementType[]): ElementType; /** * Remove singleton dimensions. * @param args * @returns */ static squeeze(...args: ElementType[]): ElementType; /** * Create MultiArray with all elements equals `fill` parameter. * @param fill Value to fill MultiArray. * @param dimension Dimensions of created MultiArray. * @returns MultiArray filled with `fill` parameter. */ private static newFilled; /** * Create MultiArray with all elements filled with `fillFunction` result. * The parameter passed to `fillFunction` is a linear index of element. * @param fillFunction Function to be called and the result fills element of MultiArray created. * @param dimension Dimensions of created MultiArray. * @returns MultiArray filled with `fillFunction` results for each element. */ private static newFilledEach; /** * Create array of all zeros. * @param dimension * @returns */ static zeros(...dimension: ElementType[]): ElementType; /** * Create array of all ones. * @param dimension * @returns */ static ones(...dimension: ElementType[]): ElementType; /** * Uniformly distributed pseudorandom numbers distributed on the * interval (0, 1). * @param dimension * @returns */ static rand(...dimension: ElementType[]): ElementType; /** * Uniformly distributed pseudorandom integers. * @param imax * @param args * @returns */ static randi(range: ElementType, ...dimension: ElementType[]): ElementType; /** * Return the concatenation of N-D array objects, ARRAY1, ARRAY2, ..., * ARRAYN along dimension `DIM`. * @param DIM Dimension of concatenation. * @param ARRAY Arrays to concatenate. * @returns Concatenated arrays along dimension `DIM`. */ static cat(DIM: ElementType, ...ARRAY: ElementType[]): MultiArray; /** * Concatenate arrays horizontally. * @param ARRAY Arrays to concatenate horizontally. * @returns Concatenated arrays horizontally. */ static horzcat(...ARRAY: ElementType[]): MultiArray; /** * Concatenate arrays vertically. * @param ARRAY Arrays to concatenate vertically. * @returns Concatenated arrays vertically. */ static vertcat(...ARRAY: ElementType[]): MultiArray; /** * Calculate sum of elements along dimension DIM. * @param M Array * @param DIM Dimension * @returns Array with sum of elements along dimension DIM. */ static sum(M: MultiArray, DIM?: ElementType): ElementType; /** * Calculate sum of squares of elements along dimension DIM. * @param M Matrix * @param DIM Dimension * @returns One dimensional matrix with sum of squares of elements along dimension DIM. */ static sumsq(M: MultiArray, DIM?: ElementType): ElementType; /** * Calculate product of elements along dimension DIM. * @param M Matrix * @param DIM Dimension * @returns One dimensional matrix with product of elements along dimension DIM. */ static prod(M: MultiArray, DIM?: ElementType): ElementType; /** * Calculate average or mean of elements along dimension DIM. * @param M Matrix * @param DIM Dimension * @returns One dimensional matrix with product of elements along dimension DIM. */ static mean(M: MultiArray, DIM?: ElementType): ElementType; /** * Base method of min and max user functions. * @param op 'min' or 'max'. * @param args One to three arguments like user function. * @returns Return like user function. */ private static minMax; /** * Minimum elements of array. * @param M * @returns */ static min(...args: ElementType[]): MultiArray | AST.NodeReturnList | undefined; /** * Maximum elements of array. * @param M * @returns */ static max(...args: ElementType[]): MultiArray | AST.NodeReturnList | undefined; /** * Base method of cummin and cummax user functions. * @param op 'min' or 'max'. * @param M MultiArray. * @param DIM Dimension in which the cumulative operation occurs. * @returns MultiArray with cumulative values along dimension DIM. */ private static cumMinMax; /** * * @param M * @param DIM * @returns */ static cummin(M: ElementType, DIM?: ElementType): AST.NodeReturnList; /** * * @param M * @param DIM * @returns */ static cummax(M: ElementType, DIM?: ElementType): AST.NodeReturnList; /** * * @param op * @param M * @param DIM * @returns */ private static cumSumProd; /** * * @param M * @param DIM * @returns */ static cumsum(M: ElementType, DIM?: ElementType): ElementType; /** * * @param M * @param DIM * @returns */ static cumprod(M: ElementType, DIM?: ElementType): ElementType; /** * * @param args * @returns */ static struct(...args: ElementType[]): ElementType; } export { CoreFunctions }; export default CoreFunctions;