Skip to content

Commit 910e515

Browse files
fix: add argument validation for trials
--- 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: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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 ---
1 parent ade68cf commit 910e515

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

lib/node_modules/@stdlib/ml/strided/dkmeans-init-plus-plus/lib/dkmeans_init_plus_plus.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ var ndarray = require( './ndarray.js' );
8181
* @param {PositiveInteger} trials - number of potential centroids per iteration (>= 1)
8282
* @param {*} seed - PRNG seed
8383
* @throws {TypeError} first argument must be a valid order
84+
* @throws {TypeError} tenth argument must be a valid trials (>=1)
8485
* @throws {RangeError} sixth argument must be greater than or equal to max(1,N)
8586
* @throws {RangeError} eighth argument must be greater than or equal to max(1,N)
8687
* @returns {Float64Array} centroids
@@ -117,6 +118,9 @@ function dkmeansInitPlusPlus( order, k, M, N, out, LDO, X, LDX, metric, trials,
117118
if ( !isLayout( order ) ) {
118119
throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) );
119120
}
121+
if ( trials < 1 ) {
122+
throw new TypeError( format( 'invalid argument. Tenth argument must be a valid trials (>=1). Value: `%s`.', trials ) );
123+
}
120124
if ( isRowMajor( order ) ) {
121125
so = N;
122126
sx = N;

lib/node_modules/@stdlib/ml/strided/dkmeans-init-plus-plus/lib/ndarray.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var randu = require( '@stdlib/random/base/mt19937' ).factory;
2525
var dcopy = require( '@stdlib/blas/base/dcopy' ).ndarray;
2626
var Float64Array = require( '@stdlib/array/float64' );
2727
var PINF = require( '@stdlib/constants/float64/pinf' );
28+
var format = require( '@stdlib/string/format' );
2829
var dsquaredEuclidean = require( '@stdlib/stats/strided/distances/dsquared-euclidean' ).ndarray;
2930
var dcosine = require( '@stdlib/stats/strided/distances/dcosine-distance' ).ndarray;
3031
var dcityblock = require( '@stdlib/stats/strided/distances/dcityblock' ).ndarray;
@@ -86,6 +87,7 @@ var dcorrelation = require( '@stdlib/stats/strided/distances/dcorrelation' ).nda
8687
* @param {string} metric - distance metric
8788
* @param {PositiveInteger} trials - number of potential centroids per iteration (>= 1)
8889
* @param {*} seed - PRNG seed
90+
* @throws {TypeError} tenth argument must be a valid trials (>=1)
8991
* @returns {Float64Array} centroids
9092
*
9193
* @example
@@ -130,6 +132,10 @@ function dkmeansInitPlusPlus( k, M, N, out, so1, so2, oo, X, sx1, sx2, ox, metri
130132
var t;
131133
var r;
132134

135+
if ( trials < 1 ) {
136+
throw new TypeError( format( 'invalid argument. Thirteenth argument must be a valid trials (>=1). Value: `%s`.', trials ) );
137+
}
138+
133139
// Create seeded PRNGs:
134140
rand = randu({
135141
'seed': seed

0 commit comments

Comments
 (0)