@stdlib/strided-dispatch

Create a strided array function interface which performs multiple dispatch.

https://github.com/stdlib-js/strided-dispatch

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.0%) to scientific vocabulary

Keywords

array dispatch javascript multimethod multimethods multiple-dispatch node node-js nodejs stdlib strided
Last synced: 6 months ago · JSON representation ·

Repository

Create a strided array function interface which performs multiple dispatch.

Basic Info
Statistics
  • Stars: 2
  • Watchers: 3
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
array dispatch javascript multimethod multimethods multiple-dispatch node node-js nodejs stdlib strided
Created over 4 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Citation Security

README.md

About stdlib...

We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.

The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.

When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.

To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!

dispatch

NPM version Build Status Coverage Status <!-- dependencies -->

Create a strided array function interface which performs multiple dispatch.

## Installation ```bash npm install @stdlib/strided-dispatch ``` Alternatively, - To load the package in a website via a `script` tag without installation and bundlers, use the [ES Module][es-module] available on the [`esm`][esm-url] branch (see [README][esm-readme]). - If you are using Deno, visit the [`deno`][deno-url] branch (see [README][deno-readme] for usage intructions). - For use in Observable, or in browser/node environments, use the [Universal Module Definition (UMD)][umd] build available on the [`umd`][umd-url] branch (see [README][umd-readme]). The [branches.md][branches-url] file summarizes the available branches and displays a diagram illustrating their relationships. To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.
## Usage ```javascript var dispatch = require( '@stdlib/strided-dispatch' ); ``` #### dispatch( fcns, types, data, nargs, nin, nout ) Returns a strided array function interface which performs multiple dispatch. ```javascript var unary = require( '@stdlib/strided-base-unary' ); var Float64Array = require( '@stdlib/array-float64' ); var Float32Array = require( '@stdlib/array-float32' ); function foo( x ) { return x * 10.0; } function bar( x ) { return x * 5.0; } // Define a list of strided array functions for applying a unary callback: var fcns = [ unary, unary ]; // Define a one-dimensional list of input and output array types: var types = [ 'float64', 'float64', // input, output 'float32', 'float32' // input, output ]; // Define a list of callbacks which should be applied based on the provided array types: var data = [ foo, bar ]; // Define the total number of input arguments: var nargs = 7; // N + input_array_dtype + input_array + input_array_stride + output_array_dtype + output_array + output_array_stride // Define the number of input strided arrays: var nin = 1; // Define the number of output strided arrays: var nout = 1; // Create a strided array function interface: var strided = dispatch( fcns, types, data, nargs, nin, nout ); // ... var x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); var y = new Float64Array( x.length ); strided( x.length, 'float64', x, 1, 'float64', y, 1 ); // y => [ 10.0, 20.0, 30.0 ] x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); y = new Float32Array( x.length ); strided( x.length, 'float32', x, 1, 'float32', y, 1 ); // y => [ 5.0, 10.0, 15.0 ] ``` The function accepts the following arguments: - **fcns**: list of strided array functions. - **types**: one-dimensional list of strided array argument [data types][@stdlib/strided/dtypes]. The length of `types` must be the number of strided array functions multiplied by `nin+nout`. If `fcns` is a function, rather than a list, the number of strided array functions is computed as `types.length / (nin+nout)`. - **data**: strided array function data (e.g., callbacks). If a list, the length of `data` must equal the number of strided array functions. If `null`, a returned strided array function interface does **not** provide a `data` argument to an invoked strided array function. - **nargs**: total number of strided array function interface arguments (including data types, strides, and offsets). - **nin**: number of input strided arrays. - **nout**: number of output strided arrays.
## Notes - Without offsets, a returned strided array function interface has the following signature: ```text f( N, dtypeX, x, strideX, dtypeY, y, strideY, ... ) ``` where - **N**: number of indexed elements. - **dtypeX**: [data type][@stdlib/strided/dtypes] for `x`. - **x**: strided array. - **strideX**: index increment for `x`. - **dtypeY**: [data type][@stdlib/strided/dtypes] for `y`. - **y**: strided array. - **strideY**: index increment for `y`. - **...**: additional strided arrays and associated [data types][@stdlib/strided/dtypes] and strides. - The number of strided array function interface parameters is derived from `nargs`, the number of input strided arrays is derived from `nin`, and the number of output strided arrays is derived from `nout`. - Without offsets, the number of parameters must obey the following relation: ```text nargs = 3*(nout+nin) + 1 ``` - With offsets, the number of parameters must obey the following relation: ```text nargs = 4*(nout+nin) + 1 ``` - With offsets, a returned strided array function interface has the following signature: ```text f( N, dtypeX, x, strideX, offsetX, dtypeY, y, strideY, offsetY, ... ) ``` where - **N**: number of indexed elements. - **dtypeX**: [data type][@stdlib/strided/dtypes] for `x`. - **x**: strided array. - **strideX**: index increment for `x`. - **offsetX**: starting index for `x`. - **dtypeY**: [data type][@stdlib/strided/dtypes] for `y`. - **y**: strided array. - **strideY**: index increment for `y`. - **offsetY**: starting index for `y`. - **...**: additional strided arrays and associated [data types][@stdlib/strided/dtypes], strides, and offsets. The choice of which strided array function interface to return depends on the use case. The former is suitable for typed array views; while the latter affords alternative indexing semantics more suitable for n-dimensional arrays (ndarrays). - Without offsets, a strided array function (i.e., a value provided for the `fcns` argument) should have the following signature: ```text f( arrays, shape, strides[, data] ) ``` where - **arrays**: array containing strided input and output arrays. - **shape**: array containing a single element, the number of indexed elements. - **strides**: array containing the stride lengths for the strided input and output arrays. - **data**: strided array function data (e.g., a callback). - With offsets, a strided array function should have the following signature: ```text f( arrays, shape, strides, offsets[, data] ) ``` where - **offsets**: array containing the starting indices (i.e., index offsets) for the strided input and output arrays. - For convenience, a single strided array function may be provided which will be invoked whenever the strided array argument data types match a sequence of types in `types`. Providing a single strided array function is particularly convenient for the case where, regardless of array data types, traversing arrays remains the same, but the strided array function `data` differs (e.g., callbacks which differ based on the array data types). For example, the following ```javascript var unary = require( '@stdlib/strided-base-unary' ); function foo( x ) { return x * 10.0; } function bar( x ) { return x * 5.0; } var fcns = [ unary, unary ]; var types = [ 'float64', 'float64', 'float32', 'float32' ]; var data = [ foo, bar ]; var strided = dispatch( fcns, types, data, 7, 1, 1 ); ``` is equivalent to ```javascript var unary = require( '@stdlib/strided-base-unary' ); function foo( x ) { return x * 10.0; } function bar( x ) { return x * 5.0; } var types = [ 'float64', 'float64', 'float32', 'float32' ]; var data = [ foo, bar ]; var strided = dispatch( unary, types, data, 7, 1, 1 ); ```
## Examples ```javascript var unary = require( '@stdlib/strided-base-unary' ).ndarray; var abs = require( '@stdlib/math-base-special-abs' ); var Float64Array = require( '@stdlib/array-float64' ); var dispatch = require( '@stdlib/strided-dispatch' ); var types = [ 'float64', 'float64' ]; var data = [ abs ]; var strided = dispatch( unary, types, data, 9, 1, 1 ); var x = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); var y = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); strided( 3, 'float64', x, 1, 2, 'float64', y, 1, 2 ); console.log( y ); // => [ 0.0, 0.0, 3.0, 4.0, 5.0 ] ```
* * * ## Notice This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. #### Community [![Chat][chat-image]][chat-url] --- ## License See [LICENSE][stdlib-license]. ## Copyright Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors].

