Skip to content

Commit 8724153

Browse files
committed
Auto-generated commit
1 parent 1e7317f commit 8724153

32 files changed

+752
-645
lines changed

Diff for: .github/.keepalive

-1
This file was deleted.

Diff for: NOTICE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Copyright (c) 2016-2023 The Stdlib Authors.
1+
Copyright (c) 2016-2024 The Stdlib Authors.

Diff for: README.md

+32-28
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ limitations under the License.
3333

3434
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
3535

36-
> Create an array containing pseudorandom numbers drawn from a [discrete uniform][@stdlib/random/base/discete-uniform] distribution.
36+
> Create an array containing pseudorandom numbers drawn from a [discrete uniform][@stdlib/random/base/discrete-uniform] distribution.
3737
3838
<section class="installation">
3939

@@ -63,7 +63,7 @@ var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
6363

6464
#### discreteUniform( len, a, b\[, options] )
6565

66-
Returns an array containing pseudorandom numbers drawn from a [discrete uniform][@stdlib/random/base/discete-uniform] distribution.
66+
Returns an array containing pseudorandom numbers drawn from a [discrete uniform][@stdlib/random/base/discrete-uniform] distribution.
6767

6868
```javascript
6969
var out = discreteUniform( 10, -10, 10 );
@@ -92,9 +92,32 @@ var out = discreteUniform( 10, -10, 10, opts );
9292
// returns [...]
9393
```
9494

95+
#### discreteUniform.assign( a, b, out )
96+
97+
Fills an array with pseudorandom numbers drawn from a [discrete uniform][@stdlib/random/base/discrete-uniform] distribution.
98+
99+
```javascript
100+
var zeros = require( '@stdlib/array-zeros' );
101+
102+
var x = zeros( 10, 'float64' );
103+
// returns <Float64Array>
104+
105+
var out = discreteUniform.assign( -10, 10, x );
106+
// returns <Float64Array>
107+
108+
var bool = ( out === x );
109+
// returns true
110+
```
111+
112+
The function has the following parameters:
113+
114+
- **a**: minimum support.
115+
- **b**: maximum support.
116+
- **out**: output array.
117+
95118
#### discreteUniform.factory( \[a, b, ]\[options] )
96119

97-
Returns a function for creating arrays containing pseudorandom numbers drawn from a [discrete uniform][@stdlib/random/base/discete-uniform] distribution.
120+
Returns a function for creating arrays containing pseudorandom numbers drawn from a [discrete uniform][@stdlib/random/base/discrete-uniform] distribution.
98121

99122
```javascript
100123
var random = discreteUniform.factory();
@@ -106,7 +129,7 @@ var len = out.length;
106129
// returns 10
107130
```
108131

109-
If provided `a` and `b`, the returned generator returns random variates from the specified distribution.
132+
If provided distribution parameters, the returned generator returns random variates from the specified distribution.
110133

111134
```javascript
112135
var random = discreteUniform.factory( -10, 10 );
@@ -118,7 +141,7 @@ out = random( 10 );
118141
// returns <Float64Array>
119142
```
120143

121-
If not provided `a` and `b`, the returned generator requires that both parameters be provided at each invocation.
144+
If not provided distribution parameters, the returned generator requires that distribution parameters be provided at each invocation.
122145

123146
```javascript
124147
var random = discreteUniform.factory();
@@ -132,8 +155,7 @@ out = random( 10, -10, 10 );
132155

133156
The function accepts the following `options`:
134157

135-
- **prng**: pseudorandom number generator for generating uniformly distributed pseudorandom numbers. 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).
136-
- **seed**: pseudorandom number generator seed.
158+
- **prng**: pseudorandom number generator for generating uniformly distributed pseudorandom integers. If provided, the function **ignores** both the `state` and `seed` options. In order to seed the returned pseudorandom number generator, one must seed the provided `prng` (assuming the provided `prng` is seedable). The provided PRNG **must** have `MIN` and `MAX` properties specifying the minimum and maximum possible pseudorandom integers.
137159
- **state**: a [`Uint32Array`][@stdlib/array/uint32] containing pseudorandom number generator state. If provided, the function ignores the `seed` option.
138160
- **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`.
139161
- **dtype**: default output array data type. Must be a [real-valued data type][@stdlib/array/typed-real-dtypes] or "generic". Default: `'float64'`.
@@ -339,7 +361,7 @@ var x2 = random( 5 );
339361
var x3 = random( 5 );
340362

