Skip to content

Commit

Permalink
Type definition missing for matrixFrom* josdejong#3115
Browse files Browse the repository at this point in the history
  • Loading branch information
Hudsxn committed Feb 1, 2024
1 parent 10657e5 commit 7f0a8a2
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion types/index.d.ts
Expand Up @@ -18,6 +18,13 @@ export type MathCollection = MathArray | Matrix
export type MathType = MathScalarType | MathCollection
export type MathExpression = string | string[] | MathCollection

// add type for Matrix Callback Function and Matrix Storage Format
export type MatrixStorageFormat = 'dense' | 'sparse'

export interface MatrixFromFunctionCallback<T extends (number | BigNumber)[]> {
(value: T): number | BigNumber
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type FactoryFunction<T> = (scope: any) => T

Expand Down Expand Up @@ -698,7 +705,7 @@ export interface MathJsInstance extends MathJsFactory {
* @param format The Matrix storage format
* @returns The created Matrix
*/
matrix(format?: 'sparse' | 'dense'): Matrix
matrix(format?: MatrixStorageFormat): Matrix
/**
* @param data A multi dimensional array
* @param format The Matrix storage format
Expand Down Expand Up @@ -1203,6 +1210,56 @@ export interface MathJsInstance extends MathJsFactory {
hypot<T extends number | BigNumber>(...args: T[]): T
hypot<T extends number | BigNumber>(args: T[]): T

/**
* Create a dense matrix from vectors as individual rows. If you pass column vectors, they will be transposed (but not conjugated!)
* @param rows - a multi-dimensional number array or matrix
*/
matrixFromRows<T extends (number | BigNumber)[] | Matrix>(...rows: T[]): T[]
matrixFromRows<T extends (number | BigNumber)[] | Matrix>(rows: T): T[]

/**
* Create a dense matrix from vectors as individual columns. If you pass row vectors, they will be transposed (but not conjugated!)
* @param cols - a multi-dimensional number array or matrix
*/
matrixFromColumns<T extends (number | BigNumber)[] | Matrix>(
...cols: T[]
): T[] | Matrix
matrixFromColumns<T extends (number | BigNumber)[] | Matrix>(
cols: T
): T[] | Matrix
/**
* Create a matrix by evaluating a generating function at each index. The simplest overload returns a multi-dimensional array as long as size is an array. Passing size as a Matrix or specifying a format will result in returning a Matrix.
* @param size - the size of the matrix to be created
* @param fn - Callback function invoked for every entry in the matrix
* @param format - The Matrix storage format, either 'dense' or 'sparse'
* @param datatype - Type of the values
*/
matrixFromFunction<T extends (number | BigNumber)[] | Matrix>(
size: T,
fn: MatrixFromFunctionCallback<(number | BigNumber)[]>
): T[] | Matrix
matrixFromFunction<T extends (number | BigNumber)[] | Matrix>(
size: T,
fn: MatrixFromFunctionCallback<(number | BigNumber)[]>,
format: MatrixStorageFormat
): T[] | Matrix
matrixFromFunction<T extends (number | BigNumber)[] | Matrix>(
size: T,
fn: MatrixFromFunctionCallback<(number | BigNumber)[]>,
format: MatrixStorageFormat,
datatype: string
): T[] | Matrix
matrixFromFunction<T extends (number | BigNumber)[] | Matrix>(
size: T,
format: MatrixStorageFormat,
fn: MatrixFromFunctionCallback<(number | BigNumber)[]>
): T[] | Matrix
matrixFromFunction<T extends (number | BigNumber)[] | Matrix>(
size: T,
format: MatrixStorageFormat,
datatype: string,
fn: MatrixFromFunctionCallback<(number | BigNumber)[]>
): T[] | Matrix
/**
* Calculate the least common multiple for two or more values or arrays.
* lcm is defined as: lcm(a, b) = abs(a * b) / gcd(a, b) For matrices,
Expand Down

0 comments on commit 7f0a8a2

Please sign in to comment.