@stdlib/random-strided-normal 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
package/NOTICE ADDED
@@ -0,0 +1 @@
1
+ Copyright (c) 2016-2023 The Stdlib Authors.
package/README.md ADDED
@@ -0,0 +1,303 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2023 The Stdlib Authors.
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ -->
20
+
21
+ # Normal Random Numbers
22
+
23
+ [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
24
+
25
+ > Fill a strided array with pseudorandom numbers drawn from a [normal][@stdlib/random/base/normal] distribution.
26
+
27
+ <section class="installation">
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ npm install @stdlib/random-strided-normal
33
+ ```
34
+
35
+ </section>
36
+
37
+ <section class="usage">
38
+
39
+ ## Usage
40
+
41
+ ```javascript
42
+ var normal = require( '@stdlib/random-strided-normal' );
43
+ ```
44
+
45
+ #### normal( N, mu, sm, sigma, ss, out, so\[, options] )
46
+
47
+ Fills a strided array with pseudorandom numbers drawn from a [normal][@stdlib/random/base/normal] distribution.
48
+
49
+ ```javascript
50
+ var Float64Array = require( '@stdlib/array-float64' );
51
+
52
+ // Create an array:
53
+ var out = new Float64Array( 10 );
54
+
55
+ // Fill the array with pseudorandom numbers:
56
+ normal( out.length, [ 2.0 ], 0, [ 5.0 ], 0, out, 1 );
57
+ ```
58
+
59
+ The function has the following parameters:
60
+
61
+ - **N**: number of indexed elements.
62
+ - **mu**: mean.
63
+ - **sm**: index increment for `mu`.
64
+ - **sigma**: standard deviation.
65
+ - **ss**: index increment for `sigma`.
66
+ - **out**: output array.
67
+ - **so**: index increment for `out`.
68
+
69
+ The `N` and stride parameters determine which strided array elements are accessed at runtime. For example, to access every other value in `out`,
70
+
71
+ ```javascript
72
+ var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
73
+
74
+ normal( 3, [ 2.0 ], 0, [ 5.0 ], 0, out, 2 );
75
+ ```
76
+
77
+ Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
78
+
79
+ <!-- eslint-disable stdlib/capitalized-comments -->
80
+
81
+ ```javascript
82
+ var Float64Array = require( '@stdlib/array-float64' );
83
+
84
+ // Initial arrays...
85
+ var mu0 = new Float64Array( [ 0.0, 0.0, 0.0, 2.0, 2.0, 2.0 ] );
86
+ var sigma0 = new Float64Array( [ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 ] );
87
+
88
+ // Create offset views...
89
+ var mu1 = new Float64Array( mu0.buffer, mu0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
90
+ var sigma1 = new Float64Array( sigma0.buffer, sigma0.BYTES_PER_ELEMENT*3 ); // start at 4th element
91
+
92
+ // Create an output array:
93
+ var out = new Float64Array( 3 );
94
+
95
+ // Fill the output array:
96
+ normal( out.length, mu1, -2, sigma1, 1, out, 1 );
97
+ ```
98
+
99
+ The function accepts the following `options`:
100
+
101
+ - **prng**: pseudorandom number generator for generating uniformly distributed pseudorandom numbers on the interval `[0,1)`. If provided, the function **ignores** both the `state` and `seed` options. In order to seed the underlying pseudorandom number generator, one must seed the provided `prng` (assuming the provided `prng` is seedable).
102
+ - **seed**: pseudorandom number generator seed.
103
+ - **state**: a [`Uint32Array`][@stdlib/array/uint32] containing pseudorandom number generator state. If provided, the function ignores the `seed` option.
104
+ - **copy**: `boolean` indicating whether to copy a provided pseudorandom number generator state. Setting this option to `false` allows sharing state between two or more pseudorandom number generators. Setting this option to `true` ensures that an underlying generator has exclusive control over its internal state. Default: `true`.
105
+
106
+ To use a custom PRNG as the underlying source of uniformly distributed pseudorandom numbers, set the `prng` option.
107
+
108
+ ```javascript
109
+ var Float64Array = require( '@stdlib/array-float64' );
110
+ var minstd = require( '@stdlib/random-base-minstd' );
111
+
112
+ var opts = {
113
+ 'prng': minstd.normalized
114
+ };
115
+
116
+ var out = new Float64Array( 10 );
117
+ normal( out.length, [ 2.0 ], 0, [ 5.0 ], 0, out, 1, opts );
118
+ ```
119
+
120
+ To seed the underlying pseudorandom number generator, set the `seed` option.
121
+
122
+ ```javascript
123
+ var Float64Array = require( '@stdlib/array-float64' );
124
+
125
+ var opts = {
126
+ 'seed': 12345
127
+ };
128
+
129
+ var out = new Float64Array( 10 );
130
+ normal( out.length, [ 2.0 ], 0, [ 5.0 ], 0, out, 1, opts );
131
+ ```
132
+
133
+ #### normal.ndarray( N, mu, sm, om, sigma, ss, os, out, so, oo\[, options] )
134
+
135
+ Fills a strided array with pseudorandom numbers drawn from a [normal][@stdlib/random/base/normal] distribution using alternative indexing semantics.
136
+
137
+ ```javascript
138
+ var Float64Array = require( '@stdlib/array-float64' );
139
+
140
+ // Create an array:
141
+ var out = new Float64Array( 10 );
142
+
143
+ // Fill the array with pseudorandom numbers:
144
+ normal.ndarray( out.length, [ 2.0 ], 0, 0, [ 5.0 ], 0, 0, out, 1, 0 );
145
+ ```
146
+
147
+ The function has the following additional parameters:
148
+
149
+ - **om**: starting index for `mu`.
150
+ - **os**: starting index for `sigma`.
151
+ - **oo**: starting index for `out`.
152
+
153
+ While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameters support indexing semantics based on starting indices. For example, to access every other value in `out` starting from the second value,
154
+
155
+ ```javascript
156
+ var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
157
+
158
+ normal.ndarray( 3, [ 2.0 ], 0, 0, [ 5.0 ], 0, 0, out, 2, 1 );
159
+ ```
160
+
161
+ The function accepts the same `options` as documented above for `normal()`.
162
+
163
+ </section>
164
+
165
+ <!-- /.usage -->
166
+
167
+ <section class="notes">
168
+
169
+ ## Notes
170
+
171
+ - If `N <= 0`, both functions leave the output array unchanged.
172
+ - Both functions support array-like objects having getter and setter accessors for array element access.
173
+
174
+ </section>
175
+
176
+ <!-- /.notes -->
177
+
178
+ <section class="examples">
179
+
180
+ ## Examples
181
+
182
+ <!-- eslint no-undef: "error" -->
183
+
184
+ ```javascript
185
+ var zeros = require( '@stdlib/array-zeros' );
186
+ var zeroTo = require( '@stdlib/array-base-zero-to' );
187
+ var logEach = require( '@stdlib/console-log-each' );
188
+ var normal = require( '@stdlib/random-strided-normal' );
189
+
190
+ // Specify a PRNG seed:
191
+ var opts = {
192
+ 'seed': 1234
193
+ };
194
+
195
+ // Create an array:
196
+ var x1 = zeros( 10, 'float64' );
197
+
198
+ // Create a list of indices:
199
+ var idx = zeroTo( x1.length );
200
+
201
+ // Fill the array with pseudorandom numbers:
202
+ normal( x1.length, [ 2.0 ], 0, [ 5.0 ], 0, x1, 1, opts );
203
+
204
+ // Create a second array:
205
+ var x2 = zeros( 10, 'generic' );
206
+
207
+ // Fill the array with the same pseudorandom numbers:
208
+ normal( x2.length, [ 2.0 ], 0, [ 5.0 ], 0, x2, 1, opts );
209
+
210
+ // Print the array contents:
211
+ logEach( 'x1[%d] = %.2f; x2[%d] = %.2f', idx, x1, idx, x2 );
212
+ ```
213
+
214
+ </section>
215
+
216
+ <!-- /.examples -->
217
+
218
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
219
+
220
+ <section class="related">
221
+
222
+ </section>
223
+
224
+ <!-- /.related -->
225
+
226
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
227
+
228
+
229
+ <section class="main-repo" >
230
+
231
+ * * *
232
+
233
+ ## Notice
234
+
235
+ This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
236
+
237
+ For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
238
+
239
+ #### Community
240
+
241
+ [![Chat][chat-image]][chat-url]
242
+
243
+ ---
244
+
245
+ ## License
246
+
247
+ See [LICENSE][stdlib-license].
248
+
249
+
250
+ ## Copyright
251
+
252
+ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
253
+
254
+ </section>
255
+
256
+ <!-- /.stdlib -->
257
+
258
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
259
+
260
+ <section class="links">
261
+
262
+ [npm-image]: http://img.shields.io/npm/v/@stdlib/random-strided-normal.svg
263
+ [npm-url]: https://npmjs.org/package/@stdlib/random-strided-normal
264
+
265
+ [test-image]: https://github.com/stdlib-js/random-strided-normal/actions/workflows/test.yml/badge.svg?branch=v0.0.1
266
+ [test-url]: https://github.com/stdlib-js/random-strided-normal/actions/workflows/test.yml?query=branch:v0.0.1
267
+
268
+ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/random-strided-normal/main.svg
269
+ [coverage-url]: https://codecov.io/github/stdlib-js/random-strided-normal?branch=main
270
+
271
+ <!--
272
+
273
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/random-strided-normal.svg
274
+ [dependencies-url]: https://david-dm.org/stdlib-js/random-strided-normal/main
275
+
276
+ -->
277
+
278
+ [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
279
+ [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
280
+
281
+ [stdlib]: https://github.com/stdlib-js/stdlib
282
+
283
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
284
+
285
+ [umd]: https://github.com/umdjs/umd
286
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
287
+
288
+ [deno-url]: https://github.com/stdlib-js/random-strided-normal/tree/deno
289
+ [umd-url]: https://github.com/stdlib-js/random-strided-normal/tree/umd
290
+ [esm-url]: https://github.com/stdlib-js/random-strided-normal/tree/esm
291
+ [branches-url]: https://github.com/stdlib-js/random-strided-normal/blob/main/branches.md
292
+
293
+ [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-strided-normal/main/LICENSE
294
+
295
+ [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
296
+
297
+ [@stdlib/random/base/normal]: https://www.npmjs.com/package/@stdlib/random-base-normal
298
+
299
+ [@stdlib/array/uint32]: https://www.npmjs.com/package/@stdlib/array-uint32
300
+
301
+ </section>
302
+
303
+ <!-- /.links -->
@@ -0,0 +1,152 @@
1
+ /*
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 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 * as random from '@stdlib/types/random';
24
+ import { Collection } from '@stdlib/types/object';
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
+ /**
52
+ * Interface describing `normal`.
53
+ */
54
+ interface Routine {
55
+ /**
56
+ * Fills a strided array with pseudorandom numbers drawn from a normal distribution.
57
+ *
58
+ * @param N - number of indexed elements
59
+ * @param mu - mean
60
+ * @param sm - `mu` stride length
61
+ * @param sigma - standard deviation
62
+ * @param ss - `sigma` stride length
63
+ * @param out - output array
64
+ * @param so - `out` stride length
65
+ * @param options - function options
66
+ * @throws must provide valid distribution parameters
67
+ * @throws must provide valid options
68
+ * @throws must provide a valid state
69
+ * @returns output array
70
+ *
71
+ * @example
72
+ * var Float64Array = require( `@stdlib/array/float64` );
73
+ *
74
+ * // Create an array:
75
+ * var out = new Float64Array( 10 );
76
+ *
77
+ * // Fill the array with pseudorandom numbers:
78
+ * normal( out.length, [ 2.0 ], 0, [ 5.0 ], 0, out, 1 );
79
+ */
80
+ <T = any>( N: number, mu: Collection, sm: number, sigma: Collection, ss: number, out: Collection<T>, so: number, options?: Options ): Collection<T>;
81
+
82
+ /**
83
+ * Fills a strided array with pseudorandom numbers drawn from a normal distribution using alternative indexing semantics.
84
+ *
85
+ * @param N - number of indexed elements
86
+ * @param mu - mean
87
+ * @param sm - `mu` stride length
88
+ * @param om - starting index for `mu`
89
+ * @param sigma - standard deviation
90
+ * @param ss - `sigma` stride length
91
+ * @param os - starting index for `sigma`
92
+ * @param out - output array
93
+ * @param so - `out` stride length
94
+ * @param oo - starting index for `out`
95
+ * @param options - function options
96
+ * @throws must provide valid distribution parameters
97
+ * @throws must provide valid options
98
+ * @throws must provide a valid state
99
+ * @returns output array
100
+ *
101
+ * @example
102
+ * var Float64Array = require( `@stdlib/array/float64` );
103
+ *
104
+ * // Create an array:
105
+ * var out = new Float64Array( 10 );
106
+ *
107
+ * // Fill the array with pseudorandom numbers:
108
+ * normal.ndarray( out.length, [ 2.0 ], 0, 0, [ 5.0 ], 0, 0, out, 1, 0 );
109
+ */
110
+ ndarray<T = any>( N: number, mu: Collection, sm: number, om: number, sigma: Collection, ss: number, os: number, out: Collection<T>, so: number, oo: number, options?: Options ): Collection<T>;
111
+ }
112
+
113
+ /**
114
+ * Fills a strided array with pseudorandom numbers drawn from a normal distribution.
115
+ *
116
+ * @param N - number of indexed elements
117
+ * @param mu - mean
118
+ * @param sm - `mu` stride length
119
+ * @param sigma - standard deviation
120
+ * @param ss - `sigma` stride length
121
+ * @param out - output array
122
+ * @param so - `out` stride length
123
+ * @param options - function options
124
+ * @throws must provide valid distribution parameters
125
+ * @throws must provide valid options
126
+ * @throws must provide a valid state
127
+ * @returns output array
128
+ *
129
+ * @example
130
+ * var Float64Array = require( `@stdlib/array/float64` );
131
+ *
132
+ * // Create an array:
133
+ * var out = new Float64Array( 10 );
134
+ *
135
+ * // Fill the array with pseudorandom numbers:
136
+ * normal( out.length, [ 2.0 ], 0, [ 5.0 ], 0, out, 1 );
137
+ *
138
+ * @example
139
+ * var Float64Array = require( `@stdlib/array/float64` );
140
+ *
141
+ * // Create an array:
142
+ * var out = new Float64Array( 10 );
143
+ *
144
+ * // Fill the array with pseudorandom numbers:
145
+ * normal.ndarray( out.length, [ 2.0 ], 0, 0, [ 5.0 ], 0, 0, out, 1, 0 );
146
+ */
147
+ declare var normal: Routine;
148
+
149
+
150
+ // EXPORTS //
151
+
152
+ export = normal;
package/lib/index.js ADDED
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 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
+ 'use strict';
20
+
21
+ /**
22
+ * Fill a strided array with pseudorandom numbers drawn from a normal distribution.
23
+ *
24
+ * @module @stdlib/random-strided-normal
25
+ *
26
+ * @example
27
+ * var Float64Array = require( '@stdlib/array-float64' );
28
+ * var normal = require( '@stdlib/random-strided-normal' );
29
+ *
30
+ * // Create an array:
31
+ * var out = new Float64Array( 10 );
32
+ *
33
+ * // Fill the array with pseudorandom numbers:
34
+ * normal( out.length, [ 2.0 ], 0, [ 5.0 ], 0, out, 1 );
35
+ *
36
+ * @example
37
+ * var Float64Array = require( '@stdlib/array-float64' );
38
+ * var normal = require( '@stdlib/random-strided-normal' );
39
+ *
40
+ * // Create an array:
41
+ * var out = new Float64Array( 10 );
42
+ *
43
+ * // Fill the array with pseudorandom numbers:
44
+ * normal.ndarray( out.length, [ 2.0 ], 0, 0, [ 5.0 ], 0, 0, out, 1, 0 );
45
+ */
46
+
47
+ // MODULES //
48
+
49
+ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
50
+ var main = require( './main.js' );
51
+ var ndarray = require( './ndarray.js' );
52
+
53
+
54
+ // MAIN //
55
+
56
+ setReadOnly( main, 'ndarray', ndarray );
57
+
58
+
59
+ // EXPORTS //
60
+
61
+ module.exports = main;
62
+
63
+ // exports: { "ndarray": "main.ndarray" }
package/lib/main.js ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var nullary = require( '@stdlib/strided-base-nullary' );
24
+ var binary = require( '@stdlib/strided-base-binary' );
25
+ var prng = require( './prng.js' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ /**
31
+ * Fills a strided array with pseudorandom numbers drawn from a normal distribution.
32
+ *
33
+ * @param {NonNegativeInteger} N - number of indexed elements
34
+ * @param {Collection} mu - mean
35
+ * @param {integer} sm - `mu` stride length
36
+ * @param {Collection} sigma - standard deviation
37
+ * @param {integer} ss - `sigma` stride length
38
+ * @param {Collection} out - output array
39
+ * @param {integer} so - `out` stride length
40
+ * @param {Options} [options] - function options
41
+ * @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers
42
+ * @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed
43
+ * @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state
44
+ * @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state
45
+ * @throws {Error} must provide valid distribution parameters
46
+ * @throws {Error} must provide valid options
47
+ * @throws {Error} must provide a valid state
48
+ * @returns {Collection} output array
49
+ *
50
+ * @example
51
+ * var Float64Array = require( '@stdlib/array-float64' );
52
+ *
53
+ * // Create an array:
54
+ * var out = new Float64Array( 10 );
55
+ *
56
+ * // Fill the array with pseudorandom numbers:
57
+ * normal( out.length, [ 2.0 ], 0, [ 5.0 ], 0, out, 1 );
58
+ */
59
+ function normal( N, mu, sm, sigma, ss, out, so, options ) {
60
+ var rand = prng( mu, sm, 0, sigma, ss, 0, arguments.length > 7, options );
61
+ if ( rand.arity === 0 ) {
62
+ nullary( [ out ], [ N ], [ so ], rand.fcn );
63
+ return out;
64
+ }
65
+ binary( [ mu, sigma, out ], [ N ], [ sm, ss, so ], rand.fcn );
66
+ return out;
67
+ }
68
+
69
+
70
+ // EXPORTS //
71
+
72
+ module.exports = normal;
package/lib/ndarray.js ADDED
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var nullary = require( '@stdlib/strided-base-nullary' ).ndarray;
24
+ var binary = require( '@stdlib/strided-base-binary' ).ndarray;
25
+ var prng = require( './prng.js' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ /**
31
+ * Fills a strided array with pseudorandom numbers drawn from a normal distribution.
32
+ *
33
+ * @param {NonNegativeInteger} N - number of indexed elements
34
+ * @param {Collection} mu - mean
35
+ * @param {integer} sm - `mu` stride length
36
+ * @param {NonNegativeInteger} om - starting `mu` index
37
+ * @param {Collection} sigma - standard deviation
38
+ * @param {integer} ss - `sigma` stride length
39
+ * @param {NonNegativeInteger} os - starting `sigma` index
40
+ * @param {Collection} out - output array
41
+ * @param {integer} so - `out` stride length
42
+ * @param {NonNegativeInteger} oo - starting `out` index
43
+ * @param {Options} [options] - function options
44
+ * @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers
45
+ * @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed
46
+ * @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state
47
+ * @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state
48
+ * @throws {Error} must provide valid distribution parameters
49
+ * @throws {Error} must provide valid options
50
+ * @throws {Error} must provide a valid state
51
+ * @returns {Collection} output array
52
+ *
53
+ * @example
54
+ * var Float64Array = require( '@stdlib/array-float64' );
55
+ *
56
+ * // Create an array:
57
+ * var out = new Float64Array( 10 );
58
+ *
59
+ * // Fill the array with pseudorandom numbers:
60
+ * normal( out.length, [ 2.0 ], 0, 0, [ 5.0 ], 0, 0, out, 1, 0 );
61
+ */
62
+ function normal( N, mu, sm, om, sigma, ss, os, out, so, oo, options ) { // eslint-disable-line max-params
63
+ var rand = prng( mu, sm, om, sigma, ss, os, arguments.length > 10, options ); // eslint-disable-line max-len
64
+ if ( rand.arity === 0 ) {
65
+ nullary( [ out ], [ N ], [ so ], [ oo ], rand.fcn );
66
+ return out;
67
+ }
68
+ binary( [ mu, sigma, out ], [ N ], [ sm, ss, so ], [ om, os, oo ], rand.fcn ); // eslint-disable-line max-len
69
+ return out;
70
+ }
71
+
72
+
73
+ // EXPORTS //
74
+
75
+ module.exports = normal;
package/lib/prng.js ADDED
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );
24
+ var random = require( '@stdlib/random-base-normal' );
25
+
26
+
27
+ // MAIN //
28
+
29
+ /**
30
+ * Returns a function for generating pseudorandom numbers.
31
+ *
32
+ * ## Notes
33
+ *
34
+ * - The returned object has the following properties:
35
+ *
36
+ * - **arity**: number of function parameters.
37
+ * - **fcn**: function for generating pseudorandom numbers.
38
+ *
39
+ * @private
40
+ * @param {Collection} x - first parameter
41
+ * @param {integer} sx - `x` stride length
42
+ * @param {NonNegativeInteger} ox - starting `x` index
43
+ * @param {Collection} y - second parameter
44
+ * @param {integer} sy - `y` stride length
45
+ * @param {NonNegativeInteger} oy - starting `y` index
46
+ * @param {boolean} hasOptions - boolean indicating whether to process an options argument
47
+ * @param {(void|Options)} options - function options
48
+ * @returns {Object} function object
49
+ */
50
+ function clbk( x, sx, ox, y, sy, oy, hasOptions, options ) {
51
+ var out;
52
+ var v1;
53
+ var v2;
54
+
55
+ out = {
56
+ 'arity': 0,
57
+ 'fcn': null
58
+ };
59
+ if ( hasOptions ) {
60
+ if ( sx === 0 && sy === 0 ) {
61
+ if ( isAccessorArray( x ) ) {
62
+ v1 = x.get( ox );
63
+ } else {
64
+ v1 = x[ ox ];
65
+ }
66
+ if ( isAccessorArray( y ) ) {
67
+ v2 = y.get( oy );
68
+ } else {
69
+ v2 = y[ oy ];
70
+ }
71
+ out.fcn = random.factory( v1, v2, options );
72
+ return out;
73
+ }
74
+ out.fcn = random.factory( options );
75
+ } else {
76
+ out.fcn = random;
77
+ }
78
+ out.arity += 2;
79
+ return out;
80
+ }
81
+
82
+
83
+ // EXPORTS //
84
+
85
+ module.exports = clbk;
package/package.json ADDED
@@ -0,0 +1,107 @@
1
+ {
2
+ "name": "@stdlib/random-strided-normal",
3
+ "version": "0.0.1",
4
+ "description": "Fill a strided array with pseudorandom numbers drawn from a normal distribution.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "directories": {
18
+ "benchmark": "./benchmark",
19
+ "doc": "./docs",
20
+ "example": "./examples",
21
+ "lib": "./lib",
22
+ "test": "./test"
23
+ },
24
+ "types": "./docs/types",
25
+ "scripts": {
26
+ "test": "make test",
27
+ "test-cov": "make test-cov",
28
+ "examples": "make examples",
29
+ "benchmark": "make benchmark"
30
+ },
31
+ "homepage": "https://stdlib.io",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git://github.com/stdlib-js/random-strided-normal.git"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/stdlib-js/stdlib/issues"
38
+ },
39
+ "dependencies": {
40
+ "@stdlib/array-base-assert-is-accessor-array": "^0.0.1",
41
+ "@stdlib/random-base-normal": "^0.0.6",
42
+ "@stdlib/strided-base-binary": "^0.0.8",
43
+ "@stdlib/strided-base-nullary": "^0.0.7",
44
+ "@stdlib/types": "^0.0.14",
45
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7"
46
+ },
47
+ "devDependencies": {
48
+ "@stdlib/array-base-linspace": "^0.0.3",
49
+ "@stdlib/array-base-to-accessor-array": "^0.0.1",
50
+ "@stdlib/array-base-zero-to": "^0.0.6",
51
+ "@stdlib/array-filled": "^0.0.6",
52
+ "@stdlib/array-filled-by": "^0.0.2",
53
+ "@stdlib/array-float64": "^0.0.6",
54
+ "@stdlib/array-zeros": "^0.0.1",
55
+ "@stdlib/bench": "^0.0.12",
56
+ "@stdlib/console-log-each": "^0.0.2",
57
+ "@stdlib/math-base-assert-is-nan": "^0.0.8",
58
+ "@stdlib/math-base-assert-is-nanf": "^0.0.8",
59
+ "@stdlib/math-base-special-pow": "^0.0.7",
60
+ "@stdlib/random-base-uniform": "^0.0.6",
61
+ "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
62
+ "istanbul": "^0.4.1",
63
+ "tap-min": "git+https://github.com/Planeshifter/tap-min.git"
64
+ },
65
+ "engines": {
66
+ "node": ">=0.10.0",
67
+ "npm": ">2.7.0"
68
+ },
69
+ "os": [
70
+ "aix",
71
+ "darwin",
72
+ "freebsd",
73
+ "linux",
74
+ "macos",
75
+ "openbsd",
76
+ "sunos",
77
+ "win32",
78
+ "windows"
79
+ ],
80
+ "keywords": [
81
+ "stdlib",
82
+ "stdmath",
83
+ "mathematics",
84
+ "math",
85
+ "statistics",
86
+ "stats",
87
+ "prng",
88
+ "rng",
89
+ "pseudorandom",
90
+ "random",
91
+ "rand",
92
+ "normal",
93
+ "gaussian",
94
+ "continuous",
95
+ "generator",
96
+ "seed",
97
+ "seedable",
98
+ "strided",
99
+ "array",
100
+ "vector",
101
+ "ndarray"
102
+ ],
103
+ "funding": {
104
+ "type": "opencollective",
105
+ "url": "https://opencollective.com/stdlib"
106
+ }
107
+ }