Skip to content
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

feat: add lapack/base/dlacpy #2548

Merged
merged 45 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a11cb20
feat: init lapack/base/dlacpy
Pranavchiku Jul 10, 2024
635c0b8
chore: add benchmark
Pranavchiku Jul 10, 2024
5b8baf6
chore: add repl.txt
Pranavchiku Jul 10, 2024
dd76286
chore: add docs/types
Pranavchiku Jul 10, 2024
710074a
test: add and register
Pranavchiku Jul 10, 2024
47995dd
chore: remove visible lint errors
Pranavchiku Jul 10, 2024
65a9337
chore: remove lint errors
Pranavchiku Jul 10, 2024
76513d0
fix: incorrect example in index.d.ts
Pranavchiku Jul 10, 2024
3f3d27e
fix: incorrect ndarray example in index.d.ts
Pranavchiku Jul 10, 2024
1d9cdc4
fix: docs/types/test.ts
Pranavchiku Jul 11, 2024
c44e30b
chore: apply code review
Pranavchiku Jul 11, 2024
6181336
refactor: base implementation
Pranavchiku Jul 15, 2024
02089d8
refactor: lapack/base/dlacpy/lib
Pranavchiku Jul 15, 2024
610fac4
chore: minor change in lib/base.js
Pranavchiku Jul 15, 2024
f0a7502
test: refactor tests
Pranavchiku Jul 15, 2024
31bbc14
refactor: lapack/base/dlacpy/readme
Pranavchiku Jul 15, 2024
2584a0e
refactor: docs/repl.txt
Pranavchiku Jul 15, 2024
93b3f3d
docs: update docs/types
Pranavchiku Jul 15, 2024
0975cd1
bench: update benchmarks
Pranavchiku Jul 15, 2024
6dfc2e3
chore: apply review on lib/base.js
Pranavchiku Jul 15, 2024
5273392
chore: apply code review
Pranavchiku Jul 15, 2024
9346cdb
chore: use discreteUniform for example in README
Pranavchiku Jul 15, 2024
be85861
fix: incorrect readme example
Pranavchiku Jul 15, 2024
2b89b30
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into pr…
kgryte Jul 27, 2024
5852a30
refactor!: remove `order` argument and leverage loop interchange
kgryte Jul 28, 2024
d5a4845
fix: remove assertions to only apply when row-major
kgryte Jul 28, 2024
9bd7503
fix: ensure string interpolation
kgryte Jul 28, 2024
4a6b8b4
chore: consequent changes
Pranavchiku Jul 28, 2024
29e0628
chore: console statement
Pranavchiku Jul 28, 2024
cf49a15
chore: apply suggestion from code review.
Pranavchiku Jul 28, 2024
8c0e427
chore: apply suggestion from code review
Pranavchiku Jul 28, 2024
2ba8cf9
bench: restore facet in description
kgryte Jul 28, 2024
fea89d1
docs: fix descriptions
kgryte Jul 28, 2024
a18a1e2
docs: update examples
kgryte Jul 28, 2024
795a13b
refactor: use "fast" min
kgryte Jul 28, 2024
931bdc6
docs: fix description
kgryte Jul 28, 2024
f9df42b
chore: update keywords
kgryte Jul 28, 2024
7e24753
docs: update descriptions
kgryte Jul 28, 2024
0df446d
docs: fix comments
kgryte Jul 28, 2024
64c4c42
docs: fix signature
kgryte Jul 28, 2024
12f21b5
docs: update example to distinguish from subsequent example
kgryte Jul 28, 2024
f0008c5
docs: update definition
kgryte Jul 28, 2024
ef02713
test: add exception test cases
kgryte Jul 28, 2024
618a1a2
test: fix off-by-one bug and add tests
kgryte Jul 28, 2024
d5499f3
docs: remove redundant comment
kgryte Jul 28, 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/dlacpy/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.

-->

# dlacpy

> Copy all or part of a two-dimensional matrix `A` to another matrix `B`.

