From 8605a421d6d0cb99b63fa4d7db8719c0db52db47 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Thu, 14 May 2026 14:49:54 +0530 Subject: [PATCH 1/2] feat: add `ml/base/kmeans/algorithm-resolve-str` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../kmeans/algorithm-resolve-str/README.md | 121 ++++++++++++++++++ .../benchmark/benchmark.js | 81 ++++++++++++ .../docs/types/index.d.ts | 38 ++++++ .../algorithm-resolve-str/docs/types/test.ts | 28 ++++ .../algorithm-resolve-str/examples/index.js | 30 +++++ .../kmeans/algorithm-resolve-str/lib/index.js | 41 ++++++ .../kmeans/algorithm-resolve-str/lib/main.js | 55 ++++++++ .../kmeans/algorithm-resolve-str/package.json | 65 ++++++++++ .../kmeans/algorithm-resolve-str/test/test.js | 74 +++++++++++ 9 files changed, 533 insertions(+) create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/README.md create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/package.json create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/test/test.js diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/README.md b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/README.md new file mode 100644 index 000000000000..1917a9a50bbf --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/README.md @@ -0,0 +1,121 @@ + + +# resolve + +> Return the clustering algorithm string associated with a supported k-means clustering algorithm value. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var resolve = require( '@stdlib/ml/base/kmeans/algorithm-resolve-str' ); +``` + +#### resolve( value ) + +Returns the clustering algorithm string associated with a supported k-means clustering algorithm value. + +```javascript +var str2enum = require( '@stdlib/ml/base/kmeans/algorithm-str2enum' ); + +var v = resolve( 'elkan' ); +// returns 'elkan' + +v = resolve( str2enum( 'elkan' ) ); +// returns 'elkan' +``` + +If unable to resolve a k-means clustering algorithm string, the function returns `null`. + +```javascript +var v = resolve( 'beep' ); +// returns null +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var str2enum = require( '@stdlib/ml/base/kmeans/algorithm-str2enum' ); +var resolve = require( '@stdlib/ml/base/kmeans/algorithm-resolve-str' ); + +var v = resolve( str2enum( 'elkan' ) ); +// returns 'elkan' + +v = resolve( str2enum( 'lloyd' ) ); +// returns 'lloyd' +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/benchmark/benchmark.js new file mode 100644 index 000000000000..7376ad60b44b --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/benchmark/benchmark.js @@ -0,0 +1,81 @@ +/** +* @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/kmeans/algorithm-str2enum' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var resolve = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::string', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + values = [ + 'lloyd', + 'elkan' + ]; + + 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( format( '%s::integer', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + values = [ + str2enum( 'lloyd' ), + str2enum( 'elkan' ) + ]; + + 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/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/docs/types/index.d.ts new file mode 100644 index 000000000000..276dee986b95 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/docs/types/index.d.ts @@ -0,0 +1,38 @@ +/* +* @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 clustering algorithm string associated with a supported k-means clustering algorithm value. +* +* @param value - clustering algorithm value +* @returns clustering algorithm string or null +* +* @example +* var str2enum = require( '@stdlib/ml/base/kmeans/algorithm-str2enum' ); +* +* var v = resolve( str2enum( 'elkan' ) ); +* // returns 'elkan' +*/ +declare function resolve( value: any ): string | null; + + +// EXPORTS // + +export = resolve; diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/docs/types/test.ts new file mode 100644 index 000000000000..84fea09b087f --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/docs/types/test.ts @@ -0,0 +1,28 @@ +/* +* @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 resolve = require( './index' ); + + +// TESTS // + +// The function returns a string or null... +{ + resolve( 0 ); // $ExpectType string | null + resolve( 'elkan' ); // $ExpectType string | null +} diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/examples/index.js b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/examples/index.js new file mode 100644 index 000000000000..e22315828a74 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/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/kmeans/algorithm-str2enum' ); +var resolve = require( './../lib' ); + +var v = resolve( str2enum( 'elkan' ) ); +console.log( v ); +// => 'elkan' + +v = resolve( str2enum( 'lloyd' ) ); +console.log( v ); +// => 'lloyd' diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/lib/index.js b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/lib/index.js new file mode 100644 index 000000000000..f44a5cc6cdb0 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/lib/index.js @@ -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. +*/ + +'use strict'; + +/** +* Return the clustering algorithm string associated with a supported k-means clustering algorithm value. +* +* @module @stdlib/ml/base/kmeans/algorithm-resolve-str +* +* @example +* var str2enum = require( '@stdlib/ml/base/kmeans/algorithm-str2enum' ); +* var resolve = require( '@stdlib/ml/base/kmeans/algorithm-resolve-str' ); +* +* var v = resolve( str2enum( 'elkan' ) ); +* // returns 'elkan' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/lib/main.js b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/lib/main.js new file mode 100644 index 000000000000..4c94b669d19d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/lib/main.js @@ -0,0 +1,55 @@ +/** +* @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 enum2str = require( '@stdlib/ml/base/kmeans/algorithm-enum2str' ); +var str2enum = require( '@stdlib/ml/base/kmeans/algorithm-str2enum' ); + + +// MAIN // + +/** +* Returns the clustering algorithm string associated with a supported k-means clustering algorithm value. +* +* @param {*} value - clustering algorithm value +* @returns {(string|null)} clustering algorithm string or null +* +* @example +* var str2enum = require( '@stdlib/ml/base/kmeans/algorithm-str2enum' ); +* +* var v = resolve( str2enum( 'elkan' ) ); +* // returns 'elkan' +*/ +function resolve( value ) { + var t = ( typeof value ); + if ( t === 'string' ) { + return ( str2enum( value ) === null ) ? null : value; + } + if ( t === 'number' ) { + return enum2str( value ); + } + return null; +} + + +// EXPORTS // + +module.exports = resolve; diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/package.json b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/package.json new file mode 100644 index 000000000000..4f8499418c33 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/ml/base/kmeans/algorithm-resolve-str", + "version": "0.0.0", + "description": "Return the clustering algorithm string associated with a supported k-means clustering algorithm 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", + "ml", + "machine", + "learning", + "kmeans", + "algorithm", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/test/test.js b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/test/test.js new file mode 100644 index 000000000000..d77ad0e3b273 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/test/test.js @@ -0,0 +1,74 @@ +/** +* @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/kmeans/algorithm-str2enum' ); +var resolve = require( './../lib' ); + + +// VARIABLES // + +var VALUES = [ + 'lloyd', + 'elkan' +]; + + +// 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 string associated with a k-means clustering algorithm 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 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(); +}); From ded70b3e0f8afce79d1a9df6849559713b4cf010 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Thu, 14 May 2026 14:51:35 +0530 Subject: [PATCH 2/2] docs: add repl for `ml/base/kmeans/algorithm-resolve-str` --- .../algorithm-resolve-str/docs/repl.txt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/docs/repl.txt diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/docs/repl.txt new file mode 100644 index 000000000000..0d4b38e07e23 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/docs/repl.txt @@ -0,0 +1,25 @@ + +{{alias}}( value ) + Returns the clustering algorithm string associated with a supported k-means + clustering algorithm value. + + Parameters + ---------- + value: any + Clustering algorithm value. + + Returns + ------- + out: string|null + Clustering algorithm string. + + Examples + -------- + > var out = {{alias}}( 'elkan' ) + 'elkan' + > out = {{alias}}( {{alias:@stdlib/ml/base/kmeans/algorithm-str2enum}}( 'elkan' ) ) + 'elkan' + + See Also + -------- +