-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add lapack/base/dlamrg
#9831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
prajjwalbajpai
wants to merge
4
commits into
stdlib-js:develop
Choose a base branch
from
prajjwalbajpai:dlamrg
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 --> |
119 changes: 119 additions & 0 deletions
119
lib/node_modules/@stdlib/lapack/base/dlamrg/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /** | ||
| * @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 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( pkg+':len='+len, f ); | ||
| } | ||
| } | ||
|
|
||
| main(); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.