Skip to content

feat: add blas/base/matrix-triangle-resolve-enum #2497

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 3 commits into from
Jul 4, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<!--

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

-->

# resolve

> Return the enumeration constant associated with a supported BLAS matrix triangle value.

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

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var resolve = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' );
```

#### resolve( value )

Returns the enumeration constant associated with a BLAS matrix triangle value.

```javascript
var str2enum = require( '@stdlib/blas/base/matrix-triangle-str2enum' );

var v = resolve( 'lower' );
// returns <number>

v = resolve( str2enum( 'lower' ) );
// returns <number>
```

If unable to resolve an enumeration constant, the function returns `null`.

```javascript
var v = resolve( 'beep' );
// returns null
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## Notes

- Downstream consumers of this function should **not** rely on specific integer values (e.g., `UPPER == 0`). Instead, the function should be used in an opaque manner.

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

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

```javascript
var resolve = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' );

var v = resolve( 'lower' );
// returns <number>

v = resolve( 'upper' );
// returns <number>
```

</section>

<!-- /.examples -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- /.references -->

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

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* @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 isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
var str2enum = require( '@stdlib/blas/base/matrix-triangle-str2enum' );
var pkg = require( './../package.json' ).name;
var resolve = require( './../lib' );


// MAIN //

bench( pkg+'::string', function benchmark( b ) {
var values;
var out;
var i;

values = [
'lower',
'upper'
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = resolve( values[ i%values.length ] );
if ( typeof out !== 'number' ) {
b.fail( 'should return a number' );
}
}
b.toc();
if ( !isInteger( out ) ) {
b.fail( 'should return an integer' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::integer', function benchmark( b ) {
var values;
var out;
var i;

values = [
str2enum( 'lower' ),
str2enum( 'upper' )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = resolve( values[ i%values.length ] );
if ( typeof out !== 'number' ) {
b.fail( 'should return a number' );
}
}
b.toc();
if ( !isInteger( out ) ) {
b.fail( 'should return an integer' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

{{alias}}( value )
Returns the enumeration constant associated with a supported BLAS matrix
triangle value.

Downstream consumers of this function should *not* rely on specific integer
values (e.g., `UPPER == 0`). Instead, the function should be used in an
opaque manner.

Parameters
----------
value: any
Matrix triangle value.

Returns
-------
out: integer|null
Enumeration constant.

Examples
--------
> var out = {{alias}}( 'lower' )
<number>
> out = {{alias}}( {{alias:@stdlib/blas/base/matrix-triangle-str2enum}}( 'lower' ) )
<number>

See Also
--------
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* @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.
*/

// TypeScript Version: 4.1

/**
* Returns the enumeration constant associated with a BLAS matrix triangle value.
*
* ## Notes
*
* - Downstream consumers of this function should **not** rely on specific integer values (e.g., `UPPER == 0`). Instead, the function should be used in an opaque manner.
*
* @param value - matrix triangle value
* @returns enumeration constant
*
* @example
* var v = resolve( 'lower' );
* // returns <number>
*/
declare function resolve( value: any ): number | null;

Check warning on line 35 in lib/node_modules/@stdlib/blas/base/matrix-triangle-resolve-enum/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type


// EXPORTS //

export = resolve;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* @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.
*/

import resolve = require( './index' );


// TESTS //

// The function returns a number or null...
{
resolve( 0 ); // $ExpectType number | null
resolve( 'lower' ); // $ExpectType number | null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @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';

var resolve = require( './../lib' );

var v = resolve( 'lower' );
console.log( v );
// => <number>

v = resolve( 'upper' );
console.log( v );
// => <number>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @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';

/**
* Return the enumeration constant associated with a supported BLAS matrix triangle value.
*
* @module @stdlib/blas/base/matrix-triangle-resolve-enum
*
* @example
* var resolve = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' );
*
* var v = resolve( 'lower' );
* // returns <number>
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
Loading
Loading