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/dlas2 #2833

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
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
221 changes: 221 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlas2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
<!--

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

-->

# dlas2

> Compute the singular values of `2x2` matrix.

<section class = "usage">

## Usage

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

#### dlas2( F, G, H, out )

Computes the singular values of `2x2` matrix.

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

var out = new Float64Array( 2 );
dlas2( 1.0, 2.0, 3.0, out );
// out => <Float64Array>[ ~0.822, ~3.65 ]
```

The function has the following parameters:

- **F**: the (0,0) element of a 2x2 matrix.
- **G**: the (0,1) and (1,0) elements of a 2x2 matrix.
- **H**: the (1,1) element of a 2x2 matrix.
- **out**: output [`Float64Array`][mdn-float64array] containing the smaller and larger singular values respectively.

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 array:
var out0 = new Float64Array( [ 0.0, 0.0, 0.0 ] );

// Create an offset view...
var out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

dlas2( 1.0, 2.0, 3.0, out1 );
// out0 => <Float64Array>[ 0.0, ~0.822, ~3.65 ]
```

#### dlas2.ndarray( F, G, H, out, strideOut, offsetOut )

Computes the singular values of `2x2` matrix using alternative indexing semantics.

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

var out = new Float64Array( 2 );
dlas2.ndarray( 1.0, 2.0, 3.0, out, 1, 0 );
// out => <Float64Array>[ ~0.822, ~3.65 ]
```

The function has the following additional parameters:

- **strideOut**: stride length for `out`.
- **offsetOut**: starting index of `out`

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 out = new Float64Array( [ 0.0, 0.0, 0.0 ] );
dlas2.ndarray( 1.0, 2.0, 3.0, out, -1, 2 );
// out => <Float64Array>[ 0.0, ~3.65, ~0.822 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

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

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

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

var out = new Float64Array( 2 );
dlas2( 1.0, 2.0, 3.0, out );
console.log( out );
Comment on lines +120 to +122
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pranavchiku You need to go beyond just copy-pasting a prior example. This applies to all your PRs.

```

</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-dlas2]: https://www.netlib.org/lapack/explore-html/d3/dac/group__las2_ga94ed6ef29392ac8204cb0750f6cb3c8e.html#ga94ed6ef29392ac8204cb0750f6cb3c8e

[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 -->
60 changes: 60 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlas2/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @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 Float64Array = require( '@stdlib/array/float64' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var dlas2 = require( './../lib/dlas2.js' );


// MAIN //

bench( pkg, function benchmark( b ) {
var out;
var A;
var B;
var C;
var i;

b.tic();
A = ( randu() * 100.0 ) - 50.0;
B = ( randu() * 100.0 ) - 50.0;
C = ( randu() * 100.0 ) - 50.0;
out = new Float64Array( 2 );
Comment on lines +41 to +44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you doing this within the b.tic()? This benchmark needs to be refactored. It is also not clear why were are reusing out values in subsequent iterations.

for ( i = 0; i < b.iterations; i++ ) {
out = dlas2( A, B, C, out );
A = out[ i%out.length ];
B = out[ i%out.length ];
C = out[ i%out.length ];
if ( isnan( out[ i%out.length ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( out[ i%out.length ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @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 Float64Array = require( '@stdlib/array/float64' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var dlas2 = require( './../lib/ndarray.js' );


// MAIN //

bench( pkg+':ndarray', function benchmark( b ) {
var out;
var A;
var B;
var C;
var i;

A = ( randu() * 100.0 ) - 50.0;
B = ( randu() * 100.0 ) - 50.0;
C = ( randu() * 100.0 ) - 50.0;
out = new Float64Array( 2 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = dlas2( A, B, C, out, 1, 0 );
A = out[ i%out.length ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment.

B = out[ i%out.length ];
C = out[ i%out.length ];
if ( isnan( out[ i%out.length ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( out[ i%out.length ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading
Loading