Owner

  • Name: stdlib
  • Login: stdlib-js
  • Kind: organization

Standard library for JavaScript.

Citation (CITATION.cff)

cff-version: 1.2.0
title: stdlib
message: >-
  If you use this software, please cite it using the
  metadata from this file.

type: software

authors:
  - name: The Stdlib Authors
    url: https://github.com/stdlib-js/stdlib/graphs/contributors

repository-code: https://github.com/stdlib-js/stdlib
url: https://stdlib.io

abstract: |
  Standard library for JavaScript and Node.js.

keywords:
  - JavaScript
  - Node.js
  - TypeScript
  - standard library
  - scientific computing
  - numerical computing
  - statistical computing

license: Apache-2.0 AND BSL-1.0

date-released: 2016

GitHub Events

Total
  • Push event: 24
Last Year
  • Push event: 24

Committers

Last synced: about 2 years ago

All Time
  • Total Commits: 57
  • Total Committers: 1
  • Avg Commits per committer: 57.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 19
  • Committers: 1
  • Avg Commits per committer: 19.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
stdlib-bot n****y@s****o 57
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • npm 92 last-month
  • Total dependent packages: 19
  • Total dependent repositories: 17
  • Total versions: 12
  • Total maintainers: 4
npmjs.org: @stdlib/strided-dispatch

