Skip to content

Commit 63e1017

Browse files
committed
Add Typescript definitions
1 parent 0a88df5 commit 63e1017

File tree

9 files changed

+448
-0
lines changed

9 files changed

+448
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 2.0
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
/**
24+
* If provided a value, the accumulator function returns an updated mean directional accuracy. If not provided a value, the accumulator function returns the current mean directional accuracy.
25+
*
26+
* ## Notes
27+
*
28+
* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations.
29+
*
30+
* @param f - forecast value
31+
* @param a - actual value
32+
* @returns mean directional accuracy or null
33+
*/
34+
type accumulator = ( f?: number, a?: number ) => number | null;
35+
36+
/**
37+
* Returns an accumulator function which incrementally computes a moving mean directional accuracy.
38+
*
39+
* ## Notes
40+
*
41+
* - The `W` parameter defines the number of values over which to compute the moving mean directional accuracy.
42+
* - As `W` (f,a) pairs are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values.
43+
*
44+
* @param W - window size
45+
* @throws must provide a positive integer
46+
* @returns accumulator function
47+
*
48+
* @example
49+
* var accumulator = incrmmda( 3 );
50+
*
51+
* var m = accumulator();
52+
* // returns null
53+
*
54+
* m = accumulator( 2.0, 3.0 );
55+
* // returns 1.0
56+
*
57+
* m = accumulator( 5.0, 2.0 );
58+
* // returns 0.5
59+
*
60+
* m = accumulator( 3.0, 2.0 );
61+
* // returns ~0.33
62+
*
63+
* m = accumulator( 4.0, 5.0 );
64+
* // returns ~0.33
65+
*
66+
* m = accumulator();
67+
* // returns ~0.33
68+
*/
69+
declare function incrmmda( W: number ): accumulator;
70+
71+
72+
// EXPORTS //
73+
74+
export = incrmmda;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import incrmmda = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an accumulator function...
25+
{
26+
incrmmda( 3 ); // $ExpectType accumulator
27+
}
28+
29+
// The compiler throws an error if the function is provided an argument that is not a number...
30+
{
31+
incrmmda( '5' ); // $ExpectError
32+
incrmmda( true ); // $ExpectError
33+
incrmmda( false ); // $ExpectError
34+
incrmmda( null ); // $ExpectError
35+
incrmmda( undefined ); // $ExpectError
36+
incrmmda( [] ); // $ExpectError
37+
incrmmda( {} ); // $ExpectError
38+
incrmmda( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The compiler throws an error if the function is provided an invalid number of arguments...
42+
{
43+
incrmmda(); // $ExpectError
44+
incrmmda( 3, 2 ); // $ExpectError
45+
}
46+
47+
// The function returns an accumulator function which returns an accumulated result...
48+
{
49+
const acc = incrmmda( 3 );
50+
51+
acc(); // $ExpectType number | null
52+
acc( 3.14, 2.0 ); // $ExpectType number | null
53+
}
54+
55+
// The compiler throws an error if the returned accumulator function is provided invalid arguments...
56+
{
57+
const acc = incrmmda( 3 );
58+
59+
acc( '5', 2.0 ); // $ExpectError
60+
acc( true, 2.0 ); // $ExpectError
61+
acc( false, 2.0 ); // $ExpectError
62+
acc( null, 2.0 ); // $ExpectError
63+
acc( [], 2.0 ); // $ExpectError
64+
acc( {}, 2.0 ); // $ExpectError
65+
acc( ( x: number ): number => x, 2.0 ); // $ExpectError
66+
67+
acc( 3.14, '5' ); // $ExpectError
68+
acc( 3.14, true ); // $ExpectError
69+
acc( 3.14, false ); // $ExpectError
70+
acc( 3.14, null ); // $ExpectError
71+
acc( 3.14, [] ); // $ExpectError
72+
acc( 3.14, {} ); // $ExpectError
73+
acc( 3.14, ( x: number ): number => x ); // $ExpectError
74+
}

lib/node_modules/@stdlib/stats/incr/mmda/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"lib": "./lib",
2121
"test": "./test"
2222
},
23+
"types": "./docs/types",
2324
"scripts": {},
2425
"homepage": "https://github.com/stdlib-js/stdlib",
2526
"repository": {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 2.0
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
/**
24+
* If provided arguments, returns an updated sum of products; otherwise, returns the current sum of products.
25+
*
26+
* ## Notes
27+
*
28+
* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations.
29+
*
30+
* @param x - value
31+
* @param y - value
32+
* @returns sum of products
33+
*/
34+
type accumulator = ( x?: number, y?: number ) => number | null;
35+
36+
/**
37+
* Returns an accumulator function which incrementally computes a moving sum of products.
38+
*
39+
* ## Notes
40+
*
41+
* - The `W` parameter defines the number of (x,y) pairs over which to compute the moving sum of products.
42+
* - As `W` (x,y) pairs are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values.
43+
*
44+
* @param W - window size
45+
* @throws must provide a positive integer
46+
* @returns accumulator function
47+
*
48+
* @example
49+
* var accumulator = incrmsumprod( 3 );
50+
*
51+
* var sum = accumulator();
52+
* // returns null
53+
*
54+
* sum = accumulator( 2.0, 3.0 );
55+
* // returns 6.0
56+
*
57+
* sum = accumulator( -5.0, 2.0 );
58+
* // returns -4.0
59+
*
60+
* sum = accumulator( 3.0, -2.0 );
61+
* // returns -10.0
62+
*
63+
* sum = accumulator( 5.0, 3.0 );
64+
* // returns -1.0
65+
*
66+
* sum = accumulator();
67+
* // returns -1.0
68+
*/
69+
declare function incrmsumprod( W: number ): accumulator;
70+
71+
72+
// EXPORTS //
73+
74+
export = incrmsumprod;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import incrmsumprod = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an accumulator function...
25+
{
26+
incrmsumprod( 3 ); // $ExpectType accumulator
27+
}
28+
29+
// The compiler throws an error if the function is provided an argument that is not a number...
30+
{
31+
incrmsumprod( '5' ); // $ExpectError
32+
incrmsumprod( true ); // $ExpectError
33+
incrmsumprod( false ); // $ExpectError
34+
incrmsumprod( null ); // $ExpectError
35+
incrmsumprod( undefined ); // $ExpectError
36+
incrmsumprod( [] ); // $ExpectError
37+
incrmsumprod( {} ); // $ExpectError
38+
incrmsumprod( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The compiler throws an error if the function is provided an invalid number of arguments...
42+
{
43+
incrmsumprod(); // $ExpectError
44+
incrmsumprod( 3, 5 ); // $ExpectError
45+
}
46+
47+
// The function returns an accumulator function which returns an accumulated result...
48+
{
49+
const acc = incrmsumprod( 3 );
50+
51+
acc(); // $ExpectType number | null
52+
acc( 3.14, 2.0 ); // $ExpectType number | null
53+
}
54+
55+
// The compiler throws an error if the returned accumulator function is provided invalid arguments...
56+
{
57+
const acc = incrmsumprod( 3 );
58+
59+
acc( '5', 1.0 ); // $ExpectError
60+
acc( true, 1.0 ); // $ExpectError
61+
acc( false, 1.0 ); // $ExpectError
62+
acc( null, 1.0 ); // $ExpectError
63+
acc( [], 1.0 ); // $ExpectError
64+
acc( {}, 1.0 ); // $ExpectError
65+
acc( ( x: number ): number => x, 1.0 ); // $ExpectError
66+
67+
acc( 3.14, '5' ); // $ExpectError
68+
acc( 3.14, true ); // $ExpectError
69+
acc( 3.14, false ); // $ExpectError
70+
acc( 3.14, null ); // $ExpectError
71+
acc( 3.14, [] ); // $ExpectError
72+
acc( 3.14, {} ); // $ExpectError
73+
acc( 3.14, ( x: number ): number => x ); // $ExpectError
74+
}

lib/node_modules/@stdlib/stats/incr/msumprod/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"lib": "./lib",
2121
"test": "./test"
2222
},
23+
"types": "./docs/types",
2324
"scripts": {},
2425
"homepage": "https://github.com/stdlib-js/stdlib",
2526
"repository": {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 2.0
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
/**
24+
* If provided a value, the accumulator function returns an updated accumulated value. If not provided a value, the accumulator function returns the current accumulated value.
25+
*
26+
* ## Notes
27+
*
28+
* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations.
29+
*
30+
* @param x - value
31+
* @returns accumulated value or null
32+
*/
33+
type accumulator = ( x?: number ) => number | null;
34+
35+
/**
36+
* Returns an accumulator function which incrementally computes a moving variance-to-mean ratio (VMR).
37+
*
38+
* @param W - window size
39+
* @param mean - mean value
40+
* @throws first argument must be a positive integer
41+
* @returns accumulator function
42+
*
43+
* @example
44+
* var accumulator = incrmvmr( 3 );
45+
*
46+
* var F = accumulator();
47+
* // returns null
48+
*
49+
* F = accumulator( 2.0 );
50+
* // returns 0.0
51+
*
52+
* F = accumulator( 1.0 );
53+
* // returns ~0.33
54+
*
55+
* F = accumulator( 3.0 );
56+
* // returns 0.5
57+
*
58+
* F = accumulator( 7.0 );
59+
* // returns ~2.55
60+
*
61+
* F = accumulator();
62+
* // returns ~2.55
63+
*
64+
* @example
65+
* var accumulator = incrmvmr( 3, 2.0 );
66+
*/
67+
declare function incrmvmr( W: number, mean?: number ): accumulator;
68+
69+
70+
// EXPORTS //
71+
72+
export = incrmvmr;

0 commit comments

Comments
 (0)