Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
243 changes: 243 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlaruv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# dlaruv

> Return a vector of `n` random real numbers from a uniform (0,1) distribution.

<section class="usage">

## Usage

```javascript
var dlaruv = require( '@stdlib/lapack/base/dlaruv' );
```

#### dlaruv( N, ISEED, X )

Returns a vector of `N` random real numbers from a uniform (0,1) distribution.

```javascript
var Int32Array = require( '@stdlib/array/int32' );
var Float64Array = require( '@stdlib/array/float64' );

var ISEED = new Int32Array( [ 0, 1, 2, 3 ] );
var X = new Float64Array( 3 );

dlaruv( 3, ISEED, X );
// X => <Float64Array>
```

The function has the following parameters:

- **N**: number of random numbers to generate. Must be at most `128`.
- **ISEED**: [`Int32Array`][mdn-int32array] seed array of four integers. Each element must be between `0` and `4095`, and `ISEED[3]` must be odd. On exit, the seed is updated.
- **X**: output [`Float64Array`][mdn-float64array].

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.

<!-- eslint-disable stdlib/capitalized-comments -->

```javascript
var Int32Array = require( '@stdlib/array/int32' );
var Float64Array = require( '@stdlib/array/float64' );

// Initial arrays...
var ISEED0 = new Int32Array( [ 0, 0, 1, 2, 3 ] );
var X0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] );

// Create offset views...
var ISEED1 = new Int32Array( ISEED0.buffer, ISEED0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var X1 = new Float64Array( X0.buffer, X0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

dlaruv( 3, ISEED1, X1 );
// X0 => <Float64Array>
```

#### dlaruv.ndarray( N, ISEED, strideISEED, offsetISEED, X, strideX, offsetX )

Returns a vector of `N` random real numbers from a uniform (0,1) distribution using alternative indexing semantics.

```javascript
var Int32Array = require( '@stdlib/array/int32' );
var Float64Array = require( '@stdlib/array/float64' );

var ISEED = new Int32Array( [ 0, 1, 2, 3 ] );
var X = new Float64Array( 3 );

dlaruv.ndarray( 3, ISEED, 1, 0, X, 1, 0 );
// X => <Float64Array>
```

The function has the following additional parameters:

- **strideISEED**: stride length for `ISEED`.
- **offsetISEED**: starting index for `ISEED`.
- **strideX**: stride length for `X`.
- **offsetX**: starting index for `X`.

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,

<!-- eslint-disable max-len -->

```javascript
var Int32Array = require( '@stdlib/array/int32' );
var Float64Array = require( '@stdlib/array/float64' );

var ISEED = new Int32Array( [ 0, 0, 1, 2, 3 ] );
var X = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );

dlaruv.ndarray( 3, ISEED, 1, 1, X, 1, 2 );
// X => <Float64Array>
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- `dlaruv()` corresponds to the [LAPACK][LAPACK] function [`dlaruv`][lapack-dlaruv].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var Int32Array = require( '@stdlib/array/int32' );
var Float64Array = require( '@stdlib/array/float64' );
var dlaruv = require( '@stdlib/lapack/base/dlaruv' );

var ISEED = new Int32Array( [ 1, 23, 456, 3795 ] );
var X = new Float64Array( 10 );

dlaruv( X.length, ISEED, X );

console.log( X );
console.log( ISEED );
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
TODO
```

#### TODO

TODO.

```c
TODO
```

TODO

```c
TODO
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
TODO
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[lapack]: https://www.netlib.org/lapack/explore-html/

[lapack-dlaruv]: https://netlib.org/lapack/explore-html/d9/d0f/group__laruv.html

[mdn-int32array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array

[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

</section>

<!-- /.links -->
98 changes: 98 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlaruv/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var Int32Array = require( '@stdlib/array/int32' );
var Float64Array = require( '@stdlib/array/float64' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var min = require( '@stdlib/math/base/special/min' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var dlaruv = require( './../lib/dlaruv.js' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var ISEED = new Int32Array( [ 1619, 1381, 1011, 2459 ] );
var X = new Float64Array( len );
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
dlaruv( len, ISEED, X );
if ( isnan( X[ 0 ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( X[ 0 ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var min2;
var len;
var max;
var f;
var i;

min2 = 0; // 10^min
max = 2; // 10^max (capped at 128)

for ( i = min2; i <= max; i++ ) {
len = min( pow( 10, i ), 128 );
f = createBenchmark( len );
bench( format( '%s:len=%d', pkg, len ), f );
}
}

main();
Loading