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
242 changes: 242 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlamrg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
<!--

@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.

-->

# dlamrg

> Generates a permutation list to merge the entries of two independently sorted sets into a single set sorted in ascending order.

<section class="usage">

## Usage

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

#### dlamrg( N1, N2, A, DTRD1, DTRD2, index )

Generates a permutation list to merge the entries of two independently sorted sets into a single set sorted in ascending order.

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

var A = new Float64Array( [ 1.0, 3.0, 2.0, 4.0, 5.0 ] );
var index = new Int32Array( 5 );
dlamrg( 2, 3, A, 1, 1, index );
// index => <Int32Array>[ 0, 2, 1, 3, 4 ]
```

The function has the following parameters:

- **N1**: the length of the first sorted list to be merged.
- **N2**: the length of the second sorted list to be merged.
- **A**: the array containing the first and the second sorted lists to be merged as a [`Float64Array`][mdn-float64array].
- **DTRD1**: stride for the first `N1` elements in `A`.
- **DTRD2**: stride for the last `N2` elements in `A`.
- **index**: the array containing the indices of elements of `A` such that they are in ascending order.

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 Float64Array = require( '@stdlib/array/float64' );
var Int32Array = require( '@stdlib/array/int32' );
var dlamrg = require( '@stdlib/lapack/base/dlamrg' );

var A = new Float64Array( [ 1.0, 3.0, 2.0, 4.0, 5.0 ] );

// Initial array:
var index0 = new Int32Array( 6 );

// Create an offset view...
var index1 = new Int32Array( index0.buffer, index0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

dlamrg( 2, 3, A, 1, 1, index1 );
// index0 => <Int32Array>[ 0, 0, 2, 1, 3, 4 ]
```

<!-- lint disable maximum-heading-length -->

#### dlamrg.ndarray( N1, N2, A, sA, oA, DTRD1, DTRD2, index, sIndex, oIndex )

Generates a permutation list to merge the entries of two independently sorted sets into a single set sorted in ascending order.

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

var A = new Float64Array( [ 1.0, 3.0, 2.0, 4.0, 5.0 ] );
var index = new Int32Array( 5 );
dlamrg.ndarray( 2, 3, A, 1, 0, 1, 1, index, 1, 0 );
// index => <Int32Array>[ 0, 2, 1, 3, 4 ]
```

The function has the following additional parameters:

- **sA**: stride length for `A`.
- **oA**: starting index of `A`.
- **sIndex**: stride length for `index`.
- **oIndex**: starting index of `index`.

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,

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

var A = new Float64Array( [ 999.9, 1.0, 3.0, 2.0, 4.0, 5.0 ] );
var index = new Int32Array( 6 );
dlamrg.ndarray( 2, 3, A, 1, 1, 1, 1, index, 1, 1 );
// index => <Int32Array>[ 0, 1, 3, 2, 4, 5 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- `dlamrg()` corresponds to the [LAPACK][lapack] routine [`dlamrg`][lapack-dlamrg].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

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

var A = new Float64Array( [ 1.0, 3.0, 2.0, 4.0, 5.0 ] );
var index = new Int32Array( 5 );
dlamrg( 2, 3, A, 1, 1, index );
console.log( index );
```

</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-dlamrg]: https://www.netlib.org/lapack/explore-html/dd/d91/group__lamrg_gac4d67a9ef55ca13be544488dfd5de1a7.html#gac4d67a9ef55ca13be544488dfd5de1a7

[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 -->
120 changes: 120 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlamrg/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* @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 uniform = require( '@stdlib/random/array/uniform' );
var floor = require( '@stdlib/math/base/special/floor' );
var pow = require( '@stdlib/math/base/special/pow' );
var randu = require( '@stdlib/random/base/randu' );
var Int32Array = require( '@stdlib/array/int32' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var merge = require( '@stdlib/utils/merge' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var dlamrg = require( './../lib/dlamrg.js' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var index = new Int32Array( len );
var N1 = floor( randu() * len );
var N2 = len - N1;
var A1 = uniform( N1, 0.0, 100.0, options );
var A2 = uniform( N2, 0.0, 100.0, options );
var A;

A1.sort(cmp);
A2.sort(cmp);

function cmp(a, b) {
return b - a;
}

A = merge( A1, A2 );
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
dlamrg( N1, N2, A, 1, 1, index );
if ( isnan( index[ i%index.length ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( index[ i%index.length ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

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

min = 1; // 10^min
max = 6; // 10^max

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

main();
Loading