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
121 changes: 121 additions & 0 deletions lib/node_modules/@stdlib/ml/base/kmeans/metric-resolve-str/README.md
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 distance metric string associated with a supported k-means distance metric 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/metric-resolve-str' );
```

#### resolve( value )

Returns the distance metric string associated with a supported k-means distance metric value.

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

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

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

If unable to resolve a k-means distance metric 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/metric-str2enum' );
var resolve = require( '@stdlib/ml/base/kmeans/metric-resolve-str' );

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

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

</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,85 @@
/**
* @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/metric-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 = [
'sqeuclidean',
'cosine',
'correlation',
'cityblock'
];

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( 'sqeuclidean' ),
str2enum( 'cosine' ),
str2enum( 'correlation' ),
str2enum( 'cityblock' )
];

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 distance metric string associated with a supported k-means
distance metric value.

Parameters
----------
value: any
Distance metric value.

Returns
-------
out: string|null
Distance metric string.

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

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 distance metric string associated with a supported k-means distance metric value.
*
* @param value - distance metric value
* @returns distance metric string or null
*
* @example
* var str2enum = require( '@stdlib/ml/base/kmeans/metric-str2enum' );
*
* var v = resolve( str2enum( 'cosine' ) );
* // returns 'cosine'
*/
declare function resolve( value: any ): string | null;

Check warning on line 33 in lib/node_modules/@stdlib/ml/base/kmeans/metric-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( 'cosine' ); // $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/metric-str2enum' );
var resolve = require( './../lib' );

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

v = resolve( str2enum( 'sqeuclidean' ) );
console.log( v );
// => 'sqeuclidean'
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 distance metric string associated with a supported k-means distance metric value.
*
* @module @stdlib/ml/base/kmeans/metric-resolve-str
*
* @example
* var str2enum = require( '@stdlib/ml/base/kmeans/metric-str2enum' );
* var resolve = require( '@stdlib/ml/base/kmeans/metric-resolve-str' );
*
* var v = resolve( str2enum( 'cosine' ) );
* // returns 'cosine'
*/

// MODULES //

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


// EXPORTS //

module.exports = main;
Loading
Loading