341363
// Print the contents:
342-
logEach( '%d, %d, %d', x1, x2, x3 );
364+
logEach( '%f, %f, %f', x1, x2, x3 );
343365

344366
// Create another function for generating random arrays with the original state:
345367
random = discreteUniform.factory( -10, 10, {
@@ -351,7 +373,7 @@ random = discreteUniform.factory( -10, 10, {
351373
var x4 = random( 15 );
352374

353375
// Print the contents:
354-
logEach( '%d', x4 );
376+
logEach( '%f', x4 );
355377
```
356378

357379
</section>
@@ -362,14 +384,6 @@ logEach( '%d', x4 );
362384

363385
<section class="related">
364386

365-
* * *
366-
367-
## See Also
368-
369-
- <span class="package-name">[`@stdlib/random-array/uniform`][@stdlib/random/array/uniform]</span><span class="delimiter">: </span><span class="description">create an array containing pseudorandom numbers drawn from a continuous uniform distribution.</span>
370-
- <span class="package-name">[`@stdlib/random-base/discrete-uniform`][@stdlib/random/base/discrete-uniform]</span><span class="delimiter">: </span><span class="description">discrete uniform distributed pseudorandom numbers.</span>
371-
- <span class="package-name">[`@stdlib/random-strided/discrete-uniform`][@stdlib/random/strided/discrete-uniform]</span><span class="delimiter">: </span><span class="description">fill a strided array with pseudorandom numbers drawn from a discrete uniform distribution.</span>
372-
373387
</section>
374388

375389
<!-- /.related -->
@@ -443,24 +457,14 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
443457

444458
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-array-discrete-uniform/main/LICENSE
445459

446-
[@stdlib/random/base/discete-uniform]: https://github.com/stdlib-js/random-base-discete-uniform
460+
[@stdlib/random/base/discrete-uniform]: https://github.com/stdlib-js/random-base-discrete-uniform
447461

448462
[@stdlib/array/typed-real-dtypes]: https://github.com/stdlib-js/array-typed-real-dtypes
449463

450464
[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32
451465

452466
[@stdlib/array/float64]: https://github.com/stdlib-js/array-float64
453467

454-
<!-- <related-links> -->
455-
456-
[@stdlib/random/array/uniform]: https://github.com/stdlib-js/random-array-uniform
457-
458-
[@stdlib/random/base/discrete-uniform]: https://github.com/stdlib-js/random-base-discrete-uniform
459-
460-
[@stdlib/random/strided/discrete-uniform]: https://github.com/stdlib-js/random-strided-discrete-uniform
461-
462-
<!-- </related-links> -->
463-
464468
</section>
465469

466470
<!-- /.links -->

Diff for: benchmark/benchmark.float32.assign.js

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 bench = require( '@stdlib/bench-harness' );
24+
var isnanf = require( '@stdlib/math-base-assert-is-nanf' );
25+
var pow = require( '@stdlib/math-base-special-pow' );
26+
var zeros = require( '@stdlib/array-zeros' );
27+
var pkg = require( './../package.json' ).name;
28+
var random = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Creates a benchmark function.
35+
*
36+
* @private
37+
* @param {PositiveInteger} len - array length
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( len ) {
41+
return benchmark;
42+
43+
/**
44+
* Benchmark function.
45+
*
46+
* @private
47+
* @param {Benchmark} b - benchmark instance
48+
*/
49+
function benchmark( b ) {
50+
var out;
51+
var o;
52+
var i;
53+
54+
out = zeros( len, 'float32' );
55+
56+
b.tic();
57+
for ( i = 0; i < b.iterations; i++ ) {
58+
o = random.assign( -10, 10, out );
59+
if ( isnanf( o[ i%len ] ) ) {
60+
b.fail( 'should not return NaN' );
61+
}
62+
}
63+
b.toc();
64+
if ( isnanf( o[ i%len ] ) ) {
65+
b.fail( 'should not return NaN' );
66+
}
67+
b.pass( 'benchmark finished' );
68+
b.end();
69+
}
70+
}
71+
72+
73+
// MAIN //
74+
75+
/**
76+
* Main execution sequence.
77+
*
78+
* @private
79+
*/
80+
function main() {
81+
var len;
82+
var min;
83+
var max;
84+
var f;
85+
var i;
86+
87+
min = 1; // 10^min
88+
max = 6; // 10^max
89+
90+
for ( i = min; i <= max; i++ ) {
91+
len = pow( 10, i );
92+
f = createBenchmark( len );
93+
bench( pkg+':assign:dtype=float32,len='+len, f );
94+
}
95+
}
96+
97+
main();

Diff for: benchmark/benchmark.float32.factory.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var bench = require( '@stdlib/bench-harness' );
2424
var isnanf = require( '@stdlib/math-base-assert-is-nanf' );
2525
var pow = require( '@stdlib/math-base-special-pow' );
2626
var pkg = require( './../package.json' ).name;
27-
var discreteUniform = require( './../lib' );
27+
var random = require( './../lib' );
2828

2929

3030
// FUNCTIONS //
@@ -37,7 +37,7 @@ var discreteUniform = require( './../lib' );
3737
* @returns {Function} benchmark function
3838
*/
3939
function createBenchmark( len ) {
40-
var fcn = discreteUniform.factory( -10, 10, {
40+
var fcn = random.factory( -10, 10, {
4141
'dtype': 'float32'
4242
});
4343
return benchmark;

Diff for: benchmark/benchmark.float32.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var bench = require( '@stdlib/bench-harness' );
2424
var isnanf = require( '@stdlib/math-base-assert-is-nanf' );
2525
var pow = require( '@stdlib/math-base-special-pow' );
2626
var pkg = require( './../package.json' ).name;
27-
var discreteUniform = require( './../lib' );
27+
var random = require( './../lib' );
2828

2929

3030
// FUNCTIONS //
@@ -56,7 +56,7 @@ function createBenchmark( len ) {
5656

5757
b.tic();
5858
for ( i = 0; i < b.iterations; i++ ) {
59-
o = discreteUniform( len, -10, 10, opts );
59+
o = random( len, -10, 10, opts );
6060
if ( isnanf( o[ i%len ] ) ) {
6161
b.fail( 'should not return NaN' );
6262
}

Diff for: benchmark/benchmark.float64.assign.js

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 bench = require( '@stdlib/bench-harness' );
24+
var isnan = require( '@stdlib/math-base-assert-is-nan' );
25+
var pow = require( '@stdlib/math-base-special-pow' );
26+
var zeros = require( '@stdlib/array-zeros' );
27+
var pkg = require( './../package.json' ).name;
28+
var random = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Creates a benchmark function.
35+
*
36+
* @private
37+
* @param {PositiveInteger} len - array length
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( len ) {
41+
return benchmark;
42+
43+
/**
44+
* Benchmark function.
45+
*
46+
* @private
47+
* @param {Benchmark} b - benchmark instance
48+
*/
49+
function benchmark( b ) {
50+
var out;
51+
var o;
52+
var i;
53+
54+
out = zeros( len, 'float64' );
55+
56+
b.tic();
57+
for ( i = 0; i < b.iterations; i++ ) {
58+
o = random.assign( -10, 10, out );
59+
if ( isnan( o[ i%len ] ) ) {
60+
b.fail( 'should not return NaN' );
61+
}
62+
}
63+
b.toc();
64+
if ( isnan( o[ i%len ] ) ) {
65+
b.fail( 'should not return NaN' );
66+
}
67+
b.pass( 'benchmark finished' );
68+
b.end();
69+
}
70+
}
71+
72+
73+
// MAIN //
74+
75+
/**
76+
* Main execution sequence.
77+
*
78+
* @private
79+
*/
80+
function main() {
81+
var len;
82+
var min;
83+
var max;
84+
var f;
85+
var i;
86+
87+
min = 1; // 10^min
88+
max = 6; // 10^max
89+
90+
for ( i = min; i <= max; i++ ) {
91+
len = pow( 10, i );
92+
f = createBenchmark( len );
93+
bench( pkg+':assign:dtype=float64,len='+len, f );
94+
}
95+
}
96+
97+
main();

Diff for: benchmark/benchmark.float64.factory.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var bench = require( '@stdlib/bench-harness' );
2424
var isnan = require( '@stdlib/math-base-assert-is-nan' );
2525
var pow = require( '@stdlib/math-base-special-pow' );
2626
var pkg = require( './../package.json' ).name;
27-
var discreteUniform = require( './../lib' );
27+
var random = require( './../lib' );
2828

2929

3030
// FUNCTIONS //
@@ -37,7 +37,7 @@ var discreteUniform = require( './../lib' );
3737
* @returns {Function} benchmark function
3838
*/
3939
function createBenchmark( len ) {
40-
var fcn = discreteUniform.factory( -10, 10, {
40+
var fcn = random.factory( -10, 10, {
4141
'dtype': 'float64'
4242
});
4343
return benchmark;

0 commit comments

Comments
 (0)