From b192cb07d6059c33c576dd5e8c94f169ce060aa1 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Sat, 7 Mar 2026 12:01:46 +0530 Subject: [PATCH] feat: add `ml/cluster/base/kmeans/algorithms` --- .../kmeans/algorithm-enum2str/README.md | 121 ++++++++++++ .../algorithm-enum2str/benchmark/benchmark.js | 55 ++++++ .../kmeans/algorithm-enum2str/docs/repl.txt | 23 +++ .../algorithm-enum2str/docs/types/index.d.ts | 41 ++++ .../algorithm-enum2str/docs/types/test.ts | 39 ++++ .../algorithm-enum2str/examples/index.js | 30 +++ .../kmeans/algorithm-enum2str/lib/index.js | 44 +++++ .../kmeans/algorithm-enum2str/lib/main.js | 60 ++++++ .../kmeans/algorithm-enum2str/package.json | 66 +++++++ .../kmeans/algorithm-enum2str/test/test.js | 65 ++++++ .../kmeans/algorithm-resolve-enum/README.md | 124 ++++++++++++ .../benchmark/benchmark.js | 81 ++++++++ .../algorithm-resolve-enum/docs/repl.txt | 29 +++ .../docs/types/index.d.ts | 40 ++++ .../algorithm-resolve-enum/docs/types/test.ts | 28 +++ .../algorithm-resolve-enum/examples/index.js | 29 +++ .../algorithm-resolve-enum/lib/index.js | 40 ++++ .../kmeans/algorithm-resolve-enum/lib/main.js | 57 ++++++ .../algorithm-resolve-enum/package.json | 66 +++++++ .../algorithm-resolve-enum/test/test.js | 74 +++++++ .../kmeans/algorithm-resolve-str/README.md | 121 ++++++++++++ .../benchmark/benchmark.js | 81 ++++++++ .../algorithm-resolve-str/docs/repl.txt | 25 +++ .../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 | 66 +++++++ .../kmeans/algorithm-resolve-str/test/test.js | 74 +++++++ .../kmeans/algorithm-str2enum/README.md | 119 +++++++++++ .../algorithm-str2enum/benchmark/benchmark.js | 54 +++++ .../kmeans/algorithm-str2enum/docs/repl.txt | 27 +++ .../algorithm-str2enum/docs/types/index.d.ts | 40 ++++ .../algorithm-str2enum/docs/types/test.ts | 39 ++++ .../algorithm-str2enum/examples/index.js | 29 +++ .../kmeans/algorithm-str2enum/lib/index.js | 40 ++++ .../kmeans/algorithm-str2enum/lib/main.js | 56 ++++++ .../kmeans/algorithm-str2enum/package.json | 66 +++++++ .../kmeans/algorithm-str2enum/test/test.js | 66 +++++++ .../base/cluster/kmeans/algorithms/README.md | 186 ++++++++++++++++++ .../kmeans/algorithms/benchmark/benchmark.js | 48 +++++ .../cluster/kmeans/algorithms/docs/repl.txt | 22 +++ .../kmeans/algorithms/docs/types/index.d.ts | 35 ++++ .../kmeans/algorithms/docs/types/test.ts | 32 +++ .../kmeans/algorithms/examples/index.js | 36 ++++ .../ml/cluster/base/kmeans/algorithms.h | 33 ++++ .../cluster/kmeans/algorithms/lib/data.json | 4 + .../cluster/kmeans/algorithms/lib/enum.js | 51 +++++ .../cluster/kmeans/algorithms/lib/index.js | 47 +++++ .../cluster/kmeans/algorithms/lib/main.js | 44 +++++ .../cluster/kmeans/algorithms/manifest.json | 36 ++++ .../cluster/kmeans/algorithms/package.json | 67 +++++++ .../cluster/kmeans/algorithms/test/test.js | 73 +++++++ 54 files changed, 2921 insertions(+) create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/README.md create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/package.json create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/test/test.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/README.md create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/package.json create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/test/test.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/README.md create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/package.json create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/test/test.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/README.md create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/package.json create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/test/test.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/README.md create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/include/stdlib/ml/cluster/base/kmeans/algorithms.h create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/data.json create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/enum.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/manifest.json create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/package.json create mode 100644 lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/test/test.js diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/README.md b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/README.md new file mode 100644 index 000000000000..9695974bd6dd --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/README.md @@ -0,0 +1,121 @@ + + +# enum2str + +> Return the KMeans clustering algorithm string associated with a KMeans clustering algorithm enumeration constant. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var enum2str = require( '@stdlib/ml/base/cluster/kmeans/algorithm-enum2str' ); +``` + +#### enum2str( value ) + +Returns the KMeans clustering algorithm string associated with a KMeans clustering algorithm enumeration constant. + +```javascript +var str2enum = require( '@stdlib/ml/base/cluster/kmeans/algorithm-str2enum' ); + +var v = str2enum( 'lloyd' ); +// returns + +var s = enum2str( v ); +// returns 'lloyd' +``` + +If unable to resolve a KMeans clustering algorithm string, the function returns `null`. + +```javascript +var v = enum2str( -999999999 ); +// returns null +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var str2enum = require( '@stdlib/ml/base/cluster/kmeans/algorithm-str2enum' ); +var enum2str = require( '@stdlib/ml/base/cluster/kmeans/algorithm-enum2str' ); + +var str = enum2str( str2enum( 'lloyd' ) ); +// returns 'lloyd' + +str = enum2str( str2enum( 'elkan' ) ); +// returns 'elkan' +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/benchmark/benchmark.js new file mode 100644 index 000000000000..df439bd396f0 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/benchmark/benchmark.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 bench = require( '@stdlib/bench' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var str2enum = require( '@stdlib/ml/base/cluster/kmeans/algorithm-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( 'lloyd' ), + str2enum( 'elkan' ) + ]; + + 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/algorithm-enum2str/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/docs/repl.txt new file mode 100644 index 000000000000..d690d2aeccc2 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/docs/repl.txt @@ -0,0 +1,23 @@ + +{{alias}}( value ) + Returns the KMeans clustering algorithm string associated with a KMeans + clustering algorithm enumeration constant. + + Parameters + ---------- + value: integer + Clustering algorithm enumeration constant. + + Returns + ------- + out: string|null + Clustering algorithm string. + + Examples + -------- + > var out = {{alias}}( {{alias:@stdlib/ml/base/cluster/kmeans/algorithm-str2enum}}( 'lloyd' ) ) + 'lloyd' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/docs/types/index.d.ts new file mode 100644 index 000000000000..2a49201baa3e --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-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 clustering algorithm string associated with a KMeans clustering algorithm enumeration constant. +* +* @param value - enumeration constant +* @returns clustering algorithm string +* +* @example +* var str2enum = require( '@stdlib/ml/base/cluster/kmeans/algorithm-str2enum' ); +* +* var v = str2enum( 'lloyd' ); +* // returns +* +* var s = enum2str( v ); +* // returns 'lloyd' +*/ +declare function enum2str( value: number ): string | null; + + +// EXPORTS // + +export = enum2str; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/docs/types/test.ts new file mode 100644 index 000000000000..fe80992105ef --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-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/algorithm-enum2str/examples/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/examples/index.js new file mode 100644 index 000000000000..b3db3661c12a --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-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/algorithm-str2enum' ); +var enum2str = require( './../lib' ); + +var str = enum2str( str2enum( 'elkan' ) ); +console.log( str ); +// => 'elkan' + +str = enum2str( str2enum( 'lloyd' ) ); +console.log( str ); +// => 'lloyd' diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/lib/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/lib/index.js new file mode 100644 index 000000000000..68fb98fd1aea --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-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 clustering algorithm string associated with a KMeans clustering algorithm enumeration constant. +* +* @module @stdlib/ml/base/cluster/kmeans/algorithm-enum2str +* +* @example +* var str2enum = require( '@stdlib/ml/base/cluster/kmeans/algorithm-str2enum' ); +* var enum2str = require( '@stdlib/ml/base/cluster/kmeans/algorithm-enum2str' ); +* +* var v = str2enum( 'lloyd' ); +* // returns +* +* var s = enum2str( v ); +* // returns 'lloyd' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/lib/main.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/lib/main.js new file mode 100644 index 000000000000..3b4d10b8e3c7 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-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/algorithms' ).enum; + + +// VARIABLES // + +var hash = objectInverse( enumeration(), { + 'duplicates': false +}); + + +// MAIN // + +/** +* Returns the KMeans clustering algorithm string associated with a KMeans clustering algorithm enumeration constant. +* +* @param {integer} value - clustering algorithm enumeration constant +* @returns {(string|null)} clustering algorithm string or null +* +* @example +* var str2enum = require( '@stdlib/ml/base/cluster/kmeans/algorithm-str2enum' ); +* +* var v = str2enum( 'lloyd' ); +* // returns +* +* var s = enum2str( v ); +* // returns 'lloyd' +*/ +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/algorithm-enum2str/package.json b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/package.json new file mode 100644 index 000000000000..f86e908733ef --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ml/base/cluster/kmeans/algorithm-enum2str", + "version": "0.0.0", + "description": "Return the KMeans clustering algorithm string associated with a KMeans clustering algorithm 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", + "algorithm", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/test/test.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/test/test.js new file mode 100644 index 000000000000..5a13af0af6b5 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-enum2str/test/test.js @@ -0,0 +1,65 @@ +/** +* @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/algorithm-str2enum' ); +var enum2str = require( './../lib' ); + + +// VARIABLES // + +var VALUES = [ + 'lloyd', + 'elkan' +]; + + +// 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(); +}); diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/README.md b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/README.md new file mode 100644 index 000000000000..0fd2b5b23cc7 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/README.md @@ -0,0 +1,124 @@ + + +# resolve + +> Return the enumeration constant associated with a supported KMeans clustering algorithm value. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var resolve = require( '@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum' ); +``` + +#### resolve( value ) + +Returns the enumeration constant associated with a KMeans clustering algorithm value. + +```javascript +var str2enum = require( '@stdlib/ml/base/cluster/kmeans/algorithm-str2enum' ); + +var v = resolve( 'lloyd' ); +// returns + +v = resolve( str2enum( 'elkan' ) ); +// 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., `LLOYD == 0`). Instead, the function should be used in an opaque manner. + +
+ + + + + +
+ +## Examples + + + +```javascript +var resolve = require( '@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum' ); + +var v = resolve( 'lloyd' ); +// returns + +v = resolve( 'elkan' ); +// returns +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/benchmark/benchmark.js new file mode 100644 index 000000000000..dd9731209440 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/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 isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var str2enum = require( '@stdlib/ml/base/cluster/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 !== '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( 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 !== '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/algorithm-resolve-enum/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/docs/repl.txt new file mode 100644 index 000000000000..c56f89b21327 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/docs/repl.txt @@ -0,0 +1,29 @@ + +{{alias}}( value ) + Returns the enumeration constant associated with a supported KMeans + clustering algorithm value. + + Downstream consumers of this function should *not* rely on specific integer + values (e.g., `LLOYD == 0`). Instead, the function should be used in an + opaque manner. + + Parameters + ---------- + value: any + Clustering algorithm value. + + Returns + ------- + out: integer|null + Enumeration constant. + + Examples + -------- + > var out = {{alias}}( 'lloyd' ) + + > out = {{alias}}( {{alias:@stdlib/ml/base/cluster/kmeans/algorithm-str2enum}}( 'lloyd' ) ) + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/docs/types/index.d.ts new file mode 100644 index 000000000000..606a4b64e9c2 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/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 clustering algorithm value. +* +* ## Notes +* +* - Downstream consumers of this function should **not** rely on specific integer values (e.g., `LLOYD == 0`). Instead, the function should be used in an opaque manner. +* +* @param value - clustering algorithm value +* @returns enumeration constant +* +* @example +* var v = resolve( 'lloyd' ); +* // returns +*/ +declare function resolve( value: any ): number | null; + + +// EXPORTS // + +export = resolve; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/docs/types/test.ts new file mode 100644 index 000000000000..70a9aa2ce477 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/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 number or null... +{ + resolve( 0 ); // $ExpectType number | null + resolve( 'lloyd' ); // $ExpectType number | null +} diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/examples/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/examples/index.js new file mode 100644 index 000000000000..95b5dedd82bb --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/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 resolve = require( './../lib' ); + +var v = resolve( 'lloyd' ); +console.log( v ); +// => + +v = resolve( 'elkan' ); +console.log( v ); +// => diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/lib/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/lib/index.js new file mode 100644 index 000000000000..6b4c09fa1a94 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/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 supported KMeans clustering algorithm value. +* +* @module @stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum +* +* @example +* var resolve = require( '@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum' ); +* +* var v = resolve( 'lloyd' ); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/lib/main.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/lib/main.js new file mode 100644 index 000000000000..39c50bbb7aa6 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/lib/main.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 enum2str = require( '@stdlib/ml/base/cluster/kmeans/algorithm-enum2str' ); +var str2enum = require( '@stdlib/ml/base/cluster/kmeans/algorithm-str2enum' ); + + +// MAIN // + +/** +* Returns the enumeration constant associated with a supported KMeans clustering algorithm value. +* +* ## Notes +* +* - Downstream consumers of this function should **not** rely on specific integer values (e.g., `LLOYD == 0`). Instead, the function should be used in an opaque manner. +* +* @param {*} value - clustering algorithm value +* @returns {(integer|null)} enumeration constant or null +* +* @example +* var v = resolve( 'lloyd' ); +* // returns +*/ +function resolve( value ) { + var t = ( typeof value ); + if ( t === 'number' ) { + return ( enum2str( value ) ) ? value : null; + } + if ( t === 'string' ) { + return str2enum( value ); + } + return null; +} + + +// EXPORTS // + +module.exports = resolve; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/package.json b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/package.json new file mode 100644 index 000000000000..91ec718753bd --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum", + "version": "0.0.0", + "description": "Return the enumeration constant associated with a supported KMeans 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", + "cluster", + "kmeans", + "algorithm", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/test/test.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/test/test.js new file mode 100644 index 000000000000..7a427e136cd4 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-enum/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/cluster/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 enumeration constant associated with a KMeans 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 ] ), 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/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/README.md b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/README.md new file mode 100644 index 000000000000..0bb25a94936e --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/README.md @@ -0,0 +1,121 @@ + + +# resolve + +> Return the clustering algorithm string associated with a supported KMeans clustering algorithm value. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var resolve = require( '@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str' ); +``` + +#### resolve( value ) + +Returns the clustering algorithm string associated with a KMeans clustering algorithm value. + +```javascript +var str2enum = require( '@stdlib/ml/base/cluster/kmeans/algorithm-str2enum' ); + +var v = resolve( 'elkan' ); +// returns 'elkan' + +v = resolve( str2enum( 'elkan' ) ); +// returns 'elkan' +``` + +If unable to resolve a KMeans clustering algorithm string, the function returns `null`. + +```javascript +var v = resolve( 'beep' ); +// returns null +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var str2enum = require( '@stdlib/ml/base/cluster/kmeans/algorithm-str2enum' ); +var resolve = require( '@stdlib/ml/base/cluster/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/cluster/kmeans/algorithm-resolve-str/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/benchmark/benchmark.js new file mode 100644 index 000000000000..3234b82def6a --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/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/cluster/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/cluster/kmeans/algorithm-resolve-str/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/docs/repl.txt new file mode 100644 index 000000000000..22afaad9c03f --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/docs/repl.txt @@ -0,0 +1,25 @@ + +{{alias}}( value ) + Returns the clustering algorithm string associated with a supported KMeans + 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/cluster/kmeans/algorithm-str2enum}}( 'elkan' ) ) + 'elkan' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/docs/types/index.d.ts new file mode 100644 index 000000000000..807810680e9d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/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 KMeans clustering algorithm value. +* +* @param value - clustering algorithm value +* @returns clustering algorithm string +* +* @example +* var str2enum = require( '@stdlib/ml/base/cluster/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/cluster/kmeans/algorithm-resolve-str/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/docs/types/test.ts new file mode 100644 index 000000000000..84fea09b087f --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/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/cluster/kmeans/algorithm-resolve-str/examples/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/examples/index.js new file mode 100644 index 000000000000..37cef4a66794 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/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/cluster/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/cluster/kmeans/algorithm-resolve-str/lib/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/lib/index.js new file mode 100644 index 000000000000..ed99666b577a --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/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 KMeans clustering algorithm value. +* +* @module @stdlib/ml/base/cluster/kmeans/algorithm-resolve-str +* +* @example +* var str2enum = require( '@stdlib/ml/base/cluster/kmeans/algorithm-str2enum' ); +* var resolve = require( '@stdlib/ml/base/cluster/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/cluster/kmeans/algorithm-resolve-str/lib/main.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/lib/main.js new file mode 100644 index 000000000000..d990f047d3a7 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/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/cluster/kmeans/algorithm-enum2str' ); +var str2enum = require( '@stdlib/ml/base/cluster/kmeans/algorithm-str2enum' ); + + +// MAIN // + +/** +* Returns the clustering algorithm string associated with a supported KMeans clustering algorithm value. +* +* @param {*} value - clustering algorithm value +* @returns {(string|null)} clustering algorithm string or null +* +* @example +* var str2enum = require( '@stdlib/ml/base/cluster/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/cluster/kmeans/algorithm-resolve-str/package.json b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/package.json new file mode 100644 index 000000000000..ecb61af282c1 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str", + "version": "0.0.0", + "description": "Return the clustering algorithm string associated with a supported KMeans 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", + "cluster", + "kmeans", + "algorithm", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/test/test.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-resolve-str/test/test.js new file mode 100644 index 000000000000..80649c7ccade --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/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/cluster/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 KMeans 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(); +}); diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/README.md b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/README.md new file mode 100644 index 000000000000..770ca03dee3e --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/README.md @@ -0,0 +1,119 @@ + + +# str2enum + +> Return the enumeration constant associated with a KMeans clustering algorithm string. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var str2enum = require( '@stdlib/ml/base/cluster/kmeans/algorithm-str2enum' ); +``` + +#### str2enum( algorithms ) + +Returns the enumeration constant associated with a KMeans clustering algorithm string. + +```javascript +var v = str2enum( 'elkan' ); +// 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., `LLOYD == 0`). Instead, the function should be used in an opaque manner. + +
+ + + + + +
+ +## Examples + + + +```javascript +var str2enum = require( '@stdlib/ml/base/cluster/kmeans/algorithm-str2enum' ); + +var v = str2enum( 'elkan' ); +// returns + +v = str2enum( 'lloyd' ); +// returns +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/benchmark/benchmark.js new file mode 100644 index 000000000000..9b7356a2a5a4 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/benchmark/benchmark.js @@ -0,0 +1,54 @@ +/** +* @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 = [ + 'elkan', + 'lloyd' + ]; + + 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/algorithm-str2enum/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/docs/repl.txt new file mode 100644 index 000000000000..52a5557d7fc8 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/docs/repl.txt @@ -0,0 +1,27 @@ + +{{alias}}( algorithms ) + Returns the enumeration constant associated with a KMeans clustering + algorithm string. + + Downstream consumers of this function should *not* rely on specific integer + values (e.g., `LLOYD == 0`). Instead, the function should be used in an + opaque manner. + + Parameters + ---------- + algorithms: string + Clustering algorithm. + + Returns + ------- + out: integer|null + Enumeration constant. + + Examples + -------- + > var out = {{alias}}( 'elkan' ) + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/docs/types/index.d.ts new file mode 100644 index 000000000000..ece940e29bc0 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-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 clustering algorithm string. +* +* ## Notes +* +* - Downstream consumers of this function should **not** rely on specific integer values (e.g., `LLOYD == 0`). Instead, the function should be used in an opaque manner. +* +* @param algorithms - clustering algorithm string +* @returns enumeration constant +* +* @example +* var v = str2enum( 'elkan' ); +* // returns +*/ +declare function str2enum( algorithms: string ): number | null; + + +// EXPORTS // + +export = str2enum; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/docs/types/test.ts new file mode 100644 index 000000000000..ce603b6b7090 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-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( 'elkan' ); // $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/algorithm-str2enum/examples/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/examples/index.js new file mode 100644 index 000000000000..70ff04accc9f --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-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( 'elkan' ); +console.log( v ); +// => + +v = str2enum( 'lloyd' ); +console.log( v ); +// => diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/lib/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/lib/index.js new file mode 100644 index 000000000000..a3de3abbb9d9 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-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 clustering algorithm string. +* +* @module @stdlib/ml/base/cluster/kmeans/algorithm-str2enum +* +* @example +* var str2enum = require( '@stdlib/ml/base/cluster/kmeans/algorithm-str2enum' ); +* +* var v = str2enum( 'elkan' ); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/lib/main.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/lib/main.js new file mode 100644 index 000000000000..91239b247fa3 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-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/algorithms' ).enum; + + +// VARIABLES // + +var ENUM = enumeration(); + + +// MAIN // + +/** +* Returns the enumeration constant associated with a KMeans clustering algorithm string. +* +* ## Notes +* +* - Downstream consumers of this function should **not** rely on specific integer values (e.g., `LLOYD == 0`). Instead, the function should be used in an opaque manner. +* +* @param {string} algorithms - clustering algorithm string +* @returns {(integer|null)} integer value or null +* +* @example +* var v = str2enum( 'elkan' ); +* // returns +*/ +function str2enum( algorithms ) { + var v = ENUM[ algorithms ]; + 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/algorithm-str2enum/package.json b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/package.json new file mode 100644 index 000000000000..52233c05440a --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ml/base/cluster/kmeans/algorithm-str2enum", + "version": "0.0.0", + "description": "Return the enumeration constant associated with a KMeans clustering algorithm 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", + "algorithm", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/test/test.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/test/test.js new file mode 100644 index 000000000000..49863bfbd250 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithm-str2enum/test/test.js @@ -0,0 +1,66 @@ +/** +* @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/algorithm-enum2str' ); +var str2enum = require( './../lib' ); + + +// VARIABLES // + +var VALUES = [ + 'elkan', + 'lloyd' +]; + + +// 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(); +}); diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/README.md b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/README.md new file mode 100644 index 000000000000..0eecdf005729 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/README.md @@ -0,0 +1,186 @@ + + +# Clustering Algorithms + +> KMeans clustering algorithms. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var algorithms = require( '@stdlib/ml/base/cluster/kmeans/algorithms' ); +``` + +#### algorithms() + +Returns a list of KMeans clustering algorithms. + +```javascript +var out = algorithms(); +// e.g., returns [ 'lloyd', 'elkan' ] +``` + +The output array contains the following algorithms: + +- `lloyd`: classic EM-style algorithm. +- `elkan`: optimized algorithm using triangle inequality. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var algorithms = require( '@stdlib/ml/base/cluster/kmeans/algorithms' ); + +var isAlgorithm = contains( algorithms() ); + +var bool = isAlgorithm( 'lloyd' ); +// returns true + +bool = isAlgorithm( 'elkan' ); +// returns true + +bool = isAlgorithm( 'beep' ); +// returns false +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/ml/base/cluster/kmeans/algorithms.h" +``` + +#### STDLIB_ML_CLUSTER_KMEANS_ALGORITHM + +An enumeration of KMeans clustering algorithms with the following fields: + +- **STDLIB_ML_CLUSTER_KMEANS_LLOYD**: classic EM-style algorithm. +- **STDLIB_ML_CLUSTER_KMEANS_ELKAN**: optimized algorithm using triangle inequality. + +```c +#include "stdlib/ml/base/cluster/kmeans/algorithms.h" + +const enum STDLIB_ML_CLUSTER_KMEANS_ALGORITHM v = STDLIB_ML_CLUSTER_KMEANS_LLOYD; +``` + +
+ + + + + +
+ +### Notes + +- Enumeration constants should be considered opaque values, and one should **not** rely on specific integer values. + +
+ + + + + +
+ +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/benchmark/benchmark.js new file mode 100644 index 000000000000..1c08c06dd2c3 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/benchmark/benchmark.js @@ -0,0 +1,48 @@ +/** +* @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 isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var pkg = require( './../package.json' ).name; +var algorithms = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = algorithms(); + if ( out.length < 2 ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isStringArray( out ) ) { + b.fail( 'should return an array of strings' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/docs/repl.txt new file mode 100644 index 000000000000..57e347ab73ee --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/docs/repl.txt @@ -0,0 +1,22 @@ + +{{alias}}() + Returns a list of clustering algorithms. + + The output array contains the following algorithms: + + - lloyd: classic EM-style algorithm. + - elkan: optimized algorithm using triangle inequality. + + Returns + ------- + out: Array + List of algorithms. + + Examples + -------- + > var out = {{alias}}() + [ 'lloyd', 'elkan' ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/docs/types/index.d.ts new file mode 100644 index 000000000000..29ec2420b102 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/docs/types/index.d.ts @@ -0,0 +1,35 @@ +/* +* @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 a list of clustering algorithms. +* +* @returns list of clustering algorithms +* +* @example +* var list = algorithms(); +* // e.g., returns [ 'lloyd', 'elkan' ] +*/ +declare function algorithms(): Array; + + +// EXPORTS // + +export = algorithms; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/docs/types/test.ts new file mode 100644 index 000000000000..d2c24ff02a3d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/docs/types/test.ts @@ -0,0 +1,32 @@ +/* +* @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 algorithms = require( './index' ); + + +// TESTS // + +// The function returns an array of strings... +{ + algorithms(); // $ExpectType string[] +} + +// The compiler throws an error if the function is provided any arguments... +{ + algorithms( 9 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/examples/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/examples/index.js new file mode 100644 index 000000000000..346f224f9b00 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/examples/index.js @@ -0,0 +1,36 @@ +/** +* @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 contains = require( '@stdlib/array/base/assert/contains' ).factory; +var algorithms = require( './../lib' ); + +var isAlternative = contains( algorithms() ); + +var bool = isAlternative( 'lloyd' ); +console.log( bool ); +// => true + +bool = isAlternative( 'elkan' ); +console.log( bool ); +// => true + +bool = isAlternative( 'beep' ); +console.log( bool ); +// => false diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/include/stdlib/ml/cluster/base/kmeans/algorithms.h b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/include/stdlib/ml/cluster/base/kmeans/algorithms.h new file mode 100644 index 000000000000..497b1fba3979 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/include/stdlib/ml/cluster/base/kmeans/algorithms.h @@ -0,0 +1,33 @@ +/** +* @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. +*/ + +#ifndef STDLIB_ML_BASE_CLUSTER_KMEANS_ALGORITHMS_H +#define STDLIB_ML_BASE_CLUSTER_KMEANS_ALGORITHMS_H + +/** +* Enumeration of clustering algorithms. +*/ +enum STDLIB_ML_CLUSTER_KMEANS_ALGORITHMS { + // Classic EM-style algorithm: + STDLIB_ML_CLUSTER_KMEANS_LLOYD = 0, + + // Optimized algorithm using triangle inequality: + STDLIB_ML_CLUSTER_KMEANS_ELKAN, +}; + +#endif // !STDLIB_ML_BASE_CLUSTER_KMEANS_ALGORITHMS_H diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/data.json b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/data.json new file mode 100644 index 000000000000..a29165499031 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/data.json @@ -0,0 +1,4 @@ +[ + "lloyd", + "elkan" +] diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/enum.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/enum.js new file mode 100644 index 000000000000..68157ba33663 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/enum.js @@ -0,0 +1,51 @@ +/** +* @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'; + +// MAIN // + +/** +* Returns an object mapping supported algorithms to integer values for purposes of C inter-operation. +* +* ## Notes +* +* - Downstream consumers of this mapping should **not** rely on specific integer values (e.g., `LLOYD == 0`). Instead, the object should be used in an opaque manner. +* - The main purpose of this function is JavaScript and C inter-operation. +* +* @returns {Object} object mapping supported algorithms to integer values +* +* @example +* var table = enumerated(); +* // returns +*/ +function enumerated() { + // NOTE: the following should match the C `algorithms.h` enumeration!!!! + return { + // Classic EM-style algorithm: + 'lloyd': 0, + + // Optimized algorithm using triangle inequality: + 'elkan': 1 + }; +} + + +// EXPORTS // + +module.exports = enumerated; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/index.js new file mode 100644 index 000000000000..96023c90d007 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/index.js @@ -0,0 +1,47 @@ +/** +* @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 a list of KMeans clustering algorithms. +* +* @module @stdlib/ml/base/cluster/kmeans/algorithms +* +* @example +* var algorithms = require( '@stdlib/ml/base/cluster/kmeans/algorithms' ); +* +* var list = algorithms(); +* // e.g., returns [ 'lloyd', 'elkan' ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var enumeration = require( './enum.js' ); + + +// MAIN // + +setReadOnly( main, 'enum', enumeration ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/main.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/main.js new file mode 100644 index 000000000000..aad9cd45c3c0 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/lib/main.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'; + +// MODULES // + +var DATA = require( './data.json' ); + + +// MAIN // + +/** +* Returns a list of KMeans clustering algorithms. +* +* @returns {StringArray} list of clustering algorithms +* +* @example +* var list = algorithms(); +* // e.g., returns [ 'lloyd', 'elkan' ] +*/ +function algorithms() { + return DATA.slice(); +} + + +// EXPORTS // + +module.exports = algorithms; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/manifest.json b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/manifest.json new file mode 100644 index 000000000000..844d692f6439 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/package.json b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/package.json new file mode 100644 index 000000000000..b4f34385b3dd --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/ml/base/cluster/kmeans/algorithms", + "version": "0.0.0", + "description": "KMeans clustering algorithms.", + "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", + "include": "./include", + "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", + "algorithms", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/test/test.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/test/test.js new file mode 100644 index 000000000000..66ef5f471229 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/algorithms/test/test.js @@ -0,0 +1,73 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var algorithms = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof algorithms, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a list of algorithms', function test( t ) { + var expected; + var actual; + + expected = [ + 'lloyd', + 'elkan' + ]; + actual = algorithms(); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main function is an `enum` method to return an object mapping algorithms to integer values for C inter-operation', function test( t ) { + var obj; + var o; + var i; + + t.strictEqual( hasOwnProp( algorithms, 'enum' ), true, 'has property' ); + t.strictEqual( typeof algorithms.enum, 'function', 'has method' ); + + obj = algorithms.enum(); + t.strictEqual( typeof obj, 'object', 'returns expected value type' ); + + // List of values which should be supported... + o = [ + 'lloyd', + 'elkan' + ]; + for ( i = 0; i < o.length; i++ ) { + t.strictEqual( hasOwnProp( obj, o[ i ] ), true, 'has property `' + o[ i ] + '`' ); + t.strictEqual( isNonNegativeInteger( obj[ o[i] ] ), true, 'returns expected value' ); + } + + t.end(); +});