diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/README.md b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/README.md new file mode 100644 index 000000000000..06258d4f8219 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/README.md @@ -0,0 +1,119 @@ + + +# str2enum + +> Return the enumeration constant associated with a KMeans distance metric string. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); +``` + +#### str2enum( metric ) + +Returns the enumeration constant associated with a KMeans distance metric string. + +```javascript +var v = str2enum( 'cosine' ); +// 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., `SQEUCLIDEAN == 0`). Instead, the function should be used in an opaque manner. + +
+ + + + + +
+ +## Examples + + + +```javascript +var str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); + +var v = str2enum( 'cosine' ); +// returns + +v = str2enum( 'sqeuclidean' ); +// returns +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/benchmark/benchmark.js new file mode 100644 index 000000000000..e28f652d9084 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/benchmark/benchmark.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 = [ + 'sqeuclidean', + 'cosine', + 'cityblock', + 'correlation' + ]; + + 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/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/docs/repl.txt new file mode 100644 index 000000000000..1c3671674e2c --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/docs/repl.txt @@ -0,0 +1,27 @@ + +{{alias}}( metric ) + Returns the enumeration constant associated with a KMeans distance metric + string. + + Downstream consumers of this function should *not* rely on specific integer + values (e.g., `SQEUCLIDEAN == 0`). Instead, the function should be used in an + opaque manner. + + Parameters + ---------- + metric: string + Distance metric. + + Returns + ------- + out: integer|null + Enumeration constant. + + Examples + -------- + > var out = {{alias}}( 'cosine' ) + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/docs/types/index.d.ts new file mode 100644 index 000000000000..590d96e085d0 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/docs/types/index.d.ts @@ -0,0 +1,40 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 KMeans distance metric string. +* +* ## Notes +* +* - Downstream consumers of this function should **not** rely on specific integer values (e.g., `SQEUCLIDEAN == 0`). Instead, the function should be used in an opaque manner. +* +* @param metric - distance metric string +* @returns enumeration constant +* +* @example +* var v = str2enum( 'cosine' ); +* // returns +*/ +declare function str2enum( metric: string ): number | null; + + +// EXPORTS // + +export = str2enum; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/docs/types/test.ts new file mode 100644 index 000000000000..d51fc88a52c0 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/docs/types/test.ts @@ -0,0 +1,39 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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( 'cosine' ); // $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/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/examples/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/examples/index.js new file mode 100644 index 000000000000..e00bd0a188bd --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/examples/index.js @@ -0,0 +1,29 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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( 'cosine' ); +console.log( v ); +// => + +v = str2enum( 'sqeuclidean' ); +console.log( v ); +// => diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/lib/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/lib/index.js new file mode 100644 index 000000000000..5e0aad9b7fc4 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/lib/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 KMeans distance metric string. +* +* @module @stdlib/ml/base/cluster/kmeans/metric-str2enum +* +* @example +* var str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); +* +* var v = str2enum( 'cosine' ); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/lib/main.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/lib/main.js new file mode 100644 index 000000000000..185e6edc644e --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/lib/main.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var enumeration = require( '@stdlib/ml/base/cluster/kmeans/metrics' ).enum; + + +// VARIABLES // + +var ENUM = enumeration(); + + +// MAIN // + +/** +* Returns the enumeration constant associated with a KMeans distance metric string. +* +* ## Notes +* +* - Downstream consumers of this function should **not** rely on specific integer values (e.g., `SQEUCLIDEAN == 0`). Instead, the function should be used in an opaque manner. +* +* @param {string} metric - distance metric string +* @returns {(integer|null)} integer value or null +* +* @example +* var v = str2enum( 'cosine' ); +* // returns +*/ +function str2enum( metric ) { + var v = ENUM[ metric ]; + return ( isNumber( v ) ) ? v : null; // note: we include this guard to prevent walking the prototype chain +} + + +// EXPORTS // + +module.exports = str2enum; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/package.json b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/package.json new file mode 100644 index 000000000000..b6fa14cb4b54 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ml/base/cluster/kmeans/metric-str2enum", + "version": "0.0.0", + "description": "Return the enumeration constant associated with a KMeans distance metric string.", + "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", + "ml", + "machine", + "learning", + "cluster", + "kmeans", + "metric", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/test/test.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/test/test.js new file mode 100644 index 000000000000..25a5700780db --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-str2enum/test/test.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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( '@stdlib/ml/base/cluster/kmeans/metric-enum2str' ); +var str2enum = require( './../lib' ); + + +// VARIABLES // + +var VALUES = [ + 'cosine', + 'sqeuclidean', + 'cityblock', + 'correlation' +]; + + +// 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(); +});