diff --git a/CHANGELOG.md b/CHANGELOG.md index d1af309db..2d587cd7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -995,6 +995,28 @@ This release closes the following issue: +
+ +#### [@stdlib/blas/base/matrix-triangle-resolve-str](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/matrix-triangle-resolve-str) + +
+ +
+ +##### Features + +- [`50316e4`](https://github.com/stdlib-js/stdlib/commit/50316e43a7f59092f56aebcd2acfa815871ae3bf) - add `blas/base/matrix-triangle-resolve-str` [(#2496)](https://github.com/stdlib-js/stdlib/pull/2496) + +
+ + + +
+ +
+ + +
#### [@stdlib/blas/base/matrix-triangle-str2enum](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/matrix-triangle-str2enum) @@ -2389,6 +2411,7 @@ A total of 35 people contributed to this release. Thank you to the following con
+- [`50316e4`](https://github.com/stdlib-js/stdlib/commit/50316e43a7f59092f56aebcd2acfa815871ae3bf) - **feat:** add `blas/base/matrix-triangle-resolve-str` [(#2496)](https://github.com/stdlib-js/stdlib/pull/2496) _(by Pranav Goswami, Athan Reines)_ - [`1493a14`](https://github.com/stdlib-js/stdlib/commit/1493a1446311df5c8b643e3429dba4c8850fc227) - **feat:** add `blas/base/diagonal-type-*` utilities [(#2498)](https://github.com/stdlib-js/stdlib/pull/2498) _(by Pranav Goswami, Athan Reines)_ - [`04b3803`](https://github.com/stdlib-js/stdlib/commit/04b3803f90e84a700d42da7c1f0117b4676b2040) - **feat:** add `blas/base/operation-side-*` utilities [(#2499)](https://github.com/stdlib-js/stdlib/pull/2499) _(by Pranav Goswami, Athan Reines)_ - [`a61b40c`](https://github.com/stdlib-js/stdlib/commit/a61b40cedd7518a68efb28372e4bf817aeb5a319) - **feat:** add `blas/base/matrix-triangle-str2enum` and `blas/base/matrix-triangle/enum2str` [(#2495)](https://github.com/stdlib-js/stdlib/pull/2495) _(by Pranav Goswami, Athan Reines)_ diff --git a/base/matrix-triangle-resolve-str/README.md b/base/matrix-triangle-resolve-str/README.md new file mode 100644 index 000000000..01be4c9eb --- /dev/null +++ b/base/matrix-triangle-resolve-str/README.md @@ -0,0 +1,121 @@ + + +# resolve + +> Return the matrix triangle string associated with a supported BLAS matrix triangle value. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var resolve = require( '@stdlib/blas/base/matrix-triangle-resolve-str' ); +``` + +#### resolve( value ) + +Returns the matrix triangle string associated with a BLAS matrix triangle value. + +```javascript +var str2enum = require( '@stdlib/blas/base/matrix-triangle-str2enum' ); + +var v = resolve( 'upper' ); +// returns 'upper' + +v = resolve( str2enum( 'upper' ) ); +// returns 'upper' +``` + +If unable to resolve a matrix triangle string, the function returns `null`. + +```javascript +var v = resolve( 'beep' ); +// returns null +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var str2enum = require( '@stdlib/blas/base/matrix-triangle-str2enum' ); +var resolve = require( '@stdlib/blas/base/matrix-triangle-resolve-str' ); + +var v = resolve( str2enum( 'upper' ) ); +// returns 'upper' + +v = resolve( str2enum( 'lower' ) ); +// returns 'lower' +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/base/matrix-triangle-resolve-str/benchmark/benchmark.js b/base/matrix-triangle-resolve-str/benchmark/benchmark.js new file mode 100644 index 000000000..b1e78fafc --- /dev/null +++ b/base/matrix-triangle-resolve-str/benchmark/benchmark.js @@ -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 isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var str2enum = require( './../../../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 = [ + 'upper', + 'lower' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = resolve( values[ i%values.length ] ); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::integer', function benchmark( b ) { + var values; + var out; + var i; + + values = [ + str2enum( 'upper' ), + str2enum( 'lower' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = resolve( values[ i%values.length ] ); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/base/matrix-triangle-resolve-str/docs/repl.txt b/base/matrix-triangle-resolve-str/docs/repl.txt new file mode 100644 index 000000000..9dd29d846 --- /dev/null +++ b/base/matrix-triangle-resolve-str/docs/repl.txt @@ -0,0 +1,25 @@ + +{{alias}}( value ) + Returns the matrix triangle string associated with a supported BLAS matrix + triangle value. + + Parameters + ---------- + value: any + Matrix triangle value. + + Returns + ------- + out: string|null + Matrix triangle string. + + Examples + -------- + > var out = {{alias}}( 'upper' ) + 'upper' + > out = {{alias}}( {{alias:@stdlib/blas/base/matrix-triangle-str2enum}}( 'upper' ) ) + 'upper' + + See Also + -------- + diff --git a/base/matrix-triangle-resolve-str/docs/types/index.d.ts b/base/matrix-triangle-resolve-str/docs/types/index.d.ts new file mode 100644 index 000000000..b02e65e2f --- /dev/null +++ b/base/matrix-triangle-resolve-str/docs/types/index.d.ts @@ -0,0 +1,38 @@ +/* +* @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 matrix triangle string associated with a BLAS matrix triangle value. +* +* @param value - matrix triangle value +* @returns matrix triangle string +* +* @example +* var str2enum = require( '@stdlib/blas/base/matrix-triangle-str2enum' ); +* +* var v = resolve( str2enum( 'upper' ) ); +* // returns 'upper' +*/ +declare function resolve( value: any ): string | null; + + +// EXPORTS // + +export = resolve; diff --git a/base/matrix-triangle-resolve-str/docs/types/test.ts b/base/matrix-triangle-resolve-str/docs/types/test.ts new file mode 100644 index 000000000..df0a1ed0e --- /dev/null +++ b/base/matrix-triangle-resolve-str/docs/types/test.ts @@ -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 string or null... +{ + resolve( 0 ); // $ExpectType string | null + resolve( 'upper' ); // $ExpectType string | null +} diff --git a/base/matrix-triangle-resolve-str/examples/index.js b/base/matrix-triangle-resolve-str/examples/index.js new file mode 100644 index 000000000..4e9f38dd5 --- /dev/null +++ b/base/matrix-triangle-resolve-str/examples/index.js @@ -0,0 +1,30 @@ +/** +* @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 str2enum = require( './../../../base/matrix-triangle-str2enum' ); +var resolve = require( './../lib' ); + +var v = resolve( str2enum( 'upper' ) ); +console.log( v ); +// => 'upper' + +v = resolve( str2enum( 'lower' ) ); +console.log( v ); +// => 'lower' diff --git a/base/matrix-triangle-resolve-str/lib/index.js b/base/matrix-triangle-resolve-str/lib/index.js new file mode 100644 index 000000000..8e1bf6ae7 --- /dev/null +++ b/base/matrix-triangle-resolve-str/lib/index.js @@ -0,0 +1,41 @@ +/** +* @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 matrix triangle string associated with a supported BLAS matrix triangle value. +* +* @module @stdlib/blas/base/matrix-triangle-resolve-str +* +* @example +* var str2enum = require( '@stdlib/blas/base/matrix-triangle-str2enum' ); +* var resolve = require( '@stdlib/blas/base/matrix-triangle-resolve-str' ); +* +* var v = resolve( str2enum( 'upper' ) ); +* // returns 'upper' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/base/matrix-triangle-resolve-str/lib/main.js b/base/matrix-triangle-resolve-str/lib/main.js new file mode 100644 index 000000000..fe4f20f17 --- /dev/null +++ b/base/matrix-triangle-resolve-str/lib/main.js @@ -0,0 +1,55 @@ +/** +* @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 enum2str = require( './../../../base/matrix-triangle-enum2str' ); +var str2enum = require( './../../../base/matrix-triangle-str2enum' ); + + +// MAIN // + +/** +* Returns the matrix triangle string associated with a supported BLAS matrix triangle value. +* +* @param {*} value - matrix triangle value +* @returns {(string|null)} matrix triangle string or null +* +* @example +* var str2enum = require( '@stdlib/blas/base/matrix-triangle-str2enum' ); +* +* var v = resolve( str2enum( 'upper' ) ); +* // returns 'upper' +*/ +function resolve( value ) { + var t = ( typeof value ); + if ( t === 'string' ) { + return ( str2enum( value ) === null ) ? null : value; + } + if ( t === 'number' ) { + return enum2str( value ); + } + return null; +} + + +// EXPORTS // + +module.exports = resolve; diff --git a/base/matrix-triangle-resolve-str/package.json b/base/matrix-triangle-resolve-str/package.json new file mode 100644 index 000000000..53db04081 --- /dev/null +++ b/base/matrix-triangle-resolve-str/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/blas/base/matrix-triangle-resolve-str", + "version": "0.0.0", + "description": "Return the matrix triangle string associated with a supported BLAS matrix triangle value.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "blas", + "ndarray", + "matrix", + "multidimensional", + "array", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/base/matrix-triangle-resolve-str/test/test.js b/base/matrix-triangle-resolve-str/test/test.js new file mode 100644 index 000000000..7ecb2aba0 --- /dev/null +++ b/base/matrix-triangle-resolve-str/test/test.js @@ -0,0 +1,74 @@ +/** +* @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 tape = require( 'tape' ); +var str2enum = require( './../../../base/matrix-triangle-str2enum' ); +var resolve = require( './../lib' ); + + +// VARIABLES // + +var VALUES = [ + 'upper', + 'lower' +]; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof resolve, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns the matrix triangle string associated with a BLAS matrix triangle value', function test( t ) { + var v; + var i; + for ( i = 0; i < VALUES.length; i++ ) { + v = str2enum( VALUES[ i ] ); + t.strictEqual( resolve( VALUES[ i ] ), VALUES[ i ], 'returns expected value' ); + t.strictEqual( resolve( v ), VALUES[ i ], 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function returns `null` if unable to resolve a matrix triangle string', function test( t ) { + var values; + var i; + + values = [ + 'beep', + 'boop', + 'foo', + 'bar', + -99999999, + -9999999999, + -9999999999999, + true, + false + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( resolve( values[ i ] ), null, 'returns expected value' ); + } + t.end(); +});