diff --git a/.github/workflows/namespace_exports.yml b/.github/workflows/namespace_exports.yml index bc4fe0da079f..0ef90162b160 100644 --- a/.github/workflows/namespace_exports.yml +++ b/.github/workflows/namespace_exports.yml @@ -21,6 +21,12 @@ name: namespace_exports # Workflow triggers: on: + pull_request_target: + branches: + - develop + types: + - closed + # Allow the workflow to be manually run: workflow_dispatch: diff --git a/.mailmap b/.mailmap index 6b3543971592..7b5a845ca611 100644 --- a/.mailmap +++ b/.mailmap @@ -76,9 +76,6 @@ Matt Cochrane Mihir Pandit <129577900+MSP20086@users.noreply.github.com> MSP20086 -Muhammad Haris <101793258+headlessNode@users.noreply.github.com> -Muhammad Haris headlessNode - # N Naresh Jagadeesan <37257700+Infinage@users.noreply.github.com> diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 12e6f49663dd..b637fec9ecab 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -118,17 +118,7 @@ Create a [GitHub account][github-signup]. The project uses GitHub exclusively fo $ git clone https://github.com//stdlib.git ``` -where `` is your GitHub username. When cloning, avoid cloning to a directory having spaces in its path. Because this project relies heavily on `make`, any spaces in the directory path will lead to errors and inevitable frustration. - -```text -// Bad: -/home/foo/bar/beep boop/stdlib - -// Good: -/home/foo/bar/beep_boop/stdlib -``` - -The repository has a large commit history, leading to slow download times. You can reduce the download time by limiting the clone [depth][git-clone-depth]. +where `` is your GitHub username. The repository has a large commit history, leading to slow download times. You can reduce the download time by limiting the clone [depth][git-clone-depth]. @@ -162,27 +152,7 @@ And finally, add an `upstream` [remote][git-remotes] to allow syncing changes be $ git remote add upstream git://github.com/stdlib-js/stdlib.git ``` -#### Step 2: Initial Setup - -Install dependencies. - - - -```bash -$ make install -``` - -Initialize Git hooks to enable automated development processes to run prior to authoring commits and pushing changes. - - - -```bash -$ make init -``` - -Note that `make init` only needs to be run once; however, we repeat it below as **not** running it is a common omission by new contributors. - -#### Step 3: Branch +#### Step 2: Branch For modifications intended to be included in stdlib, create a new local branch. @@ -194,11 +164,11 @@ $ git checkout -b where `` is the branch name. Both the `master` and `develop` branches for the main stdlib project are protected, and direct modifications to these branches will **not** be accepted. Instead, all contributions should be made on non-master and non-develop local branches, including documentation changes and other non-code modifications. See the project [branching guide][stdlib-branching] for additional guidance. -#### Step 4: Write +#### Step 3: Write Start making your changes and/or implementing the new feature. Any text you write should follow the [text style guide][stdlib-style-guides-text], including comments and API documentation. -#### Step 5: Commit +#### Step 4: Commit Ensure that you have configured [Git][git] to know your name and email address. @@ -220,7 +190,7 @@ $ git commit When writing commit messages, follow the Git [style guide][stdlib-style-guides-git]. Adherence to project commit conventions is necessary for project automation which automatically generates release notes and changelogs from commit messages. -#### Step 6: Sync +#### Step 5: Sync To incorporate recent changes from the `upstream` repository during development, you should [rebase][git-rebase] your local branch, reapplying your local commits on top of the current upstream `HEAD`. This procedure is in contrast to performing a standard [merge][git-merge], which may interleave development histories. The rationale is twofold: @@ -236,13 +206,11 @@ $ git fetch upstream $ git rebase upstream/develop ``` -#### Step 7: Test +#### Step 6: Test Tests should accompany **all** bug fixes and features. For guidance on how to write tests, consult existing tests within the project. -**Before** submitting a [pull request][github-pull-request] to the `upstream` repository, ensure that all tests pass, including linting. To run tests locally, consult the guidance [below](#writing-tests). - -If [Git][git] hooks have been enabled, +**Before** submitting a [pull request][github-pull-request] to the `upstream` repository, ensure that all tests pass, including linting. If [Git][git] hooks have been enabled, @@ -254,7 +222,7 @@ linting should be automatically triggered prior to each commit, and test executi Any [pull requests][github-pull-request] which include failing tests and/or lint errors will **not** be accepted. -#### Step 8: Push +#### Step 7: Push Push your changes to your remote GitHub repository. @@ -266,7 +234,7 @@ $ git push origin where `` is the name of your branch. -#### Step 9: Pull Request +#### Step 8: Pull Request Once your contribution is ready to be incorporated in the `upstream` repository, open a [pull request][github-pull-request] against the `develop` branch. One or more project contributors will review the contribution, provide feedback, and potentially request changes. @@ -312,13 +280,13 @@ $ git commit -m "fixup! feat: add support for computing the absolute value" If the history needs modification, a contributor will modify the history during the merge process. The rationale for **not** rewriting public history is that doing so invalidates the commit history for anyone else who has pulled your changes, thus imposing additional burdens on collaborators to ensure that their local versions match the modified history. -#### Step 10: Land +#### Step 9: Land After any changes have been resolved and continuous integration tests have passed, a contributor will approve a [pull request][github-pull-request] for inclusion in the project. Once merged, the [pull request][github-pull-request] will be updated with the merge commit, and the [pull request][github-pull-request] will be closed. Note that, during the merge process, multiple commits will often be [squashed][git-rewriting-history]. -#### Step 11: Celebrate +#### Step 10: Celebrate **Congratulations**! You are an official contributor to stdlib! Thank you for your hard work and patience! @@ -348,7 +316,7 @@ The project can **never** have enough tests. To address areas lacking sufficient ```bash - $ make TESTS_FILTER=".*//.*" test + $ make TESTS_FILTER=.*//.* test ``` where `` is a pattern matching a particular path. For example, to test the base math `sin` package @@ -356,7 +324,7 @@ The project can **never** have enough tests. To address areas lacking sufficient ```bash - $ make TESTS_FILTER=".*/math/base/special/sin/.*" test + $ make TESTS_FILTER=.*/math/base/special/sin/.* test ``` where the pattern `.*/math/base/special/sin/.*` matches any test file whose absolute path contains `math/base/special/sin`. @@ -366,7 +334,7 @@ The project can **never** have enough tests. To address areas lacking sufficient ```bash - $ make TESTS_FILTER=".*//.*" test-cov + $ make TESTS_FILTER=.*//.* test-cov $ make view-cov ``` @@ -374,16 +342,6 @@ The project can **never** have enough tests. To address areas lacking sufficient 7. Submit the test as a [pull request][github-pull-request]. -Note that, for contributions targeting C implementations, you'll need to first compile the native add-on which provides the bridge between JavaScript and C (assuming that the package has a native add-on binding). - -```bash -$ make install-node-addons NODE_ADDONS_PATTERN="math/base/special/sin" -``` - -where the pattern `math/base/special/sin` (note the differences from the filter pattern above!) matches any add-on whose absolute path contains `math/base/special/sin`. - -Once the add-on is compiled, you can follow steps 5-7 above. - ### Writing Documentation > By contributing documentation to the project, you are agreeing to release it under the project [license][stdlib-license]. diff --git a/CONTRIBUTORS b/CONTRIBUTORS index bfb0b09e3720..6917be2bd659 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -10,10 +10,8 @@ Aman Bhansali Amit Jimiwal Anudeep Sanapala Athan Reines -Ayaka <73595362+USERSATOSHI@users.noreply.github.com> Brendan Graetz Bruno Fenzl -Bryan Elee Chinmay Joshi <86140365+JawHawk@users.noreply.github.com> Christopher Dambamuromo Dan Rose @@ -43,7 +41,6 @@ Matt Cochrane Mihir Pandit <129577900+MSP20086@users.noreply.github.com> Milan Raj Momtchil Momtchev -Muhammad Haris Naresh Jagadeesan Nithin Katta <88046362+nithinkatta@users.noreply.github.com> Ognjen Jevremović @@ -69,13 +66,10 @@ Shubham Mishra Snehil Shah <130062020+Snehil-Shah@users.noreply.github.com> Spandan Barve Stephannie Jiménez Gacha -Suraj kumar <125961509+kumarsuraj212003@users.noreply.github.com> -Tirtadwipa Manunggal Utkarsh Utkarsh Raj Varad Gupta Yernar Yergaziyev -naveen nishant-s7 <97207366+nishant-s7@users.noreply.github.com> orimiles5 <97595296+orimiles5@users.noreply.github.com> rei2hu diff --git a/lib/node_modules/@stdlib/array/mostly-safe-casts/README.md b/lib/node_modules/@stdlib/array/mostly-safe-casts/README.md index d6f682fab026..eef5ec369abc 100644 --- a/lib/node_modules/@stdlib/array/mostly-safe-casts/README.md +++ b/lib/node_modules/@stdlib/array/mostly-safe-casts/README.md @@ -121,17 +121,6 @@ for ( i = 0; i < DTYPES.length; i++ ) { @@ -142,20 +131,6 @@ for ( i = 0; i < DTYPES.length; i++ ) { [@stdlib/array/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/dtypes - - -[@stdlib/array/convert]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/convert - -[@stdlib/array/convert-same]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/convert-same - -[@stdlib/array/safe-casts]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/safe-casts - -[@stdlib/array/same-kind-casts]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/same-kind-casts - -[@stdlib/ndarray/mostly-safe-casts]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/mostly-safe-casts - - - diff --git a/lib/node_modules/@stdlib/assert/is-nonnegative-integer/README.md b/lib/node_modules/@stdlib/assert/is-nonnegative-integer/README.md index c1ae53d42dfb..ffeb509b5e8a 100644 --- a/lib/node_modules/@stdlib/assert/is-nonnegative-integer/README.md +++ b/lib/node_modules/@stdlib/assert/is-nonnegative-integer/README.md @@ -138,8 +138,6 @@ bool = isNonNegativeInteger( null ); ## See Also - [`@stdlib/assert/is-integer`][@stdlib/assert/is-integer]: test if a value is a number having an integer value. -- [`@stdlib/assert/is-nonnegative-number`][@stdlib/assert/is-nonnegative-number]: test if a value is a number having a nonnegative value. -- [`@stdlib/assert/is-number`][@stdlib/assert/is-number]: test if a value is a number. @@ -153,10 +151,6 @@ bool = isNonNegativeInteger( null ); [@stdlib/assert/is-integer]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-integer -[@stdlib/assert/is-nonnegative-number]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-nonnegative-number - -[@stdlib/assert/is-number]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-number - diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapx/README.md b/lib/node_modules/@stdlib/blas/ext/base/dapx/README.md index 1aadc282dbc5..3449170450a5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapx/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dapx/README.md @@ -32,7 +32,7 @@ var dapx = require( '@stdlib/blas/ext/base/dapx' ); #### dapx( N, alpha, x, stride ) -Adds a constant `alpha` to each element in a double-precision floating-point strided array. +Adds a constant `alpha` to each element in a double-precision floating-point strided array `x`. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -50,14 +50,16 @@ The function has the following parameters: - **x**: input [`Float64Array`][@stdlib/array/float64]. - **stride**: index increment. -The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to add a constant to every other element +The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to add a constant to every other element ```javascript var Float64Array = require( '@stdlib/array/float64' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +var N = floor( x.length / 2 ); -dapx( 4, 5.0, x, 2 ); +dapx( N, 5.0, x, 2 ); // x => [ 3.0, 1.0, 8.0, -5.0, 9.0, 0.0, 4.0, -3.0 ] ``` @@ -65,21 +67,23 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); +var floor = require( '@stdlib/math/base/special/floor' ); // Initial array... var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); // Create an offset view... var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var N = floor( x0.length/2 ); // Add a constant to every other element... -dapx( 3, 5.0, x1, 2 ); +dapx( N, 5.0, x1, 2 ); // x0 => [ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ] ``` #### dapx.ndarray( N, alpha, x, stride, offset ) -Adds a constant `alpha` to each element in a double-precision floating-point strided array using alternative indexing semantics. +Adds a constant `alpha` to each element in a double-precision floating-point strided array `x` using alternative indexing semantics. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -94,7 +98,7 @@ The function has the following additional parameters: - **offset**: starting index. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of the strided array +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `x` ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -113,7 +117,7 @@ dapx.ndarray( 3, 5.0, x, 1, x.length-3 ); ## Notes -- If `N <= 0`, both functions return the strided array unchanged. +- If `N <= 0`, both functions return `x` unchanged. @@ -126,11 +130,27 @@ dapx.ndarray( 3, 5.0, x, 1, x.length-3 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var round = require( '@stdlib/math/base/special/round' ); +var randu = require( '@stdlib/random/base/randu' ); +var Float64Array = require( '@stdlib/array/float64' ); var dapx = require( '@stdlib/blas/ext/base/dapx' ); -var x = filledarrayBy( 10, 'float64', discreteUniform( -100, 100 ) ); +var rand; +var sign; +var x; +var i; + +x = new Float64Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + rand = round( randu()*100.0 ); + sign = randu(); + if ( sign < 0.5 ) { + sign = -1.0; + } else { + sign = 1.0; + } + x[ i ] = sign * rand; +} console.log( x ); dapx( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.js index 1e2ec3f90065..a8b1105782cd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var dapx = require( './../lib/dapx.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -45,8 +40,12 @@ var rand = uniform( -10.0, 10.0 ); */ function createBenchmark( len ) { var x; + var i; - x = filledarrayBy( len, 'float64', rand ); + x = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.native.js index bec331f17271..c96243119938 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var dapx = tryRequire( resolve( __dirname, './../lib/dapx.native.js' ) ); var opts = { 'skip': ( dapx instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -50,8 +49,12 @@ var rand = uniform( -10.0, 10.0 ); */ function createBenchmark( len ) { var x; + var i; - x = filledarrayBy( len, 'float64', rand ); + x = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.ndarray.js index 0a0fd5418756..7fccdbcd49bf 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.ndarray.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var dapx = require( './../lib/ndarray.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -45,8 +40,12 @@ var rand = uniform( -10.0, 10.0 ); */ function createBenchmark( len ) { var x; + var i; - x = filledarrayBy( len, 'float64', rand ); + x = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.ndarray.native.js index 77d9e12eeb14..ea4007141b3e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var dapx = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( dapx instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -50,8 +49,12 @@ var rand = uniform( -10.0, 10.0 ); */ function createBenchmark( len ) { var x; + var i; - x = filledarrayBy( len, 'float64', rand ); + x = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapx/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dapx/docs/repl.txt index 2f77bbf08b29..80e0c0b9d3aa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapx/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dapx/docs/repl.txt @@ -3,13 +3,13 @@ Adds a constant to each element in a double-precision floating-point strided array. - The `N` and stride parameters determine which elements in the strided array - are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` are accessed + at runtime. Indexing is relative to the first index. To introduce an offset, use typed array views. - If `N <= 0`, the function returns the strided array unchanged. + If `N <= 0`, the function returns `x` unchanged. Parameters ---------- @@ -23,34 +23,40 @@ Input array. stride: integer - Index increment. + Index increment for `x`. Returns ------- x: Float64Array - Input array. + Input array `x`. Examples -------- // Standard Usage: > var x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); - > {{alias}}( x.length, 5.0, x, 1 ) + > var alpha = 5.0; + > {{alias}}( x.length, alpha, x, 1 ) [ 3.0, 6.0, 8.0, 0.0, 9.0, 4.0, 2.0 ] // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); - > {{alias}}( 3, 5.0, x, 2 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > alpha = 5.0; + > var stride = 2; + > {{alias}}( N, alpha, x, stride ) [ 3.0, 1.0, 8.0, -5.0, 9.0, -1.0, -3.0 ] // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 5.0, x1, 2 ) + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); + > alpha = 5.0; + > stride = 2; + > {{alias}}( N, alpha, x1, stride ) [ 3.0, 3.0, 1.0, 5.0, -1.0 ] > x0 [ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ] - {{alias}}.ndarray( N, alpha, x, stride, offset ) Adds a constant to each element in a double-precision floating-point strided array using alternative indexing semantics. @@ -71,26 +77,30 @@ Input array. stride: integer - Index increment. + Index increment for `x`. offset: integer - Starting index. + Starting index of `x`. Returns ------- x: Float64Array - Input array. + Input array `x`. Examples -------- // Standard Usage: > var x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); - > {{alias}}.ndarray( x.length, 5.0, x, 1, 0 ) + > var alpha = 5.0; + > {{alias}}.ndarray( x.length, alpha, x, 1, 0 ) [ 3.0, 6.0, 8.0, 0.0, 9.0, 4.0, 2.0 ] // Using an index offset: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); - > {{alias}}.ndarray( 3, 5.0, x, 2, 1 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > alpha = 5.0; + > var stride = 2; + > {{alias}}.ndarray( N, alpha, x, stride, 1 ) [ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ] See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapx/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dapx/docs/types/index.d.ts index 1211a0d34637..99f90326ef7f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapx/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/dapx/docs/types/index.d.ts @@ -29,7 +29,7 @@ interface Routine { * @param alpha - constant * @param x - input array * @param stride - stride length - * @returns input array + * @returns `x` * * @example * var Float64Array = require( '@stdlib/array/float64' ); @@ -49,7 +49,7 @@ interface Routine { * @param x - input array * @param stride - stride length * @param offset - starting index - * @returns input array + * @returns `x` * * @example * var Float64Array = require( '@stdlib/array/float64' ); @@ -69,7 +69,7 @@ interface Routine { * @param alpha - constant * @param x - input array * @param stride - stride length -* @returns input array +* @returns `x` * * @example * var Float64Array = require( '@stdlib/array/float64' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapx/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dapx/examples/index.js index 58d039e922be..55c571652632 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapx/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapx/examples/index.js @@ -18,11 +18,27 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var round = require( '@stdlib/math/base/special/round' ); +var randu = require( '@stdlib/random/base/randu' ); +var Float64Array = require( '@stdlib/array/float64' ); var dapx = require( './../lib' ); -var x = filledarrayBy( 10, 'float64', discreteUniform( -100, 100 ) ); +var rand; +var sign; +var x; +var i; + +x = new Float64Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + rand = round( randu()*100.0 ); + sign = randu(); + if ( sign < 0.5 ) { + sign = -1.0; + } else { + sign = 1.0; + } + x[ i ] = sign * rand; +} console.log( x ); dapx( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapx/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/dapx/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapx/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/dapx/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value node_dapx( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 2 ); - c_dapx( N, alpha, X, stride ); - return NULL; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapx/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/dapx/src/addon.cpp new file mode 100644 index 000000000000..7280d7e21b67 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dapx/src/addon.cpp @@ -0,0 +1,128 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/dapx.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_dapx { + + /** + * Adds a constant to each element in a double-precision floating-point strided array. + * + * ## Notes + * + * - When called from JavaScript, the function expects four arguments: + * + * - `N`: number of indexed elements + * - `alpha`: scalar + * - `X`: input array + * - `strideX`: `X` stride length + */ + napi_value node_dapx( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 4; + napi_value argv[ 4 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 4 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 4 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); + return nullptr; + } + + bool res2; + status = napi_is_typedarray( env, argv[ 2 ], &res2 ); + assert( status == napi_ok ); + if ( res2 == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float64Array." ); + return nullptr; + } + + napi_valuetype vtype3; + status = napi_typeof( env, argv[ 3 ], &vtype3 ); + assert( status == napi_ok ); + if ( vtype3 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + double alpha; + status = napi_get_value_double( env, argv[ 1 ], &alpha ); + assert( status == napi_ok ); + + int64_t strideX; + status = napi_get_value_int64( env, argv[ 3 ], &strideX ); + assert( status == napi_ok ); + + napi_typedarray_type vtype2; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype2 != napi_float64_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float64Array." ); + return nullptr; + } + if ( (N-1)*llabs(strideX) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + c_dapx( N, alpha, (double *)X, strideX ); + + return nullptr; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_dapx, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_dapx diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.dapx.js b/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.dapx.js index 539c980f43f1..1ad083a0c40f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.dapx.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.dapx.js @@ -86,7 +86,7 @@ tape( 'the function returns a reference to the input array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) { var expected; var x; @@ -102,7 +102,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if `alpha` equals `0`, the function returns the output array unchanged', function test( t ) { +tape( 'if `alpha` equals `0`, the function returns `x` unchanged', function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.dapx.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.dapx.native.js index 21e7a2240082..c90f015cb356 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.dapx.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.dapx.native.js @@ -95,7 +95,7 @@ tape( 'the function returns a reference to the input array', opts, function test t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', opts, function test( t ) { var expected; var x; @@ -111,7 +111,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if `alpha` equals `0`, the function returns the output array unchanged', opts, function test( t ) { +tape( 'if `alpha` equals `0`, the function returns `x` unchanged', opts, function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.ndarray.js index db2e07f0f97a..2cdbdfb45b20 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.ndarray.js @@ -86,7 +86,7 @@ tape( 'the function returns a reference to the input array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) { var expected; var x; @@ -102,7 +102,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if `alpha` equals `0`, the function returns the output array unchanged', function test( t ) { +tape( 'if `alpha` equals `0`, the function returns `x` unchanged', function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.ndarray.native.js index d68862de0c82..b7bce4bd8cca 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapx/test/test.ndarray.native.js @@ -95,7 +95,7 @@ tape( 'the function returns a reference to the input array', opts, function test t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', opts, function test( t ) { var expected; var x; @@ -111,7 +111,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if `alpha` equals `0`, the function returns the output array unchanged', opts, function test( t ) { +tape( 'if `alpha` equals `0`, the function returns `x` unchanged', opts, function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/README.md index 7ef97e680803..4ae499991c8e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/README.md @@ -44,8 +44,9 @@ Adds a constant to each double-precision floating-point strided array element an var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); +var N = x.length; -var v = dapxsumkbn( 3, 5.0, x, 1 ); +var v = dapxsumkbn( N, 5.0, x, 1 ); // returns 16.0 ``` @@ -55,14 +56,16 @@ The function has the following parameters: - **x**: input [`Float64Array`][@stdlib/array/float64]. - **stride**: index increment for `x`. -The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to access every other element in `x`, +The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element in `x`, ```javascript var Float64Array = require( '@stdlib/array/float64' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); +var N = floor( x.length / 2 ); -var v = dapxsumkbn( 4, 5.0, x, 2 ); +var v = dapxsumkbn( N, 5.0, x, 2 ); // returns 25.0 ``` @@ -72,11 +75,14 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var v = dapxsumkbn( 4, 5.0, x1, 2 ); +var N = floor( x0.length / 2 ); + +var v = dapxsumkbn( N, 5.0, x1, 2 ); // returns 25.0 ``` @@ -88,8 +94,9 @@ Adds a constant to each double-precision floating-point strided array element an var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); +var N = x.length; -var v = dapxsumkbn.ndarray( 3, 5.0, x, 1, 0 ); +var v = dapxsumkbn.ndarray( N, 5.0, x, 1, 0 ); // returns 16.0 ``` @@ -101,10 +108,12 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the ```javascript var Float64Array = require( '@stdlib/array/float64' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var N = floor( x.length / 2 ); -var v = dapxsumkbn.ndarray( 4, 5.0, x, 2, 1 ); +var v = dapxsumkbn.ndarray( N, 5.0, x, 2, 1 ); // returns 25.0 ``` @@ -129,11 +138,18 @@ var v = dapxsumkbn.ndarray( 4, 5.0, x, 2, 1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float64Array = require( '@stdlib/array/float64' ); var dapxsumkbn = require( '@stdlib/blas/ext/base/dapxsumkbn' ); -var x = filledarrayBy( 10, 'float64', discreteUniform( 0, 100 ) ); +var x; +var i; + +x = new Float64Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = dapxsumkbn( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.js index 4ff50f16bf0a..6872da33c834 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var dapxsumkbn = require( './../lib/dapxsumkbn.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x; + var i; + + x = new Float64Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.native.js index eda73b750834..5c0f4dc5fbc1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var dapxsumkbn = tryRequire( resolve( __dirname, './../lib/dapxsumkbn.native.js' var opts = { 'skip': ( dapxsumkbn instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x; + var i; + + x = new Float64Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.ndarray.js index be58cad1369c..36a0f01dd907 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.ndarray.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var dapxsumkbn = require( './../lib/ndarray.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x; + var i; + + x = new Float64Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.ndarray.native.js index 9d41530d4779..aac2aa92684e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var dapxsumkbn = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) var opts = { 'skip': ( dapxsumkbn instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x; + var i; + + x = new Float64Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/docs/repl.txt index e4b352bfc7da..3e7d1f3b33c3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/docs/repl.txt @@ -3,8 +3,8 @@ Adds a constant to each double-precision floating-point strided array element and computes the sum using an improved Kahan–Babuška algorithm. - The `N` and stride parameters determine which elements in the strided - array are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` are accessed + at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -39,16 +39,19 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > {{alias}}( 3, 5.0, x, 2 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > var stride = 2; + > {{alias}}( N, 5.0, x, stride ) 16.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 5.0, x1, 2) + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); + > stride = 2; + > {{alias}}( N, 5.0, x1, stride ) 14.0 - {{alias}}.ndarray( N, alpha, x, stride, offset ) Adds a constant to each double-precision floating-point strided array element and computes the sum using an improved Kahan–Babuška algorithm and @@ -89,7 +92,8 @@ // Using offset parameter: > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > {{alias}}.ndarray( 3, 5.0, x, 2, 1 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}.ndarray( N, 5.0, x, 2, 1 ) 14.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/examples/index.js index a7f4a0041261..1d2888396a02 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/examples/index.js @@ -18,11 +18,18 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float64Array = require( '@stdlib/array/float64' ); var dapxsumkbn = require( './../lib' ); -var x = filledarrayBy( 10, 'float64', discreteUniform( 0.0, 100.0 ) ); +var x; +var i; + +x = new Float64Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = dapxsumkbn( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' -#include - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 2 ); - - napi_value v; - napi_status status = napi_create_double( env, stdlib_strided_dapxsumkbn( N, alpha, X, stride ), &v ); - assert( status == napi_ok ); - - return v; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/src/addon.cpp new file mode 100644 index 000000000000..28c85ad76ebc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/src/addon.cpp @@ -0,0 +1,130 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/dapxsumkbn.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_dapxsumkbn { + + /** + * Adds a constant to each double-precision floating-point strided array element and computes the sum using an improved Kahan–Babuška algorithm. + * + * ## Notes + * + * - When called from JavaScript, the function expects four arguments: + * + * - `N`: number of indexed elements + * - `alpha`: constant + * - `X`: input array + * - `stride`: stride length + */ + napi_value node_dapxsumkbn( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 4; + napi_value argv[ 4 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 4 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 4 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); + return nullptr; + } + + bool res; + status = napi_is_typedarray( env, argv[ 2 ], &res ); + assert( status == napi_ok ); + if ( res == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float64Array." ); + return nullptr; + } + + napi_valuetype vtype3; + status = napi_typeof( env, argv[ 3 ], &vtype3 ); + assert( status == napi_ok ); + if ( vtype3 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + double alpha; + status = napi_get_value_double( env, argv[ 1 ], &alpha ); + assert( status == napi_ok ); + + int64_t stride; + status = napi_get_value_int64( env, argv[ 3 ], &stride ); + assert( status == napi_ok ); + + napi_typedarray_type vtype2; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype2 != napi_float64_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float64Array." ); + return nullptr; + } + if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + napi_value v; + status = napi_create_double( env, stdlib_strided_dapxsumkbn( N, alpha, (double *)X, stride ), &v ); + assert( status == napi_ok ); + + return v; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_dapxsumkbn, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_dapxsumkbn diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.dapxsumkbn.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.dapxsumkbn.js index d77d6e304bfb..ccd84e860586 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.dapxsumkbn.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.dapxsumkbn.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var dapxsumkbn = require( './../lib/dapxsumkbn.js' ); @@ -35,7 +36,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( dapxsumkbn.length, 4, 'returns expected value' ); + t.strictEqual( dapxsumkbn.length, 4, 'has expected arity' ); t.end(); }); @@ -94,6 +95,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -108,13 +110,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = dapxsumkbn( 4, 5.0, x, 2 ); + N = floor( x.length / 2 ); + v = dapxsumkbn( N, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; @@ -129,7 +133,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = dapxsumkbn( 4, 5.0, x, -2 ); + N = floor( x.length / 2 ); + v = dapxsumkbn( N, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); @@ -150,6 +155,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; + var N; var v; x0 = new Float64Array([ @@ -165,7 +171,9 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - v = dapxsumkbn( 4, 5.0, x1, 2 ); + N = floor(x1.length / 2); + + v = dapxsumkbn( N, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.dapxsumkbn.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.dapxsumkbn.native.js index 9b5276b82135..e8215ed13549 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.dapxsumkbn.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.dapxsumkbn.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( dapxsumkbn.length, 4, 'returns expected value' ); + t.strictEqual( dapxsumkbn.length, 4, 'has expected arity' ); t.end(); }); @@ -212,6 +213,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -226,13 +228,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = dapxsumkbn( 4, 5.0, x, 2 ); + N = floor( x.length / 2 ); + v = dapxsumkbn( N, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -247,7 +251,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = dapxsumkbn( 4, 5.0, x, -2 ); + N = floor( x.length / 2 ); + v = dapxsumkbn( N, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); @@ -268,6 +273,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; + var N; var v; x0 = new Float64Array([ @@ -283,7 +289,9 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - v = dapxsumkbn( 4, 5.0, x1, 2 ); + N = floor(x1.length / 2); + + v = dapxsumkbn( N, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.ndarray.js index 2ba7edc195fa..2a526c76e4c6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.ndarray.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var dapxsumkbn = require( './../lib/ndarray.js' ); @@ -35,7 +36,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( dapxsumkbn.length, 5, 'returns expected value' ); + t.strictEqual( dapxsumkbn.length, 5, 'has expected arity' ); t.end(); }); @@ -94,6 +95,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -108,13 +110,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = dapxsumkbn( 4, 5.0, x, 2, 0 ); + N = floor( x.length / 2 ); + v = dapxsumkbn( N, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; @@ -129,7 +133,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = dapxsumkbn( 4, 5.0, x, -2, 6 ); + N = floor( x.length / 2 ); + v = dapxsumkbn( N, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); @@ -148,6 +153,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { + var N; var x; var v; @@ -161,8 +167,9 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = dapxsumkbn( 4, 5.0, x, 2, 1 ); + v = dapxsumkbn( N, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.ndarray.native.js index 179476d28604..85d8ad4003fb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.ndarray.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 5', opts, function test( t ) { - t.strictEqual( dapxsumkbn.length, 5, 'returns expected value' ); + t.strictEqual( dapxsumkbn.length, 5, 'has expected arity' ); t.end(); }); @@ -103,6 +104,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -117,13 +119,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = dapxsumkbn( 4, 5.0, x, 2, 0 ); + N = floor( x.length / 2 ); + v = dapxsumkbn( N, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -138,7 +142,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = dapxsumkbn( 4, 5.0, x, -2, 6 ); + N = floor( x.length / 2 ); + v = dapxsumkbn( N, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); @@ -157,6 +162,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { + var N; var x; var v; @@ -170,8 +176,9 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = dapxsumkbn( 4, 5.0, x, 2, 1 ); + v = dapxsumkbn( N, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/docs/types/index.d.ts index 93cc7a29073f..e47c736c52eb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/docs/types/index.d.ts @@ -146,7 +146,7 @@ interface Namespace { * @param alpha - constant * @param x - input array * @param stride - stride length - * @returns input array + * @returns `x` * * @example * var Float64Array = require( '@stdlib/array/float64' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/README.md index f145d06db915..406a7dca47af 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/README.md @@ -44,8 +44,9 @@ Adds a constant to each single-precision floating-point strided array element an var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +var N = x.length; -var v = dsapxsum( 3, 5.0, x, 1 ); +var v = dsapxsum( N, 5.0, x, 1 ); // returns 16.0 ``` @@ -55,14 +56,16 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment for `x`. -The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element in the strided array, +The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); +var N = floor( x.length / 2 ); -var v = dsapxsum( 4, 5.0, x, 2 ); +var v = dsapxsum( N, 5.0, x, 2 ); // returns 25.0 ``` @@ -72,11 +75,14 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var v = dsapxsum( 4, 5.0, x1, 2 ); +var N = floor( x0.length / 2 ); + +var v = dsapxsum( N, 5.0, x1, 2 ); // returns 25.0 ``` @@ -88,8 +94,9 @@ Adds a constant to each single-precision floating-point strided array element an var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +var N = x.length; -var v = dsapxsum.ndarray( 3, 5.0, x, 1, 0 ); +var v = dsapxsum.ndarray( N, 5.0, x, 1, 0 ); // returns 16.0 ``` @@ -97,14 +104,16 @@ The function has the following additional parameters: - **offset**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to access every other value in the strided array starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access every other value in `x` starting from the second value ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var N = floor( x.length / 2 ); -var v = dsapxsum.ndarray( 4, 5.0, x, 2, 1 ); +var v = dsapxsum.ndarray( N, 5.0, x, 2, 1 ); // returns 25.0 ``` @@ -130,11 +139,18 @@ var v = dsapxsum.ndarray( 4, 5.0, x, 2, 1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var dsapxsum = require( '@stdlib/blas/ext/base/dsapxsum' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); +var x; +var i; + +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = dsapxsum( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.js index 87bf2ee909fc..1bc8431b4ccd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var dsapxsum = require( './../lib/dsapxsum.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.native.js index 66defd69e513..4877ac1f68e8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var dsapxsum = tryRequire( resolve( __dirname, './../lib/dsapxsum.native.js' ) ) var opts = { 'skip': ( dsapxsum instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.ndarray.js index 6299c00494a9..0a646c147af4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.ndarray.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var dsapxsum = require( './../lib/ndarray.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.ndarray.native.js index 28c13c39de37..6bc4c27d0abc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var dsapxsum = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( dsapxsum instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/docs/repl.txt index dc49fe91b05b..a8ef3a367711 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/docs/repl.txt @@ -4,8 +4,8 @@ element and computes the sum using extended accumulation and returning an extended precision result. - The `N` and `stride` parameters determine which elements in the strided - array are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` are accessed + at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -40,16 +40,19 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > {{alias}}( 3, 5.0, x, 2 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > var stride = 2; + > {{alias}}( N, 5.0, x, stride ) 16.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 5.0, x1, 2 ) + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); + > stride = 2; + > {{alias}}( N, 5.0, x1, stride ) 14.0 - {{alias}}.ndarray( N, alpha, x, stride, offset ) Adds a constant to each single-precision floating-point strided array element and computes the sum using extended accumulation and alternative @@ -89,8 +92,9 @@ 16.0 // Using offset parameter: - > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > {{alias}}.ndarray( 3, 5.0, x, 2, 1 ) + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}.ndarray( N, 5.0, x, 2, 1 ) 14.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/examples/index.js index b3278a6935c5..5cc9839becc2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/examples/index.js @@ -18,11 +18,18 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var dsapxsum = require( './../lib' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); +var x; +var i; + +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = dsapxsum( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' -#include - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, N, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 2 ); - - napi_value v; - status = napi_create_double( env, stdlib_strided_dsapxsum( N, alpha, X, stride ), &v ); - assert( status == napi_ok ); - return v; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/src/addon.cpp new file mode 100644 index 000000000000..be1bbe59606a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/src/addon.cpp @@ -0,0 +1,130 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/dsapxsum.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_dsapxsum { + + /** + * Adds a constant to each single-precision floating-point strided array element and computes the sum using extended accumulation and returning an extended precision result. + * + * ## Notes + * + * - When called from JavaScript, the function expects four arguments: + * + * - `N`: number of indexed elements + * - `alpha`: constant + * - `X`: input array + * - `stride`: stride length + */ + napi_value node_dsapxsum( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 4; + napi_value argv[ 4 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 4 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 4 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); + return nullptr; + } + + bool res; + status = napi_is_typedarray( env, argv[ 2 ], &res ); + assert( status == napi_ok ); + if ( res == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype3; + status = napi_typeof( env, argv[ 3 ], &vtype3 ); + assert( status == napi_ok ); + if ( vtype3 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + double alpha; + status = napi_get_value_double( env, argv[ 1 ], &alpha ); + assert( status == napi_ok ); + + int64_t stride; + status = napi_get_value_int64( env, argv[ 3 ], &stride ); + assert( status == napi_ok ); + + napi_typedarray_type vtype2; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype2 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + napi_value v; + status = napi_create_double( env, stdlib_strided_dsapxsum( N, (float)alpha, (float *)X, stride ), &v ); + assert( status == napi_ok ); + + return v; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_dsapxsum, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_dsapxsum diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.dsapxsum.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.dsapxsum.js index 017eaf731d73..035e7d40d230 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.dsapxsum.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.dsapxsum.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var dsapxsum = require( './../lib/dsapxsum.js' ); @@ -35,7 +36,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( dsapxsum.length, 4, 'returns expected value' ); + t.strictEqual( dsapxsum.length, 4, 'has expected arity' ); t.end(); }); @@ -102,6 +103,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -116,13 +118,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = dsapxsum( 4, 5.0, x, 2 ); + N = floor( x.length / 2 ); + v = dsapxsum( N, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; var i; @@ -138,7 +142,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = dsapxsum( 4, 5.0, x, -2 ); + N = floor( x.length / 2 ); + v = dsapxsum( N, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -167,6 +172,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; + var N; var v; x0 = new Float32Array([ @@ -182,8 +188,9 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); - v = dsapxsum( 4, 5.0, x1, 2 ); + v = dsapxsum( N, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.dsapxsum.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.dsapxsum.native.js index 49f2fc85faca..927c98c898a2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.dsapxsum.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.dsapxsum.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( dsapxsum.length, 4, 'returns expected value' ); + t.strictEqual( dsapxsum.length, 4, 'has expected arity' ); t.end(); }); @@ -220,6 +221,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -234,13 +236,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = dsapxsum( 4, 5.0, x, 2 ); + N = floor( x.length / 2 ); + v = dsapxsum( N, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; var i; @@ -256,7 +260,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = dsapxsum( 4, 5.0, x, -2 ); + N = floor( x.length / 2 ); + v = dsapxsum( N, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -285,6 +290,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; + var N; var v; x0 = new Float32Array([ @@ -300,8 +306,9 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); - v = dsapxsum( 4, 5.0, x1, 2 ); + v = dsapxsum( N, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.ndarray.js index a09095020213..53762d5de58e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.ndarray.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var dsapxsum = require( './../lib/ndarray.js' ); @@ -35,7 +36,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( dsapxsum.length, 5, 'returns expected value' ); + t.strictEqual( dsapxsum.length, 5, 'has expected arity' ); t.end(); }); @@ -102,6 +103,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -116,13 +118,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = dsapxsum( 4, 5.0, x, 2, 0 ); + N = floor( x.length / 2 ); + v = dsapxsum( N, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; var i; @@ -138,7 +142,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = dsapxsum( 4, 5.0, x, -2, 6 ); + N = floor( x.length / 2 ); + v = dsapxsum( N, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -165,6 +170,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { + var N; var x; var v; @@ -178,8 +184,9 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = dsapxsum( 4, 5.0, x, 2, 1 ); + v = dsapxsum( N, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.ndarray.native.js index 59fb184148a8..35bbebbfc1ee 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsum/test/test.ndarray.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 5', opts, function test( t ) { - t.strictEqual( dsapxsum.length, 5, 'returns expected value' ); + t.strictEqual( dsapxsum.length, 5, 'has expected arity' ); t.end(); }); @@ -111,6 +112,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -125,13 +127,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = dsapxsum( 4, 5.0, x, 2, 0 ); + N = floor( x.length / 2 ); + v = dsapxsum( N, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; var i; @@ -147,7 +151,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = dsapxsum( 4, 5.0, x, -2, 6 ); + N = floor( x.length / 2 ); + v = dsapxsum( N, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -174,6 +179,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { + var N; var x; var v; @@ -187,8 +193,9 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = dsapxsum( 4, 5.0, x, 2, 1 ); + v = dsapxsum( N, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dssum/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dssum/manifest.json index a27f5053aae0..8a60f30e0d0a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dssum/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dssum/manifest.json @@ -1,82 +1,42 @@ { - "options": { - "task": "build" - }, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "task": "build", - "src": [ - "./src/dssum.c" - ], - "include": [ - "./include" - ], - "libraries": [ - "-lm" - ], - "libpath": [], - "dependencies": [ - "@stdlib/blas/ext/base/dssumpw", - "@stdlib/napi/argv", - "@stdlib/napi/export", - "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float32array" - - ] - }, - { - "task": "benchmark", - "src": [ - "./src/dssum.c" - ], - "include": [ - "./include" - ], - "libraries": [ - "-lm" - ], - "libpath": [], - "dependencies": [ - "@stdlib/blas/ext/base/dssumpw" - ] - }, - { - "task": "examples", - "src": [ - "./src/dssum.c" - ], - "include": [ - "./include" - ], - "libraries": [ - "-lm" - ], - "libpath": [], - "dependencies": [ - "@stdlib/blas/ext/base/dssumpw" - ] - } - ] + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [ + "./src/dssum.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/ext/base/dssumpw" + ] + } + ] } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dssum/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dssum/src/addon.c index 3904a53fad15..db151490d609 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dssum/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dssum/src/addon.c @@ -35,13 +35,12 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); napi_value v; - napi_status status = napi_create_double( env, stdlib_strided_dssum( N, X, stride ), &v ); + status = napi_create_double( env, stdlib_strided_dssum( N, (float *)X, stride ), &v ); assert( status == napi_ok ); - return v; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsum/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsum/README.md index febeda650931..433f55b71bf8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsum/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsum/README.md @@ -56,14 +56,16 @@ The function has the following parameters: - **x**: input [`Float64Array`][@stdlib/array/float64]. - **stride**: index increment for `x`. -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element in the strided array, +The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the sum of every other element in `x`, ```javascript var Float64Array = require( '@stdlib/array/float64' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); +var N = floor( x.length / 2 ); -var v = dsum( 4, x, 2 ); +var v = dsum( N, x, 2 ); // returns 5.0 ``` @@ -73,11 +75,14 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var v = dsum( 4, x1, 2 ); +var N = floor( x0.length / 2 ); + +var v = dsum( N, x1, 2 ); // returns 5.0 ``` @@ -89,8 +94,9 @@ Computes the sum of double-precision floating-point strided array elements using var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); +var N = x.length; -var v = dsum.ndarray( 3, x, 1, 0 ); +var v = dsum.ndarray( N, x, 1, 0 ); // returns 1.0 ``` @@ -98,14 +104,16 @@ The function has the following additional parameters: - **offset**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other value in the strided array starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other value in `x` starting from the second value ```javascript var Float64Array = require( '@stdlib/array/float64' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var N = floor( x.length / 2 ); -var v = dsum.ndarray( 4, x, 2, 1 ); +var v = dsum.ndarray( N, x, 2, 1 ); // returns 5.0 ``` @@ -130,11 +138,18 @@ var v = dsum.ndarray( 4, x, 2, 1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float64Array = require( '@stdlib/array/float64' ); var dsum = require( '@stdlib/blas/ext/base/dsum' ); -var x = filledarrayBy( 10, 'float64', discreteUniform( 0, 100 ) ); +var x; +var i; + +x = new Float64Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = dsum( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.js index 4cea809eacf3..8ac3515ecccc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var dsum = require( './../lib/dsum.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x; + var i; + + x = new Float64Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*10.0 ) - 20.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.native.js index a5cdc68d94f8..5e221895b4de 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var dsum = tryRequire( resolve( __dirname, './../lib/dsum.native.js' ) ); var opts = { 'skip': ( dsum instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x; + var i; + + x = new Float64Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*10.0 ) - 20.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.ndarray.js index 26b8ec1af487..81fad361bd13 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.ndarray.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var dsum = require( './../lib/ndarray.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x; + var i; + + x = new Float64Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*10.0 ) - 20.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.ndarray.native.js index eff365899b03..df4cb59656d7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsum/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var dsum = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( dsum instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x; + var i; + + x = new Float64Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*10.0 ) - 20.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsum/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsum/docs/repl.txt index 377feb1ce2d3..1aa6e0bc1f97 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsum/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dsum/docs/repl.txt @@ -2,8 +2,8 @@ {{alias}}( N, x, stride ) Computes the sum of double-precision floating-point strided array elements. - The `N` and stride parameters determine which elements in the strided array - are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` are accessed + at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -33,18 +33,21 @@ > {{alias}}( x.length, x, 1 ) 1.0 - // Using `N` and stride parameters: + // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > {{alias}}( 3, x, 2 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > var stride = 2; + > {{alias}}( N, x, stride ) 1.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, x1, 2 ) + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); + > stride = 2; + > {{alias}}( N, x1, stride ) -1.0 - {{alias}}.ndarray( N, x, stride, offset ) Computes the sum of double-precision floating-point strided array elements using alternative indexing semantics. @@ -80,8 +83,9 @@ 1.0 // Using offset parameter: - > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > {{alias}}.ndarray( 3, x, 2, 1 ) + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}.ndarray( N, x, 2, 1 ) -1.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsum/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsum/examples/index.js index a04aad391efe..f4ed3bde00d2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsum/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsum/examples/index.js @@ -18,11 +18,18 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float64Array = require( '@stdlib/array/float64' ); var dsum = require( './../lib' ); -var x = filledarrayBy( 10, 'float64', discreteUniform( -100, 100 ) ); +var x; +var i; + +x = new Float64Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = dsum( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsum/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/dsum/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsum/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/dsum/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 1 ); - - napi_value v; - napi_status status = napi_create_double( env, stdlib_strided_dsum( N, X, stride ), &v ); - assert( status == napi_ok ); - - return v; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsum/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/dsum/src/addon.cpp new file mode 100644 index 000000000000..3dfacd120852 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsum/src/addon.cpp @@ -0,0 +1,117 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/dsum.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_dsum { + + /** + * Computes the sum of double-precision floating-point strided array elements. + * + * ## Notes + * + * - When called from JavaScript, the function expects three arguments: + * + * - `N`: number of indexed elements + * - `X`: input array + * - `stride`: stride length + */ + napi_value node_dsum( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 3; + napi_value argv[ 3 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 3 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + bool res; + status = napi_is_typedarray( env, argv[ 1 ], &res ); + assert( status == napi_ok ); + if ( res == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float64Array." ); + return nullptr; + } + + napi_valuetype vtype2; + status = napi_typeof( env, argv[ 2 ], &vtype2 ); + assert( status == napi_ok ); + if ( vtype2 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + int64_t stride; + status = napi_get_value_int64( env, argv[ 2 ], &stride ); + assert( status == napi_ok ); + + napi_typedarray_type vtype1; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype1 != napi_float64_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float64Array." ); + return nullptr; + } + if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + napi_value v; + status = napi_create_double( env, stdlib_strided_dsum( N, (double *)X, stride ), &v ); + assert( status == napi_ok ); + + return v; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_dsum, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_dsum diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.dsum.js b/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.dsum.js index 2dfc3d5be1c2..829371758c1d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.dsum.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.dsum.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var dsum = require( './../lib/dsum.js' ); @@ -35,7 +36,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 3', function test( t ) { - t.strictEqual( dsum.length, 3, 'returns expected value' ); + t.strictEqual( dsum.length, 3, 'has expected arity' ); t.end(); }); @@ -109,7 +110,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsum( N, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -132,7 +133,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsum( N, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -170,7 +171,7 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = 4; + N = floor(x1.length / 2); v = dsum( N, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.dsum.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.dsum.native.js index bdcb51522b5e..caf5beda25b7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.dsum.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.dsum.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 3', opts, function test( t ) { - t.strictEqual( dsum.length, 3, 'returns expected value' ); + t.strictEqual( dsum.length, 3, 'has expected arity' ); t.end(); }); @@ -200,7 +201,7 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsum( N, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -223,7 +224,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsum( N, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -261,7 +262,7 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = 4; + N = floor(x1.length / 2); v = dsum( N, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.ndarray.js index 69b88a66fa92..2e2169aacac7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.ndarray.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var dsum = require( './../lib/ndarray.js' ); @@ -35,7 +36,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( dsum.length, 4, 'returns expected value' ); + t.strictEqual( dsum.length, 4, 'has expected arity' ); t.end(); }); @@ -109,7 +110,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsum( N, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -132,7 +133,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsum( N, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -166,7 +167,7 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); - N = 4; + N = floor( x.length / 2 ); v = dsum( N, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.ndarray.native.js index ced60d19a7b4..e6ffc27b6e9b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsum/test/test.ndarray.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( dsum.length, 4, 'returns expected value' ); + t.strictEqual( dsum.length, 4, 'has expected arity' ); t.end(); }); @@ -118,7 +119,7 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsum( N, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -141,7 +142,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsum( N, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -175,7 +176,7 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); - N = 4; + N = floor( x.length / 2 ); v = dsum( N, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/README.md index 20ea8a24b5db..245aa6c28fd5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/README.md @@ -44,8 +44,9 @@ Computes the sum of double-precision floating-point strided array elements using var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); +var N = x.length; -var v = dsumkbn2( 3, x, 1 ); +var v = dsumkbn2( N, x, 1 ); // returns 1.0 ``` @@ -59,10 +60,12 @@ The `N` and `stride` parameters determine which elements in `x` are accessed at ```javascript var Float64Array = require( '@stdlib/array/float64' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); +var N = floor( x.length / 2 ); -var v = dsumkbn2( 4, x, 2 ); +var v = dsumkbn2( N, x, 2 ); // returns 5.0 ``` @@ -72,11 +75,14 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var v = dsumkbn2( 4, x1, 2 ); +var N = floor( x0.length / 2 ); + +var v = dsumkbn2( N, x1, 2 ); // returns 5.0 ``` @@ -88,8 +94,9 @@ Computes the sum of double-precision floating-point strided array elements using var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); +var N = x.length; -var v = dsumkbn2.ndarray( 3, x, 1, 0 ); +var v = dsumkbn2.ndarray( N, x, 1, 0 ); // returns 1.0 ``` @@ -104,8 +111,9 @@ var Float64Array = require( '@stdlib/array/float64' ); var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var N = floor( x.length / 2 ); -var v = dsumkbn2.ndarray( 4, x, 2, 1 ); +var v = dsumkbn2.ndarray( N, x, 2, 1 ); // returns 5.0 ``` @@ -130,11 +138,18 @@ var v = dsumkbn2.ndarray( 4, x, 2, 1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float64Array = require( '@stdlib/array/float64' ); var dsumkbn2 = require( '@stdlib/blas/ext/base/dsumkbn2' ); -var x = filledarrayBy( 10, 'float64', discreteUniform( -100, 100 ) ); +var x; +var i; + +x = new Float64Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = dsumkbn2( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.js index 66237dbf6082..afec7cc9c189 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var dsumkbn2 = require( './../lib/dsumkbn2.js' ); -// VARIABLES // - -var rand = uniform( -100.0, 100.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x; + var i; + + x = new Float64Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*10.0 ) - 20.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.native.js index 1eb8239f0d78..493ad09a311e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var dsumkbn2 = tryRequire( resolve( __dirname, './../lib/dsumkbn2.native.js' ) ) var opts = { 'skip': ( dsumkbn2 instanceof Error ) }; -var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x; + var i; + + x = new Float64Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*10.0 ) - 20.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.ndarray.js index 88a1b89b76ed..98158b67b5ef 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.ndarray.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var dsumkbn2 = require( './../lib/ndarray.js' ); -// VARIABLES // - -var rand = uniform( -100.0, 100.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x; + var i; + + x = new Float64Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*10.0 ) - 20.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.ndarray.native.js index b587ad2fde9b..7d229a4c8bbc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var dsumkbn2 = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( dsumkbn2 instanceof Error ) }; -var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x; + var i; + + x = new Float64Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*10.0 ) - 20.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/examples/index.js index c3b802e07f38..f0a9b781d101 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/examples/index.js @@ -18,11 +18,18 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float64Array = require( '@stdlib/array/float64' ); var dsumkbn2 = require( './../lib' ); -var x = filledarrayBy( 10, 'float64', discreteUniform( -100, 100 ) ); +var x; +var i; + +x = new Float64Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = dsumkbn2( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' -#include - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); - - napi_value v; - napi_create_double( env, stdlib_strided_dsumkbn2( N, X, strideX ), &v ); - - return v; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/src/addon.cpp new file mode 100644 index 000000000000..924413149a5e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/src/addon.cpp @@ -0,0 +1,117 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/dsumkbn2.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_dsumkbn2 { + + /** + * Computes the sum of double-precision floating-point strided array elements using a second-order iterative Kahan–Babuška algorithm. + * + * ## Notes + * + * - When called from JavaScript, the function expects three arguments: + * + * - `N`: number of indexed elements + * - `X`: input array + * - `stride`: stride length + */ + napi_value node_dsumkbn2( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 3; + napi_value argv[ 3 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 3 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + bool res; + status = napi_is_typedarray( env, argv[ 1 ], &res ); + assert( status == napi_ok ); + if ( res == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float64Array." ); + return nullptr; + } + + napi_valuetype vtype2; + status = napi_typeof( env, argv[ 2 ], &vtype2 ); + assert( status == napi_ok ); + if ( vtype2 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + int64_t stride; + status = napi_get_value_int64( env, argv[ 2 ], &stride ); + assert( status == napi_ok ); + + napi_typedarray_type vtype1; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype1 != napi_float64_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float64Array." ); + return nullptr; + } + if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + napi_value v; + status = napi_create_double( env, stdlib_strided_dsumkbn2( N, (double *)X, stride ), &v ); + assert( status == napi_ok ); + + return v; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_dsumkbn2, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_dsumkbn2 diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.dsumkbn2.js b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.dsumkbn2.js index 0e74cf92c7cb..3ec0e00165e4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.dsumkbn2.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.dsumkbn2.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var dsumkbn2 = require( './../lib/dsumkbn2.js' ); @@ -109,7 +110,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsumkbn2( N, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -132,7 +133,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsumkbn2( N, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -170,7 +171,7 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = 4; + N = floor(x1.length / 2); v = dsumkbn2( N, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.dsumkbn2.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.dsumkbn2.native.js index 09a7a5b243f5..520d987d2e6a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.dsumkbn2.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.dsumkbn2.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -200,7 +201,7 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsumkbn2( N, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -223,7 +224,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsumkbn2( N, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -261,7 +262,7 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = 4; + N = floor(x1.length / 2); v = dsumkbn2( N, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.ndarray.js index 6eaad80ee38d..2408d52ef7f1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.ndarray.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var dsumkbn2 = require( './../lib/ndarray.js' ); @@ -109,7 +110,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsumkbn2( N, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -132,7 +133,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsumkbn2( N, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -166,7 +167,7 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); - N = 4; + N = floor( x.length / 2 ); v = dsumkbn2( N, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.ndarray.native.js index 668f399f2ab6..ec94ebb36d3b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsumkbn2/test/test.ndarray.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -118,7 +119,7 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsumkbn2( N, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -141,7 +142,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = 4; + N = floor( x.length / 2 ); v = dsumkbn2( N, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -175,7 +176,7 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); - N = 4; + N = floor( x.length / 2 ); v = dsumkbn2( N, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md b/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md index 4c14fd5482e7..f5d6a80ae23c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md @@ -50,14 +50,16 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment. -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to add a constant to every other element +The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to add a constant to every other element ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +var N = floor( x.length / 2 ); -sapx( 4, 5.0, x, 2 ); +sapx( N, 5.0, x, 2 ); // x => [ 3.0, 1.0, 8.0, -5.0, 9.0, 0.0, 4.0, -3.0 ] ``` @@ -65,15 +67,17 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); // Initial array... var x0 = new Float32Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); // Create an offset view... var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var N = floor( x0.length/2 ); // Add a constant to every other element... -sapx( 3, 5.0, x1, 2 ); +sapx( N, 5.0, x1, 2 ); // x0 => [ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ] ``` @@ -94,7 +98,7 @@ The function has the following additional parameters: - **offset**: starting index. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of the strided array +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `x` ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -113,7 +117,7 @@ sapx.ndarray( 3, 5.0, x, 1, x.length-3 ); ## Notes -- If `N <= 0`, both functions return the input array unchanged. +- If `N <= 0`, both functions return `x` unchanged. @@ -126,11 +130,27 @@ sapx.ndarray( 3, 5.0, x, 1, x.length-3 ); ```javascript -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var round = require( '@stdlib/math/base/special/round' ); +var randu = require( '@stdlib/random/base/randu' ); +var Float32Array = require( '@stdlib/array/float32' ); var sapx = require( '@stdlib/blas/ext/base/sapx' ); -var x = filledarrayBy( 10, 'float32', uniform( -100.0, 100.0 ) ); +var rand; +var sign; +var x; +var i; + +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + rand = round( randu()*100.0 ); + sign = randu(); + if ( sign < 0.5 ) { + sign = -1.0; + } else { + sign = 1.0; + } + x[ i ] = sign * rand; +} console.log( x ); sapx( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.js index ffd0ff4adca6..fc8f88420392 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var sapx = require( './../lib/sapx.js' ); -// VARIABLES // - -var rand = uniform( -100.0, 100.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < len; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.native.js index c0d5da977159..ec66fd0dc0cd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var sapx = tryRequire( resolve( __dirname, './../lib/sapx.native.js' ) ); var opts = { 'skip': ( sapx instanceof Error ) }; -var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < len; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.js index b98d981d2b07..29b81da77048 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var sapx = require( './../lib/ndarray.js' ); -// VARIABLES // - -var rand = uniform( -100.0, 100.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < len; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.native.js index 650ac428642a..cd198d07eff6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var sapx = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( sapx instanceof Error ) }; -var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < len; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt index 42e084cc080c..0c12d6d9d792 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt @@ -3,13 +3,13 @@ Adds a constant to each element in a single-precision floating-point strided array. - The `N` and stride parameters determine which elements in the strided array - are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` are accessed + at runtime. Indexing is relative to the first index. To introduce an offset, use typed array views. - If `N <= 0`, the function returns the strided array unchanged. + If `N <= 0`, the function returns `x` unchanged. Parameters ---------- @@ -23,34 +23,40 @@ Input array. stride: integer - Index increment. + Index increment for `x`. Returns ------- x: Float32Array - Input array. + Input array `x`. Examples -------- // Standard Usage: > var x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); - > {{alias}}( x.length, 5.0, x, 1 ) + > var alpha = 5.0; + > {{alias}}( x.length, alpha, x, 1 ) [ 3.0, 6.0, 8.0, 0.0, 9.0, 4.0, 2.0 ] // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); - > {{alias}}( 3, 5.0, x, 2 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > alpha = 5.0; + > var stride = 2; + > {{alias}}( N, alpha, x, stride ) [ 3.0, 1.0, 8.0, -5.0, 9.0, -1.0, -3.0 ] // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 5.0, x1, 2 ) + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); + > alpha = 5.0; + > stride = 2; + > {{alias}}( N, alpha, x1, stride ) [ 3.0, 3.0, 1.0, 5.0, -1.0 ] > x0 [ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ] - {{alias}}.ndarray( N, alpha, x, stride, offset ) Adds a constant to each element in a single-precision floating-point strided array using alternative indexing semantics. @@ -71,26 +77,30 @@ Input array. stride: integer - Index increment. + Index increment for `x`. offset: integer - Starting index. + Starting index of `x`. Returns ------- x: Float32Array - Input array. + Input array `x`. Examples -------- // Standard Usage: > var x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); - > {{alias}}.ndarray( x.length, 5.0, x, 1, 0 ) + > var alpha = 5.0; + > {{alias}}.ndarray( x.length, alpha, x, 1, 0 ) [ 3.0, 6.0, 8.0, 0.0, 9.0, 4.0, 2.0 ] // Using an index offset: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); - > {{alias}}.ndarray( 3, 5.0, x, 2, 1 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > alpha = 5.0; + > var stride = 2; + > {{alias}}.ndarray( N, alpha, x, stride, 1 ) [ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ] See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/examples/index.js index 3e9bf3a73c87..650232f9d8e2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/examples/index.js @@ -18,12 +18,27 @@ 'use strict'; -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var round = require( '@stdlib/math/base/special/round' ); +var randu = require( '@stdlib/random/base/randu' ); +var Float32Array = require( '@stdlib/array/float32' ); var sapx = require( './../lib' ); -var x = filledarrayBy( 10, 'float32', uniform( -100.0, 100.0 ) ); +var rand; +var sign; +var x; +var i; +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + rand = round( randu()*100.0 ); + sign = randu(); + if ( sign < 0.5 ) { + sign = -1.0; + } else { + sign = 1.0; + } + x[ i ] = sign * rand; +} console.log( x ); sapx( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/sapx/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, alpha, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ) - c_sapx( N, alpha, X, strideX ); - return NULL; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.cpp new file mode 100644 index 000000000000..2d511f5f5af3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.cpp @@ -0,0 +1,128 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/sapx.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_sapx { + + /** + * Adds a constant to each element in a single-precision floating-point strided array. + * + * ## Notes + * + * - When called from JavaScript, the function expects four arguments: + * + * - `N`: number of indexed elements + * - `alpha`: scalar + * - `X`: input array + * - `strideX`: `X` stride length + */ + napi_value node_sapx( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 4; + napi_value argv[ 4 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 4 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 4 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); + return nullptr; + } + + bool res2; + status = napi_is_typedarray( env, argv[ 2 ], &res2 ); + assert( status == napi_ok ); + if ( res2 == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype3; + status = napi_typeof( env, argv[ 3 ], &vtype3 ); + assert( status == napi_ok ); + if ( vtype3 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + double alpha; + status = napi_get_value_double( env, argv[ 1 ], &alpha ); + assert( status == napi_ok ); + + int64_t strideX; + status = napi_get_value_int64( env, argv[ 3 ], &strideX ); + assert( status == napi_ok ); + + napi_typedarray_type vtype2; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype2 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(strideX) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + c_sapx( N, (float)alpha, (float *)X, strideX ); + + return nullptr; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_sapx, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_sapx diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.js index d0413321a0c2..d6af1182cc72 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.js @@ -86,7 +86,7 @@ tape( 'the function returns a reference to the input array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) { var expected; var x; @@ -102,7 +102,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if `alpha` equals `0`, the function returns the input array unchanged', function test( t ) { +tape( 'if `alpha` equals `0`, the function returns `x` unchanged', function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.native.js index 0b99f94efe61..4936985b82af 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.native.js @@ -95,7 +95,7 @@ tape( 'the function returns a reference to the input array', opts, function test t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', opts, function test( t ) { var expected; var x; @@ -111,7 +111,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if `alpha` equals `0`, the function returns the input array unchanged', opts, function test( t ) { +tape( 'if `alpha` equals `0`, the function returns `x` unchanged', opts, function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.js index 014e47e5ad8a..462982a68478 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.js @@ -86,7 +86,7 @@ tape( 'the function returns a reference to the input array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) { var expected; var x; @@ -102,7 +102,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if `alpha` equals `0`, the function returns the input array unchanged', function test( t ) { +tape( 'if `alpha` equals `0`, the function returns `x` unchanged', function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.native.js index 9f97b9f87a7c..88f1b8126580 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.native.js @@ -95,7 +95,7 @@ tape( 'the function returns a reference to the input array', opts, function test t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', opts, function test( t ) { var expected; var x; @@ -111,7 +111,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if `alpha` equals `0`, the function returns the input array unchanged', opts, function test( t ) { +tape( 'if `alpha` equals `0`, the function returns `x` unchanged', opts, function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/README.md b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/README.md index 7c7e27ae3ca7..effe09603735 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/README.md @@ -56,14 +56,16 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment for `x`. -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element in `x`, +The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); +var N = floor( x.length / 2 ); -var v = sapxsum( 4, 5.0, x, 2 ); +var v = sapxsum( N, 5.0, x, 2 ); // returns 25.0 ``` @@ -73,11 +75,14 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var v = sapxsum( 4, 5.0, x1, 2 ); +var N = floor( x0.length / 2 ); + +var v = sapxsum( N, 5.0, x1, 2 ); // returns 25.0 ``` @@ -99,14 +104,16 @@ The function has the following additional parameters: - **offset**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to access every other value in `x` starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access every other value in `x` starting from the second value ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var N = floor( x.length / 2 ); -var v = sapxsum.ndarray( 4, 5.0, x, 2, 1 ); +var v = sapxsum.ndarray( N, 5.0, x, 2, 1 ); // returns 25.0 ``` @@ -131,12 +138,22 @@ var v = sapxsum.ndarray( 4, 5.0, x, 2, 1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var sapxsum = require( '@stdlib/blas/ext/base/sapxsum' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); +var x; +var i; + +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); + +var v = sapxsum( x.length, 5.0, x, 1 ); +console.log( v ); ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.js index a3794363584e..7c7093df3de5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var sapxsum = require( './../lib/sapxsum.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.native.js index f850b14b21dc..d3efad2eac3f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var sapxsum = tryRequire( resolve( __dirname, './../lib/sapxsum.native.js' ) ); var opts = { 'skip': ( sapxsum instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.ndarray.js index 8197e74a9950..2a7a6dddc356 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.ndarray.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var sapxsum = require( './../lib/ndarray.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.ndarray.native.js index ad9b898716e7..4c3571eeb841 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var sapxsum = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( sapxsum instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/docs/repl.txt index b277320a58d3..645a563ce6ef 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/docs/repl.txt @@ -3,8 +3,8 @@ Adds a constant to each single-precision floating-point strided array element and computes the sum. - The `N` and stride parameters determine which elements in the strided - array are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` are accessed + at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -37,24 +37,27 @@ > {{alias}}( x.length, 5.0, x, 1 ) 16.0 - // Using `N` and stride parameters: + // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > {{alias}}( 3, 5.0, x, 2 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > var stride = 2; + > {{alias}}( N, 5.0, x, stride ) 16.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 5.0, x1, 2 ) + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); + > stride = 2; + > {{alias}}( N, 5.0, x1, stride ) 14.0 - {{alias}}.ndarray( N, alpha, x, stride, offset ) Adds a constant to each single-precision floating-point strided array element and computes the sum using alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the offset parameter supports indexing semantics based on a + buffer, the `offset` parameter supports indexing semantics based on a starting index. Parameters @@ -87,8 +90,9 @@ 16.0 // Using offset parameter: - > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > {{alias}}.ndarray( 3, 5.0, x, 2, 1 ) + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}.ndarray( N, 5.0, x, 2, 1 ) 14.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/examples/index.js index 9dffd93b0fc8..7124ce61ec87 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/examples/index.js @@ -18,11 +18,18 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var sapxsum = require( './../lib' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); +var x; +var i; + +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = sapxsum( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' -#include - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, alpha, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); - - napi_value v; - status = napi_create_double( env, (double)stdlib_strided_sapxsum( N, alpha, X, stride ), &v ); - assert( status == napi_ok ); - - return v; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/src/addon.cpp new file mode 100644 index 000000000000..76b29f8d478a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/src/addon.cpp @@ -0,0 +1,130 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/sapxsum.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_sapxsum { + + /** + * Adds a constant to each single-precision floating-point strided array element and computes the sum. + * + * ## Notes + * + * - When called from JavaScript, the function expects four arguments: + * + * - `N`: number of indexed elements + * - `alpha`: constant + * - `X`: input array + * - `stride`: stride length + */ + napi_value node_sapxsum( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 4; + napi_value argv[ 4 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 4 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 4 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); + return nullptr; + } + + bool res; + status = napi_is_typedarray( env, argv[ 2 ], &res ); + assert( status == napi_ok ); + if ( res == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype3; + status = napi_typeof( env, argv[ 3 ], &vtype3 ); + assert( status == napi_ok ); + if ( vtype3 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + double alpha; + status = napi_get_value_double( env, argv[ 1 ], &alpha ); + assert( status == napi_ok ); + + int64_t stride; + status = napi_get_value_int64( env, argv[ 3 ], &stride ); + assert( status == napi_ok ); + + napi_typedarray_type vtype2; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype2 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + napi_value v; + status = napi_create_double( env, (double)stdlib_strided_sapxsum( N, (float)alpha, (float *)X, stride ), &v ); + assert( status == napi_ok ); + + return v; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_sapxsum, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_sapxsum diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.ndarray.js index 6b1841d188ca..61fc59e77d03 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.ndarray.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var sapxsum = require( './../lib/ndarray.js' ); @@ -35,7 +36,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( sapxsum.length, 5, 'returns expected value' ); + t.strictEqual( sapxsum.length, 5, 'has expected arity' ); t.end(); }); @@ -94,6 +95,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -108,13 +110,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = sapxsum( 4, 5.0, x, 2, 0 ); + N = floor( x.length / 2 ); + v = sapxsum( N, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; @@ -129,7 +133,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = sapxsum( 4, 5.0, x, -2, 6 ); + N = floor( x.length / 2 ); + v = sapxsum( N, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); @@ -148,6 +153,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { + var N; var x; var v; @@ -161,8 +167,9 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = sapxsum( 4, 5.0, x, 2, 1 ); + v = sapxsum( N, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.ndarray.native.js index 6d6e3d7349d3..70b804ddb7cf 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.ndarray.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 5', opts, function test( t ) { - t.strictEqual( sapxsum.length, 5, 'returns expected value' ); + t.strictEqual( sapxsum.length, 5, 'has expected arity' ); t.end(); }); @@ -103,6 +104,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -117,13 +119,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = sapxsum( 4, 5.0, x, 2, 0 ); + N = floor( x.length / 2 ); + v = sapxsum( N, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -138,7 +142,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = sapxsum( 4, 5.0, x, -2, 6 ); + N = floor( x.length / 2 ); + v = sapxsum( N, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); @@ -157,6 +162,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { + var N; var x; var v; @@ -170,8 +176,9 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = sapxsum( 4, 5.0, x, 2, 1 ); + v = sapxsum( N, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.sapxsum.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.sapxsum.js index e69c204bcc8f..45232ed52350 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.sapxsum.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.sapxsum.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var sapxsum = require( './../lib/sapxsum.js' ); @@ -94,6 +95,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -108,13 +110,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = sapxsum( 4, 5.0, x, 2 ); + N = floor( x.length / 2 ); + v = sapxsum( N, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; @@ -129,7 +133,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = sapxsum( 4, 5.0, x, -2 ); + N = floor( x.length / 2 ); + v = sapxsum( N, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); @@ -150,6 +155,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; + var N; var v; x0 = new Float32Array([ @@ -165,8 +171,9 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); - v = sapxsum( 4, 5.0, x1, 2 ); + v = sapxsum( N, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.sapxsum.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.sapxsum.native.js index 5776424c10a5..81a46607b045 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.sapxsum.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsum/test/test.sapxsum.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( sapxsum.length, 4, 'returns expected value' ); + t.strictEqual( sapxsum.length, 4, 'has expected arity' ); t.end(); }); @@ -212,6 +213,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -226,13 +228,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = sapxsum( 4, 5.0, x, 2 ); + N = floor( x.length / 2 ); + v = sapxsum( N, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -247,7 +251,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = sapxsum( 4, 5.0, x, -2 ); + N = floor( x.length / 2 ); + v = sapxsum( N, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); @@ -268,6 +273,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; + var N; var v; x0 = new Float32Array([ @@ -283,8 +289,9 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); - v = sapxsum( 4, 5.0, x1, 2 ); + v = sapxsum( N, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/README.md index 6029f851c8dc..cac3a4097cf2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/README.md @@ -44,26 +44,28 @@ Adds a constant to each single-precision floating-point strided array element an var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +var N = x.length; -var v = sapxsumkbn( 3, 5.0, x, 1 ); +var v = sapxsumkbn( N, 5.0, x, 1 ); // returns 16.0 ``` The function has the following parameters: - **N**: number of indexed elements. -- **alpha**: scalar constant. - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment for `x`. -The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element in the strided array, +The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); +var N = floor( x.length / 2 ); -var v = sapxsumkbn( 4, 5.0, x, 2 ); +var v = sapxsumkbn( N, 5.0, x, 2 ); // returns 25.0 ``` @@ -73,11 +75,14 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var v = sapxsumkbn( 4, 5.0, x1, 2 ); +var N = floor( x0.length / 2 ); + +var v = sapxsumkbn( N, 5.0, x1, 2 ); // returns 25.0 ``` @@ -89,8 +94,9 @@ Adds a constant to each single-precision floating-point strided array element an var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +var N = x.length; -var v = sapxsumkbn.ndarray( 3, 5.0, x, 1, 0 ); +var v = sapxsumkbn.ndarray( N, 5.0, x, 1, 0 ); // returns 16.0 ``` @@ -98,14 +104,16 @@ The function has the following additional parameters: - **offset**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to access every other value in the strided array starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access every other value in `x` starting from the second value ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var N = floor( x.length / 2 ); -var v = sapxsumkbn.ndarray( 4, 5.0, x, 2, 1 ); +var v = sapxsumkbn.ndarray( N, 5.0, x, 2, 1 ); // returns 25.0 ``` @@ -130,11 +138,18 @@ var v = sapxsumkbn.ndarray( 4, 5.0, x, 2, 1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var sapxsumkbn = require( '@stdlib/blas/ext/base/sapxsumkbn' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); +var x; +var i; + +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = sapxsumkbn( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.js index 436b3c5fd9b3..99ead31c8a14 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var sapxsumkbn = require( './../lib/sapxsumkbn.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.native.js index 6533d38d9263..d0bdfbe68feb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var sapxsumkbn = tryRequire( resolve( __dirname, './../lib/sapxsumkbn.native.js' var opts = { 'skip': ( sapxsumkbn instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.ndarray.js index 2468257ec2fe..5d514a5dc971 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.ndarray.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var sapxsumkbn = require( './../lib/ndarray.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.ndarray.native.js index bcaf22fbf17a..f02a01b905b1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var sapxsumkbn = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) var opts = { 'skip': ( sapxsumkbn instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/docs/repl.txt index c19a98e099c9..7200ddeac7d0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/docs/repl.txt @@ -3,8 +3,8 @@ Adds a constant to each single-precision floating-point strided array element and computes the sum using an improved Kahan–Babuška algorithm. - The `N` and `stride` parameters determine which elements in the strided - array are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` are accessed + at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -39,16 +39,19 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > {{alias}}( 3, 5.0, x, 2 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > var stride = 2; + > {{alias}}( N, 5.0, x, stride ) 16.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 5.0, x1, 2 ) + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); + > stride = 2; + > {{alias}}( N, 5.0, x1, stride ) 14.0 - {{alias}}.ndarray( N, alpha, x, stride, offset ) Adds a constant to each single-precision floating-point strided array element and computes the sum using an improved Kahan–Babuška algorithm and @@ -88,8 +91,9 @@ 16.0 // Using offset parameter: - > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > {{alias}}.ndarray( 3, 5.0, x, 2, 1 ) + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}.ndarray( N, 5.0, x, 2, 1 ) 14.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/examples/index.js index 085e247e5682..9cf270e76a68 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/examples/index.js @@ -18,11 +18,18 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var sapxsumkbn = require( './../lib' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); +var x; +var i; + +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = sapxsumkbn( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' -#include - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, alpha, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 2 ); - - napi_value v; - napi_status status; - status = napi_create_double( env, (double)stdlib_strided_sapxsumkbn( N, alpha, X, stride ), &v ); - assert( status == napi_ok ); - return v; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/src/addon.cpp new file mode 100644 index 000000000000..0ea997785adc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/src/addon.cpp @@ -0,0 +1,130 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/sapxsumkbn.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_sapxsumkbn { + + /** + * Adds a constant to each single-precision floating-point strided array element and computes the sum using an improved Kahan–Babuška algorithm. + * + * ## Notes + * + * - When called from JavaScript, the function expects four arguments: + * + * - `N`: number of indexed elements + * - `alpha`: constant + * - `X`: input array + * - `stride`: stride length + */ + napi_value node_sapxsumkbn( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 4; + napi_value argv[ 4 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 4 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 4 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); + return nullptr; + } + + bool res; + status = napi_is_typedarray( env, argv[ 2 ], &res ); + assert( status == napi_ok ); + if ( res == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype3; + status = napi_typeof( env, argv[ 3 ], &vtype3 ); + assert( status == napi_ok ); + if ( vtype3 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + double alpha; + status = napi_get_value_double( env, argv[ 1 ], &alpha ); + assert( status == napi_ok ); + + int64_t stride; + status = napi_get_value_int64( env, argv[ 3 ], &stride ); + assert( status == napi_ok ); + + napi_typedarray_type vtype2; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype2 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + napi_value v; + status = napi_create_double( env, (double)stdlib_strided_sapxsumkbn( N, (float)alpha, (float *)X, stride ), &v ); + assert( status == napi_ok ); + + return v; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_sapxsumkbn, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_sapxsumkbn diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.ndarray.js index 9168b052806c..d2ddaba88f7c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.ndarray.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var sapxsumkbn = require( './../lib/ndarray.js' ); @@ -35,7 +36,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( sapxsumkbn.length, 5, 'returns expected value' ); + t.strictEqual( sapxsumkbn.length, 5, 'has expected arity' ); t.end(); }); @@ -94,6 +95,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -108,13 +110,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = sapxsumkbn( 4, 5.0, x, 2, 0 ); + N = floor( x.length / 2 ); + v = sapxsumkbn( N, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; @@ -129,7 +133,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = sapxsumkbn( 4, 5.0, x, -2, 6 ); + N = floor( x.length / 2 ); + v = sapxsumkbn( N, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); @@ -148,6 +153,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { + var N; var x; var v; @@ -161,8 +167,9 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = sapxsumkbn( 4, 5.0, x, 2, 1 ); + v = sapxsumkbn( N, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.ndarray.native.js index 845e5a7d30ce..5be62cd27f8e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.ndarray.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 5', opts, function test( t ) { - t.strictEqual( sapxsumkbn.length, 5, 'returns expected value' ); + t.strictEqual( sapxsumkbn.length, 5, 'has expected arity' ); t.end(); }); @@ -103,6 +104,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -117,13 +119,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = sapxsumkbn( 4, 5.0, x, 2, 0 ); + N = floor( x.length / 2 ); + v = sapxsumkbn( N, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -138,7 +142,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = sapxsumkbn( 4, 5.0, x, -2, 6 ); + N = floor( x.length / 2 ); + v = sapxsumkbn( N, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); @@ -157,6 +162,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { + var N; var x; var v; @@ -170,8 +176,9 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = sapxsumkbn( 4, 5.0, x, 2, 1 ); + v = sapxsumkbn( N, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.sapxsumkbn.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.sapxsumkbn.js index 7f1726ee0230..b428132469c2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.sapxsumkbn.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.sapxsumkbn.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var sapxsumkbn = require( './../lib/sapxsumkbn.js' ); @@ -35,7 +36,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( sapxsumkbn.length, 4, 'returns expected value' ); + t.strictEqual( sapxsumkbn.length, 4, 'has expected arity' ); t.end(); }); @@ -94,6 +95,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -108,13 +110,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = sapxsumkbn( 4, 5.0, x, 2 ); + N = floor( x.length / 2 ); + v = sapxsumkbn( N, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; @@ -129,7 +133,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = sapxsumkbn( 4, 5.0, x, -2 ); + N = floor( x.length / 2 ); + v = sapxsumkbn( N, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); @@ -150,6 +155,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; + var N; var v; x0 = new Float32Array([ @@ -165,8 +171,9 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); - v = sapxsumkbn( 4, 5.0, x1, 2 ); + v = sapxsumkbn( N, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.sapxsumkbn.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.sapxsumkbn.native.js index 34b37df19ff3..a3543c1580bb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.sapxsumkbn.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumkbn/test/test.sapxsumkbn.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( sapxsumkbn.length, 4, 'returns expected value' ); + t.strictEqual( sapxsumkbn.length, 4, 'has expected arity' ); t.end(); }); @@ -212,6 +213,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -226,13 +228,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = sapxsumkbn( 4, 5.0, x, 2 ); + N = floor( x.length / 2 ); + v = sapxsumkbn( N, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -247,7 +251,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = sapxsumkbn( 4, 5.0, x, -2 ); + N = floor( x.length / 2 ); + v = sapxsumkbn( N, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); @@ -268,6 +273,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; + var N; var v; x0 = new Float32Array([ @@ -283,8 +289,9 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); - v = sapxsumkbn( 4, 5.0, x1, 2 ); + v = sapxsumkbn( N, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/README.md index 2ea223b640e5..84439e5654c7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/README.md @@ -56,14 +56,16 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment for `x`. -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element in `x`, +The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); +var N = floor( x.length / 2 ); -var v = sapxsumpw( 4, 5.0, x, 2 ); +var v = sapxsumpw( N, 5.0, x, 2 ); // returns 25.0 ``` @@ -73,11 +75,14 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var v = sapxsumpw( 4, 5.0, x1, 2 ); +var N = floor( x0.length / 2 ); + +var v = sapxsumpw( N, 5.0, x1, 2 ); // returns 25.0 ``` @@ -103,10 +108,12 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var N = floor( x.length / 2 ); -var v = sapxsumpw.ndarray( 4, 5.0, x, 2, 1 ); +var v = sapxsumpw.ndarray( N, 5.0, x, 2, 1 ); // returns 25.0 ``` @@ -131,12 +138,18 @@ var v = sapxsumpw.ndarray( 4, 5.0, x, 2, 1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var sapxsumpw = require( '@stdlib/blas/ext/base/sapxsumpw' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); +var x; +var i; +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = sapxsumpw( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.js index 1e03ab275c86..b493f7547089 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.js @@ -21,10 +21,10 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var sapxsumpw = require( './../lib/sapxsumpw.js' ); @@ -40,9 +40,12 @@ var sapxsumpw = require( './../lib/sapxsumpw.js' ); */ function createBenchmark( len ) { var x; + var i; - x = filledarrayBy( len, 'float32', uniform( -10.0, 10.0 ) ); - + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.native.js index 756d5a078148..93db52a1f7a0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -49,9 +49,12 @@ var opts = { */ function createBenchmark( len ) { var x; + var i; - x = filledarrayBy( len, 'float32', uniform( -10.0, 10.0 ) ); - + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.ndarray.js index e680e6575f61..b6b6daac4c36 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.ndarray.js @@ -21,10 +21,10 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var sapxsumpw = require( './../lib/ndarray.js' ); @@ -40,9 +40,12 @@ var sapxsumpw = require( './../lib/ndarray.js' ); */ function createBenchmark( len ) { var x; + var i; - x = filledarrayBy( len, 'float32', uniform( -10.0, 10.0 ) ); - + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.ndarray.native.js index 00d203a97740..677788064f7f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -49,9 +49,12 @@ var opts = { */ function createBenchmark( len ) { var x; + var i; - x = filledarrayBy( len, 'float32', uniform( -10.0, 10.0 ) ); - + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/docs/repl.txt index 469b9b207f4f..acb1305e4683 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/docs/repl.txt @@ -3,7 +3,7 @@ Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation. - The `N` and stride parameters determine which elements in `x` are accessed + The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed @@ -39,18 +39,19 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); > var stride = 2; - > {{alias}}( 3, 5.0, x, stride ) + > {{alias}}( N, 5.0, x, stride ) 16.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); > stride = 2; - > {{alias}}( 3, 5.0, x1, stride ) + > {{alias}}( N, 5.0, x1, stride ) 14.0 - {{alias}}.ndarray( N, alpha, x, stride, offset ) Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation and alternative @@ -91,7 +92,8 @@ // Using offset parameter: > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > {{alias}}.ndarray( 3, 5.0, x, 2, 1 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}.ndarray( N, 5.0, x, 2, 1 ) 14.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/examples/index.js index ce7accccd889..69d0d6f8ef97 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/examples/index.js @@ -18,14 +18,18 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var sapxsumpw = require( './../lib' ); var x; +var i; -x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); - +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = sapxsumpw( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, alpha, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 2 ); - - napi_value v; - napi_status status = napi_create_double( env, (double)stdlib_strided_sapxsumpw( N, alpha, X, stride ), &v ); - assert( status == napi_ok ); - - return v; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) \ No newline at end of file diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/src/addon.cpp new file mode 100644 index 000000000000..7bcbc23495e5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/src/addon.cpp @@ -0,0 +1,130 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/sapxsumpw.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_sapxsumpw { + + /** + * Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation. + * + * ## Notes + * + * - When called from JavaScript, the function expects four arguments: + * + * - `N`: number of indexed elements + * - `alpha`: constant + * - `X`: input array + * - `stride`: stride length + */ + napi_value node_sapxsumpw( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 4; + napi_value argv[ 4 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 4 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 4 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); + return nullptr; + } + + bool res; + status = napi_is_typedarray( env, argv[ 2 ], &res ); + assert( status == napi_ok ); + if ( res == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype3; + status = napi_typeof( env, argv[ 3 ], &vtype3 ); + assert( status == napi_ok ); + if ( vtype3 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + double alpha; + status = napi_get_value_double( env, argv[ 1 ], &alpha ); + assert( status == napi_ok ); + + int64_t stride; + status = napi_get_value_int64( env, argv[ 3 ], &stride ); + assert( status == napi_ok ); + + napi_typedarray_type vtype2; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype2 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + napi_value v; + status = napi_create_double( env, (double)stdlib_strided_sapxsumpw( N, (float)alpha, (float *)X, stride ), &v ); + assert( status == napi_ok ); + + return v; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_sapxsumpw, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_sapxsumpw diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.ndarray.js index c16278d1610d..b3019ad0c618 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.ndarray.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var sapxsumpw = require( './../lib/ndarray.js' ); @@ -102,6 +103,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -116,13 +118,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = sapxsumpw( 4, 5.0, x, 2, 0 ); + N = floor( x.length / 2 ); + v = sapxsumpw( N, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; var i; @@ -138,7 +142,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = sapxsumpw( 4, 5.0, x, -2, 6 ); + N = floor( x.length / 2 ); + v = sapxsumpw( N, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -165,6 +170,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { + var N; var x; var v; @@ -178,8 +184,9 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = sapxsumpw( 4, 5.0, x, 2, 1 ); + v = sapxsumpw( N, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.ndarray.native.js index 22fa27a4bbd8..c8f11b8df159 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.ndarray.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -111,6 +112,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -125,13 +127,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = sapxsumpw( 4, 5.0, x, 2, 0 ); + N = floor( x.length / 2 ); + v = sapxsumpw( N, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; var i; @@ -147,7 +151,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = sapxsumpw( 4, 5.0, x, -2, 6 ); + N = floor( x.length / 2 ); + v = sapxsumpw( N, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -174,6 +179,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { + var N; var x; var v; @@ -187,8 +193,9 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = sapxsumpw( 4, 5.0, x, 2, 1 ); + v = sapxsumpw( N, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.sapxsumpw.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.sapxsumpw.js index 4b9c1dedbbec..0c4717aa057c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.sapxsumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.sapxsumpw.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var sapxsumpw = require( './../lib/sapxsumpw.js' ); @@ -102,6 +103,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -116,13 +118,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = sapxsumpw( 4, 5.0, x, 2 ); + N = floor( x.length / 2 ); + v = sapxsumpw( N, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; var i; @@ -138,7 +142,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = sapxsumpw( 4, 5.0, x, -2 ); + N = floor( x.length / 2 ); + v = sapxsumpw( N, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -167,6 +172,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; + var N; var v; x0 = new Float32Array([ @@ -182,8 +188,9 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); - v = sapxsumpw( 4, 5.0, x1, 2 ); + v = sapxsumpw( N, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.sapxsumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.sapxsumpw.native.js index ea0af9baf524..232f3a74259f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.sapxsumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapxsumpw/test/test.sapxsumpw.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -220,6 +221,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -234,13 +236,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = sapxsumpw( 4, 5.0, x, 2 ); + N = floor( x.length / 2 ); + v = sapxsumpw( N, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; var i; @@ -256,7 +260,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = sapxsumpw( 4, 5.0, x, -2 ); + N = floor( x.length / 2 ); + v = sapxsumpw( N, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -285,6 +290,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; + var N; var v; x0 = new Float32Array([ @@ -300,8 +306,9 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); - v = sapxsumpw( 4, 5.0, x1, 2 ); + v = sapxsumpw( N, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/README.md b/lib/node_modules/@stdlib/blas/ext/base/scusum/README.md index fc090f8e6bf8..198ec8975cf3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/README.md @@ -65,15 +65,18 @@ The function has the following parameters: - **y**: output [`Float32Array`][@stdlib/array/float32]. - **strideY**: index increment for `y`. -The `N` and `stride` parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative sum of every other element in the strided input array, +The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to compute the cumulative sum of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); var y = new Float32Array( x.length ); -var v = scusum( 4, 0.0, x, 2, y, 1 ); +var N = floor( x.length / 2 ); + +var v = scusum( N, 0.0, x, 2, y, 1 ); // y => [ 1.0, 3.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] ``` @@ -83,6 +86,7 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); // Initial arrays... var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); @@ -92,7 +96,9 @@ var y0 = new Float32Array( x0.length ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element -scusum( 4, 0.0, x1, -2, y1, 1 ); +var N = floor( x0.length / 2 ); + +scusum( N, 0.0, x1, -2, y1, 1 ); // y0 => [ 0.0, 0.0, 0.0, 4.0, 6.0, 4.0, 5.0, 0.0 ] ``` @@ -115,15 +121,18 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetY**: starting index for `y`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, offsetX and offsetY parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative sum of every other value in the strided input array starting from the second value and to store in the last `N` elements of the strided output array starting from the last element +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, `offsetX` and `offsetY` parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative sum of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var y = new Float32Array( x.length ); -scusum.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 ); +var N = floor( x.length / 2 ); + +scusum.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ); // y => [ 0.0, 0.0, 0.0, 0.0, 5.0, 1.0, -1.0, 1.0 ] ``` @@ -148,13 +157,20 @@ scusum.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); var Float32Array = require( '@stdlib/array/float32' ); var scusum = require( '@stdlib/blas/ext/base/scusum' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); -var y = new Float32Array( x.length ); +var y; +var x; +var i; + +x = new Float32Array( 10 ); +y = new Float32Array( x.length ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.js index 69c251af827c..962e406fa06b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.js @@ -21,20 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); -var Float32Array = require( '@stdlib/array/float32' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var scusum = require( './../lib/scusum.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -45,8 +39,15 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); - var y = new Float32Array( len ); + var y; + var x; + var i; + + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.native.js index 942a4ddda88a..02c902ea4406 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.native.js @@ -22,8 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -37,7 +36,6 @@ var scusum = tryRequire( resolve( __dirname, './../lib/scusum.native.js' ) ); var opts = { 'skip': ( scusum instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -50,8 +48,15 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); - var y = new Float32Array( len ); + var x; + var y; + var i; + + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.ndarray.js index 00e014a1fe5e..125ca2e4786d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.ndarray.js @@ -21,8 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -30,11 +29,6 @@ var pkg = require( './../package.json' ).name; var scusum = require( './../lib/ndarray.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -45,8 +39,15 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); - var y = new Float32Array( len ); + var x; + var y; + var i; + + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.ndarray.native.js index 0a920dce4110..df723354c058 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/benchmark/benchmark.ndarray.native.js @@ -22,8 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -37,7 +36,6 @@ var scusum = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( scusum instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -50,8 +48,15 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); - var y = new Float32Array( len ); + var x; + var y; + var i; + + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/scusum/docs/repl.txt index d6e5e3124514..568765828a01 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/docs/repl.txt @@ -3,8 +3,8 @@ Computes the cumulative sum of single-precision floating-point strided array elements. - The `N` and `stride` parameters determine which elements in the strided - arrays are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` and `y` are + accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -47,7 +47,8 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); > y = new {{alias:@stdlib/array/float32}}( x.length ); - > {{alias}}( 3, 0.0, x, 2, y, 2 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}( N, 0.0, x, 2, y, 2 ) [ -2.0, 0.0, -1.0, 0.0, 1.0, 0.0 ] // Using view offsets: @@ -55,12 +56,12 @@ > var y0 = new {{alias:@stdlib/array/float32}}( x0.length ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); > var y1 = new {{alias:@stdlib/array/float32}}( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); - > {{alias}}( 3, 0.0, x1, 2, y1, 1 ) + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); + > {{alias}}( N, 0.0, x1, 2, y1, 1 ) [ -2.0, 0.0, -1.0 ] > y0 [ 0.0, 0.0, 0.0, -2.0, 0.0, -1.0 ] - {{alias}}.ndarray( N, sum, x, strideX, offsetX, y, strideY, offsetY ) Computes the cumulative sum of single-precision floating-point strided array elements using alternative indexing semantics. @@ -111,7 +112,8 @@ // Advanced indexing: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > y = new {{alias:@stdlib/array/float32}}( x.length ); - > {{alias}}.ndarray( 3, 0.0, x, 2, 1, y, -1, y.length-1 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ) [ 0.0, 0.0, 0.0, -1.0, 0.0, -2.0 ] See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/scusum/examples/index.js index 6a92d6ab1267..15f6a4e1c3ef 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/examples/index.js @@ -18,14 +18,20 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); var Float32Array = require( '@stdlib/array/float32' ); var scusum = require( './../lib' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); -var y = new Float32Array( x.length ); +var y; +var x; +var i; +x = new Float32Array( 10 ); +y = new Float32Array( x.length ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/scusum/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' [ 1.0, -1.0, 1.0 ] * * @example * var Float32Array = require( '@stdlib/array/float32' ); +* var floor = require( '@stdlib/math/base/special/floor' ); * var scusum = require( '@stdlib/blas/ext/base/scusum' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * var y = new Float32Array( x.length ); +* var N = floor( x.length / 2 ); * -* scusum.ndarray( 4, 0.0, x, 2, 1, y, 1, 0 ); +* scusum.ndarray( N, 0.0, x, 2, 1, y, 1, 0 ); * // y => [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/ndarray.js index fc8c631d22b0..0b13094e661b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/ndarray.js @@ -40,11 +40,13 @@ var scusumkbn = require( '@stdlib/blas/ext/base/scusumkbn' ).ndarray; * * @example * var Float32Array = require( '@stdlib/array/float32' ); +* var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * var y = new Float32Array( x.length ); +* var N = floor( x.length / 2 ); * -* var v = scusum( 4, 0.0, x, 2, 1, y, 1, 0 ); +* var v = scusum( N, 0.0, x, 2, 1, y, 1, 0 ); * // returns [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] */ function scusum( N, sum, x, strideX, offsetX, y, strideY, offsetY ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/ndarray.native.js index 3f05e52ab35a..a5595b017394 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); +var Float32Array = require( '@stdlib/array/float32' ); var addon = require( './scusum.native.js' ); @@ -42,21 +41,26 @@ var addon = require( './scusum.native.js' ); * * @example * var Float32Array = require( '@stdlib/array/float32' ); +* var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * var y = new Float32Array( x.length ); +* var N = floor( x.length / 2 ); * -* var v = scusum( 4, 0.0, x, 2, 1, y, 1, 0 ); +* var v = scusum( N, 0.0, x, 2, 1, y, 1, 0 ); * // returns [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] */ function scusum( N, sum, x, strideX, offsetX, y, strideY, offsetY ) { var viewX; var viewY; - - offsetX = minViewBufferIndex( N, strideX, offsetX ); - viewX = offsetView( x, offsetX ); - offsetY = minViewBufferIndex( N, strideY, offsetY ); - viewY = offsetView( y, offsetY ); + if ( strideX < 0 ) { + offsetX += (N-1) * strideX; + } + if ( strideY < 0 ) { + offsetY += (N-1) * strideY; + } + viewX = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offsetX), x.length-offsetX ); // eslint-disable-line max-len + viewY = new Float32Array( y.buffer, y.byteOffset+(y.BYTES_PER_ELEMENT*offsetY), y.length-offsetY ); // eslint-disable-line max-len addon( N, sum, viewX, strideX, viewY, strideY ); return y; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/scusum.js b/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/scusum.js index 6c0613927f8e..8e1e046d9304 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/scusum.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/scusum.js @@ -41,8 +41,9 @@ var scusumkbn = require( '@stdlib/blas/ext/base/scusumkbn' ); * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); * var y = new Float32Array( x.length ); +* var N = x.length; * -* var v = scusum( 3, 0.0, x, 1, y, 1 ); +* var v = scusum( N, 0.0, x, 1, y, 1 ); * // returns [ 1.0, -1.0, 1.0 ] */ function scusum( N, sum, x, strideX, y, strideY ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/scusum.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/scusum.native.js index 96b9f767476f..804e5fb5590a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/scusum.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/lib/scusum.native.js @@ -41,8 +41,9 @@ var addon = require( './../src/addon.node' ); * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); * var y = new Float32Array( x.length ); +* var N = x.length; * -* var v = scusum( 3, 0.0, x, 1, y, 1 ); +* var v = scusum( N, 0.0, x, 1, y, 1 ); * // returns [ 1.0, -1.0, 1.0 ] */ function scusum( N, sum, x, strideX, y, strideY ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/scusum/manifest.json index 9f852154bd20..0c7e02a28ec0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/manifest.json @@ -1,78 +1,42 @@ { - "options": { - "task": "build" - }, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "task": "build", - "src": [ - "./src/scusum.c" - ], - "include": [ - "./include" - ], - "libraries": [ - "-lm" - ], - "libpath": [], - "dependencies": [ - "@stdlib/blas/ext/base/scusumkbn", - "stdlib/napi/export", - "stdlib/napi/argv", - "stdlib/napi/argv-int64", - "stdlib/napi/argv-float", - "stdlib/napi/argv-strided-float32array" - ] - }, - { - "task": "benchmark", - "src": [ - "./src/scusum.c" - ], - "include": [ - "./include" - ], - "libraries": [ - "-lm" - ], - "libpath": [], - "dependencies": [] - }, - { - "task": "examples", - "src": [ - "./src/scusum.c" - ], - "include": [ - "./include" - ], - "libraries": [ - "-lm" - ], - "libpath": [], - "dependencies": [] - } - ] + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [ + "./src/scusum.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/ext/base/scusumkbn" + ] + } + ] } diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/package.json b/lib/node_modules/@stdlib/blas/ext/base/scusum/package.json index bb44b07c32ff..0dcc765d7ae8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/package.json +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/package.json @@ -75,7 +75,5 @@ "single", "float32array" ], - "__stdlib__": { - "wasm": false - } + "__stdlib__": {} } diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/scusum/src/addon.c deleted file mode 100644 index 93edb179b7c5..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/src/addon.c +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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. -*/ - -#include "stdlib/blas/ext/base/scusum.h" -#include "stdlib/napi/export.h" -#include "stdlib/napi/argv.h" -#include "stdlib/napi/argv_int64.h" -#include "stdlib/napi/argv_float.h" -#include "stdlib/napi/argv_strided_float32array.h" -#include -#include - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 6 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, N, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideY, argv, 4 ); - stdlib_strided_scusum( N, sum, X, strideX, Y, strideY ); - return NULL; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/scusum/src/addon.cpp new file mode 100644 index 000000000000..6a1382842289 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/src/addon.cpp @@ -0,0 +1,164 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/scusum.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_scusum { + + /** + * Computes the cumulative sum of single-precision floating-point strided array elements. + * + * ## Notes + * + * - When called from JavaScript, the function expects six arguments: + * + * - `N`: number of indexed elements + * - `sum`: initial sum + * - `X`: input array + * - `strideX`: `X` stride length + * - `Y`: output array + * - `strideY`: `Y` stride length + */ + napi_value node_scusum( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 6; + napi_value argv[ 6 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 6 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 6 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); + return nullptr; + } + + bool res2; + status = napi_is_typedarray( env, argv[ 2 ], &res2 ); + assert( status == napi_ok ); + if ( res2 == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype3; + status = napi_typeof( env, argv[ 3 ], &vtype3 ); + assert( status == napi_ok ); + if ( vtype3 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); + return nullptr; + } + + bool res4; + status = napi_is_typedarray( env, argv[ 4 ], &res4 ); + assert( status == napi_ok ); + if ( res4 == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype5; + status = napi_typeof( env, argv[ 5 ], &vtype5 ); + assert( status == napi_ok ); + if ( vtype5 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Sixth argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + double sum; + status = napi_get_value_double( env, argv[ 1 ], &sum ); + assert( status == napi_ok ); + + int64_t strideX; + status = napi_get_value_int64( env, argv[ 3 ], &strideX ); + assert( status == napi_ok ); + + int64_t strideY; + status = napi_get_value_int64( env, argv[ 5 ], &strideY ); + assert( status == napi_ok ); + + napi_typedarray_type vtype2; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype2 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(strideX) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + napi_typedarray_type vtype4; + size_t ylen; + void *Y; + status = napi_get_typedarray_info( env, argv[ 4 ], &vtype4, &ylen, &Y, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype4 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(strideY) >= (int64_t)ylen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Fifth argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + stdlib_strided_scusum( N, (float)sum, (float *)X, strideX, (float *)Y, strideY ); + + return nullptr; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_scusum, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_scusum diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.ndarray.js index da0034ad3831..ffcae20fc948 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.ndarray.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var scusum = require( './../lib/ndarray.js' ); @@ -163,6 +164,7 @@ tape( 'the function supports an `x` stride', function test( t ) { var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 0 @@ -178,8 +180,9 @@ tape( 'the function supports an `x` stride', function test( t ) { 0.0, 0.0 ]); + N = 3; - scusum( 3, 0.0, x, 2, 0, y, 1, 0 ); + scusum( N, 0.0, x, 2, 0, y, 1, 0 ); expected = new Float32Array( [ 1.0, 4.0, 9.0, 0.0, 0.0 ] ); @@ -191,6 +194,7 @@ tape( 'the function supports a `y` stride', function test( t ) { var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 0 @@ -206,8 +210,9 @@ tape( 'the function supports a `y` stride', function test( t ) { 0.0, 0.0 // 2 ]); + N = 3; - scusum( 3, 0.0, x, 1, 0, y, 2, 0 ); + scusum( N, 0.0, x, 1, 0, y, 2, 0 ); expected = new Float32Array( [ 1.0, 0.0, 3.0, 0.0, 6.0 ] ); @@ -219,6 +224,7 @@ tape( 'the function supports negative strides', function test( t ) { var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 2 @@ -234,8 +240,9 @@ tape( 'the function supports negative strides', function test( t ) { 0.0, 0.0 ]); + N = 3; - scusum( 3, 0.0, x, -2, x.length-1, y, -1, 2 ); + scusum( N, 0.0, x, -2, x.length-1, y, -1, 2 ); expected = new Float32Array( [ 9.0, 8.0, 5.0, 0.0, 0.0 ] ); @@ -245,6 +252,7 @@ tape( 'the function supports negative strides', function test( t ) { tape( 'the function supports an `x` offset', function test( t ) { var expected; + var N; var x; var y; @@ -268,8 +276,9 @@ tape( 'the function supports an `x` offset', function test( t ) { 0.0, 0.0 ]); + N = floor( x.length / 2 ); - scusum( 4, 0.0, x, 2, 1, y, 1, 0 ); + scusum( N, 0.0, x, 2, 1, y, 1, 0 ); expected = new Float32Array( [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] ); @@ -279,6 +288,7 @@ tape( 'the function supports an `x` offset', function test( t ) { tape( 'the function supports a `y` offset', function test( t ) { var expected; + var N; var x; var y; @@ -302,8 +312,9 @@ tape( 'the function supports a `y` offset', function test( t ) { 0.0, 0.0 // 3 ]); + N = floor( x.length / 2 ); - scusum( 4, 0.0, x, 1, 0, y, 2, 1 ); + scusum( N, 0.0, x, 1, 0, y, 2, 1 ); expected = new Float32Array( [ 0.0, 2.0, 0.0, 3.0, 0.0, 5.0, 0.0, 3.0 ] ); @@ -315,6 +326,7 @@ tape( 'the function supports complex access patterns', function test( t ) { var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 0 @@ -332,8 +344,9 @@ tape( 'the function supports complex access patterns', function test( t ) { 0.0, 0.0 ]); + N = 3; - scusum( 3, 0.0, x, 2, 0, y, -1, 2 ); + scusum( N, 0.0, x, 2, 0, y, -1, 2 ); expected = new Float32Array( [ 9.0, 4.0, 1.0, 0.0, 0.0, 0.0 ] ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.ndarray.native.js index 3ae5cb53505c..ad957b847d10 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.ndarray.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -172,6 +173,7 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 0 @@ -187,8 +189,9 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { 0.0, 0.0 ]); + N = 3; - scusum( 3, 0.0, x, 2, 0, y, 1, 0 ); + scusum( N, 0.0, x, 2, 0, y, 1, 0 ); expected = new Float32Array( [ 1.0, 4.0, 9.0, 0.0, 0.0 ] ); @@ -200,6 +203,7 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 0 @@ -215,8 +219,9 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { 0.0, 0.0 // 2 ]); + N = 3; - scusum( 3, 0.0, x, 1, 0, y, 2, 0 ); + scusum( N, 0.0, x, 1, 0, y, 2, 0 ); expected = new Float32Array( [ 1.0, 0.0, 3.0, 0.0, 6.0 ] ); @@ -228,6 +233,7 @@ tape( 'the function supports negative strides', opts, function test( t ) { var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 2 @@ -243,8 +249,9 @@ tape( 'the function supports negative strides', opts, function test( t ) { 0.0, 0.0 ]); + N = 3; - scusum( 3, 0.0, x, -2, x.length-1, y, -1, 2 ); + scusum( N, 0.0, x, -2, x.length-1, y, -1, 2 ); expected = new Float32Array( [ 9.0, 8.0, 5.0, 0.0, 0.0 ] ); @@ -254,6 +261,7 @@ tape( 'the function supports negative strides', opts, function test( t ) { tape( 'the function supports an `x` offset', opts, function test( t ) { var expected; + var N; var x; var y; @@ -277,8 +285,9 @@ tape( 'the function supports an `x` offset', opts, function test( t ) { 0.0, 0.0 ]); + N = floor( x.length / 2 ); - scusum( 3, 0.0, x, 2, 1, y, 1, 0 ); + scusum( N, 0.0, x, 2, 1, y, 1, 0 ); expected = new Float32Array( [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] ); @@ -288,6 +297,7 @@ tape( 'the function supports an `x` offset', opts, function test( t ) { tape( 'the function supports a `y` offset', opts, function test( t ) { var expected; + var N; var x; var y; @@ -311,8 +321,9 @@ tape( 'the function supports a `y` offset', opts, function test( t ) { 0.0, 0.0 // 3 ]); + N = floor( x.length / 2 ); - scusum( 3, 0.0, x, 1, 0, y, 2, 1 ); + scusum( N, 0.0, x, 1, 0, y, 2, 1 ); expected = new Float32Array( [ 0.0, 2.0, 0.0, 3.0, 0.0, 5.0, 0.0, 3.0 ] ); @@ -324,6 +335,7 @@ tape( 'the function supports complex access patterns', opts, function test( t ) var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 0 @@ -341,8 +353,9 @@ tape( 'the function supports complex access patterns', opts, function test( t ) 0.0, 0.0 ]); + N = 3; - scusum( 3, 0.0, x, 2, 0, y, -1, 2 ); + scusum( N, 0.0, x, 2, 0, y, -1, 2 ); expected = new Float32Array( [ 9.0, 4.0, 1.0, 0.0, 0.0, 0.0 ] ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.scusum.js b/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.scusum.js index 85badd1053d9..b1973a63519a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.scusum.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.scusum.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var scusum = require( './../lib/scusum.js' ); @@ -35,7 +36,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 6', function test( t ) { - t.strictEqual( scusum.length, 6, 'returns expected value' ); + t.strictEqual( scusum.length, 6, 'has expected arity' ); t.end(); }); @@ -163,6 +164,7 @@ tape( 'the function supports an `x` stride', function test( t ) { var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 0 @@ -178,8 +180,9 @@ tape( 'the function supports an `x` stride', function test( t ) { 0.0, 0.0 ]); + N = 3; - scusum( 3, 0.0, x, 2, y, 1 ); + scusum( N, 0.0, x, 2, y, 1 ); expected = new Float32Array( [ 1.0, 4.0, 9.0, 0.0, 0.0 ] ); @@ -191,6 +194,7 @@ tape( 'the function supports a `y` stride', function test( t ) { var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 0 @@ -206,8 +210,9 @@ tape( 'the function supports a `y` stride', function test( t ) { 0.0, 0.0 // 2 ]); + N = 3; - scusum( 3, 0.0, x, 1, y, 2 ); + scusum( N, 0.0, x, 1, y, 2 ); expected = new Float32Array( [ 1.0, 0.0, 3.0, 0.0, 6.0 ] ); @@ -219,6 +224,7 @@ tape( 'the function supports negative strides', function test( t ) { var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 2 @@ -234,8 +240,9 @@ tape( 'the function supports negative strides', function test( t ) { 0.0, 0.0 ]); + N = 3; - scusum( 3, 0.0, x, -2, y, -1 ); + scusum( N, 0.0, x, -2, y, -1 ); expected = new Float32Array( [ 9.0, 8.0, 5.0, 0.0, 0.0 ] ); @@ -247,6 +254,7 @@ tape( 'the function supports complex access patterns', function test( t ) { var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 0 @@ -264,8 +272,9 @@ tape( 'the function supports complex access patterns', function test( t ) { 0.0, 0.0 ]); + N = 3; - scusum( 3, 0.0, x, 2, y, -1 ); + scusum( N, 0.0, x, 2, y, -1 ); expected = new Float32Array( [ 9.0, 4.0, 1.0, 0.0, 0.0, 0.0 ] ); @@ -279,6 +288,7 @@ tape( 'the function supports view offsets', function test( t ) { var y0; var x1; var y1; + var N; // Initial arrays... x0 = new Float32Array([ @@ -302,7 +312,9 @@ tape( 'the function supports view offsets', function test( t ) { x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element - scusum( 3, 0.0, x1, -2, y1, 1 ); + N = floor( x0.length / 2 ); + + scusum( N, 0.0, x1, -2, y1, 1 ); expected = new Float32Array( [ 0.0, 0.0, 0.0, 6.0, 10.0, 12.0 ] ); t.deepEqual( y0, expected, 'deep equal' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.scusum.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.scusum.native.js index ac0a872c7e72..e5b184951519 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.scusum.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusum/test/test.scusum.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 6', opts, function test( t ) { - t.strictEqual( scusum.length, 6, 'returns expected value' ); + t.strictEqual( scusum.length, 6, 'has expected arity' ); t.end(); }); @@ -172,6 +173,7 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 0 @@ -187,8 +189,9 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { 0.0, 0.0 ]); + N = 3; - scusum( 3, 0.0, x, 2, y, 1 ); + scusum( N, 0.0, x, 2, y, 1 ); expected = new Float32Array( [ 1.0, 4.0, 9.0, 0.0, 0.0 ] ); @@ -200,6 +203,7 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 0 @@ -215,8 +219,9 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { 0.0, 0.0 // 2 ]); + N = 3; - scusum( 3, 0.0, x, 1, y, 2 ); + scusum( N, 0.0, x, 1, y, 2 ); expected = new Float32Array( [ 1.0, 0.0, 3.0, 0.0, 6.0 ] ); @@ -228,6 +233,7 @@ tape( 'the function supports negative strides', opts, function test( t ) { var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 2 @@ -243,8 +249,9 @@ tape( 'the function supports negative strides', opts, function test( t ) { 0.0, 0.0 ]); + N = 3; - scusum( 3, 0.0, x, -2, y, -1 ); + scusum( N, 0.0, x, -2, y, -1 ); expected = new Float32Array( [ 9.0, 8.0, 5.0, 0.0, 0.0 ] ); @@ -256,6 +263,7 @@ tape( 'the function supports complex access patterns', opts, function test( t ) var expected; var x; var y; + var N; x = new Float32Array([ 1.0, // 0 @@ -273,8 +281,9 @@ tape( 'the function supports complex access patterns', opts, function test( t ) 0.0, 0.0 ]); + N = 3; - scusum( 3, 0.0, x, 2, y, -1 ); + scusum( N, 0.0, x, 2, y, -1 ); expected = new Float32Array( [ 9.0, 4.0, 1.0, 0.0, 0.0, 0.0 ] ); @@ -288,6 +297,7 @@ tape( 'the function supports view offsets', opts, function test( t ) { var y0; var x1; var y1; + var N; // Initial arrays... x0 = new Float32Array([ @@ -311,7 +321,9 @@ tape( 'the function supports view offsets', opts, function test( t ) { x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element - scusum( 3, 0.0, x1, -2, y1, 1 ); + N = floor( x0.length / 2 ); + + scusum( N, 0.0, x1, -2, y1, 1 ); expected = new Float32Array( [ 0.0, 0.0, 0.0, 6.0, 10.0, 12.0 ] ); t.deepEqual( y0, expected, 'deep equal' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/README.md index 9959aa54cf6a..52fb29f21720 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/README.md @@ -65,14 +65,18 @@ The function has the following parameters: - **y**: output [`Float32Array`][@stdlib/array/float32]. - **strideY**: index increment for `y`. -The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative sum of every other element in `x`, +The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to compute the cumulative sum of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); + var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); var y = new Float32Array( x.length ); -var v = scusumkbn( 4, 0.0, x, 2, y, 1 ); +var N = floor( x.length / 2 ); + +var v = scusumkbn( N, 0.0, x, 2, y, 1 ); // y => [ 1.0, 3.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] ``` @@ -82,6 +86,7 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); // Initial arrays... var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); @@ -91,7 +96,9 @@ var y0 = new Float32Array( x0.length ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element -scusumkbn( 4, 0.0, x1, -2, y1, 1 ); +var N = floor( x0.length / 2 ); + +scusumkbn( N, 0.0, x1, -2, y1, 1 ); // y0 => [ 0.0, 0.0, 0.0, 4.0, 6.0, 4.0, 5.0, 0.0 ] ``` @@ -103,9 +110,9 @@ Computes the cumulative sum of single-precision floating-point strided array ele var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -var y = new Float32Array( 3 ); +var y = new Float32Array( x.length ); -scusumkbn.ndarray( 3, 0.0, x, 1, 0, y, 1, 0 ); +scusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, 1, 0 ); // y => [ 1.0, -1.0, 1.0 ] ``` @@ -114,15 +121,18 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetY**: starting index for `y`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, offset parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative sum of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, `offsetX` and `offsetY` parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative sum of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var y = new Float32Array( x.length ); -scusumkbn.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 ); +var N = floor( x.length / 2 ); + +scusumkbn.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ); // y => [ 0.0, 0.0, 0.0, 0.0, 5.0, 1.0, -1.0, 1.0 ] ``` @@ -147,14 +157,21 @@ scusumkbn.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var scusumkbn = require( '@stdlib/blas/ext/base/scusumkbn' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); -console.log( x ); +var y; +var x; +var i; -var y = filledarrayBy( x.length, 'float32', discreteUniform( 0, 10 ) ); +x = new Float32Array( 10 ); +y = new Float32Array( x.length ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} +console.log( x ); console.log( y ); scusumkbn( x.length, 0.0, x, 1, y, -1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.js index d3306232854f..ca32b4ad981b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var scusumkbn = require( './../lib/scusumkbn.js' ); -// VARIABLES // - -var rand = uniform( -100.0, 100.0 ); - - // FUNCTIONS // /** @@ -44,8 +39,15 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); - var y = filledarrayBy( len, 'float32', rand ); + var y; + var x; + var i; + + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.native.js index 5ec896713745..a3bb22085569 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var scusumkbn = tryRequire( resolve( __dirname, './../lib/scusumkbn.native.js' ) var opts = { 'skip': ( scusumkbn instanceof Error ) }; -var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -49,8 +48,15 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); - var y = filledarrayBy( len, 'float32', rand ); + var x; + var y; + var i; + + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.ndarray.js index b515bb63eec5..9e68c42d396a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.ndarray.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var scusumkbn = require( './../lib/ndarray.js' ); -// VARIABLES // - -var rand = uniform( -100.0, 100.0 ); - - // FUNCTIONS // /** @@ -44,8 +39,15 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); - var y = filledarrayBy( len, 'float32', rand ); + var x; + var y; + var i; + + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.ndarray.native.js index a9ac4955e25a..793fe23e7e48 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var scusumkbn = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ) var opts = { 'skip': ( scusumkbn instanceof Error ) }; -var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -49,8 +48,15 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); - var y = filledarrayBy( len, 'float32', rand ); + var x; + var y; + var i; + + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/docs/repl.txt index a64a884cd6b1..470a0986b764 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/docs/repl.txt @@ -3,8 +3,8 @@ Computes the cumulative sum of single-precision floating-point strided array elements using an improved Kahan–Babuška algorithm. - The `N` and stride parameters determine which elements in the strided arrays - are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` and `y` are + accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -44,10 +44,11 @@ > {{alias}}( x.length, 0.0, x, 1, y, 1 ) [ 1.0, -1.0, 1.0 ] - // Using `N` and stride parameters: + // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); > y = new {{alias:@stdlib/array/float32}}( x.length ); - > {{alias}}( 3, 0.0, x, 2, y, 2 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}( N, 0.0, x, 2, y, 2 ) [ -2.0, 0.0, -1.0, 0.0, 1.0, 0.0 ] // Using view offsets: @@ -61,15 +62,14 @@ > y0 [ 0.0, 0.0, 0.0, -2.0, 0.0, -1.0 ] - {{alias}}.ndarray( N, sum, x, strideX, offsetX, y, strideY, offsetY ) Computes the cumulative sum of single-precision floating-point strided array elements using an improved Kahan–Babuška algorithm and alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the offset parameters support indexing semantics based on - starting indices. + buffer, the `offset` parameter supports indexing semantics based on a + starting index. Parameters ---------- @@ -113,7 +113,8 @@ // Advanced indexing: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > y = new {{alias:@stdlib/array/float32}}( x.length ); - > {{alias}}.ndarray( 3, 0.0, x, 2, 1, y, -1, y.length-1 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ) [ 0.0, 0.0, 0.0, -1.0, 0.0, -2.0 ] See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/examples/index.js index c3c81e53b3b9..d7a9f78e0502 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/examples/index.js @@ -18,14 +18,21 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var scusumkbn = require( './../lib' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); -console.log( x ); +var y; +var x; +var i; -var y = filledarrayBy( x.length, 'float32', discreteUniform( 0, 10 ) ); +x = new Float32Array( 10 ); +y = new Float32Array( x.length ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} +console.log( x ); console.log( y ); scusumkbn( x.length, 0.0, x, 1, y, -1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 6 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, sum, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 4 ); - stdlib_strided_scusumkbn( N, sum, X, strideX, Y, strideY ); - return NULL; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/src/addon.cpp new file mode 100644 index 000000000000..22e1547fbbcf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/src/addon.cpp @@ -0,0 +1,164 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/scusumkbn.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_scusumkbn { + + /** + * Computes the cumulative sum of single-precision floating-point strided array elements using an improved Kahan–Babuška algorithm. + * + * ## Notes + * + * - When called from JavaScript, the function expects six arguments: + * + * - `N`: number of indexed elements + * - `sum`: initial sum + * - `X`: input array + * - `strideX`: `X` stride length + * - `Y`: output array + * - `strideY`: `Y` stride length + */ + napi_value node_scusumkbn( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 6; + napi_value argv[ 6 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 6 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 6 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); + return nullptr; + } + + bool res2; + status = napi_is_typedarray( env, argv[ 2 ], &res2 ); + assert( status == napi_ok ); + if ( res2 == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype3; + status = napi_typeof( env, argv[ 3 ], &vtype3 ); + assert( status == napi_ok ); + if ( vtype3 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); + return nullptr; + } + + bool res4; + status = napi_is_typedarray( env, argv[ 4 ], &res4 ); + assert( status == napi_ok ); + if ( res4 == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype5; + status = napi_typeof( env, argv[ 5 ], &vtype5 ); + assert( status == napi_ok ); + if ( vtype5 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Sixth argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + double sum; + status = napi_get_value_double( env, argv[ 1 ], &sum ); + assert( status == napi_ok ); + + int64_t strideX; + status = napi_get_value_int64( env, argv[ 3 ], &strideX ); + assert( status == napi_ok ); + + int64_t strideY; + status = napi_get_value_int64( env, argv[ 5 ], &strideY ); + assert( status == napi_ok ); + + napi_typedarray_type vtype2; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype2 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(strideX) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + napi_typedarray_type vtype4; + size_t ylen; + void *Y; + status = napi_get_typedarray_info( env, argv[ 4 ], &vtype4, &ylen, &Y, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype4 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(strideY) >= (int64_t)ylen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Fifth argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + stdlib_strided_scusumkbn( N, (float)sum, (float *)X, strideX, (float *)Y, strideY ); + + return nullptr; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_scusumkbn, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_scusumkbn diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.ndarray.js index 4601130a1bc1..62706d6e2918 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.ndarray.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var scusumkbn = require( './../lib/ndarray.js' ); @@ -140,7 +141,7 @@ tape( 'the function returns a reference to the output array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', function test( t ) { var expected; var x; var y; @@ -151,10 +152,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumkbn( -1, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumkbn( 0, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); @@ -275,7 +276,7 @@ tape( 'the function supports an `x` offset', function test( t ) { 0.0, 0.0 ]); - N = 4; + N = floor( x.length / 2 ); scusumkbn( N, 0.0, x, 2, 1, y, 1, 0 ); @@ -311,7 +312,7 @@ tape( 'the function supports a `y` offset', function test( t ) { 0.0, 0.0 // 3 ]); - N = 4; + N = floor( x.length / 2 ); scusumkbn( N, 0.0, x, 1, 0, y, 2, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.ndarray.native.js index 19a253895cd2..5c83a10832dd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.ndarray.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -149,7 +150,7 @@ tape( 'the function returns a reference to the output array', opts, function tes t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', opts, function test( t ) { var expected; var x; var y; @@ -160,10 +161,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumkbn( -1, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumkbn( 0, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); @@ -284,7 +285,7 @@ tape( 'the function supports an `x` offset', opts, function test( t ) { 0.0, 0.0 ]); - N = 4; + N = floor( x.length / 2 ); scusumkbn( N, 0.0, x, 2, 1, y, 1, 0 ); @@ -320,7 +321,7 @@ tape( 'the function supports a `y` offset', opts, function test( t ) { 0.0, 0.0 // 3 ]); - N = 4; + N = floor( x.length / 2 ); scusumkbn( N, 0.0, x, 1, 0, y, 2, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.scusumkbn.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.scusumkbn.js index facea33903bb..f83c515697d7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.scusumkbn.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.scusumkbn.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var scusumkbn = require( './../lib/scusumkbn.js' ); @@ -140,7 +141,7 @@ tape( 'the function returns a reference to the output array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', function test( t ) { var expected; var x; var y; @@ -151,10 +152,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumkbn( -1, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumkbn( 0, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); @@ -311,7 +312,7 @@ tape( 'the function supports view offsets', function test( t ) { x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element - N = 3; + N = floor( x0.length / 2 ); scusumkbn( N, 0.0, x1, -2, y1, 1 ); expected = new Float32Array( [ 0.0, 0.0, 0.0, 6.0, 10.0, 12.0 ] ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.scusumkbn.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.scusumkbn.native.js index 7b9c97bec979..9f5e939cca86 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.scusumkbn.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/test/test.scusumkbn.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -149,7 +150,7 @@ tape( 'the function returns a reference to the output array', opts, function tes t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', opts, function test( t ) { var expected; var x; var y; @@ -160,10 +161,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumkbn( -1, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumkbn( 0, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); @@ -320,7 +321,7 @@ tape( 'the function supports view offsets', opts, function test( t ) { x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element - N = 3; + N = floor( x0.length / 2 ); scusumkbn( N, 0.0, x1, -2, y1, 1 ); expected = new Float32Array( [ 0.0, 0.0, 0.0, 6.0, 10.0, 12.0 ] ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/README.md b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/README.md index 76711bfe20aa..157068603988 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/README.md @@ -65,15 +65,18 @@ The function has the following parameters: - **y**: output [`Float32Array`][@stdlib/array/float32]. - **strideY**: index increment for `y`. -The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative sum of every other element in `x`, +The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to compute the cumulative sum of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); var y = new Float32Array( x.length ); -var v = scusumkbn2( 4, 0.0, x, 2, y, 1 ); +var N = floor( x.length / 2 ); + +var v = scusumkbn2( N, 0.0, x, 2, y, 1 ); // y => [ 1.0, 3.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] ``` @@ -83,6 +86,7 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); // Initial arrays... var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); @@ -92,7 +96,9 @@ var y0 = new Float32Array( x0.length ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element -scusumkbn2( 4, 0.0, x1, -2, y1, 1 ); +var N = floor( x0.length / 2 ); + +scusumkbn2( N, 0.0, x1, -2, y1, 1 ); // y0 => [ 0.0, 0.0, 0.0, 4.0, 6.0, 4.0, 5.0, 0.0 ] ``` @@ -104,9 +110,9 @@ Computes the cumulative sum of single-precision floating-point strided array ele var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -var y = new Float32Array( 3 ); +var y = new Float32Array( x.length ); -scusumkbn2.ndarray( 3, 0.0, x, 1, 0, y, 1, 0 ); +scusumkbn2.ndarray( x.length, 0.0, x, 1, 0, y, 1, 0 ); // y => [ 1.0, -1.0, 1.0 ] ``` @@ -115,15 +121,18 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetY**: starting index for `y`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, offset parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative sum of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, `offsetX` and `offsetY` parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative sum of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var y = new Float32Array( x.length ); -scusumkbn2.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 ); +var N = floor( x.length / 2 ); + +scusumkbn2.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ); // y => [ 0.0, 0.0, 0.0, 0.0, 5.0, 1.0, -1.0, 1.0 ] ``` @@ -148,16 +157,21 @@ scusumkbn2.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var scusumkbn2 = require( '@stdlib/blas/ext/base/scusumkbn2' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); +var y; +var x; +var i; +x = new Float32Array( 10 ); +y = new Float32Array( x.length ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); - -var y = filledarrayBy( x.length, 'float32', discreteUniform( 0, 10 ) ); - console.log( y ); scusumkbn2( x.length, 0.0, x, 1, y, -1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.js index 4a8201013ca1..0af540bf80dc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var scusumkbn2 = require( './../lib/scusumkbn2.js' ); -// VARIABLES // - -var rand = uniform( -100.0, 100.0 ); - - // FUNCTIONS // /** @@ -44,8 +39,15 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); - var y = filledarrayBy( len, 'float32', rand ); + var y; + var x; + var i; + + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.native.js index b19255d0b9af..e8aab4db618a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var scusumkbn2 = tryRequire( resolve( __dirname, './../lib/scusumkbn2.native.js' var opts = { 'skip': ( scusumkbn2 instanceof Error ) }; -var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -49,8 +48,15 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); - var y = filledarrayBy( len, 'float32', rand ); + var x; + var y; + var i; + + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.ndarray.js index 99eaa0a272b4..5d7eaf750b0a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.ndarray.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var scusumkbn2 = require( './../lib/ndarray.js' ); -// VARIABLES // - -var rand = uniform( -100.0, 100.0 ); - - // FUNCTIONS // /** @@ -44,8 +39,15 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); - var y = filledarrayBy( len, 'float32', rand ); + var x; + var y; + var i; + + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.ndarray.native.js index 138307c744d3..e9d2dbdff513 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var scusumkbn2 = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) var opts = { 'skip': ( scusumkbn2 instanceof Error ) }; -var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -49,8 +48,15 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); - var y = filledarrayBy( len, 'float32', rand ); + var x; + var y; + var i; + + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/docs/repl.txt index 1994b0296f7d..18cb152928c2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/docs/repl.txt @@ -1,13 +1,13 @@ {{alias}}( N, sum, x, strideX, y, strideY ) - Computes the cumulative sum of single-precision floating-point strided - array elements using a second-order iterative Kahan–Babuška algorithm. + Computes the cumulative sum of single-precision floating-point strided array + elements using a second-order iterative Kahan–Babuška algorithm. - The `N` and stride parameters determine which elements in the strided - arrays are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` and `y` are + accessed at runtime. - Indexing is relative to the first index. To introduce an offset, use - a typed array view. + Indexing is relative to the first index. To introduce an offset, use a typed + array view. If `N <= 0`, the function returns `y` unchanged. @@ -44,10 +44,11 @@ > {{alias}}( x.length, 0.0, x, 1, y, 1 ) [ 1.0, -1.0, 1.0 ] - // Using `N` and stride parameters: + // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); > y = new {{alias:@stdlib/array/float32}}( x.length ); - > {{alias}}( 3, 0.0, x, 2, y, 2 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}( N, 0.0, x, 2, y, 2 ) [ -2.0, 0.0, -1.0, 0.0, 1.0, 0.0 ] // Using view offsets: @@ -61,16 +62,14 @@ > y0 [ 0.0, 0.0, 0.0, -2.0, 0.0, -1.0 ] - {{alias}}.ndarray( N, sum, x, strideX, offsetX, y, strideY, offsetY ) - Computes the cumulative sum of single-precision floating-point strided - array elements using a second-order iterative Kahan–Babuška algorithm and + Computes the cumulative sum of single-precision floating-point strided array + elements using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the `offsetX` and `offsetY` parameter supports indexing semantics - based on starting indices. - + buffer, the `offset` parameter supports indexing semantics based on a + starting index. Parameters ---------- @@ -98,13 +97,11 @@ offsetY: integer Starting index for `y`. - Returns ------- out: Float32Array Output array. - Examples -------- // Standard Usage: @@ -116,10 +113,10 @@ // Advanced indexing: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > y = new {{alias:@stdlib/array/float32}}( x.length ); - > {{alias}}.ndarray( 3, 0.0, x, 2, 1, y, -1, y.length-1 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ) [ 0.0, 0.0, 0.0, -1.0, 0.0, -2.0 ] - See Also -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/examples/index.js index 4f33d6985df7..20c325bb0ba9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/examples/index.js @@ -18,14 +18,21 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var scusumkbn2 = require( './../lib' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); -console.log( x ); +var y; +var x; +var i; -var y = filledarrayBy( x.length, 'float32', discreteUniform( 0, 10 ) ); +x = new Float32Array( 10 ); +y = new Float32Array( x.length ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} +console.log( x ); console.log( y ); scusumkbn2( x.length, 0.0, x, 1, y, -1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 6 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, sum, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 4 ); - stdlib_strided_scusumkbn2( N, sum, X, strideX, Y, strideY ); - return NULL; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) \ No newline at end of file diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/src/addon.cpp new file mode 100644 index 000000000000..80986dfd402a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/src/addon.cpp @@ -0,0 +1,164 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/scusumkbn2.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_scusumkbn2 { + + /** + * Computes the cumulative sum of single-precision floating-point strided array elements using a second-order iterative Kahan–Babuška algorithm. + * + * ## Notes + * + * - When called from JavaScript, the function expects six arguments: + * + * - `N`: number of indexed elements + * - `sum`: initial sum + * - `X`: input array + * - `strideX`: `X` stride length + * - `Y`: output array + * - `strideY`: `Y` stride length + */ + napi_value node_scusumkbn2( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 6; + napi_value argv[ 6 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 6 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 6 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); + return nullptr; + } + + bool res2; + status = napi_is_typedarray( env, argv[ 2 ], &res2 ); + assert( status == napi_ok ); + if ( res2 == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype3; + status = napi_typeof( env, argv[ 3 ], &vtype3 ); + assert( status == napi_ok ); + if ( vtype3 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); + return nullptr; + } + + bool res4; + status = napi_is_typedarray( env, argv[ 4 ], &res4 ); + assert( status == napi_ok ); + if ( res4 == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype5; + status = napi_typeof( env, argv[ 5 ], &vtype5 ); + assert( status == napi_ok ); + if ( vtype5 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Sixth argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + double sum; + status = napi_get_value_double( env, argv[ 1 ], &sum ); + assert( status == napi_ok ); + + int64_t strideX; + status = napi_get_value_int64( env, argv[ 3 ], &strideX ); + assert( status == napi_ok ); + + int64_t strideY; + status = napi_get_value_int64( env, argv[ 5 ], &strideY ); + assert( status == napi_ok ); + + napi_typedarray_type vtype2; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype2 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(strideX) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + napi_typedarray_type vtype4; + size_t ylen; + void *Y; + status = napi_get_typedarray_info( env, argv[ 4 ], &vtype4, &ylen, &Y, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype4 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(strideY) >= (int64_t)ylen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Fifth argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + stdlib_strided_scusumkbn2( N, (float)sum, (float *)X, strideX, (float *)Y, strideY ); + + return nullptr; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_scusumkbn2, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_scusumkbn2 diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.ndarray.js index ac063f99514e..d20010cc70aa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.ndarray.js @@ -141,7 +141,7 @@ tape( 'the function returns a reference to the output array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', function test( t ) { var expected; var x; var y; @@ -152,10 +152,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumkbn2( -1, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumkbn2( 0, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns `expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.ndarray.native.js index 276b557a13f7..2429e597281e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.ndarray.native.js @@ -150,7 +150,7 @@ tape( 'the function returns a reference to the output array', opts, function tes t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', opts, function test( t ) { var expected; var x; var y; @@ -161,10 +161,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumkbn2( -1, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumkbn2( 0, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.scusumkbn2.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.scusumkbn2.js index 713316d3568e..56a1e6437516 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.scusumkbn2.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.scusumkbn2.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var scusumkbn2 = require( './../lib/scusumkbn2.js' ); @@ -140,7 +141,7 @@ tape( 'the function returns a reference to the output array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', function test( t ) { var expected; var x; var y; @@ -151,10 +152,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumkbn2( -1, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumkbn2( 0, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); @@ -327,7 +328,7 @@ tape( 'the function supports view offsets', function test( t ) { x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element - N = 3; + N = floor( x0.length / 2 ); scusumkbn2( N, 0.0, x1, -2, y1, 1 ); expected = new Float32Array( [ 0.0, 0.0, 0.0, 6.0, 10.0, 12.0 ] ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.scusumkbn2.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.scusumkbn2.native.js index 705537999ddc..bca6a9b6cc4f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.scusumkbn2.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/test/test.scusumkbn2.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -149,7 +150,7 @@ tape( 'the function returns a reference to the output array', opts, function tes t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', opts, function test( t ) { var expected; var x; var y; @@ -160,10 +161,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumkbn2( -1, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumkbn2( 0, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); @@ -336,7 +337,7 @@ tape( 'the function supports view offsets', opts, function test( t ) { x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element - N = 3; + N = floor( x0.length / 2 ); scusumkbn2( N, 0.0, x1, -2, y1, 1 ); expected = new Float32Array( [ 0.0, 0.0, 0.0, 6.0, 10.0, 12.0 ] ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/README.md b/lib/node_modules/@stdlib/blas/ext/base/scusumors/README.md index bc247cf7aae6..6cd5c5951743 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/README.md @@ -65,15 +65,18 @@ The function has the following parameters: - **y**: output [`Float32Array`][@stdlib/array/float32]. - **strideY**: index increment for `y`. -The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative sum of every other element in `x`, +The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to compute the cumulative sum of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); var y = new Float32Array( x.length ); -var v = scusumors( 4, 0.0, x, 2, y, 1 ); +var N = floor( x.length / 2 ); + +var v = scusumors( N, 0.0, x, 2, y, 1 ); // y => [ 1.0, 3.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] ``` @@ -83,6 +86,7 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); // Initial arrays... var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); @@ -92,7 +96,9 @@ var y0 = new Float32Array( x0.length ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element -scusumors( 4, 0.0, x1, -2, y1, 1 ); +var N = floor( x0.length / 2 ); + +scusumors( N, 0.0, x1, -2, y1, 1 ); // y0 => [ 0.0, 0.0, 0.0, 4.0, 6.0, 4.0, 5.0, 0.0 ] ``` @@ -115,15 +121,18 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetY**: starting index for `y`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, offset parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative sum of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, `offsetX` and `offsetY` parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative sum of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var y = new Float32Array( x.length ); -scusumors.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 ); +var N = floor( x.length / 2 ); + +scusumors.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ); // y => [ 0.0, 0.0, 0.0, 0.0, 5.0, 1.0, -1.0, 1.0 ] ``` @@ -135,7 +144,7 @@ scusumors.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 ); ## Notes -- If `N <= 0`, both functions return the output array unchanged. +- If `N <= 0`, both functions return `y` unchanged. - Ordinary recursive summation (i.e., a "simple" sum) is performant, but can incur significant numerical error. If performance is paramount and error tolerated, using ordinary recursive summation is acceptable; in all other cases, exercise due caution. @@ -149,14 +158,20 @@ scusumors.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); var Float32Array = require( '@stdlib/array/float32' ); var scusumors = require( '@stdlib/blas/ext/base/scusumors' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); -var y = new Float32Array( x.length ); +var y; +var x; +var i; +x = new Float32Array( 10 ); +y = new Float32Array( x.length ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.js index 2f42a28b2db3..0cd850d46e76 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.js @@ -21,8 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -42,10 +41,13 @@ var scusumors = require( './../lib/scusumors.js' ); function createBenchmark( len ) { var y; var x; + var i; - x = filledarrayBy( len, 'float32', uniform( -10.0, 10.0 ) ); + x = new Float32Array( len ); y = new Float32Array( len ); - + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.native.js index 4256c5fc0c77..1b3f1a4e25b3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.native.js @@ -22,8 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -51,10 +50,13 @@ var opts = { function createBenchmark( len ) { var x; var y; + var i; - x = filledarrayBy( len, 'float32', uniform( -10.0, 10.0 ) ); + x = new Float32Array( len ); y = new Float32Array( len ); - + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.ndarray.js index 2c987c262a8a..e4c8659972a1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.ndarray.js @@ -21,8 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -42,10 +41,13 @@ var scusumors = require( './../lib/ndarray.js' ); function createBenchmark( len ) { var x; var y; + var i; - x = filledarrayBy( len, 'float32', uniform( -10.0, 10.0 ) ); + x = new Float32Array( len ); y = new Float32Array( len ); - + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.ndarray.native.js index 37cc520539ab..c90db53814c7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.ndarray.native.js @@ -22,8 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -51,10 +50,13 @@ var opts = { function createBenchmark( len ) { var x; var y; + var i; - x = filledarrayBy( len, 'float32', uniform( -10.0, 10.0 ) ); + x = new Float32Array( len ); y = new Float32Array( len ); - + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/scusumors/docs/repl.txt index c16d450b275c..86553568a61b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/docs/repl.txt @@ -3,8 +3,8 @@ Computes the cumulative sum of single-precision floating-point strided array elements using ordinary recursive summation. - The `N` and stride parameters determine which elements in the strided arrays - are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` and `y` are + accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -44,10 +44,11 @@ > {{alias}}( x.length, 0.0, x, 1, y, 1 ) [ 1.0, -1.0, 1.0 ] - // Using `N` and stride parameters: + // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); > y = new {{alias:@stdlib/array/float32}}( x.length ); - > {{alias}}( 3, 0.0, x, 2, y, 2 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}( N, 0.0, x, 2, y, 2 ) [ -2.0, 0.0, -1.0, 0.0, 1.0, 0.0 ] // Using view offsets: @@ -55,12 +56,12 @@ > var y0 = new {{alias:@stdlib/array/float32}}( x0.length ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); > var y1 = new {{alias:@stdlib/array/float32}}( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); - > {{alias}}( 3, 0.0, x1, 2, y1, 1 ) + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); + > {{alias}}( N, 0.0, x1, 2, y1, 1 ) [ -2.0, 0.0, -1.0 ] > y0 [ 0.0, 0.0, 0.0, -2.0, 0.0, -1.0 ] - {{alias}}.ndarray( N, sum, x, strideX, offsetX, y, strideY, offsetY ) Computes the cumulative sum of single-precision floating-point strided array elements using ordinary recursive summation and alternative indexing @@ -112,7 +113,8 @@ // Advanced indexing: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > y = new {{alias:@stdlib/array/float32}}( x.length ); - > {{alias}}.ndarray( 3, 0.0, x, 2, 1, y, -1, y.length-1 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ) [ 0.0, 0.0, 0.0, -1.0, 0.0, -2.0 ] See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/scusumors/examples/index.js index 7bb9a381a349..cc8eb5a7773c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/examples/index.js @@ -18,14 +18,20 @@ 'use strict'; +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); var Float32Array = require( '@stdlib/array/float32' ); -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); var scusumors = require( './../lib' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); -var y = new Float32Array( x.length ); +var y; +var x; +var i; +x = new Float32Array( 10 ); +y = new Float32Array( x.length ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/scusumors/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/scusumors/lib/ndarray.js index 210f8a30aa55..f05bb342b5ba 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/lib/ndarray.js @@ -40,11 +40,13 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); * * @example * var Float32Array = require( '@stdlib/array/float32' ); +* var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * var y = new Float32Array( x.length ); +* var N = floor( x.length / 2 ); * -* var v = scusumors( 4, 0.0, x, 2, 1, y, 1, 0 ); +* var v = scusumors( N, 0.0, x, 2, 1, y, 1, 0 ); * // returns [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] */ function scusumors( N, sum, x, strideX, offsetX, y, strideY, offsetY ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumors/lib/ndarray.native.js index 1e5087b5aa64..7edd250e3ee3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); +var Float32Array = require( '@stdlib/array/float32' ); var addon = require( './scusumors.native.js' ); @@ -42,23 +41,26 @@ var addon = require( './scusumors.native.js' ); * * @example * var Float32Array = require( '@stdlib/array/float32' ); +* var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * var y = new Float32Array( x.length ); +* var N = floor( x.length / 2 ); * -* var v = scusumors( 4, 0.0, x, 2, 1, y, 1, 0 ); +* var v = scusumors( N, 0.0, x, 2, 1, y, 1, 0 ); * // returns [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] */ function scusumors( N, sum, x, strideX, offsetX, y, strideY, offsetY ) { var viewX; var viewY; - - offsetX = minViewBufferIndex( N, strideX, offsetX ); - offsetY = minViewBufferIndex( N, strideY, offsetY ); - - viewX = offsetView( x, offsetX ); - viewY = offsetView( y, offsetY ); - + if ( strideX < 0 ) { + offsetX += (N-1) * strideX; + } + if ( strideY < 0 ) { + offsetY += (N-1) * strideY; + } + viewX = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offsetX), x.length-offsetX ); // eslint-disable-line max-len + viewY = new Float32Array( y.buffer, y.byteOffset+(y.BYTES_PER_ELEMENT*offsetY), y.length-offsetY ); // eslint-disable-line max-len addon( N, sum, viewX, strideX, viewY, strideY ); return y; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/scusumors/manifest.json index 17c6d6c978f5..dd9cf0d5f8f5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/manifest.json @@ -1,77 +1,40 @@ { - "options": { - "task": "build" - }, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "task": "build", - "src": [ - "./src/scusumors.c" - ], - "include": [ - "./include" - ], - "libraries": [ - "-lm" - ], - "libpath": [], - "dependencies": [ - "@stdlib/napi/export", - "@stdlib/napi/argv", - "@stdlib/napi/argv-float", - "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float32array" - ] - }, - { - "task": "benchmark", - "src": [ - "./src/scusumors.c" - ], - "include": [ - "./include" - ], - "libraries": [ - "-lm" - ], - "libpath": [], - "dependencies": [] - }, - { - "task": "examples", - "src": [ - "./src/scusumors.c" - ], - "include": [ - "./include" - ], - "libraries": [ - "-lm" - ], - "libpath": [], - "dependencies": [] - } - ] + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [ + "./src/scusumors.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] + } + ] } diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/package.json b/lib/node_modules/@stdlib/blas/ext/base/scusumors/package.json index 304a98bca137..5c17c6a8bd56 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/package.json +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/package.json @@ -76,7 +76,5 @@ "single", "float32array" ], - "__stdlib__": { - "wasm": false - } + "__stdlib__": {} } diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/scusumors/src/addon.c deleted file mode 100644 index ace217d1c331..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/src/addon.c +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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. -*/ - -#include "stdlib/blas/ext/base/scusumors.h" -#include "stdlib/napi/export.h" -#include "stdlib/napi/argv.h" -#include "stdlib/napi/argv_float.h" -#include "stdlib/napi/argv_int64.h" -#include "stdlib/napi/argv_strided_float32array.h" -#include - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 6 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, sum, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 4 ); - - stdlib_strided_scusumors( N, sum, X, strideX, Y, strideY ); - - return NULL; -} - - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) - diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/scusumors/src/addon.cpp new file mode 100644 index 000000000000..d3152f5005fa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/src/addon.cpp @@ -0,0 +1,164 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/scusumors.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_scusumors { + + /** + * Computes the cumulative sum of single-precision floating-point strided array elements using ordinary recursive summation. + * + * ## Notes + * + * - When called from JavaScript, the function expects six arguments: + * + * - `N`: number of indexed elements + * - `sum`: initial sum + * - `X`: input array + * - `strideX`: `X` stride length + * - `Y`: output array + * - `strideY`: `Y` stride length + */ + napi_value node_scusumors( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 6; + napi_value argv[ 6 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 6 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 6 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); + return nullptr; + } + + bool res2; + status = napi_is_typedarray( env, argv[ 2 ], &res2 ); + assert( status == napi_ok ); + if ( res2 == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype3; + status = napi_typeof( env, argv[ 3 ], &vtype3 ); + assert( status == napi_ok ); + if ( vtype3 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); + return nullptr; + } + + bool res4; + status = napi_is_typedarray( env, argv[ 4 ], &res4 ); + assert( status == napi_ok ); + if ( res4 == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype5; + status = napi_typeof( env, argv[ 5 ], &vtype5 ); + assert( status == napi_ok ); + if ( vtype5 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Sixth argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + double sum; + status = napi_get_value_double( env, argv[ 1 ], &sum ); + assert( status == napi_ok ); + + int64_t strideX; + status = napi_get_value_int64( env, argv[ 3 ], &strideX ); + assert( status == napi_ok ); + + int64_t strideY; + status = napi_get_value_int64( env, argv[ 5 ], &strideY ); + assert( status == napi_ok ); + + napi_typedarray_type vtype2; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype2 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(strideX) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + napi_typedarray_type vtype4; + size_t ylen; + void *Y; + status = napi_get_typedarray_info( env, argv[ 4 ], &vtype4, &ylen, &Y, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype4 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(strideY) >= (int64_t)ylen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Fifth argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + stdlib_strided_scusumors( N, (float)sum, (float *)X, strideX, (float *)Y, strideY ); + + return nullptr; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_scusumors, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_scusumors diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.ndarray.js index fd828a164066..5137803a2b94 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.ndarray.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var scusumors = require( './../lib/ndarray.js' ); @@ -140,7 +141,7 @@ tape( 'the function returns a reference to the output array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', function test( t ) { var expected; var x; var y; @@ -151,10 +152,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumors( -1, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumors( 0, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); @@ -267,6 +268,7 @@ tape( 'the function supports negative strides', function test( t ) { tape( 'the function supports an `x` offset', function test( t ) { var expected; + var N; var x; var y; @@ -290,8 +292,9 @@ tape( 'the function supports an `x` offset', function test( t ) { 0.0, 0.0 ]); + N = floor( x.length / 2 ); - scusumors( 4, 0.0, x, 2, 1, y, 1, 0 ); + scusumors( N, 0.0, x, 2, 1, y, 1, 0 ); expected = new Float32Array( [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] ); @@ -301,6 +304,7 @@ tape( 'the function supports an `x` offset', function test( t ) { tape( 'the function supports a `y` offset', function test( t ) { var expected; + var N; var x; var y; @@ -324,8 +328,9 @@ tape( 'the function supports a `y` offset', function test( t ) { 0.0, 0.0 // 3 ]); + N = floor( x.length / 2 ); - scusumors( 4, 0.0, x, 1, 0, y, 2, 1 ); + scusumors( N, 0.0, x, 1, 0, y, 2, 1 ); expected = new Float32Array( [ 0.0, 2.0, 0.0, 3.0, 0.0, 5.0, 0.0, 3.0 ] ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.ndarray.native.js index e62212021968..6afb73a6a122 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.ndarray.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -149,7 +150,7 @@ tape( 'the function returns a reference to the output array', opts, function tes t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', opts, function test( t ) { var expected; var x; var y; @@ -160,10 +161,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumors( -1, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumors( 0, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); @@ -276,6 +277,7 @@ tape( 'the function supports negative strides', opts, function test( t ) { tape( 'the function supports an `x` offset', opts, function test( t ) { var expected; + var N; var x; var y; @@ -299,8 +301,9 @@ tape( 'the function supports an `x` offset', opts, function test( t ) { 0.0, 0.0 ]); + N = floor( x.length / 2 ); - scusumors( 4, 0.0, x, 2, 1, y, 1, 0 ); + scusumors( N, 0.0, x, 2, 1, y, 1, 0 ); expected = new Float32Array( [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] ); @@ -310,6 +313,7 @@ tape( 'the function supports an `x` offset', opts, function test( t ) { tape( 'the function supports a `y` offset', opts, function test( t ) { var expected; + var N; var x; var y; @@ -333,8 +337,9 @@ tape( 'the function supports a `y` offset', opts, function test( t ) { 0.0, 0.0 // 3 ]); + N = floor( x.length / 2 ); - scusumors( 4, 0.0, x, 1, 0, y, 2, 1 ); + scusumors( N, 0.0, x, 1, 0, y, 2, 1 ); expected = new Float32Array( [ 0.0, 2.0, 0.0, 3.0, 0.0, 5.0, 0.0, 3.0 ] ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.scusumors.js b/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.scusumors.js index eaec9e782bce..5cdc4875ad20 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.scusumors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.scusumors.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var scusumors = require( './../lib/scusumors.js' ); @@ -140,7 +141,7 @@ tape( 'the function returns a reference to the output array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', function test( t ) { var expected; var x; var y; @@ -151,10 +152,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumors( -1, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumors( 0, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); @@ -303,6 +304,7 @@ tape( 'the function supports view offsets', function test( t ) { var y0; var x1; var y1; + var N; // Initial arrays... x0 = new Float32Array([ @@ -326,7 +328,9 @@ tape( 'the function supports view offsets', function test( t ) { x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element - scusumors( 3, 0.0, x1, -2, y1, 1 ); + N = floor( x0.length / 2 ); + + scusumors( N, 0.0, x1, -2, y1, 1 ); expected = new Float32Array( [ 0.0, 0.0, 0.0, 6.0, 10.0, 12.0 ] ); t.deepEqual( y0, expected, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.scusumors.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.scusumors.native.js index f8241221beb7..7a32188b0b38 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.scusumors.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumors/test/test.scusumors.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -149,7 +150,7 @@ tape( 'the function returns a reference to the output array', opts, function tes t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', opts, function test( t ) { var expected; var x; var y; @@ -160,10 +161,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumors( -1, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumors( 0, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); @@ -312,6 +313,7 @@ tape( 'the function supports view offsets', opts, function test( t ) { var y0; var x1; var y1; + var N; // Initial arrays... x0 = new Float32Array([ @@ -335,7 +337,9 @@ tape( 'the function supports view offsets', opts, function test( t ) { x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element - scusumors( 3, 0.0, x1, -2, y1, 1 ); + N = floor( x0.length / 2 ); + + scusumors( N, 0.0, x1, -2, y1, 1 ); expected = new Float32Array( [ 0.0, 0.0, 0.0, 6.0, 10.0, 12.0 ] ); t.deepEqual( y0, expected, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/README.md index 99de471245d3..1254ee178fb2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/README.md @@ -65,15 +65,18 @@ The function has the following parameters: - **y**: output [`Float32Array`][@stdlib/array/float32]. - **strideY**: index increment for `y`. -The `N` and `stride` parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative sum of every other element in `x`, +The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to compute the cumulative sum of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); var y = new Float32Array( x.length ); -var v = scusumpw( 4, 0.0, x, 2, y, 1 ); +var N = floor( x.length / 2 ); + +var v = scusumpw( N, 0.0, x, 2, y, 1 ); // y => [ 1.0, 3.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] ``` @@ -83,6 +86,7 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); // Initial arrays... var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); @@ -92,7 +96,9 @@ var y0 = new Float32Array( x0.length ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element -scusumpw( 4, 0.0, x1, -2, y1, 1 ); +var N = floor( x0.length / 2 ); + +scusumpw( N, 0.0, x1, -2, y1, 1 ); // y0 => [ 0.0, 0.0, 0.0, 4.0, 6.0, 4.0, 5.0, 0.0 ] ``` @@ -119,11 +125,14 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var y = new Float32Array( x.length ); -scusumpw.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 ); +var N = floor( x.length / 2 ); + +scusumpw.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ); // y => [ 0.0, 0.0, 0.0, 0.0, 5.0, 1.0, -1.0, 1.0 ] ``` @@ -149,14 +158,20 @@ scusumpw.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); var Float32Array = require( '@stdlib/array/float32' ); var scusumpw = require( '@stdlib/blas/ext/base/scusumpw' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); -var y = new Float32Array( x.length ); +var y; +var x; +var i; +x = new Float32Array( 10 ); +y = new Float32Array( x.length ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.js index 9140d18b1123..b38a94746a16 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.js @@ -21,8 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -30,11 +29,6 @@ var pkg = require( './../package.json' ).name; var scusumpw = require( './../lib/scusumpw.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -45,9 +39,15 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var y = new Float32Array( len ); - var x = filledarrayBy( len, 'float32', rand ); + var y; + var x; + var i; + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.native.js index e63e3363000e..504c1bcae895 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.native.js @@ -22,8 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -37,7 +36,6 @@ var scusumpw = tryRequire( resolve( __dirname, './../lib/scusumpw.native.js' ) ) var opts = { 'skip': ( scusumpw instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -50,9 +48,15 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); - var y = new Float32Array( len ); + var x; + var y; + var i; + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.ndarray.js index 0a6f1bc6c736..f030f41e30ef 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.ndarray.js @@ -21,8 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -30,11 +29,6 @@ var pkg = require( './../package.json' ).name; var scusumpw = require( './../lib/ndarray.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -45,9 +39,15 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); - var y = new Float32Array( len ); + var x; + var y; + var i; + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.ndarray.native.js index 0a386bb1269e..ee290adbeb36 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/benchmark/benchmark.ndarray.native.js @@ -22,8 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -37,7 +36,6 @@ var scusumpw = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( scusumpw instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -50,9 +48,15 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); - var y = new Float32Array( len ); + var x; + var y; + var i; + x = new Float32Array( len ); + y = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/docs/repl.txt index 70e9f3b55348..cfb10565541b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/docs/repl.txt @@ -3,8 +3,8 @@ Computes the cumulative sum of single-precision floating-point strided array elements using pairwise summation. - The `N` and stride parameters determine which elements in the strided arrays - are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` and `y` are + accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -44,10 +44,11 @@ > {{alias}}( x.length, 0.0, x, 1, y, 1 ) [ 1.0, -1.0, 1.0 ] - // Using `N` and stride parameters: + // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); > y = new {{alias:@stdlib/array/float32}}( x.length ); - > {{alias}}( 3, 0.0, x, 2, y, 2 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}( N, 0.0, x, 2, y, 2 ) [ -2.0, 0.0, -1.0, 0.0, 1.0, 0.0 ] // Using view offsets: @@ -55,12 +56,12 @@ > var y0 = new {{alias:@stdlib/array/float32}}( x0.length ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); > var y1 = new {{alias:@stdlib/array/float32}}( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); - > {{alias}}( 3, 0.0, x1, 2, y1, 1 ) + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); + > {{alias}}( N, 0.0, x1, 2, y1, 1 ) [ -2.0, 0.0, -1.0 ] > y0 [ 0.0, 0.0, 0.0, -2.0, 0.0, -1.0 ] - {{alias}}.ndarray( N, sum, x, strideX, offsetX, y, strideY, offsetY ) Computes the cumulative sum of single-precision floating-point strided array elements using pairwise summation and alternative indexing semantics. @@ -111,7 +112,8 @@ // Advanced indexing: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > y = new {{alias:@stdlib/array/float32}}( x.length ); - > {{alias}}.ndarray( 3, 0.0, x, 2, 1, y, -1, y.length-1 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ) [ 0.0, 0.0, 0.0, -1.0, 0.0, -2.0 ] See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/examples/index.js index 64d24e25349a..0e176b0a14f9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/examples/index.js @@ -18,14 +18,20 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); var Float32Array = require( '@stdlib/array/float32' ); var scusumpw = require( './../lib' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); -var y = new Float32Array( x.length ); +var y; +var x; +var i; +x = new Float32Array( 10 ); +y = new Float32Array( x.length ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' - - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 6 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, sum, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 4 ); - - stdlib_strided_scusumpw( N, sum, X, strideX, Y, strideY ); - - return NULL; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/src/addon.cpp new file mode 100644 index 000000000000..6cb8c89e466f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/src/addon.cpp @@ -0,0 +1,164 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/scusumpw.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_scusumpw { + + /** + * Computes the cumulative sum of single-precision floating-point strided array elements using pairwise summation. + * + * ## Notes + * + * - When called from JavaScript, the function expects six arguments: + * + * - `N`: number of indexed elements + * - `sum`: initial sum + * - `X`: input array + * - `strideX`: `X` stride length + * - `Y`: output array + * - `strideY`: `Y` stride length + */ + napi_value node_scusumpw( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 6; + napi_value argv[ 6 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 6 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 6 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); + return nullptr; + } + + bool res2; + status = napi_is_typedarray( env, argv[ 2 ], &res2 ); + assert( status == napi_ok ); + if ( res2 == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype3; + status = napi_typeof( env, argv[ 3 ], &vtype3 ); + assert( status == napi_ok ); + if ( vtype3 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); + return nullptr; + } + + bool res4; + status = napi_is_typedarray( env, argv[ 4 ], &res4 ); + assert( status == napi_ok ); + if ( res4 == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype5; + status = napi_typeof( env, argv[ 5 ], &vtype5 ); + assert( status == napi_ok ); + if ( vtype5 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Sixth argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + double sum; + status = napi_get_value_double( env, argv[ 1 ], &sum ); + assert( status == napi_ok ); + + int64_t strideX; + status = napi_get_value_int64( env, argv[ 3 ], &strideX ); + assert( status == napi_ok ); + + int64_t strideY; + status = napi_get_value_int64( env, argv[ 5 ], &strideY ); + assert( status == napi_ok ); + + napi_typedarray_type vtype2; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype2 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(strideX) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + napi_typedarray_type vtype4; + size_t ylen; + void *Y; + status = napi_get_typedarray_info( env, argv[ 4 ], &vtype4, &ylen, &Y, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype4 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(strideY) >= (int64_t)ylen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Fifth argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + stdlib_strided_scusumpw( N, (float)sum, (float *)X, strideX, (float *)Y, strideY ); + + return nullptr; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_scusumpw, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_scusumpw diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.ndarray.js index b72e1617dde9..8f4b774d068a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.ndarray.js @@ -141,7 +141,7 @@ tape( 'the function returns a reference to the output array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns output array unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', function test( t ) { var expected; var x; var y; @@ -152,10 +152,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumpw( -1, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumpw( 0, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.ndarray.native.js index aae46fd36e56..5b481f1bfc2f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.ndarray.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -149,7 +150,7 @@ tape( 'the function returns a reference to the output array', opts, function tes t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns output array unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', opts, function test( t ) { var expected; var x; var y; @@ -160,10 +161,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumpw( -1, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumpw( 0, 0.0, x, 1, 0, y, 1, 0 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); @@ -276,6 +277,7 @@ tape( 'the function supports negative strides', opts, function test( t ) { tape( 'the function supports an `x` offset', opts, function test( t ) { var expected; + var N; var x; var y; @@ -299,8 +301,9 @@ tape( 'the function supports an `x` offset', opts, function test( t ) { 0.0, 0.0 ]); + N = floor( x.length / 2 ); - scusumpw( 4, 0.0, x, 2, 1, y, 1, 0 ); + scusumpw( N, 0.0, x, 2, 1, y, 1, 0 ); expected = new Float32Array( [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] ); @@ -310,6 +313,7 @@ tape( 'the function supports an `x` offset', opts, function test( t ) { tape( 'the function supports a `y` offset', opts, function test( t ) { var expected; + var N; var x; var y; @@ -333,8 +337,9 @@ tape( 'the function supports a `y` offset', opts, function test( t ) { 0.0, 0.0 // 3 ]); + N = floor( x.length / 2 ); - scusumpw( 4, 0.0, x, 1, 0, y, 2, 1 ); + scusumpw( N, 0.0, x, 1, 0, y, 2, 1 ); expected = new Float32Array( [ 0.0, 2.0, 0.0, 3.0, 0.0, 5.0, 0.0, 3.0 ] ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.scusumpw.js b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.scusumpw.js index ab929b774d78..b1a31f637e07 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.scusumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.scusumpw.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var scusumpw = require( './../lib/scusumpw.js' ); @@ -140,7 +141,7 @@ tape( 'the function returns a reference to the output array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns output array unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', function test( t ) { var expected; var x; var y; @@ -151,10 +152,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumpw( -1, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumpw( 0, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); @@ -303,6 +304,7 @@ tape( 'the function supports view offsets', function test( t ) { var y0; var x1; var y1; + var N; // Initial arrays... x0 = new Float32Array([ @@ -326,7 +328,9 @@ tape( 'the function supports view offsets', function test( t ) { x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element - scusumpw( 3, 0.0, x1, -2, y1, 1 ); + N = floor( x0.length / 2 ); + + scusumpw( N, 0.0, x1, -2, y1, 1 ); expected = new Float32Array( [ 0.0, 0.0, 0.0, 6.0, 10.0, 12.0 ] ); t.deepEqual( y0, expected, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.scusumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.scusumpw.native.js index 38fe431978f3..a37a8aaf8619 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.scusumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumpw/test/test.scusumpw.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -149,7 +150,7 @@ tape( 'the function returns a reference to the output array', opts, function tes t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', opts, function test( t ) { var expected; var x; var y; @@ -160,10 +161,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); scusumpw( -1, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); scusumpw( 0, 0.0, x, 1, y, 1 ); - t.deepEqual( y, expected, 'returns expected value' ); + t.deepEqual( y, expected, 'returns `y` unchanged' ); t.end(); }); @@ -312,6 +313,7 @@ tape( 'the function supports view offsets', opts, function test( t ) { var y0; var x1; var y1; + var N; // Initial arrays... x0 = new Float32Array([ @@ -335,7 +337,9 @@ tape( 'the function supports view offsets', opts, function test( t ) { x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element - scusumpw( 3, 0.0, x1, -2, y1, 1 ); + N = floor( x0.length / 2 ); + + scusumpw( N, 0.0, x1, -2, y1, 1 ); expected = new Float32Array( [ 0.0, 0.0, 0.0, 6.0, 10.0, 12.0 ] ); t.deepEqual( y0, expected, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/README.md b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/README.md index d432f453d087..3a45d4b0de1d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/README.md @@ -44,8 +44,9 @@ Adds a constant to each single-precision floating-point strided array element an var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +var N = x.length; -var v = sdsapxsum( 3, 5.0, x, 1 ); +var v = sdsapxsum( N, 5.0, x, 1 ); // returns 16.0 ``` @@ -55,14 +56,16 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment for `x`. -The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element in the strided array, +The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); +var N = floor( x.length / 2 ); -var v = sdsapxsum( 4, 5.0, x, 2 ); +var v = sdsapxsum( N, 5.0, x, 2 ); // returns 25.0 ``` @@ -72,11 +75,14 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var v = sdsapxsum( 4, 5.0, x1, 2 ); +var N = floor( x0.length / 2 ); + +var v = sdsapxsum( N, 5.0, x1, 2 ); // returns 25.0 ``` @@ -88,8 +94,9 @@ Adds a constant to each single-precision floating-point strided array element an var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +var N = x.length; -var v = sdsapxsum.ndarray( 3, 5.0, x, 1, 0 ); +var v = sdsapxsum.ndarray( N, 5.0, x, 1, 0 ); // returns 16.0 ``` @@ -97,14 +104,16 @@ The function has the following additional parameters: - **offset**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to access every other value in the strided array starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access every other value in `x` starting from the second value ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var N = floor( x.length / 2 ); -var v = sdsapxsum.ndarray( 4, 5.0, x, 2, 1 ); +var v = sdsapxsum.ndarray( N, 5.0, x, 2, 1 ); // returns 25.0 ``` @@ -130,11 +139,18 @@ var v = sdsapxsum.ndarray( 4, 5.0, x, 2, 1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var sdsapxsum = require( '@stdlib/blas/ext/base/sdsapxsum' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); +var x; +var i; + +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = sdsapxsum( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.js index 372fe933ceff..a2216c9fe4ef 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var sdsapxsum = require( './../lib/sdsapxsum.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.native.js index 6418d272348d..c86bd9d82530 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var sdsapxsum = tryRequire( resolve( __dirname, './../lib/sdsapxsum.native.js' ) var opts = { 'skip': ( sdsapxsum instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.ndarray.js index 17115bfd96f1..e5efd5fb39d5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.ndarray.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var sdsapxsum = require( './../lib/ndarray.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.ndarray.native.js index 9cfb7bdda60a..a8e4edcfa61a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var sdsapxsum = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ) var opts = { 'skip': ( sdsapxsum instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/docs/repl.txt index 9dca6b853208..2a238f9e8187 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/docs/repl.txt @@ -3,8 +3,8 @@ Adds a constant to each single-precision floating-point strided array element and computes the sum using extended accumulation. - The `N` and `stride` parameters determine which elements in the strided - array are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` are accessed + at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -39,16 +39,19 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > {{alias}}( 3, 5.0, x, 2 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > var stride = 2; + > {{alias}}( N, 5.0, x, stride ) 16.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 5.0, x1, 2 ) + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); + > stride = 2; + > {{alias}}( N, 5.0, x1, stride ) 14.0 - {{alias}}.ndarray( N, alpha, x, stride, offset ) Adds a constant to each single-precision floating-point strided array element and computes the sum using extended accumulation and alternative @@ -88,8 +91,9 @@ 16.0 // Using offset parameter: - > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > {{alias}}.ndarray( 3, 5.0, x, 2, 1 ) + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}.ndarray( N, 5.0, x, 2, 1 ) 14.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/examples/index.js index 9aa890c47fca..36f9176e4dc3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/examples/index.js @@ -18,11 +18,18 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var sdsapxsum = require( './../lib' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); +var x; +var i; + +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = sdsapxsum( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' -#include - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, N, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 2 ); - - napi_value v; - status = napi_create_double( env, (double)stdlib_strided_sdsapxsum( N, alpha, X, stride ), &v ); - assert( status == napi_ok ); - return v; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/src/addon.cpp new file mode 100644 index 000000000000..8628e66eb144 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/src/addon.cpp @@ -0,0 +1,130 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/sdsapxsum.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_sdsapxsum { + + /** + * Adds a constant to each single-precision floating-point strided array element and computes the sum using extended accumulation. + * + * ## Notes + * + * - When called from JavaScript, the function expects four arguments: + * + * - `N`: number of indexed elements + * - `alpha`: constant + * - `X`: input array + * - `stride`: stride length + */ + napi_value node_sdsapxsum( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 4; + napi_value argv[ 4 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 4 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 4 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); + return nullptr; + } + + bool res; + status = napi_is_typedarray( env, argv[ 2 ], &res ); + assert( status == napi_ok ); + if ( res == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype3; + status = napi_typeof( env, argv[ 3 ], &vtype3 ); + assert( status == napi_ok ); + if ( vtype3 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + double alpha; + status = napi_get_value_double( env, argv[ 1 ], &alpha ); + assert( status == napi_ok ); + + int64_t stride; + status = napi_get_value_int64( env, argv[ 3 ], &stride ); + assert( status == napi_ok ); + + napi_typedarray_type vtype2; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype2 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + napi_value v; + status = napi_create_double( env, (double)stdlib_strided_sdsapxsum( N, (float)alpha, (float *)X, stride ), &v ); + assert( status == napi_ok ); + + return v; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_sdsapxsum, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_sdsapxsum diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.ndarray.js index d00f354b1e98..5981265509bf 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.ndarray.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var sdsapxsum = require( './../lib/ndarray.js' ); @@ -35,7 +36,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( sdsapxsum.length, 5, 'returns expected value' ); + t.strictEqual( sdsapxsum.length, 5, 'has expected arity' ); t.end(); }); @@ -102,6 +103,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -116,13 +118,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = sdsapxsum( 4, 5.0, x, 2, 0 ); + N = floor( x.length / 2 ); + v = sdsapxsum( N, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; var i; @@ -138,7 +142,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = sdsapxsum( 4, 5.0, x, -2, 6 ); + N = floor( x.length / 2 ); + v = sdsapxsum( N, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -165,6 +170,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { + var N; var x; var v; @@ -178,8 +184,9 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = sdsapxsum( 4, 5.0, x, 2, 1 ); + v = sdsapxsum( N, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.ndarray.native.js index 68d3e1ad68e6..3d3f07d13981 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.ndarray.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 5', opts, function test( t ) { - t.strictEqual( sdsapxsum.length, 5, 'returns expected value' ); + t.strictEqual( sdsapxsum.length, 5, 'has expected arity' ); t.end(); }); @@ -111,6 +112,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -125,13 +127,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = sdsapxsum( 4, 5.0, x, 2, 0 ); + N = floor( x.length / 2 ); + v = sdsapxsum( N, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; var i; @@ -147,7 +151,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = sdsapxsum( 4, 5.0, x, -2, 6 ); + N = floor( x.length / 2 ); + v = sdsapxsum( N, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -174,6 +179,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { + var N; var x; var v; @@ -187,8 +193,9 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = sdsapxsum( 4, 5.0, x, 2, 1 ); + v = sdsapxsum( N, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.sdsapxsum.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.sdsapxsum.js index dfea74599972..ec903a47ba3e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.sdsapxsum.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.sdsapxsum.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var sdsapxsum = require( './../lib/sdsapxsum.js' ); @@ -35,7 +36,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( sdsapxsum.length, 4, 'returns expected value' ); + t.strictEqual( sdsapxsum.length, 4, 'has expected arity' ); t.end(); }); @@ -102,6 +103,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -116,13 +118,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = sdsapxsum( 4, 5.0, x, 2 ); + N = floor( x.length / 2 ); + v = sdsapxsum( N, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; var i; @@ -138,7 +142,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = sdsapxsum( 4, 5.0, x, -2 ); + N = floor( x.length / 2 ); + v = sdsapxsum( N, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -167,6 +172,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; + var N; var v; x0 = new Float32Array([ @@ -182,8 +188,9 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); - v = sdsapxsum( 4, 5.0, x1, 2 ); + v = sdsapxsum( N, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.sdsapxsum.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.sdsapxsum.native.js index 2a5c5be8791e..9432146dd898 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.sdsapxsum.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsum/test/test.sdsapxsum.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( sdsapxsum.length, 4, 'returns expected value' ); + t.strictEqual( sdsapxsum.length, 4, 'has expected arity' ); t.end(); }); @@ -220,6 +221,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -234,13 +236,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = sdsapxsum( 4, 5.0, x, 2 ); + N = floor( x.length / 2 ); + v = sdsapxsum( N, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; var i; @@ -256,7 +260,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = sdsapxsum( 4, 5.0, x, -2 ); + N = floor( x.length / 2 ); + v = sdsapxsum( N, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -285,6 +290,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; + var N; var v; x0 = new Float32Array([ @@ -300,8 +306,9 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); - v = sdsapxsum( 4, 5.0, x1, 2 ); + v = sdsapxsum( N, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/README.md index 2e81b95e5a86..92d2dbf3ca44 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/README.md @@ -44,26 +44,28 @@ Adds a constant to each single-precision floating-point strided array element an var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +var N = x.length; -var v = sdsapxsumpw( 3, 5.0, x, 1 ); +var v = sdsapxsumpw( N, 5.0, x, 1 ); // returns 16.0 ``` The function has the following parameters: - **N**: number of indexed elements. -- **alpha**: scalar constant. - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment for `x`. -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element in the strided array, +The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); +var N = floor( x.length / 2 ); -var v = sdsapxsumpw( 4, 5.0, x, 2 ); +var v = sdsapxsumpw( N, 5.0, x, 2 ); // returns 25.0 ``` @@ -73,11 +75,14 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var v = sdsapxsumpw( 4, 5.0, x1, 2 ); +var N = floor( x0.length / 2 ); + +var v = sdsapxsumpw( N, 5.0, x1, 2 ); // returns 25.0 ``` @@ -89,8 +94,9 @@ Adds a constant to each single-precision floating-point strided array element an var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +var N = x.length; -var v = sdsapxsumpw.ndarray( 3, 5.0, x, 1, 0 ); +var v = sdsapxsumpw.ndarray( N, 5.0, x, 1, 0 ); // returns 16.0 ``` @@ -98,14 +104,16 @@ The function has the following additional parameters: - **offset**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to access every other value in the strided array starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access every other value in `x` starting from the second value ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var N = floor( x.length / 2 ); -var v = sdsapxsumpw.ndarray( 4, 5.0, x, 2, 1 ); +var v = sdsapxsumpw.ndarray( N, 5.0, x, 2, 1 ); // returns 25.0 ``` @@ -131,11 +139,18 @@ var v = sdsapxsumpw.ndarray( 4, 5.0, x, 2, 1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var sdsapxsumpw = require( '@stdlib/blas/ext/base/sdsapxsumpw' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); +var x; +var i; + +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = sdsapxsumpw( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.js index 628e2e1b421c..f5da2ba3722b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var sdsapxsumpw = require( './../lib/sdsapxsumpw.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.native.js index e74c78320c40..71f43a2bd63d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var sdsapxsumpw = tryRequire( resolve( __dirname, './../lib/sdsapxsumpw.native.j var opts = { 'skip': ( sdsapxsumpw instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.ndarray.js index 12ad6958b2ed..143d69637931 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.ndarray.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var sdsapxsumpw = require( './../lib/ndarray.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.ndarray.native.js index 9cfd9de3a1a1..f2830827f9d7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var sdsapxsumpw = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) var opts = { 'skip': ( sdsapxsumpw instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*20.0 ) - 10.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/docs/repl.txt index 8159c3b7a159..1f8a87d66ffa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/docs/repl.txt @@ -4,8 +4,8 @@ element and computes the sum using pairwise summation with extended accumulation. - The `N` and stride parameters determine which elements in the strided array - are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` are accessed + at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -40,16 +40,19 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > {{alias}}( 3, 5.0, x, 2 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > var stride = 2; + > {{alias}}( N, 5.0, x, stride ) 16.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 5.0, x1, 2 ) + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); + > stride = 2; + > {{alias}}( N, 5.0, x1, stride ) 14.0 - {{alias}}.ndarray( N, alpha, x, stride, offset ) Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended @@ -89,9 +92,11 @@ 16.0 // Using offset parameter: - > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > {{alias}}.ndarray( 3, 5.0, x, 2, 1 ) + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}.ndarray( N, 5.0, x, 2, 1 ) 14.0 See Also -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/examples/c/example.c index cb3499d52896..2f6283c56361 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/examples/c/example.c @@ -22,7 +22,7 @@ int main( void ) { // Create a strided array: - const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + const float x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; // Specify the number of elements: const int64_t N = 4; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/examples/index.js index 3557cd7adbd9..dcefd402bd3e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/examples/index.js @@ -18,11 +18,18 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var sdsapxsumpw = require( './../lib' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( -100.0, 100.0 ) ); +var x; +var i; + +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = sdsapxsumpw( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' -#include - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, alpha, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 2 ); - - napi_value v; - napi_status status = napi_create_double( env, (double)stdlib_strided_sdsapxsumpw( N, alpha, X, stride ), &v ); - assert( status == napi_ok ); - - return v; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/src/addon.cpp new file mode 100644 index 000000000000..879e6f6cdf5e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/src/addon.cpp @@ -0,0 +1,130 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/sdsapxsumpw.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_sdsapxsumpw { + + /** + * Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation. + * + * ## Notes + * + * - When called from JavaScript, the function expects four arguments: + * + * - `N`: number of indexed elements + * - `alpha`: constant + * - `X`: input array + * - `stride`: stride length + */ + napi_value node_sdsapxsumpw( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 4; + napi_value argv[ 4 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 4 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 4 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); + return nullptr; + } + + bool res; + status = napi_is_typedarray( env, argv[ 2 ], &res ); + assert( status == napi_ok ); + if ( res == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype3; + status = napi_typeof( env, argv[ 3 ], &vtype3 ); + assert( status == napi_ok ); + if ( vtype3 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + double alpha; + status = napi_get_value_double( env, argv[ 1 ], &alpha ); + assert( status == napi_ok ); + + int64_t stride; + status = napi_get_value_int64( env, argv[ 3 ], &stride ); + assert( status == napi_ok ); + + napi_typedarray_type vtype2; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype2 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + napi_value v; + status = napi_create_double( env, (double)stdlib_strided_sdsapxsumpw( N, (float)alpha, (float *)X, stride ), &v ); + assert( status == napi_ok ); + + return v; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_sdsapxsumpw, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_sdsapxsumpw diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.ndarray.js index b4b46f9bc3aa..473c556734fa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.ndarray.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var sdsapxsumpw = require( './../lib/ndarray.js' ); @@ -35,7 +36,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( sdsapxsumpw.length, 5, 'returns expected value' ); + t.strictEqual( sdsapxsumpw.length, 5, 'has expected arity' ); t.end(); }); @@ -102,6 +103,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -116,13 +118,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = sdsapxsumpw( 4, 5.0, x, 2, 0 ); + N = floor( x.length / 2 ); + v = sdsapxsumpw( N, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; var i; @@ -138,7 +142,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = sdsapxsumpw( 4, 5.0, x, -2, 6 ); + N = floor( x.length / 2 ); + v = sdsapxsumpw( N, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -165,6 +170,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { + var N; var x; var v; @@ -178,8 +184,9 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = sdsapxsumpw( 4, 5.0, x, 2, 1 ); + v = sdsapxsumpw( N, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.ndarray.native.js index f16fc008f44a..416d2a1a87cb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.ndarray.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 5', opts, function test( t ) { - t.strictEqual( sdsapxsumpw.length, 5, 'returns expected value' ); + t.strictEqual( sdsapxsumpw.length, 5, 'has expected arity' ); t.end(); }); @@ -111,6 +112,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -125,13 +127,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = sdsapxsumpw( 4, 5.0, x, 2, 0 ); + N = floor( x.length / 2 ); + v = sdsapxsumpw( N, 5.0, x, 2, 0 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; var i; @@ -147,7 +151,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = sdsapxsumpw( 4, 5.0, x, -2, 6 ); + N = floor( x.length / 2 ); + v = sdsapxsumpw( N, 5.0, x, -2, 6 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -174,6 +179,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { + var N; var x; var v; @@ -187,8 +193,9 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = sdsapxsumpw( 4, 5.0, x, 2, 1 ); + v = sdsapxsumpw( N, 5.0, x, 2, 1 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.sdsapxsumpw.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.sdsapxsumpw.js index 0d9f9d1f3555..1f91f94e14c4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.sdsapxsumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.sdsapxsumpw.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var sdsapxsumpw = require( './../lib/sdsapxsumpw.js' ); @@ -35,7 +36,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( sdsapxsumpw.length, 4, 'returns expected value' ); + t.strictEqual( sdsapxsumpw.length, 4, 'has expected arity' ); t.end(); }); @@ -102,6 +103,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -116,13 +118,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = sdsapxsumpw( 4, 5.0, x, 2 ); + N = floor( x.length / 2 ); + v = sdsapxsumpw( N, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; var i; @@ -138,7 +142,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = sdsapxsumpw( 4, 5.0, x, -2 ); + N = floor( x.length / 2 ); + v = sdsapxsumpw( N, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -167,6 +172,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; + var N; var v; x0 = new Float32Array([ @@ -182,8 +188,9 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); - v = sdsapxsumpw( 4, 5.0, x1, 2 ); + v = sdsapxsumpw( N, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.sdsapxsumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.sdsapxsumpw.native.js index 29a8b8fec72c..17eb088bcc75 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.sdsapxsumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.sdsapxsumpw.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( sdsapxsumpw.length, 4, 'returns expected value' ); + t.strictEqual( sdsapxsumpw.length, 4, 'has expected arity' ); t.end(); }); @@ -220,6 +221,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -234,13 +236,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = sdsapxsumpw( 4, 5.0, x, 2 ); + N = floor( x.length / 2 ); + v = sdsapxsumpw( N, 5.0, x, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; var i; @@ -256,7 +260,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = sdsapxsumpw( 4, 5.0, x, -2 ); + N = floor( x.length / 2 ); + v = sdsapxsumpw( N, 5.0, x, -2 ); t.strictEqual( v, 25.0, 'returns expected value' ); @@ -285,6 +290,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; + var N; var v; x0 = new Float32Array([ @@ -300,8 +306,9 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); - v = sdsapxsumpw( 4, 5.0, x1, 2 ); + v = sdsapxsumpw( N, 5.0, x1, 2 ); t.strictEqual( v, 25.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn/src/addon.c index 92fad314939d..9e9eb48f64b8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn/src/addon.c @@ -39,7 +39,7 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 1 ); napi_value v; - napi_status status = napi_create_double( env, (double)stdlib_strided_ssumkbn( N, X, stride ), &v ); + napi_status status = napi_create_double( env, (double)stdlib_strided_ssumkbn( N, (float *)X, stride ), &v ); assert( status == napi_ok ); return v; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/README.md b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/README.md index 559b9b5ba945..437751242871 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/README.md @@ -44,8 +44,9 @@ Computes the sum of single-precision floating-point strided array elements using var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +var N = x.length; -var v = ssumkbn2( 3, x, 1 ); +var v = ssumkbn2( N, x, 1 ); // returns 1.0 ``` @@ -55,14 +56,16 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment for `x`. -The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element in the strided array, +The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the sum of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); +var N = floor( x.length / 2 ); -var v = ssumkbn2( 4, x, 2 ); +var v = ssumkbn2( N, x, 2 ); // returns 5.0 ``` @@ -72,11 +75,14 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var v = ssumkbn2( 4, x1, 2 ); +var N = floor( x0.length / 2 ); + +var v = ssumkbn2( N, x1, 2 ); // returns 5.0 ``` @@ -88,8 +94,9 @@ Computes the sum of single-precision floating-point strided array elements using var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +var N = x.length; -var v = ssumkbn2.ndarray( 3, x, 1, 0 ); +var v = ssumkbn2.ndarray( N, x, 1, 0 ); // returns 1.0 ``` @@ -97,14 +104,16 @@ The function has the following additional parameters: - **offset**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other value in the strided array starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other value in `x` starting from the second value ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var N = floor( x.length / 2 ); -var v = ssumkbn2.ndarray( 4, x, 2, 1 ); +var v = ssumkbn2.ndarray( N, x, 2, 1 ); // returns 5.0 ``` @@ -129,11 +138,18 @@ var v = ssumkbn2.ndarray( 4, x, 2, 1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var ssumkbn2 = require( '@stdlib/blas/ext/base/ssumkbn2' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); +var x; +var i; + +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = ssumkbn2( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.js index 60bdbb4563cd..394665f62bf2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var ssumkbn2 = require( './../lib/ssumkbn2.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*10.0 ) - 20.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.native.js index a1eaec4f45c1..2feafbee87e2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var ssumkbn2 = tryRequire( resolve( __dirname, './../lib/ssumkbn2.native.js' ) ) var opts = { 'skip': ( ssumkbn2 instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*10.0 ) - 20.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.ndarray.js index 98e5b5a90024..062fd192be69 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.ndarray.js @@ -21,19 +21,14 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var ssumkbn2 = require( './../lib/ndarray.js' ); -// VARIABLES // - -var rand = uniform( -10.0, 10.0 ); - - // FUNCTIONS // /** @@ -44,7 +39,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*10.0 ) - 20.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.ndarray.native.js index dbec12a0f3ce..76397613a614 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,7 +36,6 @@ var ssumkbn2 = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( ssumkbn2 instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -49,7 +48,13 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x; + var i; + + x = new Float32Array( len ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = ( randu()*10.0 ) - 20.0; + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/docs/repl.txt index 8f336b417db4..a8be18cc3450 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/docs/repl.txt @@ -3,8 +3,8 @@ Computes the sum of single-precision floating-point strided array elements using a second-order iterative Kahan–Babuška algorithm. - The `N` and `stride` parameters determine which elements in the strided - array are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` are accessed + at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -36,16 +36,19 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > {{alias}}( 3, x, 2 ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > var stride = 2; + > {{alias}}( N, x, stride ) 1.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, x1, 2 ) + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); + > stride = 2; + > {{alias}}( N, x1, stride ) -1.0 - {{alias}}.ndarray( N, x, stride, offset ) Computes the sum of single-precision floating-point strided array elements using a second-order iterative Kahan–Babuška algorithm and alternative @@ -82,8 +85,9 @@ 1.0 // Using offset parameter: - > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > {{alias}}.ndarray( 3, x, 2, 1 ) + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}.ndarray( N, x, 2, 1 ) -1.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/examples/index.js index bbee99dcd2c7..5b24e5f8b704 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/examples/index.js @@ -18,11 +18,18 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); var ssumkbn2 = require( './../lib' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); +var x; +var i; + +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( randu()*100.0 ); +} console.log( x ); var v = ssumkbn2( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/include.gypi index 26476a8c2655..868c5c12e852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.c', + '<(src_dir)/addon.cpp', ' -#include - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 1 ); - - napi_value v; - napi_status status = napi_create_double( env, (double)stdlib_strided_ssumkbn2( N, X, stride ), &v ); - assert( status == napi_ok ); - - return v; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/src/addon.cpp new file mode 100644 index 000000000000..5d81667e5c7d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/src/addon.cpp @@ -0,0 +1,117 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +#include "stdlib/blas/ext/base/ssumkbn2.h" +#include +#include +#include +#include +#include + +/** +* Add-on namespace. +*/ +namespace stdlib_blas_ext_base_ssumkbn2 { + + /** + * Computes the sum of single-precision floating-point strided array elements using a second-order iterative Kahan–Babuška algorithm. + * + * ## Notes + * + * - When called from JavaScript, the function expects three arguments: + * + * - `N`: number of indexed elements + * - `X`: input array + * - `stride`: stride length + */ + napi_value node_ssumkbn2( napi_env env, napi_callback_info info ) { + napi_status status; + + size_t argc = 3; + napi_value argv[ 3 ]; + status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); + assert( status == napi_ok ); + + if ( argc < 3 ) { + napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." ); + return nullptr; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); + return nullptr; + } + + bool res; + status = napi_is_typedarray( env, argv[ 1 ], &res ); + assert( status == napi_ok ); + if ( res == false ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); + return nullptr; + } + + napi_valuetype vtype2; + status = napi_typeof( env, argv[ 2 ], &vtype2 ); + assert( status == napi_ok ); + if ( vtype2 != napi_number ) { + napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." ); + return nullptr; + } + + int64_t N; + status = napi_get_value_int64( env, argv[ 0 ], &N ); + assert( status == napi_ok ); + + int64_t stride; + status = napi_get_value_int64( env, argv[ 2 ], &stride ); + assert( status == napi_ok ); + + napi_typedarray_type vtype1; + size_t xlen; + void *X; + status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr ); + assert( status == napi_ok ); + if ( vtype1 != napi_float32_array ) { + napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); + return nullptr; + } + if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { + napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." ); + return nullptr; + } + + napi_value v; + status = napi_create_double( env, (double)stdlib_strided_ssumkbn2( N, (float *)X, stride ), &v ); + assert( status == napi_ok ); + + return v; + } + + napi_value Init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fcn; + status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_ssumkbn2, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; + } + + NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) +} // end namespace stdlib_blas_ext_base_ssumkbn2 diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ndarray.js index dfcae8688377..8306f677fa00 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ndarray.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var ssumkbn2 = require( './../lib/ndarray.js' ); @@ -94,6 +95,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -108,13 +110,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = ssumkbn2( 4, x, 2, 0 ); + N = floor( x.length / 2 ); + v = ssumkbn2( N, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; @@ -129,7 +133,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = ssumkbn2( 4, x, -2, 6 ); + N = floor( x.length / 2 ); + v = ssumkbn2( N, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -148,6 +153,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { + var N; var x; var v; @@ -161,8 +167,9 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = ssumkbn2( 4, x, 2, 1 ); + v = ssumkbn2( N, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ndarray.native.js index 3e618933ed7c..bd682835479f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ndarray.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -103,6 +104,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -117,13 +119,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = ssumkbn2( 4, x, 2, 0 ); + N = floor( x.length / 2 ); + v = ssumkbn2( N, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -138,7 +142,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = ssumkbn2( 4, x, -2, 6 ); + N = floor( x.length / 2 ); + v = ssumkbn2( N, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -157,6 +162,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { + var N; var x; var v; @@ -170,8 +176,9 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); + N = floor( x.length / 2 ); - v = ssumkbn2( 4, x, 2, 1 ); + v = ssumkbn2( N, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ssumkbn2.js b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ssumkbn2.js index 090bb4c85990..382dbb43d231 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ssumkbn2.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ssumkbn2.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var ssumkbn2 = require( './../lib/ssumkbn2.js' ); @@ -94,6 +95,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -108,13 +110,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - v = ssumkbn2( 4, x, 2 ); + N = floor( x.length / 2 ); + v = ssumkbn2( N, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; @@ -129,7 +133,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - v = ssumkbn2( 4, x, -2 ); + N = floor( x.length / 2 ); + v = ssumkbn2( N, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -150,6 +155,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; + var N; var v; x0 = new Float32Array([ @@ -165,8 +171,9 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); - v = ssumkbn2( 4, x1, 2 ); + v = ssumkbn2( N, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ssumkbn2.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ssumkbn2.native.js index d86d11fbda9d..c975280fdf76 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ssumkbn2.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumkbn2/test/test.ssumkbn2.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -185,6 +186,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -199,13 +201,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - v = ssumkbn2( 4, x, 2 ); + N = floor( x.length / 2 ); + v = ssumkbn2( N, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -220,7 +224,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - v = ssumkbn2( 4, x, -2 ); + N = floor( x.length / 2 ); + v = ssumkbn2( N, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -241,6 +246,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; + var N; var v; x0 = new Float32Array([ @@ -256,8 +262,9 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); - v = ssumkbn2( 4, x1, 2 ); + v = ssumkbn2( N, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/ssumors/src/addon.c index 0a5df0031a98..a5ada7b08c1e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumors/src/addon.c @@ -39,7 +39,7 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 1 ); napi_value v; - napi_status status = napi_create_double( env, (double)stdlib_strided_ssumors( N, X, stride ), &v ); + napi_status status = napi_create_double( env, (double)stdlib_strided_ssumors( N, (float *)X, stride ), &v ); assert( status == napi_ok ); return v; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/src/addon.c index 60ee16c25d1c..b53060ca3dd9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/src/addon.c @@ -39,7 +39,7 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 1 ); napi_value v; - napi_status status = napi_create_double( env, (double)stdlib_strided_ssumpw( N, X, stride ), &v ); + napi_status status = napi_create_double( env, (double)stdlib_strided_ssumpw( N, (float *)X, stride ), &v ); assert( status == napi_ok ); return v; diff --git a/lib/node_modules/@stdlib/buffer/alloc-unsafe/README.md b/lib/node_modules/@stdlib/buffer/alloc-unsafe/README.md index fd58aa5b5a1c..1ac2484196b2 100644 --- a/lib/node_modules/@stdlib/buffer/alloc-unsafe/README.md +++ b/lib/node_modules/@stdlib/buffer/alloc-unsafe/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# allocUnsafe +# alloc > Allocate a [buffer][@stdlib/buffer/ctor] having a specified number of bytes. diff --git a/lib/node_modules/@stdlib/constants/float32/half-pi/include/stdlib/constants/float32/half_pi.h b/lib/node_modules/@stdlib/constants/float32/half-pi/include/stdlib/constants/float32/half_pi.h deleted file mode 100644 index 8b7089769cee..000000000000 --- a/lib/node_modules/@stdlib/constants/float32/half-pi/include/stdlib/constants/float32/half_pi.h +++ /dev/null @@ -1,27 +0,0 @@ -/** -* @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. -*/ - -#ifndef STDLIB_CONSTANTS_FLOAT32_HALF_PI_H -#define STDLIB_CONSTANTS_FLOAT32_HALF_PI_H - -/** -* Macro for one half times the mathematical constant π. -*/ -#define STDLIB_CONSTANT_FLOAT32_HALF_PI 1.5707963267948966f - -#endif // !STDLIB_CONSTANTS_FLOAT32_HALF_PI_H diff --git a/lib/node_modules/@stdlib/math/base/assert/is-composite/package.json b/lib/node_modules/@stdlib/math/base/assert/is-composite/package.json index 85d452b4aca1..eda5f90d078d 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-composite/package.json +++ b/lib/node_modules/@stdlib/math/base/assert/is-composite/package.json @@ -14,14 +14,11 @@ } ], "main": "./lib", - "gypfile": true, "directories": { "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", - "include": "./include", "lib": "./lib", - "src": "./src", "test": "./test" }, "types": "./docs/types", diff --git a/lib/node_modules/@stdlib/math/base/special/acscd/README.md b/lib/node_modules/@stdlib/math/base/special/acscd/README.md index 050bc5f3e842..2a8d438970ce 100644 --- a/lib/node_modules/@stdlib/math/base/special/acscd/README.md +++ b/lib/node_modules/@stdlib/math/base/special/acscd/README.md @@ -81,94 +81,6 @@ for ( i = 0; i < x.length; i++ ) { - - -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/math/base/special/acscd.h" -``` - -#### stdlib_base_acscd( x ) - -Computes the [arccosecant][arccosecant] (in degrees) of a double-precision floating-point number. - -```c -double out = stdlib_base_acscd( 1.0 ); -// returns 90.0 - -out = stdlib_base_acscd( 2.0 ); -// returns ~30.0 -``` - -The function accepts the following arguments: - -- **x**: `[in] double` input value. - -```c -double stdlib_base_acscd( const double x ); -``` - -
- - - - - -
- -
- - - - - -
- -### Examples - -```c -#include "stdlib/math/base/special/acscd.h" -#include - -int main( void ) { - const double x[] = { 1.0, 1.45, 1.89, 2.33, 2.78, 3.22, 3.66, 4.11, 4.55, 5.0 }; - - double v; - int i; - for ( i = 0; i < 10; i++ ) { - v = stdlib_base_acscd( x[ i ] ); - printf( "acscd(%lf) = %lf\n", x[ i ], v ); - } -} -``` - -
- - - -
- - -