-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add ml/base/cluster/kmeans/metric-enum2str
#10841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nakul-krishnakumar
wants to merge
2
commits into
stdlib-js:develop
Choose a base branch
from
nakul-krishnakumar:kmeans-metric-enum2str
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| <!-- | ||
|
|
||
| @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. | ||
|
|
||
| --> | ||
|
|
||
| # enum2str | ||
|
|
||
| > Return the KMeans distance metric string associated with a KMeans distance metric enumeration constant. | ||
|
|
||
| <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="intro"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.intro --> | ||
|
|
||
| <!-- Package usage documentation. --> | ||
|
|
||
| <section class="usage"> | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| var enum2str = require( '@stdlib/ml/base/cluster/kmeans/metric-enum2str' ); | ||
| ``` | ||
|
|
||
| #### enum2str( value ) | ||
|
|
||
| Returns the KMeans distance metric string associated with a KMeans distance metric enumeration constant. | ||
|
|
||
| ```javascript | ||
| var str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); | ||
|
|
||
| var v = str2enum( 'sqeuclidean' ); | ||
| // returns <number> | ||
|
|
||
| var s = enum2str( v ); | ||
| // returns 'sqeuclidean' | ||
| ``` | ||
|
|
||
| If unable to resolve a KMeans distance metric string, the function returns `null`. | ||
|
|
||
| ```javascript | ||
| var v = enum2str( -999999999 ); | ||
| // returns null | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> | ||
|
|
||
| <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="notes"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.notes --> | ||
|
|
||
| <!-- Package usage examples. --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ## Examples | ||
|
|
||
| <!-- eslint no-undef: "error" --> | ||
|
|
||
| ```javascript | ||
| var str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); | ||
| var enum2str = require( '@stdlib/ml/base/cluster/kmeans/metric-enum2str' ); | ||
|
|
||
| var str = enum2str( str2enum( 'sqeuclidean' ) ); | ||
| // returns 'sqeuclidean' | ||
|
|
||
| str = enum2str( str2enum( 'cosine' ) ); | ||
| // returns 'cosine' | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.examples --> | ||
|
|
||
| <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="references"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.references --> | ||
|
|
||
| <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
|
||
| <section class="related"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.related --> | ||
|
|
||
| <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="links"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.links --> |
57 changes: 57 additions & 0 deletions
57
lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| // MODULES // | ||
|
|
||
| var bench = require( '@stdlib/bench' ); | ||
| var isString = require( '@stdlib/assert/is-string' ).isPrimitive; | ||
| var str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); | ||
| var pkg = require( './../package.json' ).name; | ||
| var enum2str = require( './../lib' ); | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| bench( pkg, function benchmark( b ) { | ||
| var values; | ||
| var out; | ||
| var i; | ||
|
|
||
| values = [ | ||
| str2enum( 'sqeuclidean' ), | ||
| str2enum( 'cosine' ), | ||
| str2enum( 'cityblock' ), | ||
| str2enum( 'correlation' ) | ||
| ]; | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| out = enum2str( values[ i%values.length ] ); | ||
| if ( typeof out !== 'string' ) { | ||
| b.fail( 'should return a string' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( !isString( out ) ) { | ||
| b.fail( 'should return a string' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| }); |
23 changes: 23 additions & 0 deletions
23
lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/docs/repl.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
|
|
||
| {{alias}}( value ) | ||
| Returns the KMeans distance metric string associated with a KMeans | ||
| distance metric enumeration constant. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| value: integer | ||
| Distance metric enumeration constant. | ||
|
|
||
| Returns | ||
| ------- | ||
| out: string|null | ||
| Distance metric string. | ||
|
|
||
| Examples | ||
| -------- | ||
| > var out = {{alias}}( {{alias:@stdlib/ml/base/cluster/kmeans/metric-str2enum}}( 'sqeuclidean' ) ) | ||
| 'sqeuclidean' | ||
|
|
||
| See Also | ||
| -------- | ||
|
|
||
41 changes: 41 additions & 0 deletions
41
lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/docs/types/index.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // TypeScript Version: 4.1 | ||
|
|
||
| /** | ||
| * Returns the KMeans distance metric string associated with a KMeans distance metric enumeration constant. | ||
| * | ||
| * @param value - enumeration constant | ||
| * @returns distance metric string | ||
| * | ||
| * @example | ||
| * var str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); | ||
| * | ||
| * var v = str2enum( 'sqeuclidean' ); | ||
| * // returns <number> | ||
| * | ||
| * var s = enum2str( v ); | ||
| * // returns 'sqeuclidean' | ||
| */ | ||
| declare function enum2str( value: number ): string | null; | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| export = enum2str; |
39 changes: 39 additions & 0 deletions
39
lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/docs/types/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } |
30 changes: 30 additions & 0 deletions
30
lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/examples/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| var str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); | ||
| var enum2str = require( './../lib' ); | ||
|
|
||
| var str = enum2str( str2enum( 'cosine' ) ); | ||
| console.log( str ); | ||
| // => 'cosine' | ||
|
|
||
| str = enum2str( str2enum( 'sqeuclidean' ) ); | ||
| console.log( str ); | ||
| // => 'sqeuclidean' |
44 changes: 44 additions & 0 deletions
44
lib/node_modules/@stdlib/ml/base/cluster/kmeans/metric-enum2str/lib/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Return the KMeans distance metric string associated with a KMeans distance metric enumeration constant. | ||
| * | ||
| * @module @stdlib/ml/base/cluster/kmeans/metric-enum2str | ||
| * | ||
| * @example | ||
| * var str2enum = require( '@stdlib/ml/base/cluster/kmeans/metric-str2enum' ); | ||
| * var enum2str = require( '@stdlib/ml/base/cluster/kmeans/metric-enum2str' ); | ||
| * | ||
| * var v = str2enum( 'sqeuclidean' ); | ||
| * // returns <number> | ||
| * | ||
| * var s = enum2str( v ); | ||
| * // returns 'sqeuclidean' | ||
| */ | ||
|
|
||
| // MODULES // | ||
|
|
||
| var main = require( './main.js' ); | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| module.exports = main; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.