Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

-->

# resolve

> Return the clustering algorithm string associated with a supported k-means clustering algorithm value.

<!-- 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 resolve = require( '@stdlib/ml/base/kmeans/algorithm-resolve-str' );
```

#### resolve( value )

Returns the clustering algorithm string associated with a supported k-means clustering algorithm value.

```javascript
var str2enum = require( '@stdlib/ml/base/kmeans/algorithm-str2enum' );

var v = resolve( 'elkan' );
// returns 'elkan'

v = resolve( str2enum( 'elkan' ) );
// returns 'elkan'
```

If unable to resolve a k-means clustering algorithm string, the function returns `null`.

```javascript
var v = resolve( 'beep' );
// returns null
```

</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/kmeans/algorithm-str2enum' );
var resolve = require( '@stdlib/ml/base/kmeans/algorithm-resolve-str' );

var v = resolve( str2enum( 'elkan' ) );
// returns 'elkan'

v = resolve( str2enum( 'lloyd' ) );
// returns 'lloyd'
```

</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 -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
var str2enum = require( '@stdlib/ml/base/kmeans/algorithm-str2enum' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var resolve = require( './../lib' );


// MAIN //

bench( format( '%s::string', pkg ), function benchmark( b ) {
var values;
var out;
var i;

values = [
'lloyd',
'elkan'
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = resolve( values[ i%values.length ] );
if ( typeof out !== 'string' ) {
b.fail( 'should return a string' );
}
}
b.toc();
if ( !isString( out ) ) {
b.fail( 'should return a string' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::integer', pkg ), function benchmark( b ) {
var values;
var out;
var i;

values = [
str2enum( 'lloyd' ),
str2enum( 'elkan' )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = resolve( values[ i%values.length ] );
if ( typeof out !== 'string' ) {
b.fail( 'should return a string' );
}
}
b.toc();
if ( !isString( out ) ) {
b.fail( 'should return a string' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

{{alias}}( value )
Returns the clustering algorithm string associated with a supported k-means
clustering algorithm value.

Parameters
----------
value: any
Clustering algorithm value.

Returns
-------
out: string|null
Clustering algorithm string.

Examples
--------
> var out = {{alias}}( 'elkan' )
'elkan'
> out = {{alias}}( {{alias:@stdlib/ml/base/kmeans/algorithm-str2enum}}( 'elkan' ) )
'elkan'

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// TypeScript Version: 4.1

/**
* Returns the clustering algorithm string associated with a supported k-means clustering algorithm value.
*
* @param value - clustering algorithm value
* @returns clustering algorithm string or null
*
* @example
* var str2enum = require( '@stdlib/ml/base/kmeans/algorithm-str2enum' );
*
* var v = resolve( str2enum( 'elkan' ) );
* // returns 'elkan'
*/
declare function resolve( value: any ): string | null;

Check warning on line 33 in lib/node_modules/@stdlib/ml/base/kmeans/algorithm-resolve-str/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type


// EXPORTS //

export = resolve;
Original file line number Diff line number Diff line change
@@ -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
}
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/kmeans/algorithm-str2enum' );
var resolve = require( './../lib' );

var v = resolve( str2enum( 'elkan' ) );
console.log( v );
// => 'elkan'

v = resolve( str2enum( 'lloyd' ) );
console.log( v );
// => 'lloyd'
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.
*/

'use strict';

/**
* Return the clustering algorithm string associated with a supported k-means clustering algorithm value.
*
* @module @stdlib/ml/base/kmeans/algorithm-resolve-str
*
* @example
* var str2enum = require( '@stdlib/ml/base/kmeans/algorithm-str2enum' );
* var resolve = require( '@stdlib/ml/base/kmeans/algorithm-resolve-str' );
*
* var v = resolve( str2enum( 'elkan' ) );
* // returns 'elkan'
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
Loading
Loading