Skip to content

Commit

Permalink
Improve quantileSeq typings (#3198)
Browse files Browse the repository at this point in the history
* Improve quantileSeq typings

* Add tests, revert comment changes

* Fix type tests
  • Loading branch information
domdomegg authored May 16, 2024
1 parent 599f4ee commit ffa3a2e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
14 changes: 13 additions & 1 deletion test/typescript-tests/testTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2454,7 +2454,7 @@ MathNode examples
}

/*
min/max return types
Statistics functions' return types
*/
{
const math = create(all, {})
Expand Down Expand Up @@ -2526,6 +2526,18 @@ min/max return types
expectTypeOf(math.median(123, math.bignumber('456'))).toMatchTypeOf<
number | BigNumber | Fraction | Complex | Unit
>()

expectTypeOf(math.quantileSeq([1, 2, 3], 0.75)).toMatchTypeOf<number>()
expectTypeOf(math.quantileSeq([[1, 2, 3]], 0.75)).toMatchTypeOf<number>()
expectTypeOf(
math.quantileSeq([math.bignumber('123')], 0.75)
).toMatchTypeOf<BigNumber>()
expectTypeOf(math.quantileSeq(math.matrix([1, 2, 3]), 0.75)).toMatchTypeOf<
MathScalarType | MathArray
>()
expectTypeOf(
math.quantileSeq([math.unit('5cm'), math.unit('10cm')], 0.75)
).toMatchTypeOf<Unit>()
}

/*
Expand Down
15 changes: 14 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2805,6 +2805,19 @@ export interface MathJsInstance extends MathJsFactory {
*/
prod(A: MathCollection): MathScalarType

/**
* @param A A single matrix
* @param probOrN prob is the order of the quantile, while N is the
* amount of evenly distributed steps of probabilities; only one of
* these options can be provided
* @param sorted =false is data sorted in ascending order
* @returns Quantile(s)
*/
quantileSeq<T extends MathScalarType>(
A: T[] | T[][],
prob: number | BigNumber | MathArray,
sorted?: boolean
): T
/**
* Compute the prob order quantile of a matrix or a list with values.
* The sequence is sorted and the middle value is returned. Supported
Expand All @@ -2823,7 +2836,7 @@ export interface MathJsInstance extends MathJsFactory {
A: MathCollection,
prob: number | BigNumber | MathArray,
sorted?: boolean
): number | BigNumber | Unit | MathArray
): MathScalarType | MathArray

/**
* Compute the standard deviation of a matrix or a list with values. The
Expand Down

0 comments on commit ffa3a2e

Please sign in to comment.