Create a strided array function interface which performs multiple dispatch.

  • Homepage: https://stdlib.io
  • License: Apache-2.0
  • Latest release: 0.2.2
    published over 1 year ago
  • Versions: 12
  • Dependent Packages: 19
  • Dependent Repositories: 17
  • Downloads: 92 Last month
Rankings
Dependent packages count: 1.2%
Dependent repos count: 3.1%
Average: 8.9%
Downloads: 9.1%
Stargazers count: 15.0%
Forks count: 15.9%
Funding
  • type: opencollective
  • url: https://opencollective.com/stdlib
Last synced: 6 months ago

Dependencies

package.json npm
  • @stdlib/array-float32 ^0.0.x development
  • @stdlib/array-float64 ^0.0.x development
  • @stdlib/array-int32 ^0.0.x development
  • @stdlib/array-int8 ^0.0.x development
  • @stdlib/array-uint8 ^0.0.x development
  • @stdlib/assert-is-array ^0.0.x development
  • @stdlib/bench ^0.0.x development
  • @stdlib/math-base-assert-is-nan ^0.0.x development
  • @stdlib/math-base-special-pow ^0.0.x development
  • @stdlib/math-base-special-sin ^0.0.x development
  • @stdlib/ndarray-base-buffer-dtype ^0.0.x development
  • @stdlib/strided-base-binary ^0.0.x development
  • @stdlib/strided-base-nullary ^0.0.x development
  • @stdlib/strided-base-quaternary ^0.0.x development
  • @stdlib/strided-base-quinary ^0.0.x development
  • @stdlib/strided-base-ternary ^0.0.x development
  • @stdlib/strided-base-unary ^0.0.x development
  • @stdlib/strided-dtypes ^0.0.x development
  • istanbul ^0.4.1 development
  • tap-spec 5.x.x development
  • tape git+https://github.com/kgryte/tape.git#fix/globby development
  • @stdlib/assert-is-collection ^0.0.x
  • @stdlib/assert-is-function ^0.0.x
  • @stdlib/assert-is-function-array ^0.0.x
  • @stdlib/assert-is-integer ^0.0.x
  • @stdlib/assert-is-nonnegative-integer ^0.0.x
  • @stdlib/assert-is-positive-integer ^0.0.x
  • @stdlib/math-base-special-abs ^0.0.x
  • @stdlib/string-format ^0.0.x
  • @stdlib/types ^0.0.x
.github/workflows/benchmark.yml actions
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
.github/workflows/cancel.yml actions
  • styfle/cancel-workflow-action 0.11.0 composite
.github/workflows/close_pull_requests.yml actions
  • superbrothers/close-pull-request v3 composite
.github/workflows/examples.yml actions
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
.github/workflows/npm_downloads.yml actions
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • actions/upload-artifact v3 composite
  • distributhor/workflow-webhook v3 composite
.github/workflows/productionize.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • stdlib-js/bundle-action main composite
  • stdlib-js/transform-errors-action main composite
.github/workflows/publish.yml actions
  • JS-DevTools/npm-publish v1 composite
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • styfle/cancel-workflow-action 0.11.0 composite
.github/workflows/test.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
.github/workflows/test_bundles.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • denoland/setup-deno v1 composite
.github/workflows/test_coverage.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • codecov/codecov-action v3 composite
  • distributhor/workflow-webhook v3 composite
.github/workflows/test_install.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite