diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/README.md b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/README.md new file mode 100644 index 000000000000..71132d4fa967 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/README.md @@ -0,0 +1,121 @@ + + +# enum2str + +> Return the KMeans distance metric string associated with a KMeans distance metric enumeration constant. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var enum2str = require( '@stdlib/ml/base/cluster/kmeans/metric-enum2str' ); +``` + +#### enum2str( value ) + +Returns the KMeans distance metric string associated with a KMeans distance metric enumeration constant. + +```javascript +var str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); + +var v = str2enum( 'sqeuclidean' ); +// returns + +var s = enum2str( v ); +// returns 'sqeuclidean' +``` + +If unable to resolve a KMeans distance metric string, the function returns `null`. + +```javascript +var v = enum2str( -999999999 ); +// returns null +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); +var enum2str = require( '@stdlib/ml/base/cluster/kmeans/metric-enum2str' ); + +var str = enum2str( str2enum( 'sqeuclidean' ) ); +// returns 'sqeuclidean' + +str = enum2str( str2enum( 'cosine' ) ); +// returns 'cosine' +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/benchmark/benchmark.js new file mode 100644 index 000000000000..3078f97847f0 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/benchmark/benchmark.js @@ -0,0 +1,57 @@ +/** +* @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 isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-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( 'sqeuclidean' ), + str2enum( 'cosine' ), + str2enum( 'cityblock' ), + str2enum( 'correlation' ) + ]; + + 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/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/docs/repl.txt new file mode 100644 index 000000000000..09c6281a0682 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/docs/repl.txt @@ -0,0 +1,23 @@ + +{{alias}}( value ) + Returns the KMeans distance metric string associated with a KMeans distance + metric enumeration constant. + + Parameters + ---------- + value: integer + Distance metric enumeration constant. + + Returns + ------- + out: string|null + Distance metric string. + + Examples + -------- + > var out = {{alias}}( {{alias:@stdlib/ml/base/cluster/kmeans/metric-str2enum}}( 'sqeuclidean' ) ) + 'sqeuclidean' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/docs/types/index.d.ts new file mode 100644 index 000000000000..a56042d5e22c --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/docs/types/index.d.ts @@ -0,0 +1,41 @@ +/* +* @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 KMeans distance metric string associated with a KMeans distance metric enumeration constant. +* +* @param value - enumeration constant +* @returns distance metric string +* +* @example +* var str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); +* +* var v = str2enum( 'sqeuclidean' ); +* // returns +* +* var s = enum2str( v ); +* // returns 'sqeuclidean' +*/ +declare function enum2str( value: number ): string | null; + + +// EXPORTS // + +export = enum2str; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/docs/types/test.ts new file mode 100644 index 000000000000..fe80992105ef --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/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 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/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/examples/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/examples/index.js new file mode 100644 index 000000000000..c338f68b8681 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/examples/index.js @@ -0,0 +1,30 @@ +/** +* @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( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); +var enum2str = require( './../lib' ); + +var str = enum2str( str2enum( 'cosine' ) ); +console.log( str ); +// => 'cosine' + +str = enum2str( str2enum( 'sqeuclidean' ) ); +console.log( str ); +// => 'sqeuclidean' diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/lib/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/lib/index.js new file mode 100644 index 000000000000..d08138e3b06d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/lib/index.js @@ -0,0 +1,44 @@ +/** +* @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 KMeans distance metric string associated with a KMeans distance metric enumeration constant. +* +* @module @stdlib/ml/base/cluster/kmeans/metric-enum2str +* +* @example +* var str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); +* var enum2str = require( '@stdlib/ml/base/cluster/kmeans/metric-enum2str' ); +* +* var v = str2enum( 'sqeuclidean' ); +* // returns +* +* var s = enum2str( v ); +* // returns 'sqeuclidean' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/lib/main.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/lib/main.js new file mode 100644 index 000000000000..ecdd98eab18c --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/lib/main.js @@ -0,0 +1,60 @@ +/** +* @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 isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var objectInverse = require( '@stdlib/object/inverse' ); +var enumeration = require( '@stdlib/ml/base/cluster/kmeans/metrics' ).enum; + + +// VARIABLES // + +var hash = objectInverse( enumeration(), { + 'duplicates': false +}); + + +// MAIN // + +/** +* Returns the KMeans distance metric string associated with a KMeans distance metric enumeration constant. +* +* @param {integer} value - distance metric enumeration constant +* @returns {(string|null)} distance metric string or null +* +* @example +* var str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); +* +* var v = str2enum( 'sqeuclidean' ); +* // returns +* +* var s = enum2str( v ); +* // returns 'sqeuclidean' +*/ +function enum2str( value ) { + var v = hash[ value ]; + return ( isString( v ) ) ? v : null; // note: we include this guard to prevent walking the prototype chain +} + + +// EXPORTS // + +module.exports = enum2str; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/package.json b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/package.json new file mode 100644 index 000000000000..3536718fbc15 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ml/base/cluster/kmeans/metric-enum2str", + "version": "0.0.0", + "description": "Return the KMeans distance metric string associated with a KMeans distance metric 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", + "ml", + "machine", + "learning", + "cluster", + "kmeans", + "metric", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/test/test.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/test/test.js new file mode 100644 index 000000000000..e96bc3a4571c --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/test/test.js @@ -0,0 +1,67 @@ +/** +* @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 str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); +var enum2str = require( './../lib' ); + + +// VARIABLES // + +var VALUES = [ + 'sqeuclidean', + 'cosine', + 'cityblock', + 'correlation' +]; + + +// 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 string associated with an 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 a 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(); +});