<section class = "usage">

## Usage

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

#### dlacpy( order, uplo, M, N, A, LDA, B, LDB )

Copies all or part of a two-dimensional matrix `A` to another matrix `B`.

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

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

dlacpy( 'row-major', 'all', 2, 2, A, 2, B, 2 );
// B => <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]
```

The function has the following parameters:

- **order**: storage layout.
- **uplo**: specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied.
Pranavchiku marked this conversation as resolved.
Show resolved Hide resolved
- **M**: number of rows in `A`.
- **N**: number of columns in `A`.
- **A**: input [`Float64Array`][mdn-float64array].
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
- **B**: output [`Float64Array`][mdn-float64array].
- **LDB**: stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`).

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' );

// Initial arrays...
var A0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
var B0 = new Float64Array( 5 );

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

dlacpy( 'row-major', 'all', 2, 2, A1, 2, B1, 2 );
// B0 => <Float64Array>[ 0.0, 2.0, 3.0, 4.0, 5.0 ]
```

#### dlacpy.ndarray( order, uplo, M, N, A, LDA, offsetA, B, LDB, offsetB )
Pranavchiku marked this conversation as resolved.
Show resolved Hide resolved

Copies all or part of a two-dimensional matrix `A` to another matrix `B` using alternative indexing semantics.

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

var A = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] );
var B = new Float64Array( [ 0.0, 0.0, 11.0, 312.0, 53.0, 412.0 ] );

dlacpy.ndarray( 'row-major', 'all', 2, 2, A, 2, 1, 1, B, 2, 1, 2 );
// B => <Float64Array>[ 0.0, 0.0, 1.0, 2.0, 3.0, 4.0 ]
```

The function has the following parameters:

- **order**: storage layout.
- **uplo**: specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied.
Pranavchiku marked this conversation as resolved.
Show resolved Hide resolved
- **M**: number of rows in `A`.
- **N**: number of columns in `A`.
- **A**: input [`Float64Array`][mdn-float64array].
- **strideA1**: stride of the first dimension of `A`
Pranavchiku marked this conversation as resolved.
Show resolved Hide resolved
- **strideA2**: stride of the second dimension of `A`
- **offsetA**: starting index for `A`.
- **B**: output [`Float64Array`][mdn-float64array].
- **strideB1**: stride of the first dimension of `B`
- **strideB2**: stride of the second dimension of `B`
- **offsetB**: starting index for `B`.

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 A = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] );
var B = new Float64Array( [ 0.0, 0.0, 11.0, 312.0, 53.0, 412.0 ] );

dlacpy.ndarray( 'row-major', 'all', 2, 2, A, 2, 1, 1, B, 2, 1, 2 );
// B => <Float64Array>[ 0.0, 0.0, 1.0, 2.0, 3.0, 4.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

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

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var uniform = require( '@stdlib/random/array/uniform' );
var dlacpy = require( '@stdlib/lapack/base/dlacpy' );

var M = 5;
var N = 8;

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

var A = uniform( M * N, -10.0, 10.0, opts );
var B = uniform( M * N, -10.0, 10.0, opts );

dlacpy( 'row-major', 'all', M, N, A, N, B, N );
console.log( B );
Pranavchiku marked this conversation as resolved.
Show resolved Hide resolved
```

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

[dlacpy]: https://www.netlib.org/lapack/explore-html/d0/d9e/group__lacpy_gaba7ee02955a93bf8af4a432c98734e65.html#gaba7ee02955a93bf8af4a432c98734e65

[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 -->
105 changes: 105 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlacpy/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 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 dlacpy = require( './../lib/dlacpy.js' );


// FUNCTIONS //

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

opts = {
'dtype': 'float64'
};

A = uniform( N*N, -10.0, 10.0, opts );
B = uniform( N*N, -10.0, 10.0, opts );
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 = dlacpy( 'column-major', 'all', N, N, A, N, B, N );
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