Skip to content

feat: add javascript implementation for lapack/base/dlaswp #2483

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

Merged
merged 61 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
c92f72c
feat: add initial implementation for lapack/base/dlaswp
Pranavchiku Jul 1, 2024
eece712
chore: update dlaswp.js
Pranavchiku Jul 1, 2024
b35d940
chore: update dlaswp.js
Pranavchiku Jul 1, 2024
5f84f99
chore: update dlaswp.js
Pranavchiku Jul 1, 2024
711aa9b
chore: lib/index.js
Pranavchiku Jul 1, 2024
b0eec9a
chore: add dlaswp.js
Pranavchiku Jul 1, 2024
4649c54
chore: add main.js
Pranavchiku Jul 1, 2024
44075d2
chore: delete lapack/blas/dlaswp.js
Pranavchiku Jul 1, 2024
dd393d4
chore: add example
Pranavchiku Jul 1, 2024
40349ca
chore: add README.md
Pranavchiku Jul 1, 2024
e19ff82
chore: add package.json
Pranavchiku Jul 1, 2024
559824a
chore: add README.md
Pranavchiku Jul 1, 2024
9dcfa53
chore: add repl.txt
Pranavchiku Jul 1, 2024
b761225
chore: add test.ts
Pranavchiku Jul 1, 2024
d3f8069
chore: add index.d.ts
Pranavchiku Jul 1, 2024
15a6b5a
chore: add benchmark
Pranavchiku Jul 1, 2024
6326803
fix: row-major implementation
Pranavchiku Jul 1, 2024
682b172
test: add tests
Pranavchiku Jul 1, 2024
dccfcf8
chore: apply suggestion and replace incX with strideIPIV
Pranavchiku Jul 1, 2024
d88b69b
chore: apply suggestion in index.d.ts
Pranavchiku Jul 1, 2024
6514e12
chore: add all files
Pranavchiku Jul 1, 2024
486985f
chore: show sipiv instead of strideIPIV in readme and repl
Pranavchiku Jul 1, 2024
01237eb
chore: apply code review
Pranavchiku Jul 1, 2024
2a0cf83
chore: apply code review
Pranavchiku Jul 1, 2024
1cb1206
chore: apply suggestions from code review
Pranavchiku Jul 1, 2024
3a6dc5c
test: update incorrect description
Pranavchiku Jul 2, 2024
62e1af9
chore: update base.js description
Pranavchiku Jul 2, 2024
1a91314
chore: link to LAPACK doc in readme
Pranavchiku Jul 2, 2024
8610f1a
chore: update package level description
Pranavchiku Jul 2, 2024
a336167
chore: introduce offsetIPIV and consequent changes
Pranavchiku Jul 2, 2024
d2507ac
bench: update data generation
kgryte Jul 3, 2024
b436402
refactor: reorder parameters
kgryte Jul 4, 2024
6001634
test: reorder parameters
kgryte Jul 4, 2024
db68b19
chore: consequent changes of parameter reorder
Pranavchiku Jul 5, 2024
d5bcee5
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into pr…
kgryte Jul 10, 2024
c5f42cd
temp: save snapshot
kgryte Jul 11, 2024
fee1ce6
refactor: update to support matrix strides
kgryte Jul 11, 2024
f317d45
test: rename fixtures and update ndarray tests
kgryte Jul 11, 2024
ddfd2c7
fix: account for layout when passing stride arguments and update tests
kgryte Jul 11, 2024
3e53660
docs: fix parameters and resolve lint errors
kgryte Jul 11, 2024
d668fe1
docs: fix example
kgryte Jul 11, 2024
5c29c0f
docs: update example
kgryte Jul 11, 2024
81b27ac
chore: consequent changes
Pranavchiku Jul 11, 2024
4c663d3
fix: incorrect readme example
Pranavchiku Jul 11, 2024
5af48c0
bench: add facet for the number of interchanged rows
kgryte Jul 11, 2024
254f41f
bench: add facet for measuring performance for different layouts
kgryte Jul 11, 2024
8c47131
docs: update descriptions
kgryte Jul 11, 2024
0f69c03
docs: update descriptions
kgryte Jul 11, 2024
402d5c8
docs: update example
kgryte Jul 11, 2024
70dc36f
chore: update keywords
kgryte Jul 11, 2024
03eed0f
fix: ensure support for applying pivots in reverse
kgryte Jul 12, 2024
461749a
refactor: remove comments
kgryte Jul 12, 2024
9b9dbce
test: add tests for applying pivots in reverse with an IPIV stride
kgryte Jul 12, 2024
45facca
test: add tests for appying pivots in reverse with an IPIV offset
kgryte Jul 12, 2024
1ec29ed
test: add tests for positive `k1` value
kgryte Jul 12, 2024
0a99eed
docs: update copy
kgryte Jul 12, 2024
b50c740
test: add stride tests
kgryte Jul 13, 2024
be33a85
test: add error handling tests
kgryte Jul 13, 2024
6247f98
docs: add example
kgryte Jul 13, 2024
8dd21b6
docs: update copy
kgryte Jul 13, 2024
9019417
docs: fix note
kgryte Jul 13, 2024
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
252 changes: 252 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlaswp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
<!--

