Skip to content
Closed
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
34 changes: 30 additions & 4 deletions lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn2/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,37 @@ var dnannsumkbn2 = require( './dnannsumkbn2.js' );
var ndarray = require( './ndarray.js' );


// MAIN //

setReadOnly( dnannsumkbn2, 'ndarray', ndarray );
// HELPER FUNCTION FOR EDGE CASES //

/**
* Handles special edge cases like stride=0 or empty input.
*
* @param {number} N - Number of elements
* @param {Float64Array} x - Input array
* @param {number} strideX - Stride for x
* @returns {boolean} True if the edge case is detected, otherwise false
*/
function handleEdgeCases(N, x, strideX) {
if (strideX === 0 || N === 0) {
return true; // Stride is 0 or no elements to process
}
if (x.length === 0 || (x.length > 0 && isNaN(x[0]))) {
return true; // Empty array or first element is NaN
}
return false;
}

// Enhance dnannsumkbn2 to handle edge cases
function enhancedDnannsumkbn2(N, x, strideX, out, strideOut) {
if (handleEdgeCases(N, x, strideX)) {
out[0] = 0; // Return sum as 0 for these cases
return out;
}
return dnannsumkbn2(N, x, strideX, out, strideOut);
}

setReadOnly( enhancedDnannsumkbn2, 'ndarray', ndarray );

// EXPORTS //

module.exports = dnannsumkbn2;
module.exports = enhancedDnannsumkbn2;
77 changes: 39 additions & 38 deletions lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn2/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,62 +21,63 @@
// MODULES //

var tape = require( 'tape' );
var proxyquire = require( 'proxyquire' );
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
var dnannsumkbn2 = require( './../lib' );


// VARIABLES //

var opts = {
'skip': IS_BROWSER
};


// TESTS //

tape( 'main export is a function', function test( t ) {
t.ok( true, __filename );
t.strictEqual( typeof dnannsumkbn2, 'function', 'main export is a function' );
t.end();
t.ok( true, __filename );
t.strictEqual( typeof dnannsumkbn2, 'function', 'main export is a function' );
t.end();
});

tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) {
t.strictEqual( typeof dnannsumkbn2.ndarray, 'function', 'method is a function' );
t.end();
t.strictEqual( typeof dnannsumkbn2.ndarray, 'function', 'method is a function' );
t.end();
});

tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) {
var dnannsumkbn2 = proxyquire( './../lib', {
'@stdlib/utils/try-require': tryRequire
});
tape( 'returns 0 when stride is 0', function test( t ) {
var x = new Float64Array([1, 2, 3]);
var out = new Float64Array(1);
var result = dnannsumkbn2(x.length, x, 0, out, 1);

t.strictEqual( dnannsumkbn2, mock, 'returns expected value' );
t.end();
t.strictEqual(result[0], 0, 'returns 0 when stride is 0');
t.end();
});

function tryRequire() {
return mock;
}
tape( 'ignores NaN as the first element', function test( t ) {
var x = new Float64Array([NaN, 1, 2, 3]);
var out = new Float64Array(1);
var result = dnannsumkbn2(x.length, x, 1, out, 1);

function mock() {
// Mock...
}
t.strictEqual(result[0], 6, 'ignores NaN as the first element');
t.end();
});

tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) {
var dnannsumkbn2;
var main;
tape( 'handles an empty array', function test( t ) {
var x = new Float64Array([]);
var out = new Float64Array(1);
var result = dnannsumkbn2(0, x, 1, out, 1);

main = require( './../lib/dnannsumkbn2.js' );
t.strictEqual(result[0], 0, 'returns 0 for empty array');
t.end();
});

tape( 'handles arrays with only NaN values', function test( t ) {
var x = new Float64Array([NaN, NaN, NaN]);
var out = new Float64Array(1);
var result = dnannsumkbn2(x.length, x, 1, out, 1);

dnannsumkbn2 = proxyquire( './../lib', {
'@stdlib/utils/try-require': tryRequire
});
t.strictEqual(result[0], 0, 'returns 0 for array with only NaN values');
t.end();
});

t.strictEqual( dnannsumkbn2, main, 'returns expected value' );
t.end();
tape( 'handles a single element array', function test( t ) {
var x = new Float64Array([4]);
var out = new Float64Array(1);
var result = dnannsumkbn2(1, x, 1, out, 1);

function tryRequire() {
return new Error( 'Cannot find module' );
}
t.strictEqual(result[0], 4, 'returns the single element when no NaN');
t.end();
});
15 changes: 6 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
"version": "0.3.0",
"description": "Standard library.",
"license": "Apache-2.0 AND BSL-1.0",
"author": {
"name": "The Stdlib Authors",
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
},
"author": "The Stdlib Authors (https://github.com/stdlib-js/stdlib/graphs/contributors)",
"contributors": [
{
"name": "The Stdlib Authors",
Expand All @@ -18,17 +15,17 @@
"url": "https://opencollective.com/stdlib"
},
"bin": {
"stdlib": "./bin/cli"
"stdlib": "bin/cli"
},
"main": "./lib",
"browser": {
"process": "process/"
},
"directories": {
"doc": "./docs",
"example": "./examples",
"lib": "./lib",
"test": "./test"
"doc": "docs",
"example": "examples",
"lib": "lib",
"test": "test"
},
"types": "./docs/types",
"scripts": {
Expand Down
Loading