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 blas/base/dtrsm #2518

Open
wants to merge 37 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2252453
feat: add blas/base/dtrsm/lib
Pranavchiku Jul 6, 2024
12708a5
chore: apply suggestions from code review
Pranavchiku Jul 6, 2024
4b951ba
enh: support offsetA and offsetB
Pranavchiku Jul 6, 2024
5d0646d
fix: incorrect base implementation
Pranavchiku Jul 8, 2024
4fe27b2
chore: add examples
Pranavchiku Jul 8, 2024
510cc17
chore: add readme
Pranavchiku Jul 8, 2024
6569dc8
chore: add package.json
Pranavchiku Jul 8, 2024
bc4f4c2
fix: incorrect readme example
Pranavchiku Jul 8, 2024
d121f15
chore: add repl.txt
Pranavchiku Jul 8, 2024
6b3562f
chore: add docs/types
Pranavchiku Jul 8, 2024
2f00ec3
chore: add benchmark
Pranavchiku Jul 8, 2024
78d49ac
test: add and register
Pranavchiku Jul 8, 2024
9ad1e43
enh: files in lib/
Pranavchiku Jul 8, 2024
851ed80
fix: incorrect description of ndarray api in readme
Pranavchiku Jul 8, 2024
93204fd
refactor: base implementation
Pranavchiku Jul 9, 2024
86d36ca
fix: lint warnings in base.js
Pranavchiku Jul 9, 2024
df96605
chore: apply code review
Pranavchiku Jul 9, 2024
8b7a997
fix: lint error in repl.txt part 1
Pranavchiku Jul 9, 2024
4ff0296
Merge branch 'dtrsm' of https://github.com/Pranavchiku/stdlib into dtrsm
Pranavchiku Jul 9, 2024
6ceef42
refactor: base implementation and consequent changes
Pranavchiku Jul 24, 2024
acc78cc
refactor: repl.txt
Pranavchiku Jul 24, 2024
35db166
chore: apply suggestion from code review
Pranavchiku Jul 24, 2024
48b8231
refactor: base implementation to compute offsets before loop
Pranavchiku Jul 24, 2024
2eea9ee
chore: work in progress
Pranavchiku Jul 25, 2024
53e44c9
Merge branch 'develop' into dtrsm
Pranavchiku Jul 25, 2024
355a56e
refactor: remove fixtures
Pranavchiku Jul 25, 2024
17b2671
refactor: remove fixtures from ndarray tests
Pranavchiku Jul 25, 2024
9deb187
refactor: docs/repl.txt
Pranavchiku Jul 25, 2024
5f3be19
chore: update description of tests
Pranavchiku Jul 25, 2024
2bae813
chore: update description of ndarray tests
Pranavchiku Jul 25, 2024
b50078f
test: add tests for complex access patterns
Pranavchiku Jul 25, 2024
7e295de
fix: incorrect spelling of contiguous
Pranavchiku Jul 25, 2024
6585a6a
chore: apply suggestions from code review
Pranavchiku Jul 25, 2024
f710cd3
Merge branch 'develop' into dtrsm
Pranavchiku Aug 8, 2024
03532e0
refactor: base implementation and consequent changes
Pranavchiku Aug 8, 2024
d0183d3
test: add more values
Pranavchiku Aug 8, 2024
449f2d5
Merge branch 'dtrsm' of https://github.com/Pranavchiku/stdlib into dtrsm
Pranavchiku Aug 8, 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
241 changes: 241 additions & 0 deletions lib/node_modules/@stdlib/blas/base/dtrsm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
<!--

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

-->

# dtrsm

> Solve matrix equation `op(A) * X = alpha * B` or `X * op(A) = alpha * B` where `alpha` is a scalar, `X` and `B` are `m` by `n` matrices, `A` is a unit, or non-unit, upper or lower triangular matrix and `op(A)` is one of `op(A) = A` or `op(A) = A^T`. The matrix `X` is overwritten on `B`.

<section class = "usage">

## Usage

```javascript
var dtrsm = require( '@stdlib/blas/base/dtrsm' );
```

#### dtrsm( order, side, uplo, transa, diag, m, n, alpha, A, LDA, B, LDB )

Solves matrix equation `op(A) * X = alpha * B` or `X * op(A) = alpha * B` where `alpha` is a scalar, `X` and `B` are `m` by `n` matrices, `A` is a unit, or non-unit, upper or lower triangular matrix and `op(A)` is one of `op(A) = A` or `op(A) = A^T`. The matrix `X` is overwritten on `B`.

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

A = new Float64Array( [ 1.0, 3.0, 0.0, 4.0 ] );
B = new Float64Array( [ 5.0, 7.0, 0.0, 8.0 ] );

dtrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 2, 6.0, A, 2, B, 2 );
// B => <Float64Array>[ 30.0, 6.0, 0.0, 12.0 ]
```

The function has the following parameters:

- **order**: storage layout of `A` and `B`.
- **side**: specifies whether `op( A )` appears on the left or right side of `X`.
- **uplo**: specifies whether the upper or lower triangular part of the matrix `A` is supplied.
- **transa**: specifies the form of `op( A )` to be used in the matrix multiplication.
- **diag**: specifies whether or not `A` is unit triangular.
- **m**: number of rows in `B`.
- **n**: number of columns in `B`.
- **alpha**: scalar constant.
- **A**: input matrix `A`.
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
- **B**: input matrix `B`.
- **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( [ 0.0, 1.0, 3.0, 0.0, 4.0 ] );
var B0 = new Float64Array( [ 0.0, 5.0, 7.0, 0.0, 8.0 ] );

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

dtrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 2, 6.0, A1, 2, B1, 2 );
// B0 => <Float64Array>[ 0.0, 30.0, 6.0, 0.0, 12.0 ]
```

#### dtrsm.ndarray( o, s, ul, t, d, m, n, α, A, sa1, sa2, oa, B, sb1, sb2, ob )

Solves matrix equation `op(A) * X = alpha * B` or `X * op(A) = alpha * B` using alternative indexing semantics and where `alpha` is a scalar, `X` and `B` are `m` by `n` matrices, `A` is a unit, or non-unit, upper or lower triangular matrix and `op(A)` is one of `op(A) = A` or `op(A) = A^T`. The matrix `X` is overwritten on `B`.

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

A = new Float64Array( [ 0.0, 0.0, 1.0, 3.0, 0.0, 4.0 ] );
B = new Float64Array( [ 0.0, 5.0, 7.0, 0.0, 8.0 ] );

dtrsm.ndarray( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 2, 6.0, A, 2, 1, 2, B, 2, 1, 1 );
// B => <Float64Array>[ 0.0, 30.0, 6.0, 0.0, 12.0 ]
```

The function has the following additional parameters:
Pranavchiku marked this conversation as resolved.
Show resolved Hide resolved

- **sa1**: stride of the first dimension of `A`.
- **sa2**: stride of the second dimension of `A`.
- **oa**: starting index for `A`.
- **sb1**: stride of the first dimension of `B`.
- **sb2**: stride of the second dimension of `B`.
- **ob**: 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' );

A = new Float64Array( [ 0.0, 0.0, 1.0, 3.0, 0.0, 4.0 ] );
B = new Float64Array( [ 0.0, 5.0, 7.0, 0.0, 8.0 ] );

dtrsm.ndarray( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 2, 6.0, A, 2, 1, 2, B, 2, 1, 1 );
// B => <Float64Array>[ 0.0, 30.0, 6.0, 0.0, 12.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- `dtrsm()` corresponds to the [BLAS][blas] level 3 function [`dtrsm`][dtrsm].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

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

var A = new Float64Array( [ 1.0, 0.0, 3.0, 4.0 ] );
var B = new Float64Array( [ 5.0, 0.0, 7.0, 8.0 ] );

dtrsm( 'row-major', 'left', 'lower', 'no-transpose', 'non-unit', 2, 2, 6.0, A, 2, B, 2 );
console.log( B );
```

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

[blas]: http://www.netlib.org/blas

[dtrsm]: https://www.netlib.org/lapack/explore-html/d9/de5/group__trsm_ga7120d931d7b1a15e12d50d328799df8a.html#ga7120d931d7b1a15e12d50d328799df8a

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

</section>

<!-- /.links -->
104 changes: 104 additions & 0 deletions lib/node_modules/@stdlib/blas/base/dtrsm/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* @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 dtrsm = require( './../lib/dtrsm.js' );


// FUNCTIONS //

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

A = uniform( N*N, 1.0, 10.0, {
'dtype': 'float64'
});
B = uniform( N*N, 1.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 = dtrsm( 'column-major', 'left', 'upper', 'no-transpose', 'non-unit', N, N, 1.0, 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