@license Apache-2.0

Copyright (c) 2024 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.

-->

# dsymv

> Perform a series of row interchanges on an input matrix.

<section class = "usage">

## Usage

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

#### dlaswp( N, A, LDA, k1, k2, IPIV, sipiv )

Perform a series of row interchanges on an input matrix.

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

var IPIV = new Int32Array( [ 2, 0, 1 ] );
var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );

dlaswp( 'row-major', 2, A, 2, 0, 2, IPIV, 1 );
// A => <Float64Array>[ 3.0, 4.0, 1.0, 2.0, 5.0, 6.0 ]
```

The function has the following parameters:

- **order**: storage layout.
- **N**: number of columns in `A`.
- **A**: input `Float64Array`.
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
- **k1**: index of first row to interchange.
- **k2**: index of last row to interchange.
- **IPIV**: vector of pivot indices.
- **sipiv**: index increment for `IPIV`.

The increment parameters determine how elements in the IPIV array are accessed at runtime. For example, to iterate over the elements of `IPIV` in reverse order,

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

var IPIV = new Int32Array( [ 2, 0, 0, 0, 1 ] );
var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );

dlaswp( 'row-major', 2, A, 2, 0, 2, IPIV, 2 );
// A => <Float64Array>[ 3.0, 4.0, 1.0, 2.0, 5.0, 6.0, 7.0, 8.0, 9.0 ]
```

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 IPIV0 = new Int32Array( [ 0, 2, 0, 1] );
var A0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );

// Create offset views...
var IPIV1 = new Int32Array( IPIV0.buffer, IPIV0.BYTES_PER_ELEMENT*1 ); // start at 1st element
var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 1st element

dlaswp( 'row-major', 2, A1, 2, 0, 2, IPIV1, 1 );
// A0 => <Float64Array>[ 0.0, 3.0, 4.0, 1.0, 2.0, 5.0, 6.0 ]
```

#### dlaswp.ndarray( order, N, A, sa1, sa2, oa, k1, k2, inck, IPIV, sipiv, oipiv )

Performs a series of row interchanges on the matrix `A` using pivot indices stored in `IPIV` and alternative indexing semantics.

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

var IPIV = new Int32Array( [ 2, 0, 1 ] );
var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );

dlaswp.ndarray( 'row-major', 2, A, 2, 1, 0, 0, 2, 1, IPIV, 1, 0 );
// A => <Float64Array>[ 3.0, 4.0, 1.0, 2.0, 5.0, 6.0 ]
```

The function has the following additional parameters:

- **sa1**: stride of the first dimension of `A`.
- **sa2**: stride of the second dimension of `A`.
- **oa**: starting index for `A`.
- **inck**: direction in which to apply pivots (-1 to apply pivots in reverse order; otherwise, apply in provided order).
- **oipiv**: starting index for `IPIV`.

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

var IPIV = new Int32Array( [ 2, 0, 1 ] );
var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );

dlaswp.ndarray( 'row-major', 2, A, 2, 1, 0, 0, 2, 1, IPIV, 1, 0 );
// A => <Float64Array>[ 3.0, 4.0, 1.0, 2.0, 5.0, 6.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- `dlaswp()` is a [LAPACK][lapack] routine.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

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

var IPIV = new Int32Array( [ 2, 0, 1 ] );
var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );

dlaswp( 'column-major', 2, A, 2, 0, 2, IPIV, 1 );
console.log( A );
```

</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/

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

</section>

<!-- /.links -->
105 changes: 105 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlaswp/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var pkg = require( './../package.json' ).name;
var dlaswp = require( './../lib/dlaswp.js' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} N - number of elements along each dimension
* @returns {Function} benchmark function
*/
function createBenchmark( N ) {
var IPIV;
var A;

IPIV = discreteUniform( 5, 0, N-1, {
'dtype': 'int32'
});
A = uniform( N*N, -10.0, 10.0, {
'dtype': 'float64'
});
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = dlaswp( 'column-major', N, A, N, 0, 2, IPIV, 1 );
if ( isnan( z[ i%z.length ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( z[ i%z.length ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

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

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

for ( i = min; i <= max; i++ ) {
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
f = createBenchmark( N );
bench( pkg+':order=column-major,size='+(N*N), f );
}
}

main();
Loading
Loading