Skip to content
Draft
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
37 changes: 18 additions & 19 deletions lib/node_modules/@stdlib/ml/incr/kmeans/lib/euclidean.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* 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.
Expand All @@ -20,7 +20,16 @@

// MODULES //

var sqrt = require( '@stdlib/math/base/special/sqrt' );
var dnrm2 = require( '@stdlib/blas/base/dnrm2' );
var dcopy = require( '@stdlib/blas/base/dcopy' );
var daxpy = require( '@stdlib/blas/base/daxpy' );
var Float64Array = require( '@stdlib/array/float64' );


// VARIABLES //

// to compute X + (-1)*Y

Check warning on line 31 in lib/node_modules/@stdlib/ml/incr/kmeans/lib/euclidean.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Comments should begin with an uppercase character
var ALPHA = -1;


// MAIN //
Expand All @@ -38,23 +47,13 @@
* @param {NonNegativeInteger} offsetY - index offset
* @returns {number} Euclidean distance
*/
function euclidean( N, X, strideX, offsetX, Y, strideY, offsetY ) { // TODO: remove and use BLAS implementation
var xi;
var yi;
var d;
var s;
var i;

xi = offsetX;
yi = offsetY;
s = 0.0;
for ( i = 0; i < N; i++ ) {
d = X[ xi ] - Y[ yi ];
s += d * d;
xi += strideX;
yi += strideY;
}
return sqrt( s );
function euclidean( N, X, strideX, offsetX, Y, strideY, offsetY ) {
var diff;

diff = new Float64Array( N );
dcopy.ndarray( N, X, strideX, offsetX, diff, 1, 0 ); // Magic number `0` for offset since `diff` is contiguous
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

daxpy.ndarray( N, ALPHA, Y, strideY, offsetY, diff, 1, 0 );
return dnrm2( N, diff, 1 );
}


Expand Down