Skip to content

Commit 7d190e7

Browse files
committed
feat: add TypeScript declarations
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent fe103d4 commit 7d190e7

File tree

3 files changed

+725
-1
lines changed

3 files changed

+725
-1
lines changed

lib/node_modules/@stdlib/random/tools/unary/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ The method has the following parameters:
112112
The method accepts the following options:
113113

114114
- **dtype**: output ndarray data type. Setting this option overrides the output data type policy.
115-
- **order**: memory layout. Setting this option overrides the default memory layout order.
115+
- **order**: memory layout. Setting this option overrides the default memory layout.
116116
- **mode**: specifies how to handle indices which exceed ndarray dimensions.
117117
- **submode**: specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis.
118118
- **readonly**: boolean indicating whether an ndarray should be read-only.
Lines changed: 321 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,321 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray';
24+
import { ArrayLike } from '@stdlib/types/array';
25+
import { PRNG } from '@stdlib/types/random';
26+
27+
/**
28+
* Interface defining constructor options.
29+
*/
30+
interface ConstructorOptions {
31+
/**
32+
* Default memory layout.
33+
*/
34+
order?: Order;
35+
}
36+
37+
/**
38+
* Interface defining options.
39+
*/
40+
interface Options {
41+
/**
42+
* Output ndarray data type.
43+
*
44+
* ## Notes
45+
*
46+
* - Setting this option overrides the output data type policy.
47+
*/
48+
dtype?: DataType;
49+
50+
/**
51+
* Memory layout.
52+
*
53+
* ## Notes
54+
*
55+
* - Setting this option overrides the default memory layout.
56+
*/
57+
order?: Order;
58+
59+
/**
60+
* Specifies how to handle indices which exceed ndarray dimensions.
61+
*/
62+
mode?: Mode;
63+
64+
/**
65+
* Specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis.
66+
*/
67+
submode?: ArrayLike<Mode>;
68+
69+
/**
70+
* Boolean indicating whether an ndarray should be read-only.
71+
*/
72+
readonly?: boolean;
73+
}
74+
75+
/**
76+
* Interface defining class policies.
77+
*/
78+
interface Policies {
79+
/**
80+
* Output data type policy.
81+
*/
82+
output: OutputPolicy;
83+
}
84+
85+
/**
86+
* Interface for generating pseudorandom values drawn from a unary PRNG.
87+
*/
88+
interface UnaryPRNG<T, U> extends PRNG {
89+
/**
90+
* Returns a pseudorandom value.
91+
*
92+
* @param param1 - PRNG parameter
93+
* @returns pseudorandom value
94+
*/
95+
( param1: T ): U;
96+
}
97+
98+
/**
99+
* Class for creating ndarrays filled with pseudorandom values drawn from a unary PRNG.
100+
*/
101+
declare class RandomArray<T, U> {
102+
/**
103+
* Constructor for creating ndarrays filled with pseudorandom values drawn from a unary PRNG.
104+
*
105+
* @param prng - unary pseudorandom value generator
106+
* @param idtypes - list of supported input data types
107+
* @param odtypes - list of supported output data types
108+
* @param policies - dispatch policies
109+
* @param options - function options
110+
* @returns instance
111+
*
112+
* @example
113+
* var dtypes = require( '@stdlib/ndarray/dtypes' );
114+
* var exponential = require( '@stdlib/random/base/exponential' );
115+
*
116+
* var idt = dtypes( 'real_and_generic' );
117+
* var odt = dtypes( 'real_floating_point_and_generic' );
118+
*
119+
* var policies = {
120+
* 'output': 'real_floating_point_and_generic'
121+
* };
122+
* var options = {
123+
* 'order': 'row-major'
124+
* };
125+
*
126+
* var rand = new Random( exponential, idt, odt, policies, options );
127+
*
128+
* var v = rand.generate( [ 2, 2 ], 2.0 );
129+
* // returns <ndarray>
130+
*/
131+
constructor( prng: UnaryPRNG<T, U>, idtypes: ArrayLike<DataType>, odtypes: ArrayLike<DataType>, policies: Policies, options?: ConstructorOptions );
132+
133+
/**
134+
* Returns an array filled with pseudorandom values drawn from a unary PRNG.
135+
*
136+
* @param shape - output shape
137+
* @param param1 - PRNG parameter
138+
* @param options - function options
139+
* @returns output ndarray
140+
*
141+
* @example
142+
* var dtypes = require( '@stdlib/ndarray/dtypes' );
143+
* var exponential = require( '@stdlib/random/base/exponential' );
144+
*
145+
* var idt = dtypes( 'real_and_generic' );
146+
* var odt = dtypes( 'real_floating_point_and_generic' );
147+
*
148+
* var policies = {
149+
* 'output': 'real_floating_point_and_generic'
150+
* };
151+
* var options = {
152+
* 'order': 'row-major'
153+
* };
154+
*
155+
* var rand = new Random( exponential, idt, odt, policies, options );
156+
*
157+
* var v = rand.generate( [ 2, 2 ], 2.0 );
158+
* // returns <ndarray>
159+
*/
160+
generate( shape: Shape, param1: T | typedndarray<T>, options?: Options ): typedndarray<U>;
161+
162+
/**
163+
* Fills an ndarray with pseudorandom values drawn from a unary PRNG.
164+
*
165+
* @param param1 - PRNG parameter
166+
* @param out - output ndarray
167+
* @returns output ndarray
168+
*
169+
* @example
170+
* var dtypes = require( '@stdlib/ndarray/dtypes' );
171+
* var ndzeros = require( '@stdlib/ndarray/zeros' );
172+
* var exponential = require( '@stdlib/random/base/exponential' );
173+
*
174+
* var idt = dtypes( 'real_and_generic' );
175+
* var odt = dtypes( 'real_floating_point_and_generic' );
176+
*
177+
* var policies = {
178+
* 'output': 'real_floating_point_and_generic'
179+
* };
180+
* var options = {
181+
* 'order': 'row-major'
182+
* };
183+
*
184+
* var rand = new Random( exponential, idt, odt, policies, options );
185+
*
186+
* var out = ndzeros( [ 2, 2 ] );
187+
* var v = rand.assign( 2.0, out );
188+
* // returns <ndarray>
189+
*
190+
* var bool = ( v === out );
191+
* // returns true
192+
*/
193+
assign( param1: T | typedndarray<T>, out: typedndarray<U> ): typedndarray<U>;
194+
}
195+
196+
/**
197+
* Interface defining a constructor which is both "newable" and "callable".
198+
*/
199+
interface RandomArrayConstructor {
200+
/**
201+
* Constructor for creating ndarrays filled with pseudorandom values drawn from a unary PRNG.
202+
*
203+
* @param prng - unary pseudorandom value generator
204+
* @param idtypes - list of supported input data types
205+
* @param odtypes - list of supported output data types
206+
* @param policies - dispatch policies
207+
* @param options - function options
208+
* @returns instance
209+
*
210+
* @example
211+
* var dtypes = require( '@stdlib/ndarray/dtypes' );
212+
* var exponential = require( '@stdlib/random/base/exponential' );
213+
*
214+
* var idt = dtypes( 'real_and_generic' );
215+
* var odt = dtypes( 'real_floating_point_and_generic' );
216+
*
217+
* var policies = {
218+
* 'output': 'real_floating_point_and_generic'
219+
* };
220+
* var options = {
221+
* 'order': 'row-major'
222+
* };
223+
*
224+
* var rand = new Random( exponential, idt, odt, policies, options );
225+
*
226+
* var v = rand.generate( [ 2, 2 ], 2.0 );
227+
* // returns <ndarray>
228+
*/
229+
new<T = unknown, U = unknown>( prng: UnaryPRNG<T, U>, idtypes: ArrayLike<DataType>, odtypes: ArrayLike<DataType>, policies: Policies, options?: ConstructorOptions ): RandomArray<T, U>;
230+
231+
/**
232+
* Constructor for creating ndarrays filled with pseudorandom values drawn from a unary PRNG.
233+
*
234+
* @param prng - unary pseudorandom value generator
235+
* @param idtypes - list of supported input data types
236+
* @param odtypes - list of supported output data types
237+
* @param policies - dispatch policies
238+
* @param options - function options
239+
* @returns instance
240+
*
241+
* @example
242+
* var dtypes = require( '@stdlib/ndarray/dtypes' );
243+
* var exponential = require( '@stdlib/random/base/exponential' );
244+
*
245+
* var idt = dtypes( 'real_and_generic' );
246+
* var odt = dtypes( 'real_floating_point_and_generic' );
247+
*
248+
* var policies = {
249+
* 'output': 'real_floating_point_and_generic'
250+
* };
251+
* var options = {
252+
* 'order': 'row-major'
253+
* };
254+
*
255+
* var rand = new Random( exponential, idt, odt, policies, options );
256+
*
257+
* var v = rand.generate( [ 2, 2 ], 2.0 );
258+
* // returns <ndarray>
259+
*/
260+
<T = unknown, U = unknown>( prng: UnaryPRNG<T, U>, idtypes: ArrayLike<DataType>, odtypes: ArrayLike<DataType>, policies: Policies, options?: ConstructorOptions ): RandomArray<T, U>;
261+
}
262+
263+
/**
264+
* Constructor for creating ndarrays filled with pseudorandom values drawn from a unary PRNG.
265+
*
266+
* @param prng - unary pseudorandom value generator
267+
* @param idtypes - list of supported input data types
268+
* @param odtypes - list of supported output data types
269+
* @param policies - dispatch policies
270+
* @param options - function options
271+
* @returns instance
272+
*
273+
* @example
274+
* var dtypes = require( '@stdlib/ndarray/dtypes' );
275+
* var exponential = require( '@stdlib/random/base/exponential' );
276+
*
277+
* var idt = dtypes( 'real_and_generic' );
278+
* var odt = dtypes( 'real_floating_point_and_generic' );
279+
*
280+
* var policies = {
281+
* 'output': 'real_floating_point_and_generic'
282+
* };
283+
* var options = {
284+
* 'order': 'row-major'
285+
* };
286+
*
287+
* var rand = new Random( exponential, idt, odt, policies, options );
288+
*
289+
* var v = rand.generate( [ 2, 2 ], 2.0 );
290+
* // returns <ndarray>
291+
*
292+
* @example
293+
* var dtypes = require( '@stdlib/ndarray/dtypes' );
294+
* var ndzeros = require( '@stdlib/ndarray/zeros' );
295+
* var exponential = require( '@stdlib/random/base/exponential' );
296+
*
297+
* var idt = dtypes( 'real_and_generic' );
298+
* var odt = dtypes( 'real_floating_point_and_generic' );
299+
*
300+
* var policies = {
301+
* 'output': 'real_floating_point_and_generic'
302+
* };
303+
* var options = {
304+
* 'order': 'row-major'
305+
* };
306+
*
307+
* var rand = new Random( exponential, idt, odt, policies, options );
308+
*
309+
* var out = ndzeros( [ 2, 2 ] );
310+
* var v = rand.assign( 2.0, out );
311+
* // returns <ndarray>
312+
*
313+
* var bool = ( v === out );
314+
* // returns true
315+
*/
316+
declare var ctor: RandomArrayConstructor;
317+
318+
319+
// EXPORTS //
320+
321+
export = ctor;

0 commit comments

Comments
 (0)