From d0de2b66e7e8cb809296dd3bf6632f1f8797fce8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 4 Jul 2024 22:18:30 +0000 Subject: [PATCH] Auto-generated commit --- CHANGELOG.md | 89 +++++++++++++ base/operation-side-enum2str/README.md | 121 +++++++++++++++++ .../benchmark/benchmark.js | 55 ++++++++ base/operation-side-enum2str/docs/repl.txt | 23 ++++ .../docs/types/index.d.ts | 41 ++++++ .../docs/types/test.ts | 39 ++++++ .../operation-side-enum2str/examples/index.js | 30 +++++ base/operation-side-enum2str/lib/index.js | 44 +++++++ base/operation-side-enum2str/lib/main.js | 59 +++++++++ base/operation-side-enum2str/package.json | 66 ++++++++++ base/operation-side-enum2str/test/test.js | 65 +++++++++ base/operation-side-resolve-enum/README.md | 124 ++++++++++++++++++ .../benchmark/benchmark.js | 80 +++++++++++ .../operation-side-resolve-enum/docs/repl.txt | 29 ++++ .../docs/types/index.d.ts | 40 ++++++ .../docs/types/test.ts | 28 ++++ .../examples/index.js | 29 ++++ base/operation-side-resolve-enum/lib/index.js | 40 ++++++ base/operation-side-resolve-enum/lib/main.js | 57 ++++++++ base/operation-side-resolve-enum/package.json | 66 ++++++++++ base/operation-side-resolve-enum/test/test.js | 74 +++++++++++ base/operation-side-resolve-str/README.md | 121 +++++++++++++++++ .../benchmark/benchmark.js | 80 +++++++++++ base/operation-side-resolve-str/docs/repl.txt | 25 ++++ .../docs/types/index.d.ts | 38 ++++++ .../docs/types/test.ts | 28 ++++ .../examples/index.js | 30 +++++ base/operation-side-resolve-str/lib/index.js | 41 ++++++ base/operation-side-resolve-str/lib/main.js | 55 ++++++++ base/operation-side-resolve-str/package.json | 66 ++++++++++ base/operation-side-resolve-str/test/test.js | 74 +++++++++++ base/operation-side-str2enum/README.md | 119 +++++++++++++++++ .../benchmark/benchmark.js | 54 ++++++++ base/operation-side-str2enum/docs/repl.txt | 26 ++++ .../docs/types/index.d.ts | 40 ++++++ .../docs/types/test.ts | 39 ++++++ .../operation-side-str2enum/examples/index.js | 29 ++++ base/operation-side-str2enum/lib/index.js | 40 ++++++ base/operation-side-str2enum/lib/main.js | 55 ++++++++ base/operation-side-str2enum/package.json | 66 ++++++++++ base/operation-side-str2enum/test/test.js | 66 ++++++++++ 41 files changed, 2291 insertions(+) create mode 100644 base/operation-side-enum2str/README.md create mode 100644 base/operation-side-enum2str/benchmark/benchmark.js create mode 100644 base/operation-side-enum2str/docs/repl.txt create mode 100644 base/operation-side-enum2str/docs/types/index.d.ts create mode 100644 base/operation-side-enum2str/docs/types/test.ts create mode 100644 base/operation-side-enum2str/examples/index.js create mode 100644 base/operation-side-enum2str/lib/index.js create mode 100644 base/operation-side-enum2str/lib/main.js create mode 100644 base/operation-side-enum2str/package.json create mode 100644 base/operation-side-enum2str/test/test.js create mode 100644 base/operation-side-resolve-enum/README.md create mode 100644 base/operation-side-resolve-enum/benchmark/benchmark.js create mode 100644 base/operation-side-resolve-enum/docs/repl.txt create mode 100644 base/operation-side-resolve-enum/docs/types/index.d.ts create mode 100644 base/operation-side-resolve-enum/docs/types/test.ts create mode 100644 base/operation-side-resolve-enum/examples/index.js create mode 100644 base/operation-side-resolve-enum/lib/index.js create mode 100644 base/operation-side-resolve-enum/lib/main.js create mode 100644 base/operation-side-resolve-enum/package.json create mode 100644 base/operation-side-resolve-enum/test/test.js create mode 100644 base/operation-side-resolve-str/README.md create mode 100644 base/operation-side-resolve-str/benchmark/benchmark.js create mode 100644 base/operation-side-resolve-str/docs/repl.txt create mode 100644 base/operation-side-resolve-str/docs/types/index.d.ts create mode 100644 base/operation-side-resolve-str/docs/types/test.ts create mode 100644 base/operation-side-resolve-str/examples/index.js create mode 100644 base/operation-side-resolve-str/lib/index.js create mode 100644 base/operation-side-resolve-str/lib/main.js create mode 100644 base/operation-side-resolve-str/package.json create mode 100644 base/operation-side-resolve-str/test/test.js create mode 100644 base/operation-side-str2enum/README.md create mode 100644 base/operation-side-str2enum/benchmark/benchmark.js create mode 100644 base/operation-side-str2enum/docs/repl.txt create mode 100644 base/operation-side-str2enum/docs/types/index.d.ts create mode 100644 base/operation-side-str2enum/docs/types/test.ts create mode 100644 base/operation-side-str2enum/examples/index.js create mode 100644 base/operation-side-str2enum/lib/index.js create mode 100644 base/operation-side-str2enum/lib/main.js create mode 100644 base/operation-side-str2enum/package.json create mode 100644 base/operation-side-str2enum/test/test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 198c828c7..829263126 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -951,6 +951,94 @@ This release closes the following issue: +
+ +#### [@stdlib/blas/base/operation-side-enum2str](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/operation-side-enum2str) + +
+ +
+ +##### Features + +- [`04b3803`](https://github.com/stdlib-js/stdlib/commit/04b3803f90e84a700d42da7c1f0117b4676b2040) - add `blas/base/operation-side-*` utilities [(#2499)](https://github.com/stdlib-js/stdlib/pull/2499) + +
+ + + +
+ +
+ + + +
+ +#### [@stdlib/blas/base/operation-side-resolve-enum](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/operation-side-resolve-enum) + +
+ +
+ +##### Features + +- [`04b3803`](https://github.com/stdlib-js/stdlib/commit/04b3803f90e84a700d42da7c1f0117b4676b2040) - add `blas/base/operation-side-*` utilities [(#2499)](https://github.com/stdlib-js/stdlib/pull/2499) + +
+ + + +
+ +
+ + + +
+ +#### [@stdlib/blas/base/operation-side-resolve-str](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/operation-side-resolve-str) + +
+ +
+ +##### Features + +- [`04b3803`](https://github.com/stdlib-js/stdlib/commit/04b3803f90e84a700d42da7c1f0117b4676b2040) - add `blas/base/operation-side-*` utilities [(#2499)](https://github.com/stdlib-js/stdlib/pull/2499) + +
+ + + +
+ +
+ + + +
+ +#### [@stdlib/blas/base/operation-side-str2enum](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/operation-side-str2enum) + +
+ +
+ +##### Features + +- [`04b3803`](https://github.com/stdlib-js/stdlib/commit/04b3803f90e84a700d42da7c1f0117b4676b2040) - add `blas/base/operation-side-*` utilities [(#2499)](https://github.com/stdlib-js/stdlib/pull/2499) + +
+ + + +
+ +
+ + +
#### [@stdlib/blas/base/operation-sides](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/operation-sides) @@ -2213,6 +2301,7 @@ A total of 35 people contributed to this release. Thank you to the following con
+- [`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)_ - [`bc23559`](https://github.com/stdlib-js/stdlib/commit/bc2355981ffa28082d8e23273887501bd3ba674a) - **feat:** add support for specifying the index offset for `AP` _(by Athan Reines)_ - [`43b84f7`](https://github.com/stdlib-js/stdlib/commit/43b84f7b8614a31ed5985c010572da16b2b5186d) - **refactor:** use utility to resolve an index offset _(by Athan Reines)_ diff --git a/base/operation-side-enum2str/README.md b/base/operation-side-enum2str/README.md new file mode 100644 index 000000000..6f407dc14 --- /dev/null +++ b/base/operation-side-enum2str/README.md @@ -0,0 +1,121 @@ + + +# enum2str + +> Return the BLAS operation side string associated with a BLAS operation side enumeration constant. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var enum2str = require( '@stdlib/blas/base/operation-side-enum2str' ); +``` + +#### enum2str( operation ) + +Returns the BLAS operation side string associated with a BLAS operation side enumeration constant. + +```javascript +var str2enum = require( '@stdlib/blas/base/operation-side-str2enum' ); + +var v = str2enum( 'left' ); +// returns + +var s = enum2str( v ); +// returns 'left' +``` + +If unable to resolve an operation string, the function returns `null`. + +```javascript +var v = enum2str( -999999999 ); +// returns null +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var str2enum = require( '@stdlib/blas/base/operation-side-str2enum' ); +var enum2str = require( '@stdlib/blas/base/operation-side-enum2str' ); + +var str = enum2str( str2enum( 'left' ) ); +// returns 'left' + +str = enum2str( str2enum( 'right' ) ); +// returns 'right' +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/base/operation-side-enum2str/benchmark/benchmark.js b/base/operation-side-enum2str/benchmark/benchmark.js new file mode 100644 index 000000000..2cfc24c09 --- /dev/null +++ b/base/operation-side-enum2str/benchmark/benchmark.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 bench = require( '@stdlib/bench' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var str2enum = require( './../../../base/operation-side-str2enum' ); +var pkg = require( './../package.json' ).name; +var enum2str = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var out; + var i; + + values = [ + str2enum( 'left' ), + str2enum( 'right' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = enum2str( 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/operation-side-enum2str/docs/repl.txt b/base/operation-side-enum2str/docs/repl.txt new file mode 100644 index 000000000..a9e6a0ef3 --- /dev/null +++ b/base/operation-side-enum2str/docs/repl.txt @@ -0,0 +1,23 @@ + +{{alias}}( operation ) + Returns the BLAS operation side string associated with a BLAS operation + side enumeration constant. + + Parameters + ---------- + operation: integer + Operation enumeration constant. + + Returns + ------- + out: string|null + Operation string. + + Examples + -------- + > var out = {{alias}}( {{alias:@stdlib/blas/base/operation-side-str2enum}}( 'left' ) ) + 'left' + + See Also + -------- + diff --git a/base/operation-side-enum2str/docs/types/index.d.ts b/base/operation-side-enum2str/docs/types/index.d.ts new file mode 100644 index 000000000..b2fd02fdb --- /dev/null +++ b/base/operation-side-enum2str/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/** +* Returns the BLAS operation side string associated with a BLAS operation side enumeration constant. +* +* @param operation - enumeration constant +* @returns operation string +* +* @example +* var str2enum = require( '@stdlib/blas/base/operation-side-str2enum' ); +* +* var v = str2enum( 'left' ); +* // returns +* +* var s = enum2str( v ); +* // returns 'left' +*/ +declare function enum2str( operation: number ): string | null; + + +// EXPORTS // + +export = enum2str; diff --git a/base/operation-side-enum2str/docs/types/test.ts b/base/operation-side-enum2str/docs/types/test.ts new file mode 100644 index 000000000..65833e593 --- /dev/null +++ b/base/operation-side-enum2str/docs/types/test.ts @@ -0,0 +1,39 @@ +/* +* @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 enum2str = require( './index' ); + + +// TESTS // + +// The function returns a string or null... +{ + enum2str( 0 ); // $ExpectType string | null +} + +// The compiler throws an error if not provided a number... +{ + enum2str( '10' ); // $ExpectError + enum2str( true ); // $ExpectError + enum2str( false ); // $ExpectError + enum2str( null ); // $ExpectError + enum2str( undefined ); // $ExpectError + enum2str( [] ); // $ExpectError + enum2str( {} ); // $ExpectError + enum2str( ( x: number ): number => x ); // $ExpectError +} diff --git a/base/operation-side-enum2str/examples/index.js b/base/operation-side-enum2str/examples/index.js new file mode 100644 index 000000000..827e3f0b5 --- /dev/null +++ b/base/operation-side-enum2str/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/operation-side-str2enum' ); +var enum2str = require( './../lib' ); + +var str = enum2str( str2enum( 'left' ) ); +console.log( str ); +// => 'left' + +str = enum2str( str2enum( 'right' ) ); +console.log( str ); +// => 'right' diff --git a/base/operation-side-enum2str/lib/index.js b/base/operation-side-enum2str/lib/index.js new file mode 100644 index 000000000..987294de4 --- /dev/null +++ b/base/operation-side-enum2str/lib/index.js @@ -0,0 +1,44 @@ +/** +* @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 BLAS operation side string associated with a BLAS operation side enumeration constant. +* +* @module @stdlib/blas/base/operation-side-enum2str +* +* @example +* var str2enum = require( '@stdlib/blas/base/operation-side-str2enum' ); +* var enum2str = require( '@stdlib/blas/base/operation-side-enum2str' ); +* +* var v = str2enum( 'left' ); +* // returns +* +* var s = enum2str( v ); +* // returns 'left' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/base/operation-side-enum2str/lib/main.js b/base/operation-side-enum2str/lib/main.js new file mode 100644 index 000000000..f73e64666 --- /dev/null +++ b/base/operation-side-enum2str/lib/main.js @@ -0,0 +1,59 @@ +/** +* @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 objectInverse = require( '@stdlib/utils/object-inverse' ); +var enumeration = require( './../../../base/operation-sides' ).enum; + + +// VARIABLES // + +var hash = objectInverse( enumeration(), { + 'duplicates': false +}); + + +// MAIN // + +/** +* Returns the BLAS operation side string associated with a BLAS operation side enumeration constant. +* +* @param {integer} operation - operation enumeration constant +* @returns {(string|null)} operation string or null +* +* @example +* var str2enum = require( '@stdlib/blas/base/operation-side-str2enum' ); +* +* var v = str2enum( 'left' ); +* // returns +* +* var s = enum2str( v ); +* // returns 'left' +*/ +function enum2str( operation ) { + var v = hash[ operation ]; + return ( typeof v === 'string' ) ? v : null; // note: we include this guard to prevent walking the prototype chain +} + + +// EXPORTS // + +module.exports = enum2str; diff --git a/base/operation-side-enum2str/package.json b/base/operation-side-enum2str/package.json new file mode 100644 index 000000000..7833774d2 --- /dev/null +++ b/base/operation-side-enum2str/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/blas/base/operation-side-enum2str", + "version": "0.0.0", + "description": "Return the BLAS operation side string associated with a BLAS operation side enumeration constant.", + "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", + "operation", + "multidimensional", + "array", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/base/operation-side-enum2str/test/test.js b/base/operation-side-enum2str/test/test.js new file mode 100644 index 000000000..111287c3f --- /dev/null +++ b/base/operation-side-enum2str/test/test.js @@ -0,0 +1,65 @@ +/** +* @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/operation-side-str2enum' ); +var enum2str = require( './../lib' ); + + +// VARIABLES // + +var VALUES = [ + 'right', + 'left' +]; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof enum2str, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns the operation string associated with a BLAS operation side enumeration constant', function test( t ) { + var i; + for ( i = 0; i < VALUES.length; i++ ) { + t.strictEqual( enum2str( str2enum( VALUES[ i ] ) ), VALUES[ i ], 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function returns `null` if unable to resolve an operation string', function test( t ) { + var values; + var i; + + values = [ + -9999999, + -999999999, + -99999999999 + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( enum2str( values[ i ] ), null, 'returns expected value' ); + } + t.end(); +}); diff --git a/base/operation-side-resolve-enum/README.md b/base/operation-side-resolve-enum/README.md new file mode 100644 index 000000000..0b01668fb --- /dev/null +++ b/base/operation-side-resolve-enum/README.md @@ -0,0 +1,124 @@ + + +# resolve + +> Return the enumeration constant associated with a supported BLAS operation side value. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var resolve = require( '@stdlib/blas/base/operation-side-resolve-enum' ); +``` + +#### resolve( operation ) + +Returns the enumeration constant associated with a BLAS operation side value. + +```javascript +var str2enum = require( '@stdlib/blas/base/operation-side-str2enum' ); + +var v = resolve( 'right' ); +// returns + +v = resolve( str2enum( 'right' ) ); +// returns +``` + +If unable to resolve an enumeration constant, the function returns `null`. + +```javascript +var v = resolve( 'beep' ); +// returns null +``` + +
+ + + + + +
+ +## Notes + +- Downstream consumers of this function should **not** rely on specific integer values (e.g., `LEFT == 0`). Instead, the function should be used in an opaque manner. + +
+ + + + + +
+ +## Examples + + + +```javascript +var resolve = require( '@stdlib/blas/base/operation-side-resolve-enum' ); + +var v = resolve( 'right' ); +// returns + +v = resolve( 'left' ); +// returns +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/base/operation-side-resolve-enum/benchmark/benchmark.js b/base/operation-side-resolve-enum/benchmark/benchmark.js new file mode 100644 index 000000000..a9c69d8b9 --- /dev/null +++ b/base/operation-side-resolve-enum/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 isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var str2enum = require( './../../../base/operation-side-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 = [ + 'right', + 'left' + ]; + + 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( 'right' ), + str2enum( 'left' ) + ]; + + 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(); +}); diff --git a/base/operation-side-resolve-enum/docs/repl.txt b/base/operation-side-resolve-enum/docs/repl.txt new file mode 100644 index 000000000..768197071 --- /dev/null +++ b/base/operation-side-resolve-enum/docs/repl.txt @@ -0,0 +1,29 @@ + +{{alias}}( operation ) + Returns the enumeration constant associated with a supported BLAS operation + side value. + + Downstream consumers of this function should *not* rely on specific integer + values (e.g., `LEFT == 0`). Instead, the function should be used in an + opaque manner. + + Parameters + ---------- + operation: any + Operation value. + + Returns + ------- + out: integer|null + Enumeration constant. + + Examples + -------- + > var out = {{alias}}( 'right' ) + + > out = {{alias}}( {{alias:@stdlib/blas/base/operation-side-str2enum}}( 'right' ) ) + + + See Also + -------- + diff --git a/base/operation-side-resolve-enum/docs/types/index.d.ts b/base/operation-side-resolve-enum/docs/types/index.d.ts new file mode 100644 index 000000000..12efc0dcf --- /dev/null +++ b/base/operation-side-resolve-enum/docs/types/index.d.ts @@ -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 operation side value. +* +* ## Notes +* +* - Downstream consumers of this function should **not** rely on specific integer values (e.g., `LEFT == 0`). Instead, the function should be used in an opaque manner. +* +* @param operation - operation value +* @returns enumeration constant +* +* @example +* var v = resolve( 'right' ); +* // returns +*/ +declare function resolve( operation: any ): number | null; + + +// EXPORTS // + +export = resolve; diff --git a/base/operation-side-resolve-enum/docs/types/test.ts b/base/operation-side-resolve-enum/docs/types/test.ts new file mode 100644 index 000000000..b7240d4b8 --- /dev/null +++ b/base/operation-side-resolve-enum/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 number or null... +{ + resolve( 0 ); // $ExpectType number | null + resolve( 'right' ); // $ExpectType number | null +} diff --git a/base/operation-side-resolve-enum/examples/index.js b/base/operation-side-resolve-enum/examples/index.js new file mode 100644 index 000000000..a9d51a1a5 --- /dev/null +++ b/base/operation-side-resolve-enum/examples/index.js @@ -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( 'right' ); +console.log( v ); +// => + +v = resolve( 'left' ); +console.log( v ); +// => diff --git a/base/operation-side-resolve-enum/lib/index.js b/base/operation-side-resolve-enum/lib/index.js new file mode 100644 index 000000000..53e992b14 --- /dev/null +++ b/base/operation-side-resolve-enum/lib/index.js @@ -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 operation side value. +* +* @module @stdlib/blas/base/operation-side-resolve-enum +* +* @example +* var resolve = require( '@stdlib/blas/base/operation-side-resolve-enum' ); +* +* var v = resolve( 'right' ); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/base/operation-side-resolve-enum/lib/main.js b/base/operation-side-resolve-enum/lib/main.js new file mode 100644 index 000000000..658fb1e0a --- /dev/null +++ b/base/operation-side-resolve-enum/lib/main.js @@ -0,0 +1,57 @@ +/** +* @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/operation-side-enum2str' ); +var str2enum = require( './../../../base/operation-side-str2enum' ); + + +// MAIN // + +/** +* Returns the enumeration constant associated with a supported BLAS operation side value. +* +* ## Notes +* +* - Downstream consumers of this function should **not** rely on specific integer values (e.g., `LEFT == 0`). Instead, the function should be used in an opaque manner. +* +* @param {*} operation - operation value +* @returns {(integer|null)} enumeration constant or null +* +* @example +* var v = resolve( 'right' ); +* // returns +*/ +function resolve( operation ) { + var t = ( typeof operation ); + if ( t === 'number' ) { + return ( enum2str( operation ) ) ? operation : null; + } + if ( t === 'string' ) { + return str2enum( operation ); + } + return null; +} + + +// EXPORTS // + +module.exports = resolve; diff --git a/base/operation-side-resolve-enum/package.json b/base/operation-side-resolve-enum/package.json new file mode 100644 index 000000000..86acfdc8d --- /dev/null +++ b/base/operation-side-resolve-enum/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/blas/base/operation-side-resolve-enum", + "version": "0.0.0", + "description": "Return the enumeration constant associated with a supported BLAS operation side 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", + "operation", + "multidimensional", + "array", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/base/operation-side-resolve-enum/test/test.js b/base/operation-side-resolve-enum/test/test.js new file mode 100644 index 000000000..625677de0 --- /dev/null +++ b/base/operation-side-resolve-enum/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/operation-side-str2enum' ); +var resolve = require( './../lib' ); + + +// VARIABLES // + +var VALUES = [ + 'left', + 'right' +]; + + +// 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 enumeration constant associated with a BLAS operation side value', function test( t ) { + var v; + var i; + for ( i = 0; i < VALUES.length; i++ ) { + v = str2enum( VALUES[ i ] ); + t.strictEqual( resolve( VALUES[ i ] ), v, 'returns expected value' ); + t.strictEqual( resolve( v ), v, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function returns `null` if unable to resolve an enumeration constant', 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(); +}); diff --git a/base/operation-side-resolve-str/README.md b/base/operation-side-resolve-str/README.md new file mode 100644 index 000000000..848d6d5e7 --- /dev/null +++ b/base/operation-side-resolve-str/README.md @@ -0,0 +1,121 @@ + + +# resolve + +> Return the operation side string associated with a supported BLAS operation side value. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var resolve = require( '@stdlib/blas/base/operation-side-resolve-str' ); +``` + +#### resolve( operation ) + +Returns the operation side string associated with a BLAS operation side value. + +```javascript +var str2enum = require( '@stdlib/blas/base/operation-side-str2enum' ); + +var v = resolve( 'left' ); +// returns 'left' + +v = resolve( str2enum( 'left' ) ); +// returns 'left' +``` + +If unable to resolve a operation side string, the function returns `null`. + +```javascript +var v = resolve( 'beep' ); +// returns null +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var str2enum = require( '@stdlib/blas/base/operation-side-str2enum' ); +var resolve = require( '@stdlib/blas/base/operation-side-resolve-str' ); + +var v = resolve( str2enum( 'left' ) ); +// returns 'left' + +v = resolve( str2enum( 'right' ) ); +// returns 'right' +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/base/operation-side-resolve-str/benchmark/benchmark.js b/base/operation-side-resolve-str/benchmark/benchmark.js new file mode 100644 index 000000000..4e915c8b9 --- /dev/null +++ b/base/operation-side-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/operation-side-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 = [ + 'left', + 'right' + ]; + + 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( 'left' ), + str2enum( 'right' ) + ]; + + 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/operation-side-resolve-str/docs/repl.txt b/base/operation-side-resolve-str/docs/repl.txt new file mode 100644 index 000000000..c3958a622 --- /dev/null +++ b/base/operation-side-resolve-str/docs/repl.txt @@ -0,0 +1,25 @@ + +{{alias}}( operation ) + Returns the operation side string associated with a supported BLAS operation + side value. + + Parameters + ---------- + operation: any + Operation value. + + Returns + ------- + out: string|null + Operation string. + + Examples + -------- + > var out = {{alias}}( 'left' ) + 'left' + > out = {{alias}}( {{alias:@stdlib/blas/base/operation-side-str2enum}}( 'left' ) ) + 'left' + + See Also + -------- + diff --git a/base/operation-side-resolve-str/docs/types/index.d.ts b/base/operation-side-resolve-str/docs/types/index.d.ts new file mode 100644 index 000000000..b2143d445 --- /dev/null +++ b/base/operation-side-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 operation side string associated with a BLAS operation side value. +* +* @param operation - operation value +* @returns operation side string +* +* @example +* var str2enum = require( '@stdlib/blas/base/operation-side-str2enum' ); +* +* var v = resolve( str2enum( 'left' ) ); +* // returns 'left' +*/ +declare function resolve( operation: any ): string | null; + + +// EXPORTS // + +export = resolve; diff --git a/base/operation-side-resolve-str/docs/types/test.ts b/base/operation-side-resolve-str/docs/types/test.ts new file mode 100644 index 000000000..392709cd4 --- /dev/null +++ b/base/operation-side-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( 'left' ); // $ExpectType string | null +} diff --git a/base/operation-side-resolve-str/examples/index.js b/base/operation-side-resolve-str/examples/index.js new file mode 100644 index 000000000..07bb79cad --- /dev/null +++ b/base/operation-side-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/operation-side-str2enum' ); +var resolve = require( './../lib' ); + +var v = resolve( str2enum( 'left' ) ); +console.log( v ); +// => 'left' + +v = resolve( str2enum( 'right' ) ); +console.log( v ); +// => 'right' diff --git a/base/operation-side-resolve-str/lib/index.js b/base/operation-side-resolve-str/lib/index.js new file mode 100644 index 000000000..240bb256d --- /dev/null +++ b/base/operation-side-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 operation side string associated with a supported BLAS operation side value. +* +* @module @stdlib/blas/base/operation-side-resolve-str +* +* @example +* var str2enum = require( '@stdlib/blas/base/operation-side-str2enum' ); +* var resolve = require( '@stdlib/blas/base/operation-side-resolve-str' ); +* +* var v = resolve( str2enum( 'left' ) ); +* // returns 'left' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/base/operation-side-resolve-str/lib/main.js b/base/operation-side-resolve-str/lib/main.js new file mode 100644 index 000000000..90d01866b --- /dev/null +++ b/base/operation-side-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/operation-side-enum2str' ); +var str2enum = require( './../../../base/operation-side-str2enum' ); + + +// MAIN // + +/** +* Returns the operation side string associated with a supported BLAS operation side value. +* +* @param {*} operation - operation value +* @returns {(string|null)} operation side string or null +* +* @example +* var str2enum = require( '@stdlib/blas/base/operation-side-str2enum' ); +* +* var v = resolve( str2enum( 'left' ) ); +* // returns 'left' +*/ +function resolve( operation ) { + var t = ( typeof operation ); + if ( t === 'string' ) { + return ( str2enum( operation ) === null ) ? null : operation; + } + if ( t === 'number' ) { + return enum2str( operation ); + } + return null; +} + + +// EXPORTS // + +module.exports = resolve; diff --git a/base/operation-side-resolve-str/package.json b/base/operation-side-resolve-str/package.json new file mode 100644 index 000000000..f5f718fde --- /dev/null +++ b/base/operation-side-resolve-str/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/blas/base/operation-side-resolve-str", + "version": "0.0.0", + "description": "Return the operation side string associated with a supported BLAS operation side 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", + "operation", + "multidimensional", + "array", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/base/operation-side-resolve-str/test/test.js b/base/operation-side-resolve-str/test/test.js new file mode 100644 index 000000000..f791ed97e --- /dev/null +++ b/base/operation-side-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/operation-side-str2enum' ); +var resolve = require( './../lib' ); + + +// VARIABLES // + +var VALUES = [ + 'right', + 'left' +]; + + +// 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 operation side string associated with a BLAS operation side 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 operation side 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(); +}); diff --git a/base/operation-side-str2enum/README.md b/base/operation-side-str2enum/README.md new file mode 100644 index 000000000..771c920ec --- /dev/null +++ b/base/operation-side-str2enum/README.md @@ -0,0 +1,119 @@ + + +# str2enum + +> Return the enumeration constant associated with a BLAS operation side. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var str2enum = require( '@stdlib/blas/base/operation-side-str2enum' ); +``` + +#### str2enum( operation ) + +Return the enumeration constant associated with a BLAS operation side. + +```javascript +var v = str2enum( 'left' ); +// returns +``` + +If unable to resolve an enumeration constant, the function returns `null`. + +```javascript +var v = str2enum( 'beep' ); +// returns null +``` + +
+ + + + + +
+ +## Notes + +- Downstream consumers of this function should **not** rely on specific integer values (e.g., `LEFT == 0`). Instead, the function should be used in an opaque manner. + +
+ + + + + +
+ +## Examples + + + +```javascript +var str2enum = require( '@stdlib/blas/base/operation-side-str2enum' ); + +var v = str2enum( 'left' ); +// returns + +v = str2enum( 'right' ); +// returns +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/base/operation-side-str2enum/benchmark/benchmark.js b/base/operation-side-str2enum/benchmark/benchmark.js new file mode 100644 index 000000000..4df1a7d42 --- /dev/null +++ b/base/operation-side-str2enum/benchmark/benchmark.js @@ -0,0 +1,54 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var str2enum = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var out; + var i; + + values = [ + 'left', + 'right' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = str2enum( 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(); +}); diff --git a/base/operation-side-str2enum/docs/repl.txt b/base/operation-side-str2enum/docs/repl.txt new file mode 100644 index 000000000..acff469cc --- /dev/null +++ b/base/operation-side-str2enum/docs/repl.txt @@ -0,0 +1,26 @@ + +{{alias}}( operation ) + Returns the enumeration constant associated with a BLAS operation side. + + Downstream consumers of this function should *not* rely on specific integer + values (e.g., `LEFT == 0`). Instead, the function should be used in an + opaque manner. + + Parameters + ---------- + operation: string + Operation side. + + Returns + ------- + out: integer|null + Enumeration constant. + + Examples + -------- + > var out = {{alias}}( 'left' ) + + + See Also + -------- + diff --git a/base/operation-side-str2enum/docs/types/index.d.ts b/base/operation-side-str2enum/docs/types/index.d.ts new file mode 100644 index 000000000..9f466a872 --- /dev/null +++ b/base/operation-side-str2enum/docs/types/index.d.ts @@ -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 operation side. +* +* ## Notes +* +* - Downstream consumers of this function should **not** rely on specific integer values (e.g., `LEFT == 0`). Instead, the function should be used in an opaque manner. +* +* @param operation - operation side +* @returns enumeration constant +* +* @example +* var v = str2enum( 'left' ); +* // returns +*/ +declare function str2enum( operation: string ): number | null; + + +// EXPORTS // + +export = str2enum; diff --git a/base/operation-side-str2enum/docs/types/test.ts b/base/operation-side-str2enum/docs/types/test.ts new file mode 100644 index 000000000..7e00b5288 --- /dev/null +++ b/base/operation-side-str2enum/docs/types/test.ts @@ -0,0 +1,39 @@ +/* +* @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 str2enum = require( './index' ); + + +// TESTS // + +// The function returns a number or null... +{ + str2enum( 'left' ); // $ExpectType number | null +} + +// The compiler throws an error if not provided a string... +{ + str2enum( 10 ); // $ExpectError + str2enum( true ); // $ExpectError + str2enum( false ); // $ExpectError + str2enum( null ); // $ExpectError + str2enum( undefined ); // $ExpectError + str2enum( [] ); // $ExpectError + str2enum( {} ); // $ExpectError + str2enum( ( x: number ): number => x ); // $ExpectError +} diff --git a/base/operation-side-str2enum/examples/index.js b/base/operation-side-str2enum/examples/index.js new file mode 100644 index 000000000..23529d936 --- /dev/null +++ b/base/operation-side-str2enum/examples/index.js @@ -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 str2enum = require( './../lib' ); + +var v = str2enum( 'left' ); +console.log( v ); +// => + +v = str2enum( 'right' ); +console.log( v ); +// => diff --git a/base/operation-side-str2enum/lib/index.js b/base/operation-side-str2enum/lib/index.js new file mode 100644 index 000000000..06e9af76c --- /dev/null +++ b/base/operation-side-str2enum/lib/index.js @@ -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 BLAS operation side. +* +* @module @stdlib/blas/base/operation-side-str2enum +* +* @example +* var str2enum = require( '@stdlib/blas/base/operation-side-str2enum' ); +* +* var v = str2enum( 'left' ); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/base/operation-side-str2enum/lib/main.js b/base/operation-side-str2enum/lib/main.js new file mode 100644 index 000000000..b69c5f82d --- /dev/null +++ b/base/operation-side-str2enum/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 enumeration = require( './../../../base/operation-sides' ).enum; + + +// VARIABLES // + +var ENUM = enumeration(); + + +// MAIN // + +/** +* Returns the enumeration constant associated with a BLAS operation side. +* +* ## Notes +* +* - Downstream consumers of this function should **not** rely on specific integer values (e.g., `LEFT == 0`). Instead, the function should be used in an opaque manner. +* +* @param {string} operation - operation side +* @returns {(integer|null)} integer value or null +* +* @example +* var v = str2enum( 'left' ); +* // returns +*/ +function str2enum( operation ) { + var v = ENUM[ operation ]; + return ( typeof v === 'number' ) ? v : null; // note: we include this guard to prevent walking the prototype chain +} + + +// EXPORTS // + +module.exports = str2enum; diff --git a/base/operation-side-str2enum/package.json b/base/operation-side-str2enum/package.json new file mode 100644 index 000000000..7bef247ca --- /dev/null +++ b/base/operation-side-str2enum/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/blas/base/operation-side-str2enum", + "version": "0.0.0", + "description": "Return the enumeration constant associated with a BLAS operation side.", + "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", + "operation", + "multidimensional", + "array", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/base/operation-side-str2enum/test/test.js b/base/operation-side-str2enum/test/test.js new file mode 100644 index 000000000..54a46874f --- /dev/null +++ b/base/operation-side-str2enum/test/test.js @@ -0,0 +1,66 @@ +/** +* @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 enum2str = require( './../../../base/operation-side-enum2str' ); +var str2enum = require( './../lib' ); + + +// VARIABLES // + +var VALUES = [ + 'left', + 'right' +]; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof str2enum, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns the enumeration constant associated with a string', function test( t ) { + var i; + for ( i = 0; i < VALUES.length; i++ ) { + t.strictEqual( enum2str( str2enum( VALUES[ i ] ) ), VALUES[ i ], 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function returns `null` if unable to resolve an enumeration constant', function test( t ) { + var values; + var i; + + values = [ + 'beep', + 'boop', + 'foo', + 'bar' + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( str2enum( values[ i ] ), null, 'returns expected value' ); + } + t.end(); +});