Skip to content

Commit de37f07

Browse files
committed
Add Typescript annotations
1 parent 629ab16 commit de37f07

12 files changed

Lines changed: 648 additions & 0 deletions

File tree

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
import * as random from '@stdlib/types/random';
24+
import { Iterator } from '@stdlib/types/iter';
25+
26+
/**
27+
* Interface defining function options.
28+
*/
29+
interface Options {
30+
/**
31+
* Pseudorandom number generator which generates uniformly distributed pseudorandom numbers.
32+
*/
33+
prng?: random.PRNG;
34+
35+
/**
36+
* Pseudorandom number generator seed.
37+
*/
38+
seed?: random.PRNGSeedMT19937;
39+
40+
/**
41+
* Pseudorandom number generator state.
42+
*/
43+
state?: random.PRNGStateMT19937;
44+
45+
/**
46+
* Specifies whether to copy a provided pseudorandom number generator state (default: `true`).
47+
*/
48+
copy?: boolean;
49+
50+
/**
51+
* Number of iterations.
52+
*/
53+
iter?: number;
54+
}
55+
56+
/**
57+
* Interface for iterators of pseudorandom numbers drawn from an exponential distribution.
58+
*/
59+
interface RandIter extends Iterator {
60+
/**
61+
* Underlying PRNG.
62+
*/
63+
readonly PRNG: random.PRNG;
64+
65+
/**
66+
* PRNG seed.
67+
*/
68+
readonly seed: random.PRNGSeedMT19937;
69+
70+
/**
71+
* PRNG seed length.
72+
*/
73+
readonly seedLength: number;
74+
75+
/**
76+
* PRNG state.
77+
*/
78+
state: random.PRNGStateMT19937;
79+
80+
/**
81+
* PRNG state length.
82+
*/
83+
readonly stateLength: number;
84+
85+
/**
86+
* PRNG state size (in bytes).
87+
*/
88+
readonly byteLength: number;
89+
}
90+
91+
/**
92+
* Returns an iterator for generating pseudorandom numbers drawn from an exponential distribution.
93+
*
94+
* @param lambda - rate parameter
95+
* @param options - function options
96+
* @throws `lambda` must be a positive number
97+
* @throws must provide valid options
98+
* @throws must provide a valid state
99+
* @returns iterator
100+
*
101+
* @example
102+
* var iter = iterator( 3.0 );
103+
*
104+
* var r = iter.next().value;
105+
* // returns <number>
106+
*
107+
* r = iter.next().value;
108+
* // returns <number>
109+
*
110+
* r = iter.next().value;
111+
* // returns <number>
112+
*
113+
* // ...
114+
*/
115+
declare function iterator( lambda: number, options?: Options ): RandIter;
116+
117+
118+
// EXPORTS //
119+
120+
export = iterator;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 iterator = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an iterator...
25+
{
26+
iterator( 3.0 );
27+
iterator( 5.0, {} );
28+
iterator( 5.0, { 'iter': 10 } );
29+
}
30+
31+
// The compiler throws an error if the function is provided an invalid input argument...
32+
{
33+
iterator( '2.0', ); // $ExpectError
34+
iterator( true ); // $ExpectError
35+
iterator( { 'iter': 'beep' } ); // $ExpectError
36+
}
37+
38+
// The compiler throws an error if the function is provided insufficient arguments...
39+
{
40+
iterator(); // $ExpectError
41+
}

lib/node_modules/@stdlib/random/iter/exponential/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lib": "./lib",
2222
"test": "./test"
2323
},
24+
"types": "./docs/types",
2425
"scripts": {},
2526
"homepage": "https://github.com/stdlib-js/stdlib",
2627
"repository": {
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
import * as random from '@stdlib/types/random';
24+
import { Iterator } from '@stdlib/types/iter';
25+
26+
/**
27+
* Interface defining function options.
28+
*/
29+
interface Options {
30+
/**
31+
* Pseudorandom number generator which generates uniformly distributed pseudorandom numbers.
32+
*/
33+
prng?: random.PRNG;
34+
35+
/**
36+
* Pseudorandom number generator seed.
37+
*/
38+
seed?: random.PRNGSeedMT19937;
39+
40+
/**
41+
* Pseudorandom number generator state.
42+
*/
43+
state?: random.PRNGStateMT19937;
44+
45+
/**
46+
* Specifies whether to copy a provided pseudorandom number generator state (default: `true`).
47+
*/
48+
copy?: boolean;
49+
50+
/**
51+
* Number of iterations.
52+
*/
53+
iter?: number;
54+
}
55+
56+
/**
57+
* Interface for iterators of pseudorandom numbers drawn from a geometric distribution.
58+
*/
59+
interface RandIter extends Iterator {
60+
/**
61+
* Underlying PRNG.
62+
*/
63+
readonly PRNG: random.PRNG;
64+
65+
/**
66+
* PRNG seed.
67+
*/
68+
readonly seed: random.PRNGSeedMT19937;
69+
70+
/**
71+
* PRNG seed length.
72+
*/
73+
readonly seedLength: number;
74+
75+
/**
76+
* PRNG state.
77+
*/
78+
state: random.PRNGStateMT19937;
79+
80+
/**
81+
* PRNG state length.
82+
*/
83+
readonly stateLength: number;
84+
85+
/**
86+
* PRNG state size (in bytes).
87+
*/
88+
readonly byteLength: number;
89+
}
90+
91+
/**
92+
* Returns an iterator for generating pseudorandom numbers drawn from a geometric distribution.
93+
*
94+
* @param p - success probability
95+
* @param options - function options
96+
* @throws `p` must be a probability
97+
* @throws must provide valid options
98+
* @throws must provide a valid state
99+
* @returns iterator
100+
*
101+
* @example
102+
* var iter = iterator( 0.2 );
103+
*
104+
* var r = iter.next().value;
105+
* // returns <number>
106+
*
107+
* r = iter.next().value;
108+
* // returns <number>
109+
*
110+
* r = iter.next().value;
111+
* // returns <number>
112+
*
113+
* // ...
114+
*/
115+
declare function iterator( p: number, options?: Options ): RandIter;
116+
117+
118+
// EXPORTS //
119+
120+
export = iterator;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 iterator = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an iterator...
25+
{
26+
iterator( 0.3 );
27+
iterator( 0.5, {} );
28+
iterator( 0.5, { 'iter': 10 } );
29+
}
30+
31+
// The compiler throws an error if the function is provided an invalid input argument...
32+
{
33+
iterator( '0.2', ); // $ExpectError
34+
iterator( true ); // $ExpectError
35+
iterator( { 'iter': 'beep' } ); // $ExpectError
36+
}
37+
38+
// The compiler throws an error if the function is provided insufficient arguments...
39+
{
40+
iterator(); // $ExpectError
41+
}

lib/node_modules/@stdlib/random/iter/geometric/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lib": "./lib",
2222
"test": "./test"
2323
},
24+
"types": "./docs/types",
2425
"scripts": {},
2526
"homepage": "https://github.com/stdlib-js/stdlib",
2627
"repository": {

0 commit comments

Comments
 (0)