From 28b7d25f68c1c55899dfd47ca0c98ffcdb89e40f Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Thu, 2 May 2024 00:38:34 +0100 Subject: [PATCH 1/3] Improve quantileSeq typings --- types/index.d.ts | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 966ae1b766..4b37763c86 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2655,7 +2655,7 @@ export interface MathJsInstance extends MathJsFactory { */ max(...args: MathScalarType[]): MathScalarType /** - * @param A A single matrix + * @param A An array of scalar values * @param dimension The maximum over the selected dimension * @returns The maximum value */ @@ -2685,7 +2685,7 @@ export interface MathJsInstance extends MathJsFactory { */ mean(...args: MathScalarType[]): MathScalarType /** - * @param A A single matrix + * @param A An array of scalar values * @param dimension The mean over the selected dimension * @returns The mean value */ @@ -2742,7 +2742,7 @@ export interface MathJsInstance extends MathJsFactory { */ min(...args: MathScalarType[]): MathScalarType /** - * @param A A single matrix + * @param A An array of scalar values * @param dimension The minimum over the selected dimension * @returns The minimum value */ @@ -2771,7 +2771,7 @@ export interface MathJsInstance extends MathJsFactory { */ mode(...args: MathScalarType[]): MathScalarType[] /** - * @param A A single matrix + * @param A An array of scalar values * @returns The mode value */ mode(A: T[] | T[][]): T[] @@ -2795,7 +2795,7 @@ export interface MathJsInstance extends MathJsFactory { */ prod(...args: MathScalarType[]): MathScalarType /** - * @param A A single matrix + * @param A An array of scalar values * @returns The product of all values */ prod(A: T[] | T[][]): T @@ -2805,6 +2805,19 @@ export interface MathJsInstance extends MathJsFactory { */ prod(A: MathCollection): MathScalarType + /** + * @param A An array of scalar values + * @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( + 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 @@ -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 @@ -2901,7 +2914,7 @@ export interface MathJsInstance extends MathJsFactory { */ sum(...args: MathScalarType[]): MathScalarType /** - * @param A A single matrix + * @param A An array of scalar values * @param dimension The sum over the selected dimension * @returns The sum of all values */ From 18d8df005cc9a4929244cafef141eed395451dd5 Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Sat, 11 May 2024 00:49:23 +0100 Subject: [PATCH 2/3] Add tests, revert comment changes --- test/typescript-tests/testTypes.ts | 14 +++++++++++++- types/index.d.ts | 14 +++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/test/typescript-tests/testTypes.ts b/test/typescript-tests/testTypes.ts index 1d4f31e09a..83321ec52a 100644 --- a/test/typescript-tests/testTypes.ts +++ b/test/typescript-tests/testTypes.ts @@ -2454,7 +2454,7 @@ MathNode examples } /* -min/max return types +Statistics functions' return types */ { const math = create(all, {}) @@ -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() + expectTypeOf(math.quantileSeq([[1, 2, 3]], 0.75)).toMatchTypeOf() + expectTypeOf( + math.quantileSeq([math.bignumber('123')], 0.75) + ).toMatchTypeOf() + expectTypeOf(math.quantileSeq(math.matrix([1, 2, 3]), 0.75)).toMatchTypeOf< + MathScalarType | MathArray + >() + expectTypeOf( + math.quantileSeq([math.unit('5cm'), math.unit('10cm')]) + ).toMatchTypeOf() } /* diff --git a/types/index.d.ts b/types/index.d.ts index 4b37763c86..a7e56e2e93 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2655,7 +2655,7 @@ export interface MathJsInstance extends MathJsFactory { */ max(...args: MathScalarType[]): MathScalarType /** - * @param A An array of scalar values + * @param A A single matrix * @param dimension The maximum over the selected dimension * @returns The maximum value */ @@ -2685,7 +2685,7 @@ export interface MathJsInstance extends MathJsFactory { */ mean(...args: MathScalarType[]): MathScalarType /** - * @param A An array of scalar values + * @param A A single matrix * @param dimension The mean over the selected dimension * @returns The mean value */ @@ -2742,7 +2742,7 @@ export interface MathJsInstance extends MathJsFactory { */ min(...args: MathScalarType[]): MathScalarType /** - * @param A An array of scalar values + * @param A A single matrix * @param dimension The minimum over the selected dimension * @returns The minimum value */ @@ -2771,7 +2771,7 @@ export interface MathJsInstance extends MathJsFactory { */ mode(...args: MathScalarType[]): MathScalarType[] /** - * @param A An array of scalar values + * @param A A single matrix * @returns The mode value */ mode(A: T[] | T[][]): T[] @@ -2795,7 +2795,7 @@ export interface MathJsInstance extends MathJsFactory { */ prod(...args: MathScalarType[]): MathScalarType /** - * @param A An array of scalar values + * @param A A single matrix * @returns The product of all values */ prod(A: T[] | T[][]): T @@ -2806,7 +2806,7 @@ export interface MathJsInstance extends MathJsFactory { prod(A: MathCollection): MathScalarType /** - * @param A An array of scalar values + * @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 @@ -2914,7 +2914,7 @@ export interface MathJsInstance extends MathJsFactory { */ sum(...args: MathScalarType[]): MathScalarType /** - * @param A An array of scalar values + * @param A A single matrix * @param dimension The sum over the selected dimension * @returns The sum of all values */ From a70e26dd1261dfa676aea90d01037e28eedbe078 Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Wed, 15 May 2024 22:42:33 +0100 Subject: [PATCH 3/3] Fix type tests --- test/typescript-tests/testTypes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/typescript-tests/testTypes.ts b/test/typescript-tests/testTypes.ts index 83321ec52a..caa78be3e8 100644 --- a/test/typescript-tests/testTypes.ts +++ b/test/typescript-tests/testTypes.ts @@ -2536,7 +2536,7 @@ Statistics functions' return types MathScalarType | MathArray >() expectTypeOf( - math.quantileSeq([math.unit('5cm'), math.unit('10cm')]) + math.quantileSeq([math.unit('5cm'), math.unit('10cm')], 0.75) ).toMatchTypeOf() }