From 828d3ee174de3502cfbdc7a4d5e3a973c444a531 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Sat, 13 Jun 2026 20:28:40 +0530 Subject: [PATCH 1/5] feat: add `ml/base/kmeans/stats/struct-factory` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../kmeans/stats/struct-factory/README.md | 144 +++++++++++++++++ .../struct-factory/benchmark/benchmark.js | 54 +++++++ .../kmeans/stats/struct-factory/docs/repl.txt | 25 +++ .../struct-factory/docs/types/index.d.ts | 139 ++++++++++++++++ .../stats/struct-factory/docs/types/test.ts | 149 ++++++++++++++++++ .../stats/struct-factory/examples/index.js | 50 ++++++ .../kmeans/stats/struct-factory/lib/index.js | 43 +++++ .../kmeans/stats/struct-factory/lib/main.js | 78 +++++++++ .../kmeans/stats/struct-factory/package.json | 65 ++++++++ .../kmeans/stats/struct-factory/test/test.js | 140 ++++++++++++++++ 10 files changed, 887 insertions(+) create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/README.md create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/package.json create mode 100644 lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/README.md new file mode 100644 index 000000000000..aa1ac2e8d8d7 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/README.md @@ -0,0 +1,144 @@ + + +# structFactory + +> Create a new [`struct`][@stdlib/dstructs/struct] constructor tailored to a specified floating-point data type. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var structFactory = require( '@stdlib/ml/base/kmeans/stats/struct-factory' ); +``` + +#### structFactory( dtype ) + +Returns a new [`struct`][@stdlib/dstructs/struct] constructor tailored to a specified floating-point data type. + +```javascript +var Struct = structFactory( 'float64' ); +// returns + +var s = new Struct(); +// returns +``` + +The function supports the following parameters: + +- **dtype**: floating-point data type for storing floating-point results. Must be either `'float64'` or `'float32'`. + +
+ + + + + +
+ +## Notes + +- A [`struct`][@stdlib/dstructs/struct] provides a fixed-width composite data structure for storing kmeans clustering statistics and provides an ABI-stable data layout for JavaScript-C interoperation. + +
+ + + + + +
+ +## Examples + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Int32Array = require( '@stdlib/array/int32' ); +var structFactory = require( '@stdlib/ml/base/kmeans/stats/struct-factory' ); + +var Struct = structFactory( 'float64' ); +var results = new Struct({ + 'nObs': new Int32Array( [ 3, 2 ] ), + 'sumSquaredDist': new Float64Array( [ 9.998, 11.412 ] ), + 'meanSquaredDist': new Float64Array( [ 4.353, 2.897 ] ), + 'stdevSquaredDist': new Float64Array( [ 1.232, 8.913 ] ) +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); + +Struct = structFactory( 'float32' ); +results = new Struct({ + 'nObs': new Int32Array( [ 3, 2 ] ), + 'sumSquaredDist': new Float32Array( [ 9.998, 11.412 ] ), + 'meanSquaredDist': new Float32Array( [ 4.353, 2.897 ] ), + 'stdevSquaredDist': new Float32Array( [ 1.232, 8.913 ] ) +}); + +str = results.toString({ + 'format': 'linear' +}); +console.log( str ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/benchmark/benchmark.js new file mode 100644 index 000000000000..f4c4a1b9ec96 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/benchmark/benchmark.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isFunction = require( '@stdlib/assert/is-function' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 'float64', + 'float32' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = factory( values[ i%values.length ] ); + if ( typeof v !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( !isFunction( v ) ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/repl.txt new file mode 100644 index 000000000000..d551f4c65250 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/repl.txt @@ -0,0 +1,25 @@ + +{{alias}}( dtype ) + Returns a new struct constructor tailored to a specified floating-point data + type. + + Parameters + ---------- + dtype: string + Floating-point data type for storing floating-point statistics. + + Returns + ------- + fcn: Function + Struct constructor. + + Examples + -------- + > var S = {{alias}}( 'float64' ); + > var r = new S(); + > r.toString() + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/index.d.ts new file mode 100644 index 000000000000..e5a0de36d735 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/index.d.ts @@ -0,0 +1,139 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 + +/** +* Interface describing cluster statistics. +*/ +interface Statistics { + /** + * Number of observations in each cluster. + */ + nObs?: Int32Array; + + /** + * Sum of squared distance from cluster centroids. + */ + sumSquaredDist?: T; + + /** + * Mean squared distance from cluster centroids. + */ + meanSquaredDist?: T; + + /** + * Standard deviation of squared distance from cluster centroids. + */ + stdevSquaredDist?: T; +} + +/** +* Interface describing a struct data structure. +*/ +declare class Struct { + /** + * Struct constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns struct + */ + constructor( arg?: ArrayBuffer | Statistics, byteOffset?: number, byteLength?: number ); + + /** + * Number of observations in each cluster. + */ + nObs: Int32Array; + + /** + * Sum of squared distance from cluster centroids. + */ + sumSquaredDist: T; + + /** + * Mean squared distance from cluster centroids. + */ + meanSquaredDist: T; + + /** + * Standard deviation of squared distance from cluster centroids. + */ + stdevSquaredDist: T; +} + +/** +* Interface defining a struct constructor which is both "newable" and "callable". +*/ +interface StructConstructor { + /** + * Struct constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns struct + */ + new( arg?: ArrayBuffer | Statistics, byteOffset?: number, byteLength?: number ): Struct; + + /** + * Struct constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns struct + */ + ( arg?: ArrayBuffer | Statistics, byteOffset?: number, byteLength?: number ): Struct; +} + +/** +* Returns a new struct constructor tailored to a specified floating-point data type. +* +* @param dtype - floating-point data type for storing floating-point statistics +* @returns struct constructor +* +* @example +* var Struct = structFactory( 'float64' ); +* // returns +* +* var s = new Struct(); +* // returns +*/ +declare function structFactory( dtype: 'float64' ): StructConstructor; + +/** +* Returns a new struct constructor tailored to a specified floating-point data type. +* +* @param dtype - floating-point data type for storing floating-point statistics +* @returns struct constructor +* +* @example +* var Struct = structFactory( 'float32' ); +* // returns +* +* var s = new Struct(); +* // returns +*/ +declare function structFactory( dtype: 'float32' ): StructConstructor; + + +// EXPORTS // + +export = structFactory; diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts new file mode 100644 index 000000000000..3b39ecbee7c2 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts @@ -0,0 +1,149 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 structFactory = require( './index' ); + + +// TESTS // + +// The function returns a function... +{ + structFactory( 'float64' ); // $ExpectType StructConstructor + structFactory( 'float32' ); // $ExpectType StructConstructor +} + +// The compiler throws an error if not provided a supported data type... +{ + structFactory( 10 ); // $ExpectError + structFactory( true ); // $ExpectError + structFactory( false ); // $ExpectError + structFactory( null ); // $ExpectError + structFactory( undefined ); // $ExpectError + structFactory( [] ); // $ExpectError + structFactory( {} ); // $ExpectError + structFactory( ( x: number ): number => x ); // $ExpectError +} + +// The function returns a function which returns a struct object... +{ + const Struct = structFactory( 'float64' ); + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const s1 = new Struct( new ArrayBuffer( 80 ) ); // $ExpectType Struct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const s2 = new Struct( new ArrayBuffer( 80 ), 8 ); // $ExpectType Struct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const s3 = new Struct( new ArrayBuffer( 80 ), 8, 16 ); // $ExpectType Struct +} + +// The returned constructor can be invoked without `new`... +{ + const Struct = structFactory( 'float64' ); + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const s1 = Struct( new ArrayBuffer( 80 ) ); // $ExpectType Struct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const s2 = Struct( new ArrayBuffer( 80 ), 8 ); // $ExpectType Struct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const s3 = Struct( new ArrayBuffer( 80 ), 8, 16 ); // $ExpectType Struct +} + +// The results object has the expected properties (float64)... +{ + const Struct = structFactory( 'float64' ); + const s = new Struct( {} ); + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + s.nObs; // $ExpectType Int32Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + s.sumSquaredDist; // $ExpectType Float64Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + s.meanSquaredDist; // $ExpectType Float64Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + s.meanSquaredDist; // $ExpectType Float64Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + s.stdevSquaredDist; // $ExpectType Float64Array +} + +// The results object has the expected properties (float32)... +{ + const Struct = structFactory( 'float32' ); + const s = new Struct( {} ); + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + s.nObs; // $ExpectType Int32Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + s.sumSquaredDist; // $ExpectType Float32Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + s.meanSquaredDist; // $ExpectType Float32Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + s.meanSquaredDist; // $ExpectType Float32Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + s.stdevSquaredDist; // $ExpectType Float32Array +} + +// The compiler throws an error if the constructor is provided a first argument which is not an ArrayBuffer or object... +{ + const Struct = structFactory( 'float64' ); + + new Struct( 'abc' ); // $ExpectError + new Struct( 123 ); // $ExpectError + new Struct( true ); // $ExpectError + new Struct( false ); // $ExpectError + new Struct( null ); // $ExpectError + new Struct( [] ); // $ExpectError + new Struct( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the constructor is provided a second argument which is not a number... +{ + const Struct = structFactory( 'float64' ); + + new Struct( new ArrayBuffer( 80 ), 'abc' ); // $ExpectError + new Struct( new ArrayBuffer( 80 ), true ); // $ExpectError + new Struct( new ArrayBuffer( 80 ), false ); // $ExpectError + new Struct( new ArrayBuffer( 80 ), null ); // $ExpectError + new Struct( new ArrayBuffer( 80 ), [] ); // $ExpectError + new Struct( new ArrayBuffer( 80 ), {} ); // $ExpectError + new Struct( new ArrayBuffer( 80 ), ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the constructor is provided a third argument which is not a number... +{ + const Struct = structFactory( 'float64' ); + + new Struct( new ArrayBuffer( 80 ), 8, 'abc' ); // $ExpectError + new Struct( new ArrayBuffer( 80 ), 8, true ); // $ExpectError + new Struct( new ArrayBuffer( 80 ), 8, false ); // $ExpectError + new Struct( new ArrayBuffer( 80 ), 8, null ); // $ExpectError + new Struct( new ArrayBuffer( 80 ), 8, [] ); // $ExpectError + new Struct( new ArrayBuffer( 80 ), 8, {} ); // $ExpectError + new Struct( new ArrayBuffer( 80 ), 8, ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/examples/index.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/examples/index.js new file mode 100644 index 000000000000..75530ce6b68c --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/examples/index.js @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Int32Array = require( '@stdlib/array/int32' ); +var structFactory = require( './../lib' ); + +var Struct = structFactory( 'float64' ); +var results = new Struct({ + 'nObs': new Int32Array( [ 3, 2 ] ), + 'sumSquaredDist': new Float64Array( [ 9.998, 11.412 ] ), + 'meanSquaredDist': new Float64Array( [ 4.353, 2.897 ] ), + 'stdevSquaredDist': new Float64Array( [ 1.232, 8.913 ] ) +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); + +Struct = structFactory( 'float32' ); +results = new Struct({ + 'nObs': new Int32Array( [ 3, 2 ] ), + 'sumSquaredDist': new Float32Array( [ 9.998, 11.412 ] ), + 'meanSquaredDist': new Float32Array( [ 4.353, 2.897 ] ), + 'stdevSquaredDist': new Float32Array( [ 1.232, 8.913 ] ) +}); + +str = results.toString({ + 'format': 'linear' +}); +console.log( str ); diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/index.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/index.js new file mode 100644 index 000000000000..bcee018de3d9 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +/** +* Create a new struct constructor tailored to a specified floating-point data type. +* +* @module @stdlib/ml/base/kmeans/stats/struct-factory +* +* @example +* var structFactory = require( '@stdlib/ml/base/kmeans/stats/struct-factory' ); +* +* var Struct = structFactory( 'float64' ); +* // returns +* +* var s = new Struct(); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/main.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/main.js new file mode 100644 index 000000000000..957c8633514e --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/main.js @@ -0,0 +1,78 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 struct = require( '@stdlib/dstructs/struct' ); + + +// MAIN // + +/** +* Returns a new struct constructor tailored to a specified floating-point data type. +* +* @param {string} dtype - floating-point data type +* @returns {Function} struct constructor +* +* @example +* var Struct = factory( 'float64' ); +* // returns +* +* var s = new Struct(); +* // returns +*/ +function factory( dtype ) { + var schema = [ + { + 'name': 'nObs', + 'description': 'number of observations in each cluster', + 'type': 'int32', + 'length': 2, + 'castingMode': 'safe' + }, + { + 'name': 'sumSquaredDist', + 'description': 'sum of squared distances from cluster centroids', + 'type': dtype, + 'length': 2, + 'castingMode': 'mostly-safe' + }, + { + 'name': 'meanSquaredDist', + 'description': 'mean squared distance from cluster centroids', + 'type': dtype, + 'length': 2, + 'castingMode': 'mostly-safe' + }, + { + 'name': 'stdevSquaredDist', + 'description': 'standard deviation of squared distances from cluster centroids', + 'type': dtype, + 'length': 2, + 'castingMode': 'mostly-safe' + } + ]; + return struct( schema ); +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/package.json b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/package.json new file mode 100644 index 000000000000..0bb630b7b4e9 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/ml/base/kmeans/stats/struct-factory", + "version": "0.0.0", + "description": "Create a new struct constructor tailored to a specified floating-point data type.", + "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", + "stats", + "ml", + "machine learning", + "kmeans", + "utilities", + "utility", + "utils", + "util", + "struct", + "statistics" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js new file mode 100644 index 000000000000..6d0c3f8a0182 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js @@ -0,0 +1,140 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Int32Array = require( '@stdlib/array/int32' ); +var structFactory = require( './../lib' ); + + +// FUNCTIONS // + +function isSameInt32Array( a, b ) { + var i; + + for ( i = 0; i < a.length; i++ ) { + if ( a[ i ] !== b[ i ] ) { + return false; + } + } + return true; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof structFactory, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not a supported data type', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + structFactory( value ); + }; + } +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (dtype=float64)', function test( t ) { + var expected; + var actual; + var Struct; + + Struct = structFactory( 'float64' ); + t.strictEqual( typeof Struct, 'function', 'returns expected value' ); + + actual = new Struct({ + 'nObs': new Int32Array( [ 3, 2 ] ), + 'sumSquaredDist': new Float64Array( [ 9.998, 11.412 ] ), + 'meanSquaredDist': new Float64Array( [ 4.353, 2.897 ] ), + 'stdevSquaredDist': new Float64Array( [ 1.232, 8.913 ] ) + }); + + expected = { + 'nObs': new Int32Array( [ 3, 2 ] ), + 'sumSquaredDist': new Float64Array( [ 9.998, 11.412 ] ), + 'meanSquaredDist': new Float64Array( [ 4.353, 2.897 ] ), + 'stdevSquaredDist': new Float64Array( [ 1.232, 8.913 ] ) + }; + + t.strictEqual( actual instanceof Struct, true, 'returns expected value' ); + t.strictEqual( isSameInt32Array( actual.sumSquaredDist, expected.sumSquaredDist ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.sumSquaredDist, expected.sumSquaredDist ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.meanSquaredDist, expected.meanSquaredDist ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.stdevSquaredDist, expected.stdevSquaredDist ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (dtype=float32)', function test( t ) { + var expected; + var actual; + var Struct; + + Struct = structFactory( 'float32' ); + t.strictEqual( typeof Struct, 'function', 'returns expected value' ); + + actual = new Struct({ + 'nObs': new Int32Array( [ 3, 2 ] ), + 'sumSquaredDist': new Float32Array( [ 9.998, 11.412 ] ), + 'meanSquaredDist': new Float32Array( [ 4.353, 2.897 ] ), + 'stdevSquaredDist': new Float32Array( [ 1.232, 8.913 ] ) + }); + + expected = { + 'nObs': new Int32Array( [ 3, 2 ] ), + 'sumSquaredDist': new Float32Array( [ 9.998, 11.412 ] ), + 'meanSquaredDist': new Float32Array( [ 4.353, 2.897 ] ), + 'stdevSquaredDist': new Float32Array( [ 1.232, 8.913 ] ) + }; + + t.strictEqual( actual instanceof Struct, true, 'returns expected value' ); + t.strictEqual( isSameInt32Array( actual.sumSquaredDist, expected.sumSquaredDist ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.sumSquaredDist, expected.sumSquaredDist ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.meanSquaredDist, expected.meanSquaredDist ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.stdevSquaredDist, expected.stdevSquaredDist ), true, 'returns expected value' ); + t.end(); +}); From cf5fd83ddf49ebfd3c25da3a0696edd89e63957d Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Sat, 13 Jun 2026 21:00:18 +0530 Subject: [PATCH 2/5] feat: add function arg `k` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../kmeans/stats/struct-factory/README.md | 9 ++-- .../struct-factory/benchmark/benchmark.js | 4 +- .../kmeans/stats/struct-factory/docs/repl.txt | 7 +++- .../struct-factory/docs/types/index.d.ts | 10 +++-- .../stats/struct-factory/docs/types/test.ts | 34 +++++++++++---- .../stats/struct-factory/examples/index.js | 4 +- .../kmeans/stats/struct-factory/lib/index.js | 2 +- .../kmeans/stats/struct-factory/lib/main.js | 13 +++--- .../kmeans/stats/struct-factory/test/test.js | 42 ++++++++++++++++--- 9 files changed, 91 insertions(+), 34 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/README.md index aa1ac2e8d8d7..61f5d1c1e021 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/README.md +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/README.md @@ -40,12 +40,12 @@ limitations under the License. var structFactory = require( '@stdlib/ml/base/kmeans/stats/struct-factory' ); ``` -#### structFactory( dtype ) +#### structFactory( dtype, k ) Returns a new [`struct`][@stdlib/dstructs/struct] constructor tailored to a specified floating-point data type. ```javascript -var Struct = structFactory( 'float64' ); +var Struct = structFactory( 'float64', 5 ); // returns var s = new Struct(); @@ -55,6 +55,7 @@ var s = new Struct(); The function supports the following parameters: - **dtype**: floating-point data type for storing floating-point results. Must be either `'float64'` or `'float32'`. +- **k**: number of centroids. @@ -86,7 +87,7 @@ var Float32Array = require( '@stdlib/array/float32' ); var Int32Array = require( '@stdlib/array/int32' ); var structFactory = require( '@stdlib/ml/base/kmeans/stats/struct-factory' ); -var Struct = structFactory( 'float64' ); +var Struct = structFactory( 'float64', 2 ); var results = new Struct({ 'nObs': new Int32Array( [ 3, 2 ] ), 'sumSquaredDist': new Float64Array( [ 9.998, 11.412 ] ), @@ -99,7 +100,7 @@ var str = results.toString({ }); console.log( str ); -Struct = structFactory( 'float32' ); +Struct = structFactory( 'float32', 2 ); results = new Struct({ 'nObs': new Int32Array( [ 3, 2 ] ), 'sumSquaredDist': new Float32Array( [ 9.998, 11.412 ] ), diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/benchmark/benchmark.js index f4c4a1b9ec96..1d8bfd935464 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/benchmark/benchmark.js @@ -31,16 +31,18 @@ var factory = require( './../lib' ); bench( pkg, function benchmark( b ) { var values; var v; + var k; var i; values = [ 'float64', 'float32' ]; + k = 10; b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = factory( values[ i%values.length ] ); + v = factory( values[ i%values.length ], k ); if ( typeof v !== 'function' ) { b.fail( 'should return a function' ); } diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/repl.txt index d551f4c65250..878f735724f3 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/repl.txt +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( dtype ) +{{alias}}( dtype, k ) Returns a new struct constructor tailored to a specified floating-point data type. @@ -8,6 +8,9 @@ dtype: string Floating-point data type for storing floating-point statistics. + k: integer + Number of centroids. + Returns ------- fcn: Function @@ -15,7 +18,7 @@ Examples -------- - > var S = {{alias}}( 'float64' ); + > var S = {{alias}}( 'float64', 3 ); > var r = new S(); > r.toString() diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/index.d.ts index e5a0de36d735..fec61abdf5c6 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/index.d.ts @@ -107,31 +107,33 @@ interface StructConstructor { * Returns a new struct constructor tailored to a specified floating-point data type. * * @param dtype - floating-point data type for storing floating-point statistics +* @param k - number of centroids * @returns struct constructor * * @example -* var Struct = structFactory( 'float64' ); +* var Struct = structFactory( 'float64', 5 ); * // returns * * var s = new Struct(); * // returns */ -declare function structFactory( dtype: 'float64' ): StructConstructor; +declare function structFactory( dtype: 'float64', k: number ): StructConstructor; /** * Returns a new struct constructor tailored to a specified floating-point data type. * * @param dtype - floating-point data type for storing floating-point statistics +* @param k - number of centroids * @returns struct constructor * * @example -* var Struct = structFactory( 'float32' ); +* var Struct = structFactory( 'float32', 5 ); * // returns * * var s = new Struct(); * // returns */ -declare function structFactory( dtype: 'float32' ): StructConstructor; +declare function structFactory( dtype: 'float32', k: number ): StructConstructor; // EXPORTS // diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts index 3b39ecbee7c2..822162a103ab 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts @@ -23,8 +23,10 @@ import structFactory = require( './index' ); // The function returns a function... { - structFactory( 'float64' ); // $ExpectType StructConstructor - structFactory( 'float32' ); // $ExpectType StructConstructor + var k = 5; + + structFactory( 'float64', k ); // $ExpectType StructConstructor + structFactory( 'float32', k ); // $ExpectType StructConstructor } // The compiler throws an error if not provided a supported data type... @@ -41,7 +43,9 @@ import structFactory = require( './index' ); // The function returns a function which returns a struct object... { - const Struct = structFactory( 'float64' ); + var k = 5; + + const Struct = structFactory( 'float64', k ); // eslint-disable-next-line @typescript-eslint/no-unused-vars const s1 = new Struct( new ArrayBuffer( 80 ) ); // $ExpectType Struct @@ -55,7 +59,9 @@ import structFactory = require( './index' ); // The returned constructor can be invoked without `new`... { - const Struct = structFactory( 'float64' ); + var k = 5; + + const Struct = structFactory( 'float64', k ); // eslint-disable-next-line @typescript-eslint/no-unused-vars const s1 = Struct( new ArrayBuffer( 80 ) ); // $ExpectType Struct @@ -69,7 +75,9 @@ import structFactory = require( './index' ); // The results object has the expected properties (float64)... { - const Struct = structFactory( 'float64' ); + var k = 5; + + const Struct = structFactory( 'float64', k ); const s = new Struct( {} ); // eslint-disable-next-line @typescript-eslint/no-unused-expressions @@ -90,7 +98,9 @@ import structFactory = require( './index' ); // The results object has the expected properties (float32)... { - const Struct = structFactory( 'float32' ); + var k = 5; + + const Struct = structFactory( 'float32', k ); const s = new Struct( {} ); // eslint-disable-next-line @typescript-eslint/no-unused-expressions @@ -111,7 +121,9 @@ import structFactory = require( './index' ); // The compiler throws an error if the constructor is provided a first argument which is not an ArrayBuffer or object... { - const Struct = structFactory( 'float64' ); + var k = 5; + + const Struct = structFactory( 'float64', k ); new Struct( 'abc' ); // $ExpectError new Struct( 123 ); // $ExpectError @@ -124,7 +136,9 @@ import structFactory = require( './index' ); // The compiler throws an error if the constructor is provided a second argument which is not a number... { - const Struct = structFactory( 'float64' ); + var k = 5; + + const Struct = structFactory( 'float64', k ); new Struct( new ArrayBuffer( 80 ), 'abc' ); // $ExpectError new Struct( new ArrayBuffer( 80 ), true ); // $ExpectError @@ -137,7 +151,9 @@ import structFactory = require( './index' ); // The compiler throws an error if the constructor is provided a third argument which is not a number... { - const Struct = structFactory( 'float64' ); + var k = 5; + + const Struct = structFactory( 'float64', k ); new Struct( new ArrayBuffer( 80 ), 8, 'abc' ); // $ExpectError new Struct( new ArrayBuffer( 80 ), 8, true ); // $ExpectError diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/examples/index.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/examples/index.js index 75530ce6b68c..540c9a9a2050 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/examples/index.js +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/examples/index.js @@ -23,7 +23,7 @@ var Float32Array = require( '@stdlib/array/float32' ); var Int32Array = require( '@stdlib/array/int32' ); var structFactory = require( './../lib' ); -var Struct = structFactory( 'float64' ); +var Struct = structFactory( 'float64', 2 ); var results = new Struct({ 'nObs': new Int32Array( [ 3, 2 ] ), 'sumSquaredDist': new Float64Array( [ 9.998, 11.412 ] ), @@ -36,7 +36,7 @@ var str = results.toString({ }); console.log( str ); -Struct = structFactory( 'float32' ); +Struct = structFactory( 'float32', 2 ); results = new Struct({ 'nObs': new Int32Array( [ 3, 2 ] ), 'sumSquaredDist': new Float32Array( [ 9.998, 11.412 ] ), diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/index.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/index.js index bcee018de3d9..e3a6124bcf14 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/index.js +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/index.js @@ -26,7 +26,7 @@ * @example * var structFactory = require( '@stdlib/ml/base/kmeans/stats/struct-factory' ); * -* var Struct = structFactory( 'float64' ); +* var Struct = structFactory( 'float64', 5 ); * // returns * * var s = new Struct(); diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/main.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/main.js index 957c8633514e..7c82e930efb3 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/main.js +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/main.js @@ -29,43 +29,44 @@ var struct = require( '@stdlib/dstructs/struct' ); * Returns a new struct constructor tailored to a specified floating-point data type. * * @param {string} dtype - floating-point data type +* @param {NonNegativeInteger} k - number of centroids * @returns {Function} struct constructor * * @example -* var Struct = factory( 'float64' ); +* var Struct = factory( 'float64', 5 ); * // returns * * var s = new Struct(); * // returns */ -function factory( dtype ) { +function factory( dtype, k ) { var schema = [ { 'name': 'nObs', 'description': 'number of observations in each cluster', 'type': 'int32', - 'length': 2, + 'length': k, 'castingMode': 'safe' }, { 'name': 'sumSquaredDist', 'description': 'sum of squared distances from cluster centroids', 'type': dtype, - 'length': 2, + 'length': k, 'castingMode': 'mostly-safe' }, { 'name': 'meanSquaredDist', 'description': 'mean squared distance from cluster centroids', 'type': dtype, - 'length': 2, + 'length': k, 'castingMode': 'mostly-safe' }, { 'name': 'stdevSquaredDist', 'description': 'standard deviation of squared distances from cluster centroids', 'type': dtype, - 'length': 2, + 'length': k, 'castingMode': 'mostly-safe' } ]; diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js index 6d0c3f8a0182..f288e3460456 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js @@ -53,8 +53,10 @@ tape( 'main export is a function', function test( t ) { tape( 'the function throws an error if provided a first argument which is not a supported data type', function test( t ) { var values; + var k; var i; + k = 5; values = [ '5', 5, @@ -68,13 +70,43 @@ tape( 'the function throws an error if provided a first argument which is not a function noop() {} ]; for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + t.throws( badValue( values[ i ], k ), TypeError, 'throws an error when provided ' + values[ i ] ); } t.end(); - function badValue( value ) { + function badValue( value, k ) { return function badValue() { - structFactory( value ); + structFactory( value, k ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not a non negative integer', function test( t ) { + var values; + var dtype; + var i; + + dtype = 'float64'; + values = [ + '5', + -5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( dtype, values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( dtype, value ) { + return function badValue() { + structFactory( dtype, value ); }; } }); @@ -84,7 +116,7 @@ tape( 'the function returns a constructor for creating a fixed-width results obj var actual; var Struct; - Struct = structFactory( 'float64' ); + Struct = structFactory( 'float64', 2 ); t.strictEqual( typeof Struct, 'function', 'returns expected value' ); actual = new Struct({ @@ -114,7 +146,7 @@ tape( 'the function returns a constructor for creating a fixed-width results obj var actual; var Struct; - Struct = structFactory( 'float32' ); + Struct = structFactory( 'float32', 2 ); t.strictEqual( typeof Struct, 'function', 'returns expected value' ); actual = new Struct({ From 0a441785a5201225365d1c4cd75f6247c96c3e83 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Sun, 14 Jun 2026 10:42:13 +0000 Subject: [PATCH 3/5] chore: update copyright years --- .../@stdlib/ml/base/kmeans/stats/struct-factory/README.md | 2 +- .../ml/base/kmeans/stats/struct-factory/benchmark/benchmark.js | 2 +- .../ml/base/kmeans/stats/struct-factory/docs/types/index.d.ts | 2 +- .../ml/base/kmeans/stats/struct-factory/docs/types/test.ts | 2 +- .../ml/base/kmeans/stats/struct-factory/examples/index.js | 2 +- .../@stdlib/ml/base/kmeans/stats/struct-factory/lib/index.js | 2 +- .../@stdlib/ml/base/kmeans/stats/struct-factory/lib/main.js | 2 +- .../@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/README.md index 61f5d1c1e021..55f1d077ba06 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/README.md +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2025 The Stdlib Authors. +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. diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/benchmark/benchmark.js index 1d8bfd935464..ac81a9917743 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/index.d.ts index fec61abdf5c6..785b96e92fb4 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts index 822162a103ab..4e660158e9d0 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/examples/index.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/examples/index.js index 540c9a9a2050..ca5bda3b52ab 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/examples/index.js +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/index.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/index.js index e3a6124bcf14..cb6d2d98677e 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/index.js +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/main.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/main.js index 7c82e930efb3..41e936191eec 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/main.js +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js index f288e3460456..ac8294bfc1ae 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. From bde19bec0779a9a600ad1c01a1435e5a29849161 Mon Sep 17 00:00:00 2001 From: Nakul Krishnakumar Date: Fri, 19 Jun 2026 02:16:03 +0530 Subject: [PATCH 4/5] chore: update according to code review Co-authored-by: Nakul Krishnakumar Signed-off-by: Nakul Krishnakumar --- .../stats/struct-factory/docs/types/test.ts | 6 ------ .../kmeans/stats/struct-factory/test/test.js | 19 +++---------------- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts index 4e660158e9d0..7c9cb49e02e9 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/docs/types/test.ts @@ -89,9 +89,6 @@ import structFactory = require( './index' ); // eslint-disable-next-line @typescript-eslint/no-unused-expressions s.meanSquaredDist; // $ExpectType Float64Array - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - s.meanSquaredDist; // $ExpectType Float64Array - // eslint-disable-next-line @typescript-eslint/no-unused-expressions s.stdevSquaredDist; // $ExpectType Float64Array } @@ -112,9 +109,6 @@ import structFactory = require( './index' ); // eslint-disable-next-line @typescript-eslint/no-unused-expressions s.meanSquaredDist; // $ExpectType Float32Array - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - s.meanSquaredDist; // $ExpectType Float32Array - // eslint-disable-next-line @typescript-eslint/no-unused-expressions s.stdevSquaredDist; // $ExpectType Float32Array } diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js index ac8294bfc1ae..6863aab1b500 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js @@ -23,26 +23,13 @@ var tape = require( 'tape' ); var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); var isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var isEqualInt32Array = require( '@stdlib/assert/is-equal-int32array' ); var Float64Array = require( '@stdlib/array/float64' ); var Float32Array = require( '@stdlib/array/float32' ); var Int32Array = require( '@stdlib/array/int32' ); var structFactory = require( './../lib' ); -// FUNCTIONS // - -function isSameInt32Array( a, b ) { - var i; - - for ( i = 0; i < a.length; i++ ) { - if ( a[ i ] !== b[ i ] ) { - return false; - } - } - return true; -} - - // TESTS // tape( 'main export is a function', function test( t ) { @@ -134,7 +121,7 @@ tape( 'the function returns a constructor for creating a fixed-width results obj }; t.strictEqual( actual instanceof Struct, true, 'returns expected value' ); - t.strictEqual( isSameInt32Array( actual.sumSquaredDist, expected.sumSquaredDist ), true, 'returns expected value' ); + t.strictEqual( isEqualInt32Array( actual.sumSquaredDist, expected.sumSquaredDist ), true, 'returns expected value' ); t.strictEqual( isSameFloat64Array( actual.sumSquaredDist, expected.sumSquaredDist ), true, 'returns expected value' ); t.strictEqual( isSameFloat64Array( actual.meanSquaredDist, expected.meanSquaredDist ), true, 'returns expected value' ); t.strictEqual( isSameFloat64Array( actual.stdevSquaredDist, expected.stdevSquaredDist ), true, 'returns expected value' ); @@ -164,7 +151,7 @@ tape( 'the function returns a constructor for creating a fixed-width results obj }; t.strictEqual( actual instanceof Struct, true, 'returns expected value' ); - t.strictEqual( isSameInt32Array( actual.sumSquaredDist, expected.sumSquaredDist ), true, 'returns expected value' ); + t.strictEqual( isEqualInt32Array( actual.sumSquaredDist, expected.sumSquaredDist ), true, 'returns expected value' ); t.strictEqual( isSameFloat32Array( actual.sumSquaredDist, expected.sumSquaredDist ), true, 'returns expected value' ); t.strictEqual( isSameFloat32Array( actual.meanSquaredDist, expected.meanSquaredDist ), true, 'returns expected value' ); t.strictEqual( isSameFloat32Array( actual.stdevSquaredDist, expected.stdevSquaredDist ), true, 'returns expected value' ); From e7fd00434ba08aa2818252b3705b083585fd6a95 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Fri, 19 Jun 2026 02:23:55 +0530 Subject: [PATCH 5/5] test: update according to code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js index 6863aab1b500..6306b0937740 100644 --- a/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js +++ b/lib/node_modules/@stdlib/ml/base/kmeans/stats/struct-factory/test/test.js @@ -121,7 +121,7 @@ tape( 'the function returns a constructor for creating a fixed-width results obj }; t.strictEqual( actual instanceof Struct, true, 'returns expected value' ); - t.strictEqual( isEqualInt32Array( actual.sumSquaredDist, expected.sumSquaredDist ), true, 'returns expected value' ); + t.strictEqual( isEqualInt32Array( actual.nObs, expected.nObs ), true, 'returns expected value' ); t.strictEqual( isSameFloat64Array( actual.sumSquaredDist, expected.sumSquaredDist ), true, 'returns expected value' ); t.strictEqual( isSameFloat64Array( actual.meanSquaredDist, expected.meanSquaredDist ), true, 'returns expected value' ); t.strictEqual( isSameFloat64Array( actual.stdevSquaredDist, expected.stdevSquaredDist ), true, 'returns expected value' ); @@ -151,7 +151,7 @@ tape( 'the function returns a constructor for creating a fixed-width results obj }; t.strictEqual( actual instanceof Struct, true, 'returns expected value' ); - t.strictEqual( isEqualInt32Array( actual.sumSquaredDist, expected.sumSquaredDist ), true, 'returns expected value' ); + t.strictEqual( isEqualInt32Array( actual.nObs, expected.nObs ), true, 'returns expected value' ); t.strictEqual( isSameFloat32Array( actual.sumSquaredDist, expected.sumSquaredDist ), true, 'returns expected value' ); t.strictEqual( isSameFloat32Array( actual.meanSquaredDist, expected.meanSquaredDist ), true, 'returns expected value' ); t.strictEqual( isSameFloat32Array( actual.stdevSquaredDist, expected.stdevSquaredDist ), true, 'returns expected value' );