From ba0b22cf0bfb54b8e4ce2595db871cc6019c076c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 25 Nov 2024 06:40:38 +0000 Subject: [PATCH] Auto-generated commit --- .github/workflows/test_published_package.yml | 105 +++++++++++++++++++ CHANGELOG.md | 3 +- CONTRIBUTORS | 7 ++ README.md | 4 +- benchmark/c/benchmark.length.c | 2 + dist/index.js | 14 +-- dist/index.js.map | 6 +- lib/ndarray.js | 18 ++-- src/addon.c | 21 ++-- src/main.c | 6 +- 10 files changed, 146 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/test_published_package.yml diff --git a/.github/workflows/test_published_package.yml b/.github/workflows/test_published_package.yml new file mode 100644 index 0000000..fe31b24 --- /dev/null +++ b/.github/workflows/test_published_package.yml @@ -0,0 +1,105 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 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. +#/ + +# Workflow name: +name: test_published_package + +# Workflow triggers: +on: + # Run workflow on a weekly schedule: + schedule: + # * is a special character in YAML so you have to quote this string + - cron: '5 5 * * 1' + + # Run workflow upon completion of `publish` workflow run: + workflow_run: + workflows: ["publish"] + types: [completed] + + # Allow workflow to be manually run: + workflow_dispatch: + +# Workflow jobs: +jobs: + test-published: + # Define a display name: + name: 'Test running examples of published package' + + # Define the type of virtual host machine: + runs-on: ubuntu-latest + + # Define environment variables: + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + + # Run workflow job if `publish` workflow run is successful or when the workflow is manually run: + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} + + # Define the job's steps: + steps: + # Checkout the repository: + - name: 'Checkout repository' + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + + # Install Node.js: + - name: 'Install Node.js' + uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 + with: + node-version: 20 + timeout-minutes: 5 + + # Create test directory and run examples: + - name: 'Create test directory and run examples' + run: | + cd .. + mkdir test-published + cd test-published + + # Copy example file: + cp $GITHUB_WORKSPACE/examples/index.js . + + # Create a minimal package.json + echo '{ + "name": "test-published", + "version": "1.0.0", + "main": "index.js", + "dependencies": {} + }' > package.json + + # Get package name and modify example file: + PACKAGE_NAME=$(jq -r '.name' $GITHUB_WORKSPACE/package.json) + ESCAPED_PACKAGE_NAME=$(echo "$PACKAGE_NAME" | sed 's/[\/&]/\\&/g') + + sed -i "s/require( '.\/..\/lib' )/require( '$ESCAPED_PACKAGE_NAME' )/g" index.js + + # Extract and install dependencies: + DEPS=$(grep -oP "require\(\s*'([^']+)'\s*\)" index.js | sed "s/require(\s*'//" | sed "s/'\s*)//" | grep -v "^\.") + for dep in $DEPS; do + npm install $dep --save + done + + # Run the example: + node index.js + + # Send Slack notification if job fails: + - name: 'Send notification to Slack in case of failure' + uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 + with: + status: ${{ job.status }} + channel: '#npm-ci' + if: failure() diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aa38cf..6ff64f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@
-## Unreleased (2024-11-11) +## Unreleased (2024-11-25)
@@ -32,6 +32,7 @@
+- [`a39d0f3`](https://github.com/stdlib-js/stdlib/commit/a39d0f372c70df837af84d321fa0b9b3d61f453b) - **refactor:** update `offset` handling and function documentation for `blas/ext/base/dnannsumors` [(#3252)](https://github.com/stdlib-js/stdlib/pull/3252) _(by Muhammad Haris)_ - [`af8d471`](https://github.com/stdlib-js/stdlib/commit/af8d471a7e01113f814a78fc411c7949b69ca1f3) - **feat:** add C `ndarray` API and refactor `blas/ext/base/dnannsumors` [(#2991)](https://github.com/stdlib-js/stdlib/pull/2991) _(by Muhammad Haris)_ - [`898b50d`](https://github.com/stdlib-js/stdlib/commit/898b50d8d705bdf6a55db8cf1858ea1e1d257c35) - **fix:** fix includes and types _(by Philipp Burckhardt)_ - [`272ae7a`](https://github.com/stdlib-js/stdlib/commit/272ae7ac5c576c68cfab1b6e304c86407faa20cd) - **docs:** remove comment _(by Athan Reines)_ diff --git a/CONTRIBUTORS b/CONTRIBUTORS index c9f811c..30c8723 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -3,6 +3,7 @@ # Contributors listed in alphabetical order. Aayush Khanna +Abhijit AbhijitRaut04 <121740684+AbhijitRaut04@users.noreply.github.com> Adarsh Palaskar Aditya Sapra @@ -59,6 +60,7 @@ Mohammad Kaif <98884589+Kaif987@users.noreply.github.com> Momtchil Momtchev Muhammad Haris Naresh Jagadeesan +Neeraj Pathak NightKnight Nithin Katta <88046362+nithinkatta@users.noreply.github.com> Nourhan Hasan <109472010+TheNourhan@users.noreply.github.com> @@ -69,6 +71,7 @@ Prajwal Kulkarni Pranav Goswami Praneki <97080887+PraneGIT@users.noreply.github.com> Pratik <97464067+Pratik772846@users.noreply.github.com> +Pratyush Kumar Chouhan Priyansh <88396544+itsspriyansh@users.noreply.github.com> Pushpendra Chandravanshi RISHAV <115060907+rishav2404@users.noreply.github.com> @@ -79,9 +82,12 @@ Ridam Garg <67867319+RidamGarg@users.noreply.github.com> Robert Gislason Roman Stetsyk <25715951+romanstetsyk@users.noreply.github.com> Rutam <138517416+performant23@users.noreply.github.com> +Ruthwik Chikoti <145591715+ruthwikchikoti@users.noreply.github.com> Ryan Seal +Rylan Yang <137365285+rylany27@users.noreply.github.com> Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com> SarthakPaandey <145528240+SarthakPaandey@users.noreply.github.com> +Saurabh Singh Seyyed Parsa Neshaei Shashank Shekhar Singh Shivam <11shivam00@gmail.com> @@ -102,6 +108,7 @@ Utkarsh Raj UtkershBasnet <119008923+UtkershBasnet@users.noreply.github.com> Vaibhav Patel <98279986+noobCoderVP@users.noreply.github.com> Varad Gupta +Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Xiaochuan Ye Yernar Yergaziyev naveen diff --git a/README.md b/README.md index c6327f8..696ec90 100644 --- a/README.md +++ b/README.md @@ -242,7 +242,7 @@ The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. - **X**: `[in] double*` input array. - **strideX**: `[in] CBLAS_INT` stride length for `X`. -- **n**: `[out] CBLAS_INT*` number of non-NaN elements. +- **n**: `[out] CBLAS_INT*` pointer for storing the number of non-NaN elements. ```c double stdlib_strided_dnannsumors( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n ); @@ -266,7 +266,7 @@ The function accepts the following arguments: - **X**: `[in] double*` input array. - **strideX**: `[in] CBLAS_INT` stride length for `X`. - **offsetX**: `[in] CBLAS_INT` starting index for `X`. -- **n**: `[out] CBLAS_INT*` number of non-NaN elements. +- **n**: `[out] CBLAS_INT*` pointer for storing the number of non-NaN elements. ```c double stdlib_strided_dnannsumors_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n ); diff --git a/benchmark/c/benchmark.length.c b/benchmark/c/benchmark.length.c index c5c5c6c..b120333 100644 --- a/benchmark/c/benchmark.length.c +++ b/benchmark/c/benchmark.length.c @@ -114,6 +114,7 @@ static double benchmark1( int iterations, int len ) { n = 0; t = tic(); for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar v = stdlib_strided_dnannsumors( len, x, 1, &n ); if ( v != v || n < 0 ) { printf( "should not return NaN\n" ); @@ -153,6 +154,7 @@ static double benchmark2( int iterations, int len ) { n = 0; t = tic(); for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar v = stdlib_strided_dnannsumors_ndarray( len, x, 1, 0, &n ); if ( v != v || n < 0 ) { printf( "should not return NaN\n" ); diff --git a/dist/index.js b/dist/index.js index c11c91d..780aabd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,9 +1,9 @@ -"use strict";var o=function(a,e){return function(){return e||a((e={exports:{}}).exports,e),e.exports}};var p=o(function(G,d){ -var l=require('@stdlib/math-base-assert-is-nan/dist');function b(a,e,v,u,r,i,f){var q,s,n,m,c;if(q=0,n=f,a<=0)return r[n]=q,r[n+i]=0,r;if(s=u,v===0)return l(e[s])?(r[n]=q,r[n+i]=0,r):(r[n]=e[s]*a,r[n+i]=a,r);for(m=0,c=0;c[ 5.0, 4 ]\n*/\nfunction dnannsumors( N, x, strideX, offsetX, out, strideOut, offsetOut ) {\n\tvar sum;\n\tvar ix;\n\tvar io;\n\tvar n;\n\tvar i;\n\n\tsum = 0.0;\n\tio = offsetOut;\n\tif ( N <= 0 ) {\n\t\tout[ io ] = sum;\n\t\tout[ io+strideOut ] = 0;\n\t\treturn out;\n\t}\n\tix = offsetX;\n\tif ( strideX === 0 ) {\n\t\tif ( isnan( x[ ix ] ) ) {\n\t\t\tout[ io ] = sum;\n\t\t\tout[ io+strideOut ] = 0;\n\t\t\treturn out;\n\t\t}\n\t\tout[ io ] = x[ ix ] * N;\n\t\tout[ io+strideOut ] = N;\n\t\treturn out;\n\t}\n\tn = 0;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tif ( isnan( x[ ix ] ) === false ) {\n\t\t\tsum += x[ ix ];\n\t\t\tn += 1;\n\t\t}\n\t\tix += strideX;\n\t}\n\tout[ io ] = sum;\n\tout[ io+strideOut ] = n;\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dnannsumors;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar stride2offset = require( '@stdlib/strided-base-stride2offset' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive summation.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float64Array} x - input array\n* @param {integer} strideX - `x` stride length\n* @param {Float64Array} out - output array\n* @param {integer} strideOut - `out` stride length\n* @returns {Float64Array} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );\n* var out = new Float64Array( 2 );\n*\n* var v = dnannsumors( x.length, x, 1, out, 1 );\n* // returns [ 1.0, 3 ]\n*/\nfunction dnannsumors( N, x, strideX, out, strideOut ) {\n\tvar ix;\n\tvar io;\n\n\tix = stride2offset( N, strideX );\n\tif ( strideOut < 0 ) {\n\t\tio = -strideOut;\n\t} else {\n\t\tio = 0;\n\t}\n\treturn ndarray( N, x, strideX, ix, out, strideOut, io );\n}\n\n\n// EXPORTS //\n\nmodule.exports = dnannsumors;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar dnannsumors = require( './dnannsumors.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dnannsumors, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dnannsumors;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Compute the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive summation.\n*\n* @module @stdlib/blas-ext-base-dnannsumors\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dnannsumors = require( '@stdlib/blas-ext-base-dnannsumors' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );\n* var out = new Float64Array( 2 );\n*\n* var v = dnannsumors( x.length, x, 1, out, 1 );\n* // returns [ 1.0, 3 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dnannsumors = require( '@stdlib/blas-ext-base-dnannsumors' );\n*\n* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n* var out = new Float64Array( 2 );\n*\n* var v = dnannsumors.ndarray( 5, x, 2, 1, out, 1, 0 );\n* // returns [ 5.0, 4 ]\n*/\n\n// MODULES //\n\nvar join = require( 'path' ).join;\nvar tryRequire = require( '@stdlib/utils-try-require' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nvar dnannsumors;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdnannsumors = main;\n} else {\n\tdnannsumors = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dnannsumors;\n\n// exports: { \"ndarray\": \"dnannsumors.ndarray\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EA0BvD,SAASC,EAAaC,EAAGC,EAAGC,EAASC,EAASC,EAAKC,EAAWC,EAAY,CACzE,IAAIC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAJ,EAAM,EACNE,EAAKH,EACAN,GAAK,EACT,OAAAI,EAAKK,CAAG,EAAIF,EACZH,EAAKK,EAAGJ,CAAU,EAAI,EACfD,EAGR,GADAI,EAAKL,EACAD,IAAY,EAChB,OAAKJ,EAAOG,EAAGO,CAAG,CAAE,GACnBJ,EAAKK,CAAG,EAAIF,EACZH,EAAKK,EAAGJ,CAAU,EAAI,EACfD,IAERA,EAAKK,CAAG,EAAIR,EAAGO,CAAG,EAAIR,EACtBI,EAAKK,EAAGJ,CAAU,EAAIL,EACfI,GAGR,IADAM,EAAI,EACEC,EAAI,EAAGA,EAAIX,EAAGW,IACdb,EAAOG,EAAGO,CAAG,CAAE,IAAM,KACzBD,GAAON,EAAGO,CAAG,EACbE,GAAK,GAENF,GAAMN,EAEP,OAAAE,EAAKK,CAAG,EAAIF,EACZH,EAAKK,EAAGJ,CAAU,EAAIK,EACfN,CACR,CAKAP,EAAO,QAAUE,ICzFjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IAwBd,SAASC,EAAaC,EAAGC,EAAGC,EAASC,EAAKC,EAAY,CACrD,IAAIC,EACAC,EAEJ,OAAAD,EAAKR,EAAeG,EAAGE,CAAQ,EAC1BE,EAAY,EAChBE,EAAK,CAACF,EAENE,EAAK,EAECR,EAASE,EAAGC,EAAGC,EAASG,EAAIF,EAAKC,EAAWE,CAAG,CACvD,CAKAV,EAAO,QAAUG,IC/DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAc,IACdC,EAAU,IAKdF,EAAaC,EAAa,UAAWC,CAAQ,EAK7CH,EAAO,QAAUE,ICcjB,IAAIE,EAAO,QAAS,MAAO,EAAE,KACzBC,EAAa,QAAS,2BAA4B,EAClDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAO,IAKPC,EACAC,EAAMJ,EAAYD,EAAM,UAAW,aAAc,CAAE,EAClDE,EAASG,CAAI,EACjBD,EAAcD,EAEdC,EAAcC,EAMf,OAAO,QAAUD", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "isnan", "dnannsumors", "N", "x", "strideX", "offsetX", "out", "strideOut", "offsetOut", "sum", "ix", "io", "n", "i", "require_dnannsumors", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "dnannsumors", "N", "x", "strideX", "out", "strideOut", "ix", "io", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "dnannsumors", "ndarray", "join", "tryRequire", "isError", "main", "dnannsumors", "tmp"] + "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive summation.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float64Array} x - input array\n* @param {integer} strideX - `x` stride length\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {Float64Array} out - output array\n* @param {integer} strideOut - `out` stride length\n* @param {NonNegativeInteger} offsetOut - `out` starting index\n* @returns {Float64Array} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n* var out = new Float64Array( 2 );\n*\n* var v = dnannsumors( 5, x, 2, 1, out, 1, 0 );\n* // returns [ 5.0, 4 ]\n*/\nfunction dnannsumors( N, x, strideX, offsetX, out, strideOut, offsetOut ) {\n\tvar sum;\n\tvar ix;\n\tvar n;\n\tvar i;\n\n\tsum = 0.0;\n\tif ( N <= 0 ) {\n\t\tout[ offsetOut ] = sum;\n\t\tout[ offsetOut+strideOut ] = 0;\n\t\treturn out;\n\t}\n\tix = offsetX;\n\tif ( strideX === 0 ) {\n\t\tif ( isnan( x[ ix ] ) ) {\n\t\t\tout[ offsetOut ] = sum;\n\t\t\tout[ offsetOut+strideOut ] = 0;\n\t\t\treturn out;\n\t\t}\n\t\tout[ offsetOut ] = x[ ix ] * N;\n\t\tout[ offsetOut+strideOut ] = N;\n\t\treturn out;\n\t}\n\tn = 0;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tif ( isnan( x[ ix ] ) === false ) {\n\t\t\tsum += x[ ix ];\n\t\t\tn += 1;\n\t\t}\n\t\tix += strideX;\n\t}\n\tout[ offsetOut ] = sum;\n\tout[ offsetOut+strideOut ] = n;\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dnannsumors;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar stride2offset = require( '@stdlib/strided-base-stride2offset' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive summation.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float64Array} x - input array\n* @param {integer} strideX - `x` stride length\n* @param {Float64Array} out - output array\n* @param {integer} strideOut - `out` stride length\n* @returns {Float64Array} output array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );\n* var out = new Float64Array( 2 );\n*\n* var v = dnannsumors( x.length, x, 1, out, 1 );\n* // returns [ 1.0, 3 ]\n*/\nfunction dnannsumors( N, x, strideX, out, strideOut ) {\n\tvar ix;\n\tvar io;\n\n\tix = stride2offset( N, strideX );\n\tif ( strideOut < 0 ) {\n\t\tio = -strideOut;\n\t} else {\n\t\tio = 0;\n\t}\n\treturn ndarray( N, x, strideX, ix, out, strideOut, io );\n}\n\n\n// EXPORTS //\n\nmodule.exports = dnannsumors;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar dnannsumors = require( './dnannsumors.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dnannsumors, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dnannsumors;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Compute the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive summation.\n*\n* @module @stdlib/blas-ext-base-dnannsumors\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dnannsumors = require( '@stdlib/blas-ext-base-dnannsumors' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );\n* var out = new Float64Array( 2 );\n*\n* var v = dnannsumors( x.length, x, 1, out, 1 );\n* // returns [ 1.0, 3 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dnannsumors = require( '@stdlib/blas-ext-base-dnannsumors' );\n*\n* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n* var out = new Float64Array( 2 );\n*\n* var v = dnannsumors.ndarray( 5, x, 2, 1, out, 1, 0 );\n* // returns [ 5.0, 4 ]\n*/\n\n// MODULES //\n\nvar join = require( 'path' ).join;\nvar tryRequire = require( '@stdlib/utils-try-require' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nvar dnannsumors;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdnannsumors = main;\n} else {\n\tdnannsumors = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dnannsumors;\n\n// exports: { \"ndarray\": \"dnannsumors.ndarray\" }\n"], + "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EA0BvD,SAASC,EAAaC,EAAGC,EAAGC,EAASC,EAASC,EAAKC,EAAWC,EAAY,CACzE,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAM,EACDP,GAAK,EACT,OAAAI,EAAKE,CAAU,EAAIC,EACnBH,EAAKE,EAAUD,CAAU,EAAI,EACtBD,EAGR,GADAI,EAAKL,EACAD,IAAY,EAChB,OAAKJ,EAAOG,EAAGO,CAAG,CAAE,GACnBJ,EAAKE,CAAU,EAAIC,EACnBH,EAAKE,EAAUD,CAAU,EAAI,EACtBD,IAERA,EAAKE,CAAU,EAAIL,EAAGO,CAAG,EAAIR,EAC7BI,EAAKE,EAAUD,CAAU,EAAIL,EACtBI,GAGR,IADAK,EAAI,EACEC,EAAI,EAAGA,EAAIV,EAAGU,IACdZ,EAAOG,EAAGO,CAAG,CAAE,IAAM,KACzBD,GAAON,EAAGO,CAAG,EACbC,GAAK,GAEND,GAAMN,EAEP,OAAAE,EAAKE,CAAU,EAAIC,EACnBH,EAAKE,EAAUD,CAAU,EAAII,EACtBL,CACR,CAKAP,EAAO,QAAUE,ICvFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IAwBd,SAASC,EAAaC,EAAGC,EAAGC,EAASC,EAAKC,EAAY,CACrD,IAAIC,EACAC,EAEJ,OAAAD,EAAKR,EAAeG,EAAGE,CAAQ,EAC1BE,EAAY,EAChBE,EAAK,CAACF,EAENE,EAAK,EAECR,EAASE,EAAGC,EAAGC,EAASG,EAAIF,EAAKC,EAAWE,CAAG,CACvD,CAKAV,EAAO,QAAUG,IC/DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAc,IACdC,EAAU,IAKdF,EAAaC,EAAa,UAAWC,CAAQ,EAK7CH,EAAO,QAAUE,ICcjB,IAAIE,EAAO,QAAS,MAAO,EAAE,KACzBC,EAAa,QAAS,2BAA4B,EAClDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAO,IAKPC,EACAC,EAAMJ,EAAYD,EAAM,UAAW,aAAc,CAAE,EAClDE,EAASG,CAAI,EACjBD,EAAcD,EAEdC,EAAcC,EAMf,OAAO,QAAUD", + "names": ["require_ndarray", "__commonJSMin", "exports", "module", "isnan", "dnannsumors", "N", "x", "strideX", "offsetX", "out", "strideOut", "offsetOut", "sum", "ix", "n", "i", "require_dnannsumors", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "dnannsumors", "N", "x", "strideX", "out", "strideOut", "ix", "io", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "dnannsumors", "ndarray", "join", "tryRequire", "isError", "main", "dnannsumors", "tmp"] } diff --git a/lib/ndarray.js b/lib/ndarray.js index 1db0bfb..dba63a7 100644 --- a/lib/ndarray.js +++ b/lib/ndarray.js @@ -49,26 +49,24 @@ var isnan = require( '@stdlib/math-base-assert-is-nan' ); function dnannsumors( N, x, strideX, offsetX, out, strideOut, offsetOut ) { var sum; var ix; - var io; var n; var i; sum = 0.0; - io = offsetOut; if ( N <= 0 ) { - out[ io ] = sum; - out[ io+strideOut ] = 0; + out[ offsetOut ] = sum; + out[ offsetOut+strideOut ] = 0; return out; } ix = offsetX; if ( strideX === 0 ) { if ( isnan( x[ ix ] ) ) { - out[ io ] = sum; - out[ io+strideOut ] = 0; + out[ offsetOut ] = sum; + out[ offsetOut+strideOut ] = 0; return out; } - out[ io ] = x[ ix ] * N; - out[ io+strideOut ] = N; + out[ offsetOut ] = x[ ix ] * N; + out[ offsetOut+strideOut ] = N; return out; } n = 0; @@ -79,8 +77,8 @@ function dnannsumors( N, x, strideX, offsetX, out, strideOut, offsetOut ) { } ix += strideX; } - out[ io ] = sum; - out[ io+strideOut ] = n; + out[ offsetOut ] = sum; + out[ offsetOut+strideOut ] = n; return out; } diff --git a/src/addon.c b/src/addon.c index 5a454f4..b24fa01 100644 --- a/src/addon.c +++ b/src/addon.c @@ -22,6 +22,8 @@ #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" #include "stdlib/napi/argv_strided_float64array.h" +#include "stdlib/strided/base/stride2offset.h" +#include #include /** @@ -39,17 +41,10 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Out, 2, strideOut, argv, 3 ); - int io; - if ( strideOut < 0 ) { - io = -strideOut; - } else { - io = 0; - } - - double *out = Out; + int64_t io = stdlib_strided_stride2offset( 2, strideOut ); CBLAS_INT n; - out[ io ] = API_SUFFIX(stdlib_strided_dnannsumors)( N, X, strideX, &n ); - out[ io + strideOut ] = (double)n; + Out[ io ] = API_SUFFIX(stdlib_strided_dnannsumors)( N, X, strideX, &n ); + Out[ io + strideOut ] = (double)n; return NULL; } @@ -71,11 +66,9 @@ static napi_value addon_method( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Out, 2, strideOut, argv, 4 ); - int io = offsetOut; - double *out = Out; CBLAS_INT n; - out[ io ] = API_SUFFIX(stdlib_strided_dnannsumors_ndarray)( N, X, strideX, offsetX, &n ); - out[ io+strideOut ] = (double)n; + Out[ offsetOut ] = API_SUFFIX(stdlib_strided_dnannsumors_ndarray)( N, X, strideX, offsetX, &n ); + Out[ offsetOut+strideOut ] = (double)n; return NULL; } diff --git a/src/main.c b/src/main.c index a43cc7f..2b6e748 100644 --- a/src/main.c +++ b/src/main.c @@ -27,7 +27,7 @@ * @param N number of indexed elements * @param X input array * @param strideX stride length -* @param n number of non-NaN elements +* @param n pointer for storing the number of non-NaN elements * @return output value */ double API_SUFFIX(stdlib_strided_dnannsumors)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n ) { @@ -42,13 +42,13 @@ double API_SUFFIX(stdlib_strided_dnannsumors)( const CBLAS_INT N, const double * * @param X input array * @param strideX stride length * @param offsetX starting index -* @param n number of non-NaN elements +* @param n pointer for storing the number of non-NaN elements * @return output value */ double API_SUFFIX(stdlib_strided_dnannsumors_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n ) { - double sum; CBLAS_INT ix; CBLAS_INT i; + double sum; sum = 0.0; *